Ejemplo n.º 1
0
 public void publish(Application application) {
   Set<Class<?>> classes = new LinkedHashSet<>();
   Set<Class<?>> appClasses = application.getClasses();
   if (appClasses != null) {
     classes.addAll(appClasses);
   }
   if (application instanceof EverrestApplication) {
     EverrestApplication everrest = (EverrestApplication) application;
     for (Map.Entry<String, Class<?>> e : everrest.getResourceClasses().entrySet()) {
       Class<?> clazz = e.getValue();
       addResource(e.getKey(), clazz);
       classes.remove(clazz);
     }
     for (Map.Entry<String, Object> e : everrest.getResourceSingletons().entrySet()) {
       addResource(e.getKey(), e.getValue());
     }
     for (ObjectFactory<? extends ObjectModel> factory : everrest.getFactories()) {
       addFactory(factory);
       classes.remove(factory.getObjectModel().getObjectClass());
     }
   }
   for (Class<?> clazz : classes) {
     addPerRequest(clazz);
   }
   Set<Object> singletons = application.getSingletons();
   if (singletons != null) {
     for (Object instance : singletons) {
       addSingleton(instance);
     }
   }
 }
Ejemplo n.º 2
0
 @SuppressWarnings({"unchecked"})
 private void addFactory(ObjectFactory factory) {
   Class clazz = factory.getObjectModel().getObjectClass();
   if (clazz.getAnnotation(Provider.class) != null) {
     // per-request provider
     if (ContextResolver.class.isAssignableFrom(clazz)) {
       providers.addContextResolver(factory);
     }
     if (ExceptionMapper.class.isAssignableFrom(clazz)) {
       providers.addExceptionMapper(factory);
     }
     if (MessageBodyReader.class.isAssignableFrom(clazz)) {
       providers.addMessageBodyReader(factory);
     }
     if (MessageBodyWriter.class.isAssignableFrom(clazz)) {
       providers.addMessageBodyWriter(factory);
     }
   } else if (clazz.getAnnotation(Filter.class) != null) {
     // per-request filter
     if (MethodInvokerFilter.class.isAssignableFrom(clazz)) {
       providers.addMethodInvokerFilter(factory);
     }
     if (RequestFilter.class.isAssignableFrom(clazz)) {
       providers.addRequestFilter(factory);
     }
     if (ResponseFilter.class.isAssignableFrom(clazz)) {
       providers.addResponseFilter(factory);
     }
   } else if (clazz.getAnnotation(Path.class) != null) {
     // per-request resource
     resources.addResource(factory);
   }
 }