Beispiel #1
0
  private EnterpriseBeanInfo initSessionBean(
      final SessionBean s, final EjbJarInfo ejbJar, final Map m) throws OpenEJBException {
    EnterpriseBeanInfo bean = null;

    if (s.getSessionType() == SessionType.STATEFUL) {
      bean = new StatefulBeanInfo();
      bean.passivable = s.getPassivationCapable();
      final StatefulBeanInfo stateful = (StatefulBeanInfo) bean;

      copyCallbacks(s.getPostActivate(), stateful.postActivate);
      copyCallbacks(s.getPrePassivate(), stateful.prePassivate);

      copyCallbacks(s.getAfterBegin(), stateful.afterBegin);
      copyCallbacks(s.getBeforeCompletion(), stateful.beforeCompletion);
      copyCallbacks(s.getAfterCompletion(), stateful.afterCompletion);

      for (final InitMethod initMethod : s.getInitMethod()) {
        final InitMethodInfo init = new InitMethodInfo();
        init.beanMethod = toInfo(initMethod.getBeanMethod());
        init.createMethod = toInfo(initMethod.getCreateMethod());
        stateful.initMethods.add(init);
      }

      for (final RemoveMethod removeMethod : s.getRemoveMethod()) {
        final RemoveMethodInfo remove = new RemoveMethodInfo();
        remove.beanMethod = toInfo(removeMethod.getBeanMethod());
        remove.retainIfException = removeMethod.getRetainIfException();
        stateful.removeMethods.add(remove);
      }

      copyConcurrentMethods(s, ejbJar, m);

    } else if (s.getSessionType() == SessionType.MANAGED) {
      bean = new ManagedBeanInfo();
      final ManagedBeanInfo managed = (ManagedBeanInfo) bean;
      if (s
          instanceof
          ManagedBean) { // this way we support managed beans in ejb-jar.xml (not in the spec but
        // can be useful)
        managed.hidden = ((ManagedBean) s).isHidden();
      } else {
        managed.hidden = true;
      }

      copyCallbacks(s.getPostActivate(), managed.postActivate);
      copyCallbacks(s.getPrePassivate(), managed.prePassivate);

      for (final RemoveMethod removeMethod : s.getRemoveMethod()) {
        final RemoveMethodInfo remove = new RemoveMethodInfo();
        remove.beanMethod = toInfo(removeMethod.getBeanMethod());
        remove.retainIfException = removeMethod.getRetainIfException();
        managed.removeMethods.add(remove);
      }

    } else if (s.getSessionType() == SessionType.SINGLETON) {
      bean = new SingletonBeanInfo();
      final ConcurrencyManagementType type = s.getConcurrencyManagementType();
      bean.concurrencyType =
          type != null ? type.toString() : ConcurrencyManagementType.CONTAINER.toString();
      bean.loadOnStartup = s.getInitOnStartup();

      copyCallbacks(s.getAroundTimeout(), bean.aroundTimeout);
      copySchedules(s.getTimer(), bean.methodScheduleInfos);
      // See JndiEncInfoBuilder.buildDependsOnRefs for processing of DependsOn
      // bean.dependsOn.addAll(s.getDependsOn());

      copyConcurrentMethods(s, ejbJar, m);
    } else {
      bean = new StatelessBeanInfo();
      copySchedules(s.getTimer(), bean.methodScheduleInfos);
    }

    if (s.getSessionType() != SessionType.STATEFUL) {
      copyCallbacks(s.getAroundTimeout(), bean.aroundTimeout);
    }

    bean.localbean = s.getLocalBean() != null;

    bean.timeoutMethod = toInfo(s.getTimeoutMethod());

    copyCallbacks(s.getAroundInvoke(), bean.aroundInvoke);
    copyCallbacks(s.getPostConstruct(), bean.postConstruct);
    copyCallbacks(s.getPreDestroy(), bean.preDestroy);

    copyAsynchronous(s.getAsyncMethod(), bean.asynchronous);
    bean.asynchronousClasses.addAll(s.getAsynchronousClasses());

    final EjbDeployment d = (EjbDeployment) m.get(s.getEjbName());
    if (d == null) {
      throw new OpenEJBException(
          "No deployment information in openejb-jar.xml for bean "
              + s.getEjbName()
              + ". Please redeploy the jar");
    }
    bean.ejbDeploymentId = d.getDeploymentId();
    bean.containerId = d.getContainerId();

    final Icon icon = s.getIcon();
    bean.largeIcon = icon == null ? null : icon.getLargeIcon();
    bean.smallIcon = icon == null ? null : icon.getSmallIcon();
    bean.description = s.getDescription();
    bean.displayName = s.getDisplayName();
    bean.ejbClass = s.getEjbClass();
    bean.ejbName = s.getEjbName();
    bean.home = s.getHome();
    bean.remote = s.getRemote();
    bean.localHome = s.getLocalHome();
    bean.local = s.getLocal();
    bean.proxy = s.getProxy();
    bean.parents.addAll(s.getParents());
    bean.businessLocal.addAll(s.getBusinessLocal());
    bean.businessRemote.addAll(s.getBusinessRemote());
    final TransactionType txType = s.getTransactionType();
    bean.transactionType =
        txType != null ? txType.toString() : TransactionType.CONTAINER.toString();
    bean.serviceEndpoint = s.getServiceEndpoint();
    bean.properties.putAll(d.getProperties());

    bean.statefulTimeout = toInfo(s.getStatefulTimeout());

    bean.restService = s.isRestService() && !(s instanceof StatefulBean);

    return bean;
  }
Beispiel #2
0
  public EjbJarInfo buildInfo(final EjbModule jar) throws OpenEJBException {
    deploymentIds.clear();
    securityRoles.clear();

    final Map<String, EjbDeployment> ejbds = jar.getOpenejbJar().getDeploymentsByEjbName();
    final int beansDeployed = jar.getOpenejbJar().getEjbDeploymentCount();
    final int beansInEjbJar = jar.getEjbJar().getEnterpriseBeans().length;

    if (beansInEjbJar != beansDeployed) {

      for (final EnterpriseBean bean : jar.getEjbJar().getEnterpriseBeans()) {
        if (!ejbds.containsKey(bean.getEjbName())) {
          ConfigUtils.logger.warning("conf.0018", bean.getEjbName(), jar.getJarLocation());
        }
      }

      final String message =
          messages.format(
              "conf.0008",
              jar.getJarLocation(),
              String.valueOf(beansInEjbJar),
              String.valueOf(beansDeployed));
      logger.warning(message);
      throw new OpenEJBException(message);
    }

    final Map<String, EnterpriseBeanInfo> infos = new HashMap<String, EnterpriseBeanInfo>();
    final Map<String, EnterpriseBean> items = new HashMap<String, EnterpriseBean>();

    final EjbJarInfo ejbJar = new EjbJarInfo();
    ejbJar.path = jar.getJarLocation();
    ejbJar.moduleUri = jar.getModuleUri();
    ejbJar.moduleId = jar.getModuleId();
    if (jar.getEjbJar() != null && jar.getEjbJar().getModuleName() != null) {
      ejbJar.moduleName = jar.getEjbJar().getModuleName();
    } else {
      ejbJar.moduleName = jar.getModuleId();
    }

    ejbJar.watchedResources.addAll(jar.getWatchedResources());

    ejbJar.properties.putAll(jar.getProperties());
    ejbJar.properties.putAll(jar.getOpenejbJar().getProperties());

    for (final EnterpriseBean bean : jar.getEjbJar().getEnterpriseBeans()) {
      final EnterpriseBeanInfo beanInfo;
      if (bean instanceof SessionBean) {
        beanInfo = initSessionBean((SessionBean) bean, ejbJar, ejbds);
      } else if (bean instanceof EntityBean) {
        beanInfo = initEntityBean((EntityBean) bean, ejbds);
      } else if (bean instanceof MessageDrivenBean) {
        beanInfo = initMessageBean((MessageDrivenBean) bean, ejbds);
      } else {
        throw new OpenEJBException("Unknown bean type: " + bean.getClass().getName());
      }
      ejbJar.enterpriseBeans.add(beanInfo);

      if (deploymentIds.contains(beanInfo.ejbDeploymentId)) {
        final String message =
            messages.format(
                "conf.0100", beanInfo.ejbDeploymentId, jar.getJarLocation(), beanInfo.ejbName);
        logger.warning(message);
        throw new OpenEJBException(message);
      }

      deploymentIds.add(beanInfo.ejbDeploymentId);

      beanInfo.codebase = jar.getJarLocation();
      infos.put(beanInfo.ejbName, beanInfo);
      items.put(beanInfo.ejbName, bean);

      if (bean.getSecurityIdentity() != null) {
        beanInfo.runAs = bean.getSecurityIdentity().getRunAs();

        final EjbDeployment deployment = ejbds.get(beanInfo.ejbName);
        if (deployment != null) {
          for (final RoleMapping mapping : deployment.getRoleMapping()) {
            if (mapping.getRoleName().equals(beanInfo.runAs)) {
              beanInfo.runAsUser = mapping.getPrincipalName();
              break;
            }
          }
        }
      }

      initJndiNames(ejbds, beanInfo);
    }

    if (jar.getEjbJar().getAssemblyDescriptor() != null) {
      initInterceptors(jar, ejbJar);
      initSecurityRoles(jar, ejbJar);
      initMethodPermissions(jar, ejbds, ejbJar);
      initExcludesList(jar, ejbds, ejbJar);
      initMethodTransactions(jar, ejbds, ejbJar);
      initMethodConcurrency(jar, ejbds, ejbJar);
      initApplicationExceptions(jar, ejbJar);

      for (final EnterpriseBeanInfo bean : ejbJar.enterpriseBeans) {
        resolveRoleLinks(bean, items.get(bean.ejbName));
      }
    }

    if (jar.getEjbJar().getRelationships() != null) {
      initRelationships(jar, infos);
    }

    final Beans beans = jar.getBeans();
    if (beans != null) {
      ejbJar.beans = new BeansInfo();
      ejbJar.beans.version = beans.getVersion();
      ejbJar.beans.discoveryMode = beans.getBeanDiscoveryMode();
      if (beans.getScan() != null) {
        for (final Beans.Scan.Exclude exclude : beans.getScan().getExclude()) {
          final ExclusionInfo exclusionInfo = new ExclusionInfo();
          for (final Object config :
              exclude.getIfClassAvailableOrIfClassNotAvailableOrIfSystemProperty()) {
            if (Beans.Scan.Exclude.IfAvailableClassCondition.class.isInstance(config)) {
              exclusionInfo.availableClasses.add(
                  Beans.Scan.Exclude.ClassCondition.class.cast(config).getName());
            } else if (Beans.Scan.Exclude.IfNotAvailableClassCondition.class.isInstance(config)) {
              exclusionInfo.notAvailableClasses.add(
                  Beans.Scan.Exclude.ClassCondition.class.cast(config).getName());
            } else if (Beans.Scan.Exclude.IfSystemProperty.class.isInstance(config)) {
              final Beans.Scan.Exclude.IfSystemProperty systemProperty =
                  Beans.Scan.Exclude.IfSystemProperty.class.cast(config);
              if (systemProperty.getValue() == null) {
                exclusionInfo.systemPropertiesPresence.add(systemProperty.getName());
              } else {
                exclusionInfo.systemProperties.put(
                    systemProperty.getName(), systemProperty.getValue());
              }
            } else {
              throw new IllegalArgumentException("Not supported: " + config);
            }
          }

          final BeansInfo.ExclusionEntryInfo exclusionEntryInfo =
              new BeansInfo.ExclusionEntryInfo();
          exclusionEntryInfo.name = exclude.getName();
          exclusionEntryInfo.exclusion = exclusionInfo;
          ejbJar.beans.excludes.add(exclusionEntryInfo);
        }
      }

      ejbJar.beans.interceptors.addAll(beans.getInterceptors());
      ejbJar.beans.decorators.addAll(beans.getDecorators());
      ejbJar.beans.alternativeClasses.addAll(beans.getAlternativeClasses());
      ejbJar.beans.alternativeStereotypes.addAll(beans.getAlternativeStereotypes());

      ejbJar.beans.duplicatedAlternativeClasses.addAll(
          beans.getDuplicatedAlternatives().getClasses());
      ejbJar.beans.duplicatedAlternativeStereotypes.addAll(
          beans.getDuplicatedAlternatives().getStereotypes());
      ejbJar.beans.duplicatedInterceptors.addAll(beans.getDuplicatedInterceptors());
      ejbJar.beans.duplicatedDecorators.addAll(beans.getDuplicatedDecorators());

      ejbJar.beans.startupClasses.addAll(beans.getStartupBeans());

      final Map<URL, String> discoveryModeByUrl = new HashMap<>();
      if (CompositeBeans.class.isInstance(beans)) {
        discoveryModeByUrl.putAll(CompositeBeans.class.cast(beans).getDiscoveryByUrl());
      } else {
        discoveryModeByUrl.put(null, beans.getBeanDiscoveryMode());
      }
      for (final Map.Entry<URL, List<String>> next : beans.getManagedClasses().entrySet()) {
        final URL key = next.getKey();

        final BeansInfo.BDAInfo bdaInfo = new BeansInfo.BDAInfo();
        bdaInfo.managedClasses.addAll(next.getValue());
        bdaInfo.discoveryMode = discoveryModeByUrl.get(key);
        try {
          bdaInfo.uri = key == null ? null : key.toURI();
        } catch (final URISyntaxException e) {
          bdaInfo.uri = null;
        }
        ejbJar.beans.bdas.add(bdaInfo);
      }
    }

    return ejbJar;
  }