Package org.jboss.metadata.ejb.jboss

Source Code of org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData

/*
* JBoss, Home of Professional Open Source
* Copyright 2006, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.metadata.ejb.jboss;

import java.lang.reflect.Method;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import javax.ejb.TransactionAttributeType;
import javax.ejb.TransactionManagementType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import org.jboss.metadata.common.ejb.IEnterpriseBeanMetaData;
import org.jboss.metadata.ejb.spec.ContainerTransactionMetaData;
import org.jboss.metadata.ejb.spec.ContainerTransactionsMetaData;
import org.jboss.metadata.ejb.spec.EnterpriseBeanMetaData;
import org.jboss.metadata.ejb.spec.EntityBeanMetaData;
import org.jboss.metadata.ejb.spec.ExcludeListMetaData;
import org.jboss.metadata.ejb.spec.InterceptorBindingMetaData;
import org.jboss.metadata.ejb.spec.MessageDrivenBeanMetaData;
import org.jboss.metadata.ejb.spec.MethodInterfaceType;
import org.jboss.metadata.ejb.spec.MethodMetaData;
import org.jboss.metadata.ejb.spec.MethodPermissionMetaData;
import org.jboss.metadata.ejb.spec.MethodPermissionsMetaData;
import org.jboss.metadata.ejb.spec.SecurityIdentityMetaData;
import org.jboss.metadata.ejb.spec.SessionBeanMetaData;
import org.jboss.metadata.javaee.jboss.AnnotationsMetaData;
import org.jboss.metadata.javaee.jboss.IgnoreDependencyMetaData;
import org.jboss.metadata.javaee.jboss.JndiRefsMetaData;
import org.jboss.metadata.javaee.spec.AnnotatedEJBReferencesMetaData;
import org.jboss.metadata.javaee.spec.EJBLocalReferenceMetaData;
import org.jboss.metadata.javaee.spec.EJBLocalReferencesMetaData;
import org.jboss.metadata.javaee.spec.EJBReferenceMetaData;
import org.jboss.metadata.javaee.spec.EJBReferencesMetaData;
import org.jboss.metadata.javaee.spec.Environment;
import org.jboss.metadata.javaee.spec.EnvironmentEntriesMetaData;
import org.jboss.metadata.javaee.spec.EnvironmentEntryMetaData;
import org.jboss.metadata.javaee.spec.LifecycleCallbacksMetaData;
import org.jboss.metadata.javaee.spec.MessageDestinationReferenceMetaData;
import org.jboss.metadata.javaee.spec.MessageDestinationReferencesMetaData;
import org.jboss.metadata.javaee.spec.PersistenceContextReferenceMetaData;
import org.jboss.metadata.javaee.spec.PersistenceContextReferencesMetaData;
import org.jboss.metadata.javaee.spec.PersistenceUnitReferenceMetaData;
import org.jboss.metadata.javaee.spec.PersistenceUnitReferencesMetaData;
import org.jboss.metadata.javaee.spec.ResourceEnvironmentReferenceMetaData;
import org.jboss.metadata.javaee.spec.ResourceEnvironmentReferencesMetaData;
import org.jboss.metadata.javaee.spec.ResourceReferenceMetaData;
import org.jboss.metadata.javaee.spec.ResourceReferencesMetaData;
import org.jboss.metadata.javaee.spec.SecurityRoleMetaData;
import org.jboss.metadata.javaee.spec.SecurityRoleRefsMetaData;
import org.jboss.metadata.javaee.spec.ServiceReferenceMetaData;
import org.jboss.metadata.javaee.spec.ServiceReferencesMetaData;
import org.jboss.metadata.javaee.spec.TransactionManagementTypeAdapter;
import org.jboss.metadata.javaee.support.AbstractMappedMetaData;
import org.jboss.metadata.javaee.support.NamedMetaData;
import org.jboss.metadata.javaee.support.NamedMetaDataWithDescriptionGroup;
import org.jboss.metadata.javaee.support.NonNullLinkedHashSet;
import org.jboss.xb.annotations.JBossXmlConstants;
import org.jboss.xb.annotations.JBossXmlModelGroup;

/**
* enterprise-bean/{session,entity,message-driven} metadata
*
* @author <a href="adrian@jboss.com">Adrian Brock</a>
* @author Scott.Stark@jboss.org
* @version $Revision: 1.1 $
*/
@JBossXmlModelGroup(
      kind=JBossXmlConstants.MODEL_GROUP_CHOICE,
      particles={
            @JBossXmlModelGroup.Particle(element=@XmlElement(name="session"), type=JBossSessionBeanMetaData.class),
            @JBossXmlModelGroup.Particle(element=@XmlElement(name="entity"), type=JBossEntityBeanMetaData.class),
            @JBossXmlModelGroup.Particle(element=@XmlElement(name="message-driven"), type=JBossMessageDrivenBeanMetaData.class),
            @JBossXmlModelGroup.Particle(element=@XmlElement(name="consumer"), type=JBossConsumerBeanMetaData.class),
            @JBossXmlModelGroup.Particle(element=@XmlElement(name="ejb"), type=JBossGenericBeanMetaData.class),
            @JBossXmlModelGroup.Particle(element=@XmlElement(name="service"), type=JBossServiceBeanMetaData.class)})
public abstract class JBossEnterpriseBeanMetaData extends NamedMetaDataWithDescriptionGroup
   implements Environment,
   IEnterpriseBeanMetaData<JBossAssemblyDescriptorMetaData, JBossEnterpriseBeansMetaData, JBossEnterpriseBeanMetaData, JBossMetaData>
{
   /** The serialVersionUID */
   private static final long serialVersionUID = 6909774842926430193L;

   /** The enterprise bean container */
   private JBossEnterpriseBeansMetaData enterpriseBeansMetaData;
  
   /** The mapped name */
   private String mappedName;

   /** The ejb class */
   private String ejbClass;

   /** The local jndi name */
   private String localJndiName;
  
   /** Whether to throw an exception if the transaction is marked for rollback */
   private boolean exceptionOnRollback;
  
   /** Whether to persist timers */
   private boolean timerPersistence = true;
  
   /** The configuration name */
   private String configurationName;
  
   /** The invokers */
   private InvokerBindingsMetaData invokers;
  
   /** The determined invokers */
   private transient InvokerBindingsMetaData determinedInvokers;

   /** The ior security config */
   private IORSecurityConfigMetaData iorSecurityConfig;
  
   /** The security proxy */
   private String securityProxy;

   /** The environment */
   private JBossEnvironmentRefsGroupMetaData jndiEnvironmentRefsGroup;

   /** The method attributes */
   private MethodAttributesMetaData methodAttributes;
  
   /** The security domain */
   private String securityDomain;
  
   /** The dependencies */
   private Set<String> depends;
  
   /** The annotations */
   private AnnotationsMetaData annotations;

   /** Ignore dependency */
   private IgnoreDependencyMetaData ignoreDependency;

   /** The aop domain name */
   private String aopDomainName;
  
   /** The pool configuration */
   private PoolConfigMetaData poolConfig;
  
   /** The jndi refs */
   private JndiRefsMetaData jndiRefs;

   /** The security identity */
   private SecurityIdentityMetaData securityIdentity;

   /** The cached container transactions */
   private transient ContainerTransactionsMetaData cachedContainerTransactions;
  
   /** The transaction type cache */
   private transient ConcurrentHashMap<Method, TransactionAttributeType> methodTx;
   /** The transaction type */
   private TransactionManagementType transactionType;

   /**
    * Create the correct JBossEnterpriseBeanMetaData for the input
    * standard bean metadata.
    *
    * @param bean the standard bean metadata
    * @return the corresponding jboss extenstion metadata
    */
   public static JBossEnterpriseBeanMetaData newBean(EnterpriseBeanMetaData bean)
   {
      JBossEnterpriseBeanMetaData jbean = null;
      if(bean instanceof EntityBeanMetaData)
         jbean = new JBossEntityBeanMetaData();
      if(bean instanceof MessageDrivenBeanMetaData)
         jbean = new JBossMessageDrivenBeanMetaData();
      if(bean instanceof SessionBeanMetaData)
         jbean = new JBossSessionBeanMetaData();
      return jbean;
   }

   /**
    * Create a new EnterpriseBeanMetaData.
    */
   public JBossEnterpriseBeanMetaData()
   {
      // For serialization
   }

   /**
    * Get the enterpriseBeansMetaData.
    *
    * @return the enterpriseBeansMetaData.
    */
   public JBossEnterpriseBeansMetaData getEnterpriseBeansMetaData()
   {
      return enterpriseBeansMetaData;
   }

   /**
    * Set the enterpriseBeansMetaData.
    *
    * @param enterpriseBeansMetaData the enterpriseBeansMetaData.
    */
   @XmlTransient
   public void setEnterpriseBeansMetaData(JBossEnterpriseBeansMetaData enterpriseBeansMetaData)
   {
      assert enterpriseBeansMetaData != null : "enterpriseBeansMetaData is null";
     
      this.enterpriseBeansMetaData = enterpriseBeansMetaData;
   }

   /**
    * Get the jbossMetaData.
    *
    * @return the jbossMetaData.
    */
   @XmlTransient
   public JBossMetaData getJBossMetaData()
   {
      if (enterpriseBeansMetaData == null)
         return null;
      return enterpriseBeansMetaData.getEjbJarMetaData();
   }

   /**
    * Get the jbossMetaData.
    *
    * @return the jbossMetaData with check
    */
   @XmlTransient
   public JBossMetaData getJBossMetaDataWithCheck()
   {
      JBossMetaData jbossMetaData = getJBossMetaData();
      if (jbossMetaData == null)
         throw new IllegalStateException("This bean is not a part of a deployment " + this);
      return jbossMetaData;
   }

   /**
    * Get the jndiEnvironmentRefsGroup.
    *
    * @return the jndiEnvironmentRefsGroup.
    */
   public Environment getJndiEnvironmentRefsGroup()
   {
      return jndiEnvironmentRefsGroup;
   }
  
   @XmlElement(type=JBossEnvironmentRefsGroupMetaData.class)
   public void setJndiEnvironmentRefsGroup(Environment env)
   {
      if (env == null)
         throw new IllegalArgumentException("Null jndiEnvironmentRefsGroup");
      JBossEnvironmentRefsGroupMetaData jenv = (JBossEnvironmentRefsGroupMetaData) env;
      if(jndiEnvironmentRefsGroup != null)
         jndiEnvironmentRefsGroup.merge(jenv, null, null, "jboss.xml", "ejb-jar.xml", false);
      else
         jndiEnvironmentRefsGroup = jenv;
   }

   /**
    * Get the ejbName.
    *
    * @return the ejbName.
    */
   public String getEjbName()
   {
      return getName();
   }

   /**
    * Set the ejbName.
    *
    * @param ejbName the ejbName.
    * @throws IllegalArgumentException for a null ejbName
    */
   public void setEjbName(String ejbName)
   {
      setName(ejbName);
   }

   public String getEjbClass()
   {
      return ejbClass;
   }

   @XmlTransient
   public JBossMetaData getEjbJarMetaData()
   {
      return enterpriseBeansMetaData.getEjbJarMetaData();
   }

   /**
    * Get the container transactions
    *
    * @return the container transactions or null for no result
    */
   @XmlTransient
   public ContainerTransactionsMetaData getContainerTransactions()
   {
      if (cachedContainerTransactions != null)
         return cachedContainerTransactions;
      JBossAssemblyDescriptorMetaData assemblyDescriptor = getAssemblyDescriptor();
      if (assemblyDescriptor == null)
         return null;
      return assemblyDescriptor.getContainerTransactionsByEjbName(getEjbName());
   }

   /**
    * Get the method transaction type
    *
    * @param methodName the method name
    * @param params the parameters
    * @param iface the interface type
    * @return the method transaction type
    */
   public TransactionAttributeType getMethodTransactionType(String methodName, Class<?>[] params, MethodInterfaceType iface)
   {
      // default value
      TransactionAttributeType result = null;

      ContainerTransactionsMetaData containerTransactions = getContainerTransactions();
      if (containerTransactions == null || containerTransactions.isEmpty())
         return result;

      ContainerTransactionMetaData bestMatchTransaction = null;
      MethodMetaData bestMatch = null;
      for (ContainerTransactionMetaData transaction : containerTransactions)
      {
         MethodMetaData match = transaction.bestMatch(methodName, params, iface, bestMatch);
         if (match != bestMatch)
         {
            bestMatchTransaction = transaction;
            bestMatch = match;
         }
      }

      if (bestMatchTransaction != null)
         result = bestMatchTransaction.getTransAttribute();

      return result;
   }

   /**
    * Get the transaction type
    *
    * @param m the method
    * @param iface the interface type
    * @return the transaction type
    */
   public TransactionAttributeType getMethodTransactionType(Method m, MethodInterfaceType iface)
   {
      if (m == null)
         return TransactionAttributeType.SUPPORTS;

      TransactionAttributeType result = null;
      if (methodTx != null)
      {
         result = methodTx.get(m);
         if (result != null)
            return result;
      }

      result = getMethodTransactionType(m.getName(), m.getParameterTypes(), iface);

      // provide default if method is not found in descriptor
      if (result == null)
         result = TransactionAttributeType.REQUIRED;

      if (methodTx == null)
         methodTx = new ConcurrentHashMap<Method, TransactionAttributeType>();
      methodTx.put(m, result);
      return result;
   }

   /**
    * Get the exclude list
    *
    * @return the exclude list or null for no result
    */
   @XmlTransient
   public ExcludeListMetaData getExcludeList()
   {
      JBossAssemblyDescriptorMetaData assemblyDescriptor = getAssemblyDescriptor();
      if (assemblyDescriptor == null)
         return null;
      return assemblyDescriptor.getExcludeListByEjbName(getEjbName());
   }

   public String getMappedName()
   {
      return mappedName;
   }

   public void setEjbClass(String ejbClass)
   {
      this.ejbClass = ejbClass;
   }

   public void setMappedName(String mappedName)
   {
      this.mappedName = mappedName;
   }

   /**
    * Whether this is a consumer bean
    *
    * @return true when a consumer bean
    */
   @XmlTransient
   public boolean isConsumer()
   {
      return false;
   }
  
   /**
    * Whether this is a service bean
    *
    * @return true when a service bean
    */
   @XmlTransient
   public boolean isService()
   {
      return false;
   }

   /**
    * Whether this is a session bean
    *
    * @return true when a session bean
    */
   @XmlTransient
   public boolean isSession()
   {
      return false;
   }

   /**
    * Whether this is a message driven bean
    *
    * @return true when a message driven bean
    */
   @XmlTransient
   public boolean isMessageDriven()
   {
      return false;
   }

   /**
    * Whether this is an entity bean
    *
    * @return true when an entity bean
    */
   @XmlTransient
   public boolean isEntity()
   {
      return false;
   }

   /**
    * Is this container managed transactions
    *
    * @return true when CMT
    */
   @XmlTransient
   public boolean isCMT()
   {
      TransactionManagementType type = getTransactionType();
      if (type == null)
         return true;
      else
         return type == TransactionManagementType.CONTAINER;
   }

   /**
    * Is this bean managed transactions
    *
    * @return true when BMT
    */
   @XmlTransient
   public boolean isBMT()
   {
      return isCMT() == false;
   }

   public TransactionManagementType getTransactionType()
   {
      return transactionType;
   }

   @XmlJavaTypeAdapter(TransactionManagementTypeAdapter.class)
   public void setTransactionType(TransactionManagementType transactionType)
   {
      this.transactionType = transactionType;
   }

   /**
    * Get the localJndiName.
    *
    * @return the localJndiName.
    */
   public String getLocalJndiName()
   {
      return localJndiName;
   }

   /**
    * Set the localJndiName.
    *
    * @param localJndiName the localJndiName.
    * @throws IllegalArgumentException for a null localJndiName
    */
   public void setLocalJndiName(String localJndiName)
   {
      if (localJndiName == null)
         throw new IllegalArgumentException("Null localJndiName");
      this.localJndiName = localJndiName;
   }

   /**
    * Determine the localJndiName.
    *
    * @return the localJndiName.
    */
   public String determineLocalJndiName()
   {
      if (localJndiName != null)
         return localJndiName;
     
      String ejbName = getEjbName();
      // Generate a unique name based on ejbName + identityHashCode
      return "local/" + ejbName + '@' + System.identityHashCode(ejbName);
   }

   /**
    * Determine the container jndi name used in the object name
    *
    * @return the jndi name suitable for use in the object name
    */
   @XmlTransient
   public String getContainerObjectNameJndiName()
   {
      return getLocalJndiName();
   }

   /**
    * Get the exceptionOnRollback.
    *
    * @return the exceptionOnRollback.
    */
   public boolean isExceptionOnRollback()
   {
      return exceptionOnRollback;
   }

   /**
    * Set the exceptionOnRollback.
    *
    * @param exceptionOnRollback the exceptionOnRollback.
    */
   public void setExceptionOnRollback(boolean exceptionOnRollback)
   {
      this.exceptionOnRollback = exceptionOnRollback;
   }

   /**
    * Get the timerPersistence.
    *
    * @return the timerPersistence.
    */
   public boolean isTimerPersistence()
   {
      return timerPersistence;
   }

   /**
    * Set the timerPersistence.
    *
    * @param timerPersistence the timerPersistence.
    */
   public void setTimerPersistence(boolean timerPersistence)
   {
      this.timerPersistence = timerPersistence;
   }

   /**
    * Get the configurationName.
    *
    * @return the configurationName.
    */
   public String getConfigurationName()
   {
      return configurationName;
   }

   /**
    * Set the configurationName.
    *
    * @param configurationName the configurationName.
    * @throws IllegalArgumentException for a null configurationName
    */
   public void setConfigurationName(String configurationName)
   {
      if (configurationName == null)
         throw new IllegalArgumentException("Null configurationName");
      this.configurationName = configurationName;
   }
  
   /**
    * Determine the configuration name
    *
    * @return the configuration name
    */
   public String determineConfigurationName()
   {
      if (configurationName != null)
         return configurationName;
     
      return getDefaultConfigurationName();
   }

   /**
    * Get the container configuration
    *
    * @return the container configuration
    */
   public ContainerConfigurationMetaData determineContainerConfiguration()
   {
      String name = determineConfigurationName();
      ContainerConfigurationMetaData result = getJBossMetaDataWithCheck().getContainerConfiguration(name);
      if (result == null)
         throw new IllegalStateException("Container configuration not found: " + name + " available: " +  getJBossMetaDataWithCheck().getContainerConfigurations());
      return result;
   }
  
   public void setPoolConfig(PoolConfigMetaData poolConfig)
   {
      this.poolConfig = poolConfig;
   }
  
   /**
    * Get the default configuration name
    *
    * @return the default name
    */
   public abstract String getDefaultConfigurationName();

   /**
    * Get the securityProxy.
    *
    * @return the securityProxy.
    */
   public String getSecurityProxy()
   {
      return securityProxy;
   }

   /**
    * Set the securityProxy.
    *
    * @param securityProxy the securityProxy.
    * @throws IllegalArgumentException for a null securityProxy
    */
   public void setSecurityProxy(String securityProxy)
   {
      if (securityProxy == null)
         throw new IllegalArgumentException("Null securityProxy");
      this.securityProxy = securityProxy;
   }

   /**
    * Get the securityDomain.
    *
    * @return the securityDomain.
    */
   public String getSecurityDomain()
   {
      return securityDomain;
   }

   /**
    * Set the securityDomain.
    *
    * @param securityDomain the securityDomain.
    * @throws IllegalArgumentException for a null securityDomain
    */
   @XmlElement(required=false)
   public void setSecurityDomain(String securityDomain)
   {
      if (securityDomain == null)
         throw new IllegalArgumentException("Null securityDomain");
      this.securityDomain = securityDomain;
   }

   /**
    * Get the depends.
    *
    * @return the depends.
    */
   public Set<String> getDepends()
   {
      return depends;
   }

   /**
    * Set the depends.
    *
    * @param depends the depends.
    * @throws IllegalArgumentException for a null depends
    */
   @XmlElement(/*type=NonNullLinkedHashSet.class*/)
   public void setDepends(Set<String> depends)
   {
      if (depends == null)
         throw new IllegalArgumentException("Null depends");
      this.depends = depends;
   }

   /**
    * Get the depends.
    *
    * @return the depends.
    */
   public Set<String> determineAllDepends()
   {
      NonNullLinkedHashSet<String> result = new NonNullLinkedHashSet<String>();

      Set<String> depends = getDepends();
      if (depends != null)
         result.addAll(depends);
     
      ContainerConfigurationMetaData containerConfigurationMetaData = determineContainerConfiguration();
      if (containerConfigurationMetaData != null)
      {
         depends = containerConfigurationMetaData.getDepends();
         if (depends != null)
            result.addAll(depends);
      }
     
      return result;
   }

   /**
    * Get the invokers.
    *
    * @return the invokers.
    */
   public InvokerBindingsMetaData getInvokerBindings()
   {
      return invokers;
   }

   /**
    * Set the invokers.
    *
    * @param invokers the invokers.
    * @throws IllegalArgumentException for a null invokers
    */
   public void setInvokerBindings(InvokerBindingsMetaData invokers)
   {
      if (invokers == null)
         throw new IllegalArgumentException("Null invokers");
      this.invokers = invokers;
   }

   /**
    * Determine the invokers
    *
    * @return the invokers.
    */
   public InvokerBindingsMetaData determineInvokerBindings()
   {
      // We already worked it out
      if (determinedInvokers != null)
         return determinedInvokers;
     
      // Use anything configured
      if (invokers != null)
      {
         determinedInvokers = invokers;
         return determinedInvokers;
      }
     
      // Look at the container configuration
      ContainerConfigurationMetaData containerConfiguration = determineContainerConfiguration();
      Set<String> invokerProxyBindingNames = containerConfiguration.getInvokerProxyBindingNames();
      if (invokerProxyBindingNames != null && invokerProxyBindingNames.isEmpty() == false)
      {
         determinedInvokers = new InvokerBindingsMetaData();
        
         // Like the original code, they all get bound with the same name?
         String jndiName = getDefaultInvokerJndiName();
         for (String name : invokerProxyBindingNames)
         {
            InvokerBindingMetaData invoker = new InvokerBindingMetaData();
            invoker.setInvokerProxyBindingName(name);
            if (jndiName != null)
               invoker.setJndiName(jndiName);
            determinedInvokers.add(invoker);
         }
      }
      else
      {
         determinedInvokers = getDefaultInvokers();
      }
      return determinedInvokers;
   }

   /**
    * Determine an invoker binding
    *
    * @param invokerName the invoker proxy binding name
    * @return the invoke binding
    * @throws IllegalStateException if there is no such binding
    */
   public InvokerBindingMetaData determineInvokerBinding(String invokerName)
   {
      InvokerBindingMetaData binding = determineInvokerBindings().get(invokerName);
      if (binding == null)
          throw new IllegalStateException("No such binding: " + invokerName + " available: " + determinedInvokers);
      return binding;
   }

   /**
    * Determine the jndi name for invoker bindings that come from the container configuration
    *
    * @return the jndi name suitable for use on the default invoker
    */
   protected String getDefaultInvokerJndiName()
   {
      return null;
   }

   /**
    * Get the default invokers
    *
    * @return the default invokers
    */
   protected InvokerBindingsMetaData getDefaultInvokers()
   {
      InvokerBindingsMetaData bindings = new InvokerBindingsMetaData();
      InvokerBindingMetaData binding = new InvokerBindingMetaData();
      binding.setInvokerProxyBindingName(getDefaultInvokerName());
      String jndiName = getDefaultInvokerJndiName();
      if (jndiName != null)
         binding.setJndiName(getDefaultInvokerJndiName());
      bindings.add(binding);
      return bindings;
   }

   /**
    * Get the default invokers
    *
    * @return the default invokers
    */
   protected abstract String getDefaultInvokerName();

   public EJBLocalReferenceMetaData getEjbLocalReferenceByName(String name)
   {
      return AbstractMappedMetaData.getByName(name, getEjbLocalReferences());
   }

   @XmlTransient
   public EJBLocalReferencesMetaData getEjbLocalReferences()
   {
      EJBLocalReferencesMetaData refs = null;
      if(jndiEnvironmentRefsGroup != null)
         refs = jndiEnvironmentRefsGroup.getEjbLocalReferences();
      return refs;
   }

   public EJBReferenceMetaData getEjbReferenceByName(String name)
   {
      return AbstractMappedMetaData.getByName(name, getEjbReferences());
   }

   @XmlTransient
   public EJBReferencesMetaData getEjbReferences()
   {
      EJBReferencesMetaData refs = null;
      if(jndiEnvironmentRefsGroup != null)
         refs = jndiEnvironmentRefsGroup.getEjbReferences();
      return refs;
   }
   // TODO?
   @XmlTransient
   public AnnotatedEJBReferencesMetaData getAnnotatedEjbReferences()
   {
      AnnotatedEJBReferencesMetaData refs = null;
      if(jndiEnvironmentRefsGroup != null)
         refs = jndiEnvironmentRefsGroup.getAnnotatedEjbReferences();
      return refs;
   }

   @XmlTransient
   public EnvironmentEntriesMetaData getEnvironmentEntries()
   {
      EnvironmentEntriesMetaData env = null;
      if(jndiEnvironmentRefsGroup != null)
         env = jndiEnvironmentRefsGroup.getEnvironmentEntries();
      return env;
   }

   public EnvironmentEntryMetaData getEnvironmentEntryByName(String name)
   {
      return AbstractMappedMetaData.getByName(name, getEnvironmentEntries());
   }

   public MessageDestinationReferenceMetaData getMessageDestinationReferenceByName(String name)
   {
      return AbstractMappedMetaData.getByName(name, getMessageDestinationReferences());
   }

   @XmlTransient
   public MessageDestinationReferencesMetaData getMessageDestinationReferences()
   {
      MessageDestinationReferencesMetaData refs = null;
      if(jndiEnvironmentRefsGroup != null)
         refs = jndiEnvironmentRefsGroup.getMessageDestinationReferences();
      return refs;
   }

   public PersistenceContextReferenceMetaData getPersistenceContextReferenceByName(String name)
   {
      return AbstractMappedMetaData.getByName(name, getPersistenceContextRefs());
   }

   @XmlTransient
   public PersistenceContextReferencesMetaData getPersistenceContextRefs()
   {
      PersistenceContextReferencesMetaData refs = null;
      if(jndiEnvironmentRefsGroup != null)
         refs = jndiEnvironmentRefsGroup.getPersistenceContextRefs();
      return refs;
   }

   public PersistenceUnitReferenceMetaData getPersistenceUnitReferenceByName(String name)
   {
      return AbstractMappedMetaData.getByName(name, getPersistenceUnitRefs());
   }

   @XmlTransient
   public PersistenceUnitReferencesMetaData getPersistenceUnitRefs()
   {
      PersistenceUnitReferencesMetaData refs = null;
      if(jndiEnvironmentRefsGroup != null)
         refs = jndiEnvironmentRefsGroup.getPersistenceUnitRefs();
      return refs;
   }

   public PoolConfigMetaData getPoolConfig()
   {
      return poolConfig;
   }
  
   @XmlTransient
   public LifecycleCallbacksMetaData getPostConstructs()
   {
      LifecycleCallbacksMetaData lcs = null;
      if(jndiEnvironmentRefsGroup != null)
         lcs = jndiEnvironmentRefsGroup.getPostConstructs();
      return lcs;
   }

   @XmlTransient
   public LifecycleCallbacksMetaData getPreDestroys()
   {
      LifecycleCallbacksMetaData lcs = null;
      if(jndiEnvironmentRefsGroup != null)
         lcs = jndiEnvironmentRefsGroup.getPreDestroys();
      return lcs;
   }

   public ResourceEnvironmentReferenceMetaData getResourceEnvironmentReferenceByName(String name)
   {
      return AbstractMappedMetaData.getByName(name, getResourceEnvironmentReferences());
   }

   @XmlTransient
   public ResourceEnvironmentReferencesMetaData getResourceEnvironmentReferences()
   {
      ResourceEnvironmentReferencesMetaData refs = null;
      if(jndiEnvironmentRefsGroup != null)
         refs = jndiEnvironmentRefsGroup.getResourceEnvironmentReferences();
      return refs;
   }

   public ResourceReferenceMetaData getResourceReferenceByName(String name)
   {
      return AbstractMappedMetaData.getByName(name, getResourceReferences());
   }

   @XmlTransient
   public ResourceReferencesMetaData getResourceReferences()
   {
      ResourceReferencesMetaData refs = null;
      if(jndiEnvironmentRefsGroup != null)
         refs = jndiEnvironmentRefsGroup.getResourceReferences();
      return refs;
   }

   public ServiceReferenceMetaData getServiceReferenceByName(String name)
   {
      return AbstractMappedMetaData.getByName(name, getServiceReferences());
   }

   @XmlTransient
   public ServiceReferencesMetaData getServiceReferences()
   {
      ServiceReferencesMetaData refs = null;
      if(jndiEnvironmentRefsGroup != null)
         refs = jndiEnvironmentRefsGroup.getServiceReferences();
      return refs;
   }

   /**
    * Provies a common accessor that returns an empty security role refs.
    * Subclasses that support security-role-refs must override.
    * @return An empty security role refs.
    */
   @XmlTransient
   public SecurityRoleRefsMetaData getSecurityRoleRefs()
   {
      return new SecurityRoleRefsMetaData();
   }

   /**
    * Get the annotations.
    *
    * @return the annotations.
    */
   public AnnotationsMetaData getAnnotations()
   {
      return annotations;
   }

   /**
    * Set the annotations.
    *
    * @param annotations the annotations.
    * @throws IllegalArgumentException for a null annotations
    */
   @XmlElement(name="annotation")
   public void setAnnotations(AnnotationsMetaData annotations)
   {
      if (annotations == null)
         throw new IllegalArgumentException("Null annotations");
      this.annotations = annotations;
   }

   /**
    * Get the aopDomainName.
    *
    * @return the aopDomainName.
    */
   public String getAopDomainName()
   {
      return aopDomainName;
   }

   /**
    * Set the aopDomainName.
    *
    * @param aopDomainName the aopDomainName.
    * @throws IllegalArgumentException for a null aopDomainName
    */
   public void setAopDomainName(String aopDomainName)
   {
      if (aopDomainName == null)
         throw new IllegalArgumentException("Null aopDomainName");
      this.aopDomainName = aopDomainName;
   }

   /**
    * Get the jndiRefs.
    *
    * @return the jndiRefs.
    */
   public JndiRefsMetaData getJndiRefs()
   {
      return jndiRefs;
   }

   /**
    * Set the jndiRefs.
    *
    * @param jndiRefs the jndiRefs.
    * @throws IllegalArgumentException for a null jndiRefs
    */
   @XmlElement(name="jndi-ref")
   public void setJndiRefs(JndiRefsMetaData jndiRefs)
   {
      if (jndiRefs == null)
         throw new IllegalArgumentException("Null jndiRefs");
      this.jndiRefs = jndiRefs;
   }

   /**
    * Get a security role
    *
    * @param roleName the role name
    * @return the security role or null if not found
    */
   @XmlTransient
   public SecurityRoleMetaData getSecurityRole(String roleName)
   {
      JBossAssemblyDescriptorMetaData assemblyDescriptor = getJBossMetaDataWithCheck().getAssemblyDescriptor();
      if (assemblyDescriptor == null)
         return null;
      else
         return assemblyDescriptor.getSecurityRole(roleName);
   }

   /**
    * Get a security role's principals
    *
    * @param roleName the role name
    * @return the principals or null if not found
    */
   public Set<String> getSecurityRolePrincipals(String roleName)
   {
      JBossAssemblyDescriptorMetaData assemblyDescriptor = getJBossMetaDataWithCheck().getAssemblyDescriptor();
      if (assemblyDescriptor == null)
         return null;
      else
         return assemblyDescriptor.getSecurityRolePrincipals(roleName);
   }

   /**
    * Get the methods permissions
    *
    * @return the method permissions or null for no result
    */
   @XmlTransient
   public MethodPermissionsMetaData getMethodPermissions()
   {
      JBossAssemblyDescriptorMetaData assemblyDescriptor = getAssemblyDescriptor();
      if (assemblyDescriptor == null)
         return null;
      return assemblyDescriptor.getMethodPermissionsByEjbName(getEjbName());
   }

   /**
    * A somewhat tedious method that builds a Set<Principal> of the roles
    * that have been assigned permission to execute the indicated method. The
    * work performed is tedious because of the wildcard style of declaring
    * method permission allowed in the ejb-jar.xml descriptor. This method is
    * called by the Container.getMethodPermissions() when it fails to find the
    * prebuilt set of method roles in its cache.
    *
    * @param methodName the method name
    * @param params the parameters
    * @param interfaceType the interface type
    * @return The Set<String> for the application domain roles that caller principal's are to be validated against.
    */
   public Set<String> getMethodPermissions(String methodName, Class<?>[] params, MethodInterfaceType interfaceType)
   {
      Set<String> result = null;

      JBossMetaData jbossMetaData = getJBossMetaDataWithCheck();
     
      // First check the excluded method list as this takes priority over
      // all other assignments
      ExcludeListMetaData excluded = getExcludeList();
      if (excluded != null && excluded.matches(methodName, params, interfaceType))
      {
         // No one is allowed to execute this method so add a role that
         // fails to equate to any Principal or Principal name and return.
         // We don't return null to differentiate between an explicit
         // assignment of no access and no assignment information.
         if (result == null)
            result = new HashSet<String>();
         result.add(SecurityRoleNames.NOBODY_PRINCIPAL);
         return result;
      }

      // Check the permissioned methods list
      MethodPermissionsMetaData permissions = getMethodPermissions();
      if (permissions != null)
      {
         for (MethodPermissionMetaData permission : permissions)
         {
            if (permission.isNotChecked(methodName, params, interfaceType))
            {
               if (result == null)
                  result = new HashSet<String>();
               result.clear();
               result.add(SecurityRoleNames.ANYBODY_PRINCIPAL);
               break;
            }
            else if (permission.matches(methodName, params, interfaceType))
            {
               Set<String> roles = permission.getRoles();
               if (roles != null)
               {
                  if (result == null)
                     result = new HashSet<String>();
                  for (String roleName : roles)
                  {
                     // Get any extra principal names assigned to the role
                     Set<String> principals = getSecurityRolePrincipals(roleName);
                     if (principals != null)
                     {
                        for (String principal : principals)
                        {
                           result.add(principal);
                        }
                     }
                     // Also add the role name itself
                     result.add(roleName);
                  }
               }
            }
         }
      }

      if (jbossMetaData.isExcludeMissingMethods() == false && result == null)
      {
            result = new HashSet<String>();
            result.add(SecurityRoleNames.ANYBODY_PRINCIPAL);
      }

      if (result == null)
         result = Collections.emptySet();
      return result;
   }
  
   /**
    * Check to see if there was a method-permission or exclude-list statement
    * for the given method.
    *
    * @param methodName - the method name
    * @param params - the method parameter signature
    * @param interfaceType - the method interface type
    * @return true if a matching method permission exists, false if no match
    */
   public boolean hasMethodPermissions(String methodName, Class<?>[] params, MethodInterfaceType interfaceType)
   {
      // First check the excluded method list as this takes priority over
      // all other assignments
      ExcludeListMetaData excluded = getExcludeList();
      if (excluded != null && excluded.matches(methodName, params, interfaceType))
         return true;

      // Check the permissioned methods list
      MethodPermissionsMetaData permissions = getMethodPermissions();
      if (permissions != null)
      {
         for (MethodPermissionMetaData permission : permissions)
         {
            if (permission.matches(methodName, params, interfaceType))
               return true;
         }
      }

      // No match
      return false;
   }

   /**
    * Get the iorSecurityConfig.
    *
    * @return the iorSecurityConfig.
    */
   public IORSecurityConfigMetaData getIorSecurityConfig()
   {
      return iorSecurityConfig;
   }

   /**
    * Set the iorSecurityConfig.
    *
    * @param iorSecurityConfig the iorSecurityConfig.
    * @throws IllegalArgumentException for a null iorSecurityConfig
    */
   public void setIorSecurityConfig(IORSecurityConfigMetaData iorSecurityConfig)
   {
      if (iorSecurityConfig == null)
         throw new IllegalArgumentException("Null iorSecurityConfig");
      this.iorSecurityConfig = iorSecurityConfig;
   }

   /**
    * Get the ignoreDependency.
    *
    * @return the ignoreDependency.
    */
   public IgnoreDependencyMetaData getIgnoreDependency()
   {
      return ignoreDependency;
   }

   /**
    * Set the ignoreDependency.
    *
    * @param ignoreDependency the ignoreDependency.
    * @throws IllegalArgumentException for a null ignoreDependency
    */
   public void setIgnoreDependency(IgnoreDependencyMetaData ignoreDependency)
   {
      if (ignoreDependency == null)
         throw new IllegalArgumentException("Null ignoreDependency");
      this.ignoreDependency = ignoreDependency;
   }

   /**
    * Get the methodAttributes.
    *
    * @return the methodAttributes.
    */
   public MethodAttributesMetaData getMethodAttributes()
   {
      return methodAttributes;
   }

   /**
    * Set the methodAttributes.
    *
    * @param methodAttributes the methodAttributes.
    * @throws IllegalArgumentException for a null methodAttributes
    */
   public void setMethodAttributes(MethodAttributesMetaData methodAttributes)
   {
      if (methodAttributes == null)
         throw new IllegalArgumentException("Null methodAttributes");
      this.methodAttributes = methodAttributes;
   }

   /**
    * Is this method a read-only method
    *
    * @param methodName the method name
    * @return true for read only
    */
   public boolean isMethodReadOnly(String methodName)
   {
      if (methodAttributes == null)
         return false;
      return methodAttributes.isMethodReadOnly(methodName);
   }

   /**
    * Is this method a read-only method
    *
    * @param method the method
    * @return true for read only
    */
   public boolean isMethodReadOnly(Method method)
   {
      if (method == null)
         return false;
      return isMethodReadOnly(method.getName());
   }

   /**
    * Get the transaction timeout for the method
    *
    * @param methodName the method name
    * @return the transaction timeout
    */
   public int getMethodTransactionTimeout(String methodName)
   {
      if (methodAttributes == null)
         return 0;
      return methodAttributes.getMethodTransactionTimeout(methodName);
   }

   /**
    * Get the transaction timeout for the method
    *
    * @param method the method
    * @return the transaction timeout
    */
   public int getMethodTransactionTimeout(Method method)
   {
      if (method == null)
         return 0;
      return getMethodTransactionTimeout(method.getName());
   }

   /**
    * Get the securityIdentity.
    *
    * @return the securityIdentity.
    */
   public SecurityIdentityMetaData getSecurityIdentity()
   {
      return securityIdentity;
   }

   /**
    * Set the securityIdentity.
    *
    * @param securityIdentity the securityIdentity.
    * @throws IllegalArgumentException for a null securityIdentity
    */
   public void setSecurityIdentity(SecurityIdentityMetaData securityIdentity)
   {
      if (securityIdentity == null)
         throw new IllegalArgumentException("Null securityIdentity");
      this.securityIdentity = securityIdentity;
   }

   @Override
   public void merge(NamedMetaData override, NamedMetaData original)
   {
      throw new RuntimeException("wrong merge method called");
   }
  
   public void merge(JBossEnterpriseBeanMetaData override, EnterpriseBeanMetaData original)
   {
      this.merge(override, original, "jboss.xml", "ejb-jar.xml", true);
   }
   public void merge(JBossEnterpriseBeanMetaData override, EnterpriseBeanMetaData original,
         String overrideFile, String overridenFile, boolean mustOverride)
   {
      super.merge(override, original);
      if(override != null && override.getEjbClass() != null)
         setEjbClass(override.getEjbClass());
      else if(original != null && original.getEjbClass() != null)
         setEjbClass(original.getEjbClass());
      if(override != null && override.getName() != null)
         setName(override.getName());
      else if(original != null && original.getName() != null)
         setName(original.getName());
      if(override != null && override.getMappedName() != null)
         setMappedName(override.getMappedName());
      else if(original != null && original.getMappedName() != null)
         setMappedName(original.getMappedName());

      // transactionType
      if(override != null && override.getTransactionType() != null)
         transactionType = override.getTransactionType();
      else if(original != null && original.getTransactionType() != null)
         transactionType = original.getTransactionType();

      if(override != null)
      {
         if(override.getAopDomainName() != null)
            setAopDomainName(override.getAopDomainName());
         if(override.getConfigurationName() != null)
            setConfigurationName(override.getConfigurationName());
         if(override.getAnnotations() != null)
            setAnnotations(override.getAnnotations());
         if(override.getDepends() != null)
            setDepends(override.getDepends());
         setExceptionOnRollback(override.isExceptionOnRollback());
         if(override.getIgnoreDependency() != null)
            setIgnoreDependency(override.getIgnoreDependency());
         if(override.getInvokerBindings() != null)
            setInvokerBindings(override.getInvokerBindings());
         if(override.getIorSecurityConfig() != null)
            setIorSecurityConfig(override.getIorSecurityConfig());
         if(override.getSecurityProxy() != null)
            setSecurityProxy(override.getSecurityProxy());
      }

      if(this.jndiEnvironmentRefsGroup == null)
         jndiEnvironmentRefsGroup = new JBossEnvironmentRefsGroupMetaData();
      Environment env = original != null ? original.getJndiEnvironmentRefsGroup() : null;
      JBossEnvironmentRefsGroupMetaData jenv = null;
      ResourceManagersMetaData resourceMgrs = this.getJBossMetaData().getResourceManagers();
      if( override != null )
      {
         ResourceManagersMetaData resourceMgrsOverride = override.getJBossMetaData().getResourceManagers();
         if(resourceMgrsOverride != null)
            resourceMgrs = resourceMgrsOverride;
         jenv = (JBossEnvironmentRefsGroupMetaData) override.getJndiEnvironmentRefsGroup();
      }
      jndiEnvironmentRefsGroup.merge(jenv, env, resourceMgrs, overridenFile, overrideFile, mustOverride);

      // Fixup the invoker binding references on ejb refs
      InvokerBindingsMetaData invokerBindings = getInvokerBindings();
      if (invokerBindings != null && invokerBindings.isEmpty() == false)
      {
         for (InvokerBindingMetaData invokerBinding : invokerBindings)
         {
            if(invokerBinding.getEjbRefs() != null)
            {
               for(InvokerBindingMetaData.EjbRef ejbRef : invokerBinding.getEjbRefs())
               {
                  EJBReferenceMetaData targetEjbRef = jndiEnvironmentRefsGroup.getEjbReferenceByName(ejbRef.getEjbRefName());
                  if (targetEjbRef == null)
                     throw new IllegalStateException("ejb-ref " + ejbRef.getEjbRefName() + " found on invoker " + invokerBinding.getName() + " but it does not exist for ejb: " + getName());
                  targetEjbRef.addInvokerBinding(invokerBinding.getName(), ejbRef.getJndiName());
               }
            }
         }
      }
     
      // Fixup the security identity
      SecurityIdentityMetaData jbossSecurityIdentity = null;
      if (override != null && override.getSecurityIdentity() != null)
         jbossSecurityIdentity = override.getSecurityIdentity();
      SecurityIdentityMetaData originalSecurityIdentity = null;
      if(original != null)
         originalSecurityIdentity = original.getSecurityIdentity();
      if(jbossSecurityIdentity != null || originalSecurityIdentity != null)
      {
         if(securityIdentity == null)
            securityIdentity = new SecurityIdentityMetaData();
         securityIdentity.merge(jbossSecurityIdentity, originalSecurityIdentity);
      }
   }

   /**
    * Get the assembly descriptor
    *
    * @return the ejbJarMetaData.
    */
   protected JBossAssemblyDescriptorMetaData getAssemblyDescriptor()
   {
      JBossMetaData ejbJar = getEjbJarMetaData();
      if (ejbJar == null)
         return null;
      return ejbJar.getAssemblyDescriptor();
   }
  
}
TOP

Related Classes of org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData

TOP
Copyright © 2018 www.massapi.com. 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.