I implemented the approach suggested by Ole Husgaard <[EMAIL PROTECTED]> for
externalizing the container interceptors. It was a simple change and affects the
following classes:

M src/main/org/jboss/ejb/Container.java
- Added public abstract void addInterceptor(Interceptor in);

M src/main/org/jboss/ejb/ContainerFactory.java
- Changed the container interceptors setup to use the ContainerInterceptors class. An 
example:
               // Create interceptors
               int transType = ((MessageDrivenMetaData)bean).isContainerManagedTx() ? 
ContainerInterceptors.CMT :
ContainerInterceptors.BMT;
               ContainerInterceptors.addInterceptors(container, transType, 
metricsEnabled, conf.getContainerInterceptorsConf());

M src/main/org/jboss/ejb/Interceptor.java
- Removed unused import com.dreambean.ejx.ejb.EnterpriseBean;

M src/main/org/jboss/metadata/ConfigurationMetaData.java
- Added Element containerInterceptorsConf;  getContainerInterceptorsConf() + parsing.

M src/resources/org/jboss/metadata/jboss.dtd
- Added the following to the container-configuration element
<!ELEMENT container-interceptors (interceptor+)>
<!ELEMENT interceptor (#PCDATA)>
<!ATTLIST interceptor transaction     (Bean | Container | Both )  "Both">
<!ATTLIST interceptor metricsEnabled  (true | false )  "false">

New src/main/org/jboss/ejb/ContainerInterceptors.java
- A utility class that manages the logic for applying the container-interceptors
configuration to a Container:

    /** Given a container-interceptors element of a container-configuration,
    add the indicated interceptors to the container depending on the container
    transcation type and metricsEnabled flag.
    */
    public static void addInterceptors(Container container, int transType, boolean 
metricsEnabled,
         Element element)
    {
        Iterator interceptorElements = MetaData.getChildrenByTagName(element, 
"interceptor");
        String transaction = getTransactionValue(transType);
        ClassLoader loader = container.getClassLoader();
        while( interceptorElements.hasNext() )
        {
            Element ielement = (Element) interceptorElements.next();
            String transAttr = ielement.getAttribute("transaction");
            if( transAttr.length() == 0 || transAttr.equalsIgnoreCase(transaction) )
            {   // The transaction type matches the container, check the metricsEnabled
                String metricsAttr = ielement.getAttribute("metricsEnabled");
                boolean metricsInterceptor = metricsAttr.equalsIgnoreCase("true");
                if( metricsEnabled == false && metricsInterceptor == true )
                    continue;

                String className = null;
                try
                {
                    className = MetaData.getElementContent(ielement);
                    Class clazz = loader.loadClass(className);
                    Interceptor interceptor = (Interceptor) clazz.newInstance();
                    container.addInterceptor(interceptor);
                }
                catch(Exception e)
                {
                     Logger.warning("Could not load the "+className+" interceptor for 
this container");
                     Logger.exception(e);
                }
            }
        }
       // Finally we add the last interceptor from the container
       container.addInterceptor(container.createContainerInterceptor());
    }

The standardjboss.xml config file changes to include the current ContainerFactory
interceptor setups. An example:
  <container-configuration>
   <container-name>Standard Stateless SessionBean</container-name>
   <call-logging>false</call-logging>
   
<container-invoker>org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker</container-invoker>
   <container-interceptors>
    <interceptor>org.jboss.ejb.plugins.LogInterceptor</interceptor>
    <interceptor>org.jboss.ejb.plugins.SecurityInterceptor</interceptor>
    <!-- CMT -->
    <interceptor 
transaction="Container">org.jboss.ejb.plugins.TxInterceptorCMT</interceptor>
    <interceptor transaction="Container" 
metricsEnabled="true">org.jboss.ejb.plugins.MetricsInterceptor</interceptor>
    <interceptor 
transaction="Container">org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor</interceptor>
    <!-- BMT -->
    <interceptor 
transaction="Bean">org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor</interceptor>
    <interceptor 
transaction="Bean">org.jboss.ejb.plugins.TxInterceptorBMT</interceptor>
    <interceptor transaction="Bean" 
metricsEnabled="true">org.jboss.ejb.plugins.MetricsInterceptor</interceptor>
   </container-interceptors>
   <instance-pool>org.jboss.ejb.plugins.StatelessSessionInstancePool</instance-pool>
...
  </container-configuration>

Let me know if there are any objections/questions. If not, I'll commit the change
late Monday night.



Reply via email to