class ResourceReferenceConverter {

    protected ResourceReference toServerReference(T clientObject, ResourceReference resultToUpdate, ToServerConversionOptions options) throws IllegalParameterValueException {
        ResourceReference result;
        final String uriFromClient = clientObject.getUri();
        if (resultToUpdate != null && resultToUpdate.getTargetURI().equals(uriFromClient)) {
            // no update is needed. Existing ResourceReference points to the same URI
            result = resultToUpdate;
        } else {
            // if it is local resource, reference with local resource must be returned or update will fail
            // NOTE: it is always preferable to pass resultToUpdate to get actual resource from there to avoid rereading and possible errors.
            String ownersUri = options == null ? null : options.getOwnersUri();
            Resource referencedResource = validateAndGetReference(uriFromClient, ownersUri);
            final boolean local = ownersUri != null && uriFromClient.startsWith(ownersUri + "_files" + Folder.SEPARATOR);
            result = resultToUpdate == null ? new ResourceReference(referencedResource) : resultToUpdate;
            if (!local) {
                result.setReference(uriFromClient);
            }
        }
        return result;
    }

    public  ResourceReferenceConverter(ResourceConverterProvider resourceConverterProvider,
            RepositoryService repositoryService, PermissionsService permissionsService, RepositoryConfiguration configuration, ClientReferenceRestriction... restriction);

}