Package org.apache.openejb.jee

Examples of org.apache.openejb.jee.EnterpriseBean


  private void processEnterpriseBeans(EjbJar ejbJar) {
    EnterpriseBean[] enterpriseBeans = ejbJar.getEnterpriseBeans();
    Iterator<EnterpriseBean> iterator = Arrays.asList(enterpriseBeans).iterator();
    while (iterator.hasNext()) {
      EnterpriseBean bean = (EnterpriseBean) iterator.next();
      if (bean instanceof SessionBean) {
        SessionBean sessionBean = (SessionBean) bean;
        processSessionBean(sessionBean);
      } else if (bean instanceof MessageDrivenBean) {
        MessageDrivenBean messageDriven = (MessageDrivenBean) bean;
View Full Code Here


      List<Method> methods = methodPermission.getMethod();
      Iterator<Method> methodIter = methods.iterator();

      while (methodIter.hasNext()) {
        Method method = (Method) methodIter.next();
        EnterpriseBean enterpriseBean = ejbJar.getEnterpriseBean(method.getEjbName());
        try {
          MethodParams methodParams = method.getMethodParams();
          String[] params = methodParams.getMethodParam().toArray(new String[0]);
          if ((!"*".equals(method.getMethodName())) && descriptor.getExcludeList().getMethod().contains(method)) { //$NON-NLS-1$
            annotationHelper.addMethodAnnotation(enterpriseBean.getEjbClass(), method.getMethodName(), params, DenyAll.class, null);
            continue;
          }
          if (methodPermission.getUnchecked()) {
            if ("*".equals(method.getMethodName())) { //$NON-NLS-1$
              annotationHelper.addClassAnnotation(enterpriseBean.getEjbClass(), PermitAll.class, null);
            } else {
              annotationHelper.addMethodAnnotation(enterpriseBean.getEjbClass(), method.getMethodName(), params, PermitAll.class, null);
            }
          } else {
            if ("*".equals(method.getMethodName())) { //$NON-NLS-1$
              annotationHelper.addClassAnnotation(enterpriseBean.getEjbClass(), RolesAllowed.class, roleProps);
            } else {
              annotationHelper.addMethodAnnotation(enterpriseBean.getEjbClass(), method.getMethodName(), params, RolesAllowed.class, roleProps);
            }
          }
        } catch (Exception e) {
          String warning = String.format(Messages.getString("org.apache.openejb.helper.annotation.warnings.12"), "@javax.persistence.RolesAllowed", enterpriseBean.getEjbClass());
          annotationHelper.addWarning(warning);
        }
      }
    }
  }
View Full Code Here

  public void processInterceptors(EjbJar ejbJar) {
    List<InterceptorBinding> interceptorBindings = ejbJar.getAssemblyDescriptor().getInterceptorBinding();

    for (InterceptorBinding interceptorBinding : interceptorBindings) {
      EnterpriseBean bean = ejbJar.getEnterpriseBean(interceptorBinding.getEjbName());

      try {
        List<String> interceptorClasses = interceptorBinding.getInterceptorClass();
        String[] classes = interceptorClasses.toArray(new String[0]);
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put("value", classes); //$NON-NLS-1$
        if (interceptorBinding.getMethod() == null) {
          if (interceptorBinding.getExcludeDefaultInterceptors()) {
            annotationHelper.addClassAnnotation(bean.getEjbClass(), ExcludeDefaultInterceptors.class, properties);
          }

          if (interceptorBinding.getExcludeClassInterceptors()) {
            annotationHelper.addClassAnnotation(bean.getEjbClass(), ExcludeClassInterceptors.class, properties);
          }

          annotationHelper.addClassAnnotation(bean.getEjbClass(), Interceptors.class, properties);
        } else {
          NamedMethod method = interceptorBinding.getMethod();
          String[] signature = method.getMethodParams().getMethodParam().toArray(new String[0]);

          if (interceptorBinding.getExcludeDefaultInterceptors()) {
            annotationHelper.addMethodAnnotation(bean.getEjbClass(), method.getMethodName(), signature, ExcludeDefaultInterceptors.class, properties);
          }

          if (interceptorBinding.getExcludeClassInterceptors()) {
            annotationHelper.addMethodAnnotation(bean.getEjbClass(), method.getMethodName(), signature, ExcludeClassInterceptors.class, properties);
          }

          annotationHelper.addMethodAnnotation(bean.getEjbClass(), method.getMethodName(), signature, Interceptors.class, properties);
        }
      } catch (Exception e) {
        String warning = String.format(Messages.getString("org.apache.openejb.helper.annotation.warnings.12"), "@javax.interceptor.Interceptors", bean.getEjbClass());
        annotationHelper.addWarning(warning);
      }
    }
  }
View Full Code Here

  private boolean dependsOnEntityBean(EjbJar ejbJar, EnterpriseBean enterpriseBean) {
    Collection<EjbRef> ejbRefs = enterpriseBean.getEjbRef();
    for (EjbReference ejbRef : ejbRefs) {
      String ejbLink = ejbRef.getEjbLink();
     
      EnterpriseBean refBean = ejbJar.getEnterpriseBean(ejbLink);
      if (refBean != null && refBean instanceof EntityBean) {
        return true;
      }
    }

    Collection<EjbLocalRef> ejbLocalRefs = enterpriseBean.getEjbLocalRef();
    for (EjbReference ejbRef : ejbLocalRefs) {
      String ejbLink = ejbRef.getEjbLink();
     
      EnterpriseBean refBean = ejbJar.getEnterpriseBean(ejbLink);
      if (refBean != null && refBean instanceof EntityBean) {
        return true;
      }
    }
   
View Full Code Here

    }

    @Module
    public static EjbModule service() throws Exception {
        final EjbModule module = new EjbModule(new EjbJar(), new OpenejbJar());
        final EnterpriseBean bean = new SingletonBean(AdvancedBean.class).localBean();
        module.getEjbJar().addEnterpriseBean(bean);

        final Resources resources = new Resources();

        final Service feature = new Service("xml", null);
View Full Code Here

            }

        }

        for (final Bean bean : app.values()) {
            final EnterpriseBean enterpriseBean = bean.bean;

            if (!(enterpriseBean instanceof SessionBean)) {
                continue;
            }

            final SessionBean sessionBean = (SessionBean) enterpriseBean;

            if (sessionBean.getSessionType() != SessionType.SINGLETON) {
                continue;
            }

            for (final String ejbName : sessionBean.getDependsOn()) {
                final Bean referee = bean.resolveLink(ejbName);
                if (referee == null) {
                    bean.module.getValidation().fail(enterpriseBean.getEjbName(), "dependsOn.noSuchEjb", ejbName);
                } else {
                    bean.dependsOn.add(referee);
                }
            }
        }
View Full Code Here

                if (!isValidEjbAnnotationUsage(Singleton.class, beanClass, ejbName, ejbModule)) {
                    continue;
                }

                EnterpriseBean enterpriseBean = ejbJar.getEnterpriseBean(ejbName);
                if (enterpriseBean == null) {
                    enterpriseBean = new SingletonBean(ejbName, beanClass.get());
                    ejbJar.addEnterpriseBean(enterpriseBean);
                }
                if (enterpriseBean.getEjbClass() == null) {
                    enterpriseBean.setEjbClass(beanClass.get());
                }
                if (enterpriseBean instanceof SessionBean) {
                    final SessionBean sessionBean = (SessionBean) enterpriseBean;
                    sessionBean.setSessionType(SessionType.SINGLETON);

                    if (singleton.mappedName() != null) {
                        sessionBean.setMappedName(singleton.mappedName());
                    }
                }
                LegacyProcessor.process(beanClass.get(), enterpriseBean);
            }

            for (final Annotated<Class<?>> beanClass : finder.findMetaAnnotatedClasses(Stateless.class)) {
                final Stateless stateless = beanClass.getAnnotation(Stateless.class);
                final String ejbName = getEjbName(stateless, beanClass.get());

                if (!isValidEjbAnnotationUsage(Stateless.class, beanClass, ejbName, ejbModule)) {
                    continue;
                }

                EnterpriseBean enterpriseBean = ejbJar.getEnterpriseBean(ejbName);
                if (enterpriseBean == null) {
                    enterpriseBean = new StatelessBean(ejbName, beanClass.get());
                    ejbJar.addEnterpriseBean(enterpriseBean);
                }
                if (enterpriseBean.getEjbClass() == null) {
                    enterpriseBean.setEjbClass(beanClass.get());
                }
                if (enterpriseBean instanceof SessionBean) {
                    final SessionBean sessionBean = (SessionBean) enterpriseBean;
                    sessionBean.setSessionType(SessionType.STATELESS);

                    if (stateless.mappedName() != null) {
                        sessionBean.setMappedName(stateless.mappedName());
                    }
                }
                LegacyProcessor.process(beanClass.get(), enterpriseBean);
            }

            // The Specialization code is good, but it possibly needs to be moved to after the full processing of the bean
            // the plus is that it would get the required interfaces.  The minus is that it would get all the other items

            // Possibly study alternatives.  Alternatives might have different meta data completely while it seems Specializing beans inherit all meta-data

            // Anyway.. the qualifiers aren't getting inherited, so we need to fix that

            for (final Annotated<Class<?>> beanClass : finder.findMetaAnnotatedClasses(Stateful.class)) {
                final Stateful stateful = beanClass.getAnnotation(Stateful.class);
                final String ejbName = getEjbName(stateful, beanClass.get());

                if (!isValidEjbAnnotationUsage(Stateful.class, beanClass, ejbName, ejbModule)) {
                    continue;
                }

                EnterpriseBean enterpriseBean = ejbJar.getEnterpriseBean(ejbName);
                if (enterpriseBean == null) {
                    enterpriseBean = new StatefulBean(ejbName, beanClass.get());
                    ejbJar.addEnterpriseBean(enterpriseBean);
                }
                if (enterpriseBean.getEjbClass() == null) {
                    enterpriseBean.setEjbClass(beanClass.get());
                }
                if (enterpriseBean instanceof SessionBean) {
                    final SessionBean sessionBean = (SessionBean) enterpriseBean;
                    // TODO: We might be stepping on an xml override here
                    sessionBean.setSessionType(SessionType.STATEFUL);
                    if (stateful.mappedName() != null) {
                        sessionBean.setMappedName(stateful.mappedName());
                    }
                }
                LegacyProcessor.process(beanClass.get(), enterpriseBean);
            }

            for (final Annotated<Class<?>> beanClass : finder.findMetaAnnotatedClasses(ManagedBean.class)) {
                final ManagedBean managed = beanClass.getAnnotation(ManagedBean.class);
                final String ejbName = getEjbName(managed, beanClass.get());

                // TODO: this is actually against the spec, but the requirement is rather silly
                // (allowing @Stateful and @ManagedBean on the same class)
                // If the TCK doesn't complain we should discourage it
                if (!isValidEjbAnnotationUsage(ManagedBean.class, beanClass, ejbName, ejbModule)) {
                    continue;
                }

                EnterpriseBean enterpriseBean = ejbJar.getEnterpriseBean(ejbName);
                if (enterpriseBean == null) {
                    enterpriseBean = new org.apache.openejb.jee.ManagedBean(ejbName, beanClass.get());
                    ejbJar.addEnterpriseBean(enterpriseBean);
                }
                if (enterpriseBean.getEjbClass() == null) {
                    enterpriseBean.setEjbClass(beanClass.get());
                }
                if (enterpriseBean instanceof SessionBean) {
                    final SessionBean sessionBean = (SessionBean) enterpriseBean;
                    sessionBean.setSessionType(SessionType.MANAGED);
View Full Code Here

            Map<String, EnterpriseBean> beanData = ejbModule.getEjbJar().getEnterpriseBeansByEjbName();

            for (EnterpriseBeanInfo beanInfo : ejbJar.enterpriseBeans) {

                // Get the ejb-jar.xml object
                EnterpriseBean enterpriseBean = beanData.get(beanInfo.ejbName);

                // Build the JNDI info tree for the EJB
                JndiEncInfo jndi = jndiEncInfoBuilder.build(enterpriseBean, beanInfo.ejbName, ejbJar.moduleId);

                beanInfo.jndiEnc = jndi;
View Full Code Here

            EjbJar ejbJar = ejbModule.getEjbJar();
            List<Class> classes = finder.findAnnotatedClasses(Stateless.class);
            for (Class<?> beanClass : classes) {
                Stateless stateless = beanClass.getAnnotation(Stateless.class);
                String ejbName = stateless.name().length() == 0 ? beanClass.getSimpleName() : stateless.name();
                EnterpriseBean enterpriseBean = ejbJar.getEnterpriseBean(ejbName);
                if (enterpriseBean == null) {
                    enterpriseBean = new StatelessBean(ejbName, beanClass.getName());
                    ejbJar.addEnterpriseBean(enterpriseBean);
                }
                if (enterpriseBean.getEjbClass() == null) {
                    enterpriseBean.setEjbClass(beanClass.getName());
                }
                if (enterpriseBean instanceof SessionBean) {
                    SessionBean sessionBean = (SessionBean) enterpriseBean;
                    sessionBean.setSessionType(SessionType.STATELESS);
                }
            }

            classes = finder.findAnnotatedClasses(Stateful.class);
            for (Class<?> beanClass : classes) {
                Stateful stateful = beanClass.getAnnotation(Stateful.class);
                String ejbName = stateful.name().length() == 0 ? beanClass.getSimpleName() : stateful.name();
                EnterpriseBean enterpriseBean = ejbJar.getEnterpriseBean(ejbName);
                if (enterpriseBean == null) {
                    enterpriseBean = new StatefulBean(ejbName, beanClass.getName());
                    ejbJar.addEnterpriseBean(enterpriseBean);
                }
                if (enterpriseBean.getEjbClass() == null) {
                    enterpriseBean.setEjbClass(beanClass.getName());
                }
                if (enterpriseBean instanceof SessionBean) {
                    SessionBean sessionBean = (SessionBean) enterpriseBean;
                    sessionBean.setSessionType(SessionType.STATEFUL);
                }
View Full Code Here

                    }
                    link.setResId(ref.getJndiName());
                }
            }

            EnterpriseBean bean = ejbJar.getEnterpriseBeansByEjbName().get(ejb.getEjbName());
            if (bean != null) {
                Map<String, ServiceRef> serviceRefMap = bean.getServiceRefMap();
                for (org.apache.openejb.jee.sun.ServiceRef ref : ejb.getServiceRef()) {
                    String refName = ref.getServiceRefName();
                    ServiceRef serviceRef = serviceRefMap.get(refName);
                    if (serviceRef != null) {
                        Map<String,PortComponentRef> ports = new TreeMap<String,PortComponentRef>();
                        for (PortComponentRef portComponentRef : serviceRef.getPortComponentRef()) {
                            ports.put(portComponentRef.getServiceEndpointInterface(), portComponentRef);
                        }

                        for (PortInfo portInfo : ref.getPortInfo()) {
                            PortComponentRef portComponentRef = ports.get(portInfo.getServiceEndpointInterface());
                            if (portComponentRef != null) {
                                WsdlPort wsdlPort = portInfo.getWsdlPort();
                                if (wsdlPort != null) {
                                    QName qname = new QName(wsdlPort.getNamespaceURI(), wsdlPort.getLocalpart());
                                    portComponentRef.setQName(qname);
                                }
                                for (StubProperty stubProperty : portInfo.getStubProperty()) {
                                    String name = stubProperty.getName();
                                    String value = stubProperty.getValue();
                                    portComponentRef.getProperties().setProperty(name, value);
                                }
                            }
                        }

                        String wsdlOverride = ref.getWsdlOverride();
                        if (wsdlOverride != null && wsdlOverride.length() > 0) {
                            String serviceId = extractServiceId(wsdlOverride);
                            serviceRef.setMappedName(serviceId);
                        }
                    }
                }
            }

            if (ejb.getMdbResourceAdapter() != null) {
                // resource adapter id is the MDB container ID
                String resourceAdapterId = ejb.getMdbResourceAdapter().getResourceAdapterMid();
                deployment.setContainerId(resourceAdapterId);
            }

            endpointMap.put(ejb.getEjbName(), ejb.getWebserviceEndpointMap());
        }

        // map wsdl locations
        if (ejbModule.getWebservices() != null) {
            Map<String, org.apache.openejb.jee.sun.WebserviceDescription> sunDescriptions = sunEjbJar.getEnterpriseBeans().getWebserviceDescriptionMap();
            for (WebserviceDescription description : ejbModule.getWebservices().getWebserviceDescription()) {
                org.apache.openejb.jee.sun.WebserviceDescription sunDescription = sunDescriptions.get(description.getWebserviceDescriptionName());

                // get the serviceId if specified
                String serviceId = null;
                if (sunDescription != null) {
                    serviceId = extractSerivceId(sunDescription.getWsdlPublishLocation(), description.getWsdlFile());
                }
                if (serviceId != null) {
                    description.setId(serviceId);
                }

                for (PortComponent port : description.getPortComponent()) {
                    // set the ejb bind location
                    ServiceImplBean bean = port.getServiceImplBean();
                    if (bean != null && bean.getEjbLink() != null) {
                        Map<String, WebserviceEndpoint> endpoints = endpointMap.get(bean.getEjbLink());
                        if (endpoints != null) {
                            WebserviceEndpoint endpoint = endpoints.get(port.getPortComponentName());
                            if (endpoint != null && endpoint.getEndpointAddressUri() != null) {
                                port.setLocation(endpoint.getEndpointAddressUri());
                            }
View Full Code Here

TOP

Related Classes of org.apache.openejb.jee.EnterpriseBean

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.