コード例 #1
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);
   }
 }
コード例 #2
0
 private void addSingleton(Object instance) {
   Class clazz = instance.getClass();
   if (clazz.getAnnotation(Provider.class) != null) {
     // singleton provider
     if (instance instanceof ContextResolver) {
       providers.addContextResolver((ContextResolver) instance);
     }
     if (instance instanceof ExceptionMapper) {
       providers.addExceptionMapper((ExceptionMapper) instance);
     }
     if (instance instanceof MessageBodyReader) {
       providers.addMessageBodyReader((MessageBodyReader) instance);
     }
     if (instance instanceof MessageBodyWriter) {
       providers.addMessageBodyWriter((MessageBodyWriter) instance);
     }
   } else if (clazz.getAnnotation(Filter.class) != null) {
     // singleton filter
     if (instance instanceof MethodInvokerFilter) {
       providers.addMethodInvokerFilter((MethodInvokerFilter) instance);
     }
     if (instance instanceof RequestFilter) {
       providers.addRequestFilter((RequestFilter) instance);
     }
     if (instance instanceof ResponseFilter) {
       providers.addResponseFilter((ResponseFilter) instance);
     }
   } else if (clazz.getAnnotation(Path.class) != null) {
     // singleton resource
     resources.addResource(instance, null);
   }
 }
コード例 #3
0
 @SuppressWarnings({"unchecked"})
 private void addPerRequest(Class clazz) {
   if (clazz.getAnnotation(Provider.class) != null) {
     // per-request provider
     if (ContextResolver.class.isAssignableFrom(clazz)) {
       providers.addContextResolver(clazz);
     }
     if (ExceptionMapper.class.isAssignableFrom(clazz)) {
       providers.addExceptionMapper(clazz);
     }
     if (MessageBodyReader.class.isAssignableFrom(clazz)) {
       providers.addMessageBodyReader(clazz);
     }
     if (MessageBodyWriter.class.isAssignableFrom(clazz)) {
       providers.addMessageBodyWriter(clazz);
     }
   } else if (clazz.getAnnotation(Filter.class) != null) {
     // per-request filter
     if (MethodInvokerFilter.class.isAssignableFrom(clazz)) {
       providers.addMethodInvokerFilter(clazz);
     }
     if (RequestFilter.class.isAssignableFrom(clazz)) {
       providers.addRequestFilter(clazz);
     }
     if (ResponseFilter.class.isAssignableFrom(clazz)) {
       providers.addResponseFilter(clazz);
     }
   } else if (clazz.getAnnotation(Path.class) != null) {
     // per-request resource
     resources.addResource(clazz, null);
   }
 }