Package javax.enterprise.inject.spi

Examples of javax.enterprise.inject.spi.Annotated


    /**
     * Lets detect all producer methods createing instances of {@link RouteBuilder} which are annotated with {@link org.apache.camel.cdi.ContextName}
     * so they can be auto-registered
     */
    public void detectProducerRoutes(@Observes ProcessProducerMethod<?, ?> event) {
        Annotated annotated = event.getAnnotated();
        ContextName annotation = annotated.getAnnotation(ContextName.class);
        Class<?> returnType = event.getAnnotatedProducerMethod().getJavaMember().getReturnType();
        if (isRoutesBean(returnType)) {
            addRouteBuilderBean(event.getBean(), annotation);
        }
    }
View Full Code Here


    static boolean isModulePrivate(Bean<?> bean)
    {
      if (! (bean instanceof AnnotatedBean))
        return false;

      Annotated annotated = ((AnnotatedBean) bean).getAnnotated();

      if (annotated == null)
        return false;

      for (Annotation ann : annotated.getAnnotations()) {
        Class<?> annType = ann.annotationType();

        if (annType.equals(ModulePrivate.class)
            || annType.isAnnotationPresent(ModulePrivate.class)
            || annType.equals(Module.class)
View Full Code Here

      _loader = Thread.currentThread().getContextClassLoader();

      if (bean instanceof AbstractBean) {
        AbstractBean<X> absBean = (AbstractBean<X>) bean;
        Annotated annotated = absBean.getAnnotated();

        if (annotated != null
            && annotated.isAnnotationPresent(ContextDependent.class)) {
          // ioc/0e17
          _loader = null;
        }
      }
    }
View Full Code Here

  }

  public void processBean(@Observes ProcessBeanImpl event)
  {
    try {
      Annotated annotated = event.getAnnotated();
      Bean<?> bean = event.getBean();

      if (annotated == null
    || annotated.getAnnotations() == null
    || annotated.isAnnotationPresent(Enhanced.class)) {
  return;
      }

      for (Annotation ann : annotated.getAnnotations()) {
  Class annType = ann.annotationType();
 
  if (annType.equals(WebServlet.class)) {
    WebServlet webServlet = (WebServlet) ann;
     
    ServletMapping mapping = new ServletMapping();

    for (String value : webServlet.value()) {
      mapping.addURLPattern(value);
    }
   
    for (String value : webServlet.urlPatterns()) {
      mapping.addURLPattern(value);
    }
   
    mapping.setBean(bean);
 
    mapping.init();

    _webApp.addServletMapping(mapping);

    event.veto();
  }
  else if (annType.isAnnotationPresent(ServiceType.class)) {
    ServiceType serviceType
      = (ServiceType) annType.getAnnotation(ServiceType.class);

    Class factoryClass = serviceType.defaultFactory();
    ProtocolServletFactory factory
      = (ProtocolServletFactory) factoryClass.newInstance();

    factory.setServiceType(ann);
    factory.setAnnotated(annotated);

    Method urlPatternMethod = annType.getMethod("urlPattern");

    String urlPattern = (String) urlPatternMethod.invoke(ann);
     
    ServletMapping mapping = new ServletMapping();
    mapping.addURLPattern(urlPattern);
    mapping.setBean(bean);

    mapping.setProtocolFactory(factory);
 
    mapping.init();

    _webApp.addServletMapping(mapping);

    // event.veto();
  }
  else if (annType.isAnnotationPresent(ProxyType.class)) {
    ProxyType proxyType
      = (ProxyType) annType.getAnnotation(ProxyType.class);

    Class factoryClass = proxyType.defaultFactory();
    ProtocolProxyFactory proxyFactory
      = (ProtocolProxyFactory) factoryClass.newInstance();

    proxyFactory.setProxyType(ann);
    proxyFactory.setAnnotated(annotated);

    Object proxy = proxyFactory.createProxy((Class) annotated.getBaseType());

    AnnotatedTypeImpl annotatedType
      = new AnnotatedTypeImpl((Class) annotated.getBaseType());

    annotatedType.addAnnotation(EnhancedLiteral.ANNOTATION);

    BeanFactory factory
      = _beanManager.createBeanFactory(annotatedType);

    /*
    factory.name(bean.getName());

    for (Type type : bean.getTypes()) {
      factory.type(type);
    }

    */
    for (Annotation binding : annotated.getAnnotations()) {
      Class bindingType = binding.annotationType();
     
      if (bindingType.isAnnotationPresent(Qualifier.class))
        factory.binding(binding);
    }
View Full Code Here

    }
  }

  public <T> void processBean(@Observes ProcessBeanImpl<T> event)
  {
    Annotated annotated = event.getAnnotated();
    Bean<T> bean = event.getBean();

    if (annotated == null || bean instanceof EjbGeneratedBean
        || !(bean instanceof AbstractBean<?>)) {
      return;
    }

    AbstractBean<T> absBean = (AbstractBean<T>) bean;

    if (annotated.isAnnotationPresent(Stateful.class)
        || annotated.isAnnotationPresent(Stateless.class)
        || annotated.isAnnotationPresent(Singleton.class)
        || annotated.isAnnotationPresent(MessageDriven.class)
        || annotated.isAnnotationPresent(JmsMessageListener.class)) {
      EjbContainer ejbContainer = EjbContainer.create();
      AnnotatedType<T> annType = absBean.getAnnotatedType();

      if (annType != null) {
        ejbContainer.createBean(annType, absBean.getInjectionTarget());
       
        if (event instanceof ProcessBeanImpl)
          ((ProcessBeanImpl) event).veto();
      }
    }
   
    if (annotated.isAnnotationPresent(Jndi.class)) {
      Jndi jndi = annotated.getAnnotation(Jndi.class);
      String jndiName = jndi.value();
     
      if ("".equals(jndiName)) {
        jndiName = bean.getBeanClass().getSimpleName();
      }
     
      JndiBeanProxy<T> proxy = new JndiBeanProxy<T>(_injectManager, bean);
     
      if (log.isLoggable(Level.FINE))
        log.fine("bind to JNDI '" + jndiName + "' for " + bean);
                
      try {
        com.caucho.naming.Jndi.bindDeepShort(jndiName, proxy);
      } catch (Exception e) {
        log.log(Level.FINE, e.toString(), e);
      }
    }
   
    if (annotated.isAnnotationPresent(MBean.class)) {
      MBean manage = annotated.getAnnotation(MBean.class);
     
      String mbeanName = manage.value();
      if ("".equals(mbeanName))
        mbeanName = "type=" + bean.getBeanClass().getSimpleName();
     
      AnnotatedType<?> annType = (AnnotatedType<?>) annotated;
     
      try {
        Jmx.register(new BeanMBean(_injectManager, bean, annType), mbeanName);
      } catch (Exception e) {
        log.log(Level.FINE, e.toString(), e);
      }
    }

    if (annotated.isAnnotationPresent(BamService.class)) {
      BamService service = annotated.getAnnotation(BamService.class);

      HempBroker broker = HempBroker.getCurrent();

      broker.addStartupActor(event.getBean(), service.name(), service
          .threadMax());
    }

    if (annotated.isAnnotationPresent(AdminService.class)) {
      AdminService service = annotated.getAnnotation(AdminService.class);

      Server server = Server.getCurrent();

      if (server == null) {
        throw new ConfigException(L
View Full Code Here

    return null;
  }

  public AnnotatedType<T> getAnnotatedType()
  {
    Annotated annotated = getAnnotated();

    if (annotated instanceof AnnotatedType<?>)
      return (AnnotatedType<T>) annotated;
    else
      return null;
View Full Code Here

    ProcessBeanImpl<?> eventImpl = (ProcessBeanImpl<?>) event;

    if (eventImpl.getManager() != _manager)
      return;

    Annotated annotated = event.getAnnotated();
    Bean<?> bean = event.getBean();

    if (isStartup(annotated)) {
      _pendingService.add(bean);
    }
View Full Code Here

    this.environment = environment;
  }
 
  @Produces @Property
  public String get(InjectionPoint ip) {
    Annotated annotated = ip.getAnnotated();
    Property property = annotated.getAnnotation(Property.class);
    String key = property.value();
    if (isNullOrEmpty(key)) {
      key = ip.getMember().getName();
    }
    return environment.get(key);
View Full Code Here

    return baseType.getRawClass();
  }
 
  private void validateNormal(Bean<?> bean)
  {
    Annotated ann = null;
   
    if (bean instanceof AbstractBean) {
      AbstractBean absBean = (AbstractBean) bean;
     
      ann = absBean.getAnnotated();
    }
   
    if (ann == null)
      return;
   
    Type baseType = ann.getBaseType();
   
    Class<?> cl = createTargetBaseType(baseType).getRawClass();
   
    if (cl.isInterface())
      return;
View Full Code Here

      return;
   
    for (int i = beans.size() - 1; i >= 0; i--) {
      TypedBean bean = beans.get(i);
     
      Annotated ann = bean.getAnnotated();
     
      if (ann == null || ! ann.isAnnotationPresent(Specializes.class))
        continue;

      for (int j = beans.size() - 1; j >= 0; j--) {
        if (i == j)
          continue;
       
        TypedBean bean2 = beans.get(j);
       
        // XXX:
       
        Annotated ann2 = bean.getAnnotated();
       
        if (ann2 == null)
          continue;
       
        if (isSpecializes(ann, ann2) && isMatchInject(bean, bean2)) {
View Full Code Here

TOP

Related Classes of javax.enterprise.inject.spi.Annotated

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.