class RecipientIdentityResolver {

    public RecipientIdentity toIdentity(String uri) throws IllegalParameterValueException {
        RecipientIdentity identity;
        if (uri == null) {
            throw new IllegalParameterValueException(identifierLabel, "null");
        }
        String[] protocolLevel = uri.split(":");
        if (protocolLevel.length != 2) {
            throw new IllegalParameterValueException(identifierLabel, uri);
        }
        String[] segments = protocolLevel[1].split("/");

        Class<?> clazz = getClassForProtocol(protocolLevel[0]);

        if (segments.length == 0 && Tenant.class.isAssignableFrom(clazz)) {
            return new RecipientIdentity(clazz, TenantService.ORGANIZATIONS);
        }

        if (!segments[0].equals("")) {
            throw new IllegalParameterValueException(identifierLabel, uri);
        }

        if (segments.length == 2) {
            identity = new RecipientIdentity(clazz, segments[1]);
        } else if (segments.length == 3) {
            identity = new RecipientIdentity(clazz, makeIdentityId(uri, segments[1], segments[2]));
        } else {
            throw new IllegalParameterValueException(identifierLabel, uri);
        }

        return identity;
    }

}