All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.resteasy.spi.touri.ObjectToURI Maven / Gradle / Ivy

There is a newer version: 4.0.0.Beta5
Show newest version
package org.jboss.resteasy.spi.touri;

import java.util.ArrayList;
import java.util.List;

/**
 * 

* This class encapsulates how an object can be converted to a URI string. There * are three basic ways to perform the transformation: *

*
    *
  1. adding a @URITemplate("your-uri-template") to an object *
  2. having an object extend URIable and have the object perform custom logic *
  3. registering a custom URIResolver *
* * @author Solomon Duskis * @version $Revision: 1 $ */ public class ObjectToURI { private static ObjectToURI instance = null; static { instance = new ObjectToURI(); instance.defaultResolvers.add(new URIableURIResolver()); instance.defaultResolvers.add(new URITemplateAnnotationResolver()); instance.defaultResolvers.add(new MappedByAnnotationResolver()); } public static ObjectToURI getInstance() { return instance; } private List resolvers = new ArrayList(); private List defaultResolvers = new ArrayList(); public void registerURIResolver(URIResolver uriResolver) { this.resolvers.add(uriResolver); } public String resolveURI(Object object) { String result = getResolver(object, resolvers); if (result == null) { result = getResolver(object, defaultResolvers); } return result; } private String getResolver(Object object, List resolvers) { Class type = object.getClass(); for (URIResolver resolver : resolvers) { if (resolver.handles(type)) { return resolver.resolveURI(object); } } return null; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy