Package org.jboss.as.ee.component

Examples of org.jboss.as.ee.component.EEModuleDescription


    }

    public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
        final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();

        final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
        final CompositeIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
        final List<AnnotationInstance> resourceAnnotations = index.getAnnotations(EJB_ANNOTATION_NAME);

        for (AnnotationInstance annotation : resourceAnnotations) {
            final AnnotationTarget annotationTarget = annotation.target();
View Full Code Here


                        //for remote interfaces we do not want to use a normal binding
                        //we need to bind the remote proxy factory into JNDI instead to get the correct behaviour

                        if (ejbViewDescription.getMethodIntf() == MethodIntf.REMOTE || ejbViewDescription.getMethodIntf() == MethodIntf.HOME) {
                            final EJBComponentDescription componentDescription = (EJBComponentDescription) description.getComponentDescription();
                            final EEModuleDescription moduleDescription = componentDescription.getModuleDescription();
                            final String earApplicationName = moduleDescription.getEarApplicationName();
                            final Value<ClassLoader> viewClassLoader = new Value<ClassLoader>() {
                                @Override
                                public ClassLoader getValue() throws IllegalStateException, IllegalArgumentException {
                                    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
                                    return module != null ? module.getClassLoader() : null;
                                }
                            };
                            remoteFactory = new RemoteViewManagedReferenceFactory(earApplicationName, moduleDescription.getModuleName(), moduleDescription.getDistinctName(), componentDescription.getComponentName(), description.getViewClassName(), componentDescription.isStateful(),viewClassLoader);
                        }
                        final ServiceName serviceName = description.getServiceName();
                        resolvedViewName = serviceName;
                    }
                    resolved = true;
View Full Code Here

    @Override
    public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {

        final DeploymentUnit depUnit = phaseContext.getDeploymentUnit();
        final EEModuleDescription moduleDesc = depUnit.getAttachment(EE_MODULE_DESCRIPTION);
        if (moduleDesc == null) {
            return;
        }

        final CompositeIndex compositeIndex = depUnit.getAttachment(COMPOSITE_ANNOTATION_INDEX);
        if (compositeIndex == null) {
            ROOT_LOGGER.cannotFindAnnotationIndex(depUnit);
            return;
        }

        // Check if we have a BundleContext injection point
        boolean hasBundleContextResource = false;
        final DotName resourceDotName = DotName.createSimple(Resource.class.getName());
        final DotName targetDotName = DotName.createSimple(BundleContext.class.getName());
        final List<AnnotationInstance> anList = compositeIndex.getAnnotations(resourceDotName);
        for (AnnotationInstance an : anList) {
            AnnotationTarget anTarget = an.target();
            if (anTarget instanceof FieldInfo) {
                FieldInfo fieldInfo = (FieldInfo) anTarget;
                Type targetType = fieldInfo.type();
                if (targetType.name().equals(targetDotName)) {
                    hasBundleContextResource = true;
                    break;
                }
            }
        }
        if (hasBundleContextResource == false) {
            return;
        }

        final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
        if (DeploymentTypeMarker.isType(DeploymentType.WAR, depUnit)) {
            ServiceName serviceName = contextServiceNameOfModule(moduleDesc.getApplicationName(), moduleDesc.getModuleName());
            bindServices(depUnit, serviceTarget, moduleDesc, moduleDesc.getModuleName(), serviceName);
        }

        for (ComponentDescription comp : moduleDesc.getComponentDescriptions()) {
            if (comp.getNamingMode() == ComponentNamingMode.CREATE) {
                ServiceName serviceName = contextServiceNameOfComponent(moduleDesc.getApplicationName(), moduleDesc.getModuleName(), comp.getComponentName());
                bindServices(depUnit, serviceTarget, moduleDesc, comp.getComponentName(), serviceName);
            }
        }
    }
View Full Code Here

  public static final int PRIORITY = 0x2010; // after PARSE_WEB_MERGE_METADATA

  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();   
    final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
   
    // must be EE Module
    if(eeModuleDescription == null) {
      return;
    }
View Full Code Here

  /**
   * Detect an existing {@link ProcessApplication} component. 
   */
  protected ComponentDescription detectExistingComponent(DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
   
    final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final EEApplicationClasses eeApplicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
    final CompositeIndex compositeIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
   
    final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);

    // extract deployment metadata
    List<AnnotationInstance> processApplicationAnnotations = null;
    List<AnnotationInstance> postDeployAnnnotations = null;
    List<AnnotationInstance> preUndeployAnnnotations = null;
    Set<ClassInfo> servletProcessApplications = null;
   
    if(compositeIndex != null) {
      processApplicationAnnotations = compositeIndex.getAnnotations(DotName.createSimple(ProcessApplication.class.getName()));
      postDeployAnnnotations = compositeIndex.getAnnotations(DotName.createSimple(PostDeploy.class.getName()));
      preUndeployAnnnotations = compositeIndex.getAnnotations(DotName.createSimple(PreUndeploy.class.getName()));
      servletProcessApplications = compositeIndex.getAllKnownSubclasses(DotName.createSimple(ServletProcessApplication.class.getName()));
    } else {
      return null;
    }
           
    if(processApplicationAnnotations.isEmpty()) {
      // no pa found, this is not a process application deployment.
      return null;
     
    } else if(processApplicationAnnotations.size() > 1) {
      // found multiple PAs -> unsupported.     
      throw new DeploymentUnitProcessingException("Detected multiple classes annotated with @" + ProcessApplication.class.getSimpleName()
          + ". A deployment must only provide a single @" + ProcessApplication.class.getSimpleName()
          + " class.");
     
    } else {
      // found single PA
     
      AnnotationInstance annotationInstance = processApplicationAnnotations.get(0);     
      ClassInfo paClassInfo = (ClassInfo) annotationInstance.target();
      String paClassName = paClassInfo.name().toString();
     
      ComponentDescription paComponent = null;
     
      // it can either be a Servlet Process Application or a Singleton Session Bean Component or
      if(servletProcessApplications.contains(paClassInfo)) {
       
        // Servlet Process Applications can only be deployed inside Web Applications
        if(warMetaData == null) {
          throw new DeploymentUnitProcessingException("@ProcessApplication class is a ServletProcessApplication but deployment is not a Web Application.");
        }
       
        // check whether it's already a servlet context listener:
        JBossWebMetaData mergedJBossWebMetaData = warMetaData.getMergedJBossWebMetaData();
        List<ListenerMetaData> listeners = mergedJBossWebMetaData.getListeners();
        if(listeners == null) {
          listeners = new ArrayList<ListenerMetaData>();
          mergedJBossWebMetaData.setListeners(listeners);
        }
       
        boolean isListener = false;
        for (ListenerMetaData listenerMetaData : listeners) {
          if(listenerMetaData.getListenerClass().equals(paClassInfo.name().toString())) {
            isListener = true;
          }
        }
       
        if(!isListener) {
          // register as Servlet Context Listener
          ListenerMetaData listener = new ListenerMetaData();
          listener.setListenerClass(paClassName);
          listeners.add(listener);
       
          // synthesize WebComponent
          WebComponentDescription paWebComponent = new WebComponentDescription(paClassName,
              paClassName,
              eeModuleDescription,
              deploymentUnit.getServiceName(),
              eeApplicationClasses);
                       
          eeModuleDescription.addComponent(paWebComponent);
         
          deploymentUnit.addToAttachmentList(WebComponentDescription.WEB_COMPONENTS, paWebComponent.getStartServiceName());
         
          paComponent = paWebComponent;
         
        } else {
          // lookup the existing component         
          paComponent = eeModuleDescription.getComponentsByClassName(paClassName).get(0);         
        }
       
        // deactivate sci
       
                       
      } else {
       
        // if its not a ServletProcessApplication it must be a session bean component
           
        List<ComponentDescription> componentsByClassName = eeModuleDescription.getComponentsByClassName(paClassName);  
       
        if (!componentsByClassName.isEmpty() && (componentsByClassName.get(0) instanceof SessionBeanComponentDescription)) {         
          paComponent = componentsByClassName.get(0);

        } else {         
View Full Code Here

  public static final int PRIORITY = 0x2010; // after PARSE_WEB_MERGE_METADATA

  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();   
    final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
   
    // must be EE Module
    if(eeModuleDescription == null) {
      return;
    }
View Full Code Here

  /**
   * Detect an existing {@link ProcessApplication} component. 
   */
  protected ComponentDescription detectExistingComponent(DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
   
    final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final EEApplicationClasses eeApplicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
    final CompositeIndex compositeIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
   
    final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);

    // extract deployment metadata
    List<AnnotationInstance> processApplicationAnnotations = null;
    List<AnnotationInstance> postDeployAnnnotations = null;
    List<AnnotationInstance> preUndeployAnnnotations = null;
    Set<ClassInfo> servletProcessApplications = null;
   
    if(compositeIndex != null) {
      processApplicationAnnotations = compositeIndex.getAnnotations(DotName.createSimple(ProcessApplication.class.getName()));
      postDeployAnnnotations = compositeIndex.getAnnotations(DotName.createSimple(PostDeploy.class.getName()));
      preUndeployAnnnotations = compositeIndex.getAnnotations(DotName.createSimple(PreUndeploy.class.getName()));
      servletProcessApplications = compositeIndex.getAllKnownSubclasses(DotName.createSimple(ServletProcessApplication.class.getName()));
    } else {
      return null;
    }
           
    if(processApplicationAnnotations.isEmpty()) {
      // no pa found, this is not a process application deployment.
      return null;
     
    } else if(processApplicationAnnotations.size() > 1) {
      // found multiple PAs -> unsupported.     
      throw new DeploymentUnitProcessingException("Detected multiple classes annotated with @" + ProcessApplication.class.getSimpleName()
          + ". A deployment must only provide a single @" + ProcessApplication.class.getSimpleName()
          + " class.");
     
    } else {
      // found single PA
     
      AnnotationInstance annotationInstance = processApplicationAnnotations.get(0);     
      ClassInfo paClassInfo = (ClassInfo) annotationInstance.target();
      String paClassName = paClassInfo.name().toString();
     
      ComponentDescription paComponent = null;
     
      // it can either be a Servlet Process Application or a Singleton Session Bean Component or
      if(servletProcessApplications.contains(paClassInfo)) {
       
        // Servlet Process Applications can only be deployed inside Web Applications
        if(warMetaData == null) {
          throw new DeploymentUnitProcessingException("@ProcessApplication class is a ServletProcessApplication but deployment is not a Web Application.");
        }
       
        // check whether it's already a servlet context listener:
        JBossWebMetaData mergedJBossWebMetaData = warMetaData.getMergedJBossWebMetaData();
        List<ListenerMetaData> listeners = mergedJBossWebMetaData.getListeners();
        if(listeners == null) {
          listeners = new ArrayList<ListenerMetaData>();
          mergedJBossWebMetaData.setListeners(listeners);
        }
       
        boolean isListener = false;
        for (ListenerMetaData listenerMetaData : listeners) {
          if(listenerMetaData.getListenerClass().equals(paClassInfo.name().toString())) {
            isListener = true;
          }
        }
       
        if(!isListener) {
          // register as Servlet Context Listener
          ListenerMetaData listener = new ListenerMetaData();
          listener.setListenerClass(paClassName);
          listeners.add(listener);
       
          // synthesize WebComponent
          WebComponentDescription paWebComponent = new WebComponentDescription(paClassName,
              paClassName,
              eeModuleDescription,
              deploymentUnit.getServiceName(),
              eeApplicationClasses);
                       
          eeModuleDescription.addComponent(paWebComponent);
         
          deploymentUnit.getAttachment(WebAttachments.WEB_COMPONENT_INSTANTIATORS).put(paWebComponent.getComponentClassName(), new WebComponentInstantiator(deploymentUnit, paWebComponent));
         
          paComponent = paWebComponent;
         
        } else {
          // lookup the existing component         
          paComponent = eeModuleDescription.getComponentsByClassName(paClassName).get(0);         
        }
       
        // deactivate sci
       
                       
      } else {
       
        // if its not a ServletProcessApplication it must be a session bean component
           
        List<ComponentDescription> componentsByClassName = eeModuleDescription.getComponentsByClassName(paClassName);  
       
        if (!componentsByClassName.isEmpty() && (componentsByClassName.get(0) instanceof SessionBeanComponentDescription)) {         
          paComponent = componentsByClassName.get(0);

        } else {         
View Full Code Here

            return;
        }
        // right now I only support resources
        if (!resteasy.isScanResources()) return;

        final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
        if (moduleDescription == null) {
            return;
        }

        final ClassLoader loader = module.getClassLoader();

        for (final ComponentDescription component : moduleDescription.getComponentDescriptions()) {
            Class<?> componentClass = null;
            try {
                componentClass = loader.loadClass(component.getComponentClassName());
            } catch (ClassNotFoundException e) {
                throw new DeploymentUnitProcessingException(e);
            }
            if (!GetRestful.isRootResource(componentClass)) continue;

            if (component instanceof WebComponentDescription) {
                continue;
            }
            if (component instanceof SessionBeanComponentDescription) {
                Class jaxrsType = GetRestful.getSubResourceClass(componentClass);
                final String jndiName;
                if(component.getViews().size() == 1) {
                    //only 1 view, just use the simple JNDI name
                    jndiName = "java:app/" + moduleDescription.getModuleName() + "/" + componentClass.getSimpleName();
                } else {
                    final String jaxRsTypeName = jaxrsType.getName();
                    boolean found = false;
                    for(final ViewDescription view : component.getViews()) {
                        if(view.getViewClassName().equals(jaxRsTypeName)) {
                            found = true;
                            break;
                        }
                    }
                    if(!found) {
                        throw JaxrsMessages.MESSAGES.typeNameNotAnEjbView(jaxRsTypeName, component.getComponentName());
                    }
                    jndiName = "java:app/" + moduleDescription.getModuleName() + "/" + componentClass.getSimpleName() + "!" + jaxRsTypeName;
                }

                JAXRS_LOGGER.debugf("Found JAX-RS Managed Bean: %s local jndi jaxRsTypeName: %s", component.getComponentClassName(), jndiName);
                StringBuilder buf = new StringBuilder();
                buf.append(jndiName).append(";").append(component.getComponentClassName()).append(";").append("true");

                resteasy.getScannedJndiComponentResources().add(buf.toString());
                // make sure its removed from list
                resteasy.getScannedResourceClasses().remove(component.getComponentClassName());
            } else {

                String jndiName = "java:app/" + moduleDescription.getModuleName() + "/" + component.getComponentName();
                JAXRS_LOGGER.debugf("Found JAX-RS Managed Bean: %s local jndi name: %s", component.getComponentClassName(), jndiName);
                StringBuilder buf = new StringBuilder();
                buf.append(jndiName).append(";").append(component.getComponentClassName()).append(";").append("true");

                resteasy.getScannedJndiComponentResources().add(buf.toString());
View Full Code Here

            }
        }
    }

    private void handleModule(final JndiViewExtensionContext context, final DeploymentUnit deploymentUnit, final ModelNode modulesNode, final ServiceRegistry serviceRegistry) throws OperationFailedException {
        final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
        // If it isn't a EE module, just return
        if (moduleDescription == null) {
            return;
        }
        final String appName = moduleDescription.getApplicationName();
        final String moduleName = moduleDescription.getModuleName();

        final ModelNode moduleNode = modulesNode.get(moduleDescription.getModuleName());

        final ServiceName moduleContextName = ContextNames.contextServiceNameOfModule(appName, moduleName);
        final ServiceController<?> moduleContextController = serviceRegistry.getService(moduleContextName);
        if (moduleContextController != null) {
            final NamingStore moduleStore = NamingStore.class.cast(moduleContextController.getValue());
            try {
                context.addEntries(moduleNode.get("java:module"), new NamingContext(moduleStore, null));
            } catch (NamingException e) {
                throw new OperationFailedException(e, new ModelNode().set("Failed to read java:module entries for module [" + appName + ", " + moduleName + "]"));
            }

            final Collection<ComponentDescription> componentDescriptions = moduleDescription.getComponentDescriptions();
            for (ComponentDescription componentDescription : componentDescriptions) {
                final String componentName = componentDescription.getComponentName();
                final ServiceName compContextServiceName = ContextNames.contextServiceNameOfComponent(appName, moduleName, componentName);
                final ServiceController<?> compContextController = serviceRegistry.getService(compContextServiceName);
                if (compContextController != null) {
View Full Code Here

     * @throws DeploymentUnitProcessingException
     *
     */
    public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
        final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
        final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
        final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
        final CompositeIndex compositeIndex = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
        if(compositeIndex == null) {
            return;
        }
        final List<AnnotationInstance> instances = compositeIndex.getAnnotations(MANAGED_BEAN_ANNOTATION_NAME);
        if (instances == null || instances.isEmpty()) {
            return;
        }

        for (AnnotationInstance instance : instances) {
            AnnotationTarget target = instance.target();
            if (!(target instanceof ClassInfo)) {
                throw new DeploymentUnitProcessingException("The ManagedBean annotation is only allowed at the class level: " + target);
            }
            final ClassInfo classInfo = (ClassInfo) target;
            // skip if it's not a valid managed bean class
            if (!assertManagedBeanClassValidity(classInfo)) {
                continue;
            }
            final String beanClassName = classInfo.name().toString();

            // Get the managed bean name from the annotation
            final AnnotationValue nameValue = instance.value();
            final String beanName = nameValue == null || nameValue.asString().isEmpty() ? beanClassName : nameValue.asString();
            final ComponentDescription componentDescription = new ComponentDescription(beanName, beanClassName, moduleDescription, applicationClasses.getOrAddClassByName(beanClassName), deploymentUnit.getServiceName(), applicationClasses);

            // Add the view
            ViewDescription viewDescription = new ViewDescription(componentDescription, beanClassName);
            viewDescription.getConfigurators().addFirst(new ViewConfigurator() {
                public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
                    // Add MB association interceptors
                    final Object contextKey = new Object();
                    configuration.addViewPostConstructInterceptor(new ManagedBeanCreateInterceptorFactory(contextKey), InterceptorOrder.ViewPostConstruct.INSTANCE_CREATE);
                    final ManagedBeanAssociatingInterceptorFactory associatingInterceptorFactory = new ManagedBeanAssociatingInterceptorFactory(contextKey);
                    configuration.addViewInterceptor(associatingInterceptorFactory, InterceptorOrder.View.ASSOCIATING_INTERCEPTOR);
                    configuration.addViewPreDestroyInterceptor(new ManagedBeanDestroyInterceptorFactory(contextKey), InterceptorOrder.ViewPreDestroy.INSTANCE_DESTROY);
                }
            });
            viewDescription.getBindingNames().addAll(Arrays.asList("java:module/" + beanName, "java:app/" + moduleDescription.getModuleName() + "/" + beanName));
            componentDescription.getViews().add(viewDescription);
            moduleDescription.addComponent(componentDescription);

            // register a EEResourceReferenceProcessor which can process @Resource references to this managed bean.
            EEResourceReferenceProcessorRegistry.registerResourceReferenceProcessor(new ManagedBeanResourceReferenceProcessor(beanClassName));
        }
    }
View Full Code Here

TOP

Related Classes of org.jboss.as.ee.component.EEModuleDescription

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.