[jboss-cvs] JBossAS SVN: r73748 - in projects/metadata/trunk/src: main/java/org/jboss/metadata/annotation/creator/ejb and 7 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed May 28 11:19:21 EDT 2008


Author: alex.loubyansky at jboss.com
Date: 2008-05-28 11:19:20 -0400 (Wed, 28 May 2008)
New Revision: 73748

Added:
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/AbstractEnterpriseBeanProcessor.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/AbstractSessionBeanProcessor.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/AbstractTransactionAttributeProcessor.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/ApplicationExceptionProcessor.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/AroundInvokeProcessor.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/DenyAllProcessor.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/EjbNameThreadLocal.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/EntityProcessor.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/InitProcessor.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/InterceptorsProcessor.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/JBoss50Creator.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/LocalHomeProcessor.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/LocalProcessor.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/MessageDrivenProcessor.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/PermitAllProcessor.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/PostActivateMethodProcessor.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/PrePassivateMethodProcessor.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/RemoteHomeProcessor.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/RemoteProcessor.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/RemoveProcessor.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/RolesAllowedProcessor.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/RunAsProcessor.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/StatefulProcessor.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/StatelessProcessor.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/TimeoutProcessor.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/TransactionAttributeClassProcessor.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/TransactionAttributeMethodProcessor.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/jboss/
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/jboss/AbstractComponentProcessor.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/jboss/PostConstructMethodProcessor.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/jboss/PreDestroyMethodProcessor.java
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/JBossAnnotationEjb3UnitTestCase.java
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/ejb/JBossAssemblyDescriptorOverrideUnitTestCase.java
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/ejb/JBossEnterpriseBeanOverrideUnitTestCase.java
Modified:
   projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/InvokerBindingsMetaData.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/JBossAssemblyDescriptorMetaData.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/JBossEnterpriseBeanMetaData.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/JBossEnterpriseBeansMetaData.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/JBossEnvironmentRefsGroupMetaData.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/JBossMetaData.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/javaee/jboss/AnnotationsMetaData.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/javaee/support/AbstractMappedMetaData.java
Log:
JBMETA-20. JBoss5Crearor; incomplete.

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/AbstractEnterpriseBeanProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/AbstractEnterpriseBeanProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/AbstractEnterpriseBeanProcessor.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,146 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.annotation.creator.ejb.jboss;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Method;
+
+import org.jboss.metadata.annotation.creator.DeclareRolesProcessor;
+import org.jboss.metadata.annotation.creator.Processor;
+import org.jboss.metadata.annotation.creator.jboss.AbstractComponentProcessor;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBossAssemblyDescriptorMetaData;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeansMetaData;
+import org.jboss.metadata.ejb.jboss.JBossEnvironmentRefsGroupMetaData;
+import org.jboss.metadata.ejb.jboss.JBossMetaData;
+import org.jboss.metadata.ejb.spec.ExcludeListMetaData;
+import org.jboss.metadata.ejb.spec.InterceptorBindingsMetaData;
+import org.jboss.metadata.ejb.spec.MethodPermissionsMetaData;
+import org.jboss.metadata.javaee.spec.SecurityRolesMetaData;
+
+
+/**
+ * A AbstractEnterpriseBeanProcessor.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractEnterpriseBeanProcessor<MD extends JBossEnterpriseBeanMetaData>
+   extends AbstractComponentProcessor<MD>
+   implements Processor<JBossMetaData, Class<?>>
+{
+   protected abstract MD create(Class<?> beanClass);
+
+   protected AbstractEnterpriseBeanProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+      // @TransactionAttribute
+      addTypeProcessor(new TransactionAttributeClassProcessor<MD>(finder));
+      addMethodProcessor(new TransactionAttributeMethodProcessor<MD>(finder));
+      // @RunAs
+      addTypeProcessor(new RunAsProcessor(finder));
+      // @DeclareRoles
+      addTypeProcessor(new DeclareRolesProcessor(finder));
+      // @DenyAll
+      addMethodProcessor(new DenyAllProcessor(finder));
+      // @RolesAllowed
+      addTypeProcessor(new RolesAllowedProcessor<Class>(finder));
+      addMethodProcessor(new RolesAllowedProcessor<Method>(finder));
+      // @PermitAll
+      addTypeProcessor(new PermitAllProcessor<Class>(finder));
+      addMethodProcessor(new PermitAllProcessor<Method>(finder));
+      // @Interceptors
+      addTypeProcessor(new InterceptorsProcessor<Class>(finder));
+      addMethodProcessor(new InterceptorsProcessor<Method>(finder));
+   }
+
+   /**
+    * TODO: this should iterate over all method processors 
+    */
+   public void process(JBossMetaData ejbJarMetaData, Class<?> beanClass)
+   {
+      MD beanMetaData = create(beanClass);
+      if(beanMetaData == null)
+         return;
+
+      EjbNameThreadLocal.ejbName.set(beanMetaData.getEjbName());
+
+      JBossEnvironmentRefsGroupMetaData env = (JBossEnvironmentRefsGroupMetaData) beanMetaData.getJndiEnvironmentRefsGroup();
+      if(env == null)
+      {
+         env = new JBossEnvironmentRefsGroupMetaData();
+         beanMetaData.setJndiEnvironmentRefsGroup(env);
+      }
+      super.process(env, beanClass);
+
+      
+      if(ejbJarMetaData.getEnterpriseBeans() == null)
+         ejbJarMetaData.setEnterpriseBeans(new JBossEnterpriseBeansMetaData());
+      
+      ejbJarMetaData.getEnterpriseBeans().add(beanMetaData);
+      processClass(beanMetaData, beanClass);
+
+      JBossAssemblyDescriptorMetaData assembly = ejbJarMetaData.getAssemblyDescriptor();
+      if(assembly == null)
+      {
+         assembly = new JBossAssemblyDescriptorMetaData();
+         ejbJarMetaData.setAssemblyDescriptor(assembly);
+      }
+      // @DeclareRoles
+      SecurityRolesMetaData securityRoles = assembly.getSecurityRoles();
+      if(securityRoles == null)
+      {
+         securityRoles = new SecurityRolesMetaData();
+         assembly.setSecurityRoles(securityRoles);
+      }
+      super.processClass(securityRoles, beanClass);
+      // @DenyAll
+      ExcludeListMetaData excludes = assembly.getExcludeList();
+      if(excludes == null)
+      {
+         excludes = new ExcludeListMetaData();
+         assembly.setExcludeList(excludes);
+      }
+      super.processClass(excludes, beanClass);
+
+      // @RolesAllowed, @PermitAll
+      MethodPermissionsMetaData permissions = assembly.getMethodPermissions();
+      if(permissions == null)
+      {
+         permissions = new MethodPermissionsMetaData();
+         assembly.setMethodPermissions(permissions);
+      }
+      super.processClass(permissions, beanClass);
+
+      // @Interceptors
+      InterceptorBindingsMetaData interceptors = assembly.getInterceptorBindings();
+      if(interceptors == null)
+      {
+         interceptors = new InterceptorBindingsMetaData();
+         assembly.setInterceptorBindings(interceptors);
+      }
+      super.processClass(interceptors, beanClass);
+
+      EjbNameThreadLocal.ejbName.set(null);
+   }
+}

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/AbstractSessionBeanProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/AbstractSessionBeanProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/AbstractSessionBeanProcessor.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,97 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.annotation.creator.ejb.jboss;
+
+import java.lang.reflect.AnnotatedElement;
+
+import javax.ejb.TransactionManagement;
+import javax.ejb.TransactionManagementType;
+
+import org.jboss.metadata.annotation.creator.Creator;
+import org.jboss.metadata.annotation.creator.Processor;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBossMetaData;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.jboss.metadata.javaee.spec.DescriptionGroupMetaData;
+import org.jboss.metadata.javaee.spec.DescriptionImpl;
+import org.jboss.metadata.javaee.spec.DescriptionsImpl;
+
+
+/**
+ * A AbstractSessionBeanProcessor.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractSessionBeanProcessor
+   extends AbstractEnterpriseBeanProcessor<JBossSessionBeanMetaData>
+   implements Creator<Class<?>, JBossSessionBeanMetaData>, Processor<JBossMetaData, Class<?>>
+{
+
+   protected AbstractSessionBeanProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+
+      addTypeProcessor(new LocalProcessor(finder));
+      addTypeProcessor(new LocalHomeProcessor(finder));
+      addTypeProcessor(new RemoteProcessor(finder));
+      addTypeProcessor(new RemoteHomeProcessor(finder));
+
+      addMethodProcessor(new InitProcessor(finder));
+      addMethodProcessor(new TimeoutProcessor(finder));
+      addMethodProcessor(new AroundInvokeProcessor(finder));
+   }
+
+   public abstract JBossSessionBeanMetaData create(Class<?> beanClass);
+
+   protected JBossSessionBeanMetaData create(Class<?> beanClass, String name, String mappedName, String description)
+   {
+      JBossSessionBeanMetaData bean = new JBossSessionBeanMetaData();
+      bean.setEjbClass(beanClass.getName());
+      String ejbName;
+      if(name == null || name.length() == 0)
+         ejbName = beanClass.getSimpleName();
+      else
+         ejbName = name;
+      bean.setEjbName(ejbName);
+      if(mappedName != null && mappedName.length() > 0)
+         bean.setMappedName(mappedName);
+      if(description != null && description.length() > 0)
+      {
+         DescriptionGroupMetaData descriptionGroup = new DescriptionGroupMetaData();
+         DescriptionsImpl descriptions = new DescriptionsImpl();
+         DescriptionImpl descriptionImpl = new DescriptionImpl();
+         descriptionImpl.setDescription(description);
+         descriptions.add(descriptionImpl);
+         descriptionGroup.setDescriptions(descriptions);
+         bean.setDescriptionGroup(descriptionGroup);
+      }
+
+      TransactionManagement txMgmt = finder.getAnnotation(beanClass, TransactionManagement.class);
+      TransactionManagementType txType = TransactionManagementType.CONTAINER;
+      if(txMgmt != null)
+         txType = txMgmt.value();
+      bean.setTransactionType(txType);
+
+      return bean;
+   }
+}

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/AbstractTransactionAttributeProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/AbstractTransactionAttributeProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/AbstractTransactionAttributeProcessor.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.annotation.creator.ejb.jboss;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Method;
+
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+
+import org.jboss.metadata.annotation.creator.AbstractFinderUser;
+import org.jboss.metadata.annotation.creator.ProcessorUtils;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.common.ejb.IEjbJarMetaData;
+import org.jboss.metadata.ejb.jboss.JBossAssemblyDescriptorMetaData;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.spec.ContainerTransactionMetaData;
+import org.jboss.metadata.ejb.spec.ContainerTransactionsMetaData;
+import org.jboss.metadata.ejb.spec.MethodsMetaData;
+
+
+/**
+ * A AbstractTransactionAttributeProcessor.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractTransactionAttributeProcessor<E extends AnnotatedElement, T extends JBossEnterpriseBeanMetaData>
+   extends AbstractFinderUser
+{
+   protected AbstractTransactionAttributeProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+      // TODO Auto-generated constructor stub
+   }
+
+   protected abstract ContainerTransactionMetaData createContainerTransaction(String ejbName, TransactionAttribute annotation, E element);
+   
+   protected MethodsMetaData createMethods(String ejbName, Method method)
+   {
+      MethodsMetaData methods = new MethodsMetaData();
+      methods.add(ProcessorUtils.createMethod(ejbName, method));
+      return methods;
+   }
+   
+   protected TransactionAttributeType createTransAttributeType(TransactionAttribute annotation)
+   {
+      return annotation.value();
+   }
+
+   public void process(T bean, E element)
+   {
+      TransactionAttribute annotation = finder.getAnnotation(element, TransactionAttribute.class);
+      if(annotation == null)
+         return;
+      
+      IEjbJarMetaData ejbJarMetaData = bean.getEjbJarMetaData();
+      
+      if(ejbJarMetaData.getAssemblyDescriptor() == null)
+         ejbJarMetaData.setAssemblyDescriptor(new JBossAssemblyDescriptorMetaData());
+      if(ejbJarMetaData.getAssemblyDescriptor().getContainerTransactions() == null)
+         ejbJarMetaData.getAssemblyDescriptor().setContainerTransactions(new ContainerTransactionsMetaData());
+      
+      ContainerTransactionMetaData transaction = createContainerTransaction(bean.getEjbName(), annotation, element);
+      ejbJarMetaData.getAssemblyDescriptor().getContainerTransactions().add(transaction);
+   }
+}

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/ApplicationExceptionProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/ApplicationExceptionProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/ApplicationExceptionProcessor.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, 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.annotation.creator.ejb.jboss;
+
+import java.lang.reflect.AnnotatedElement;
+
+import javax.ejb.ApplicationException;
+
+import org.jboss.metadata.annotation.creator.AbstractFinderUser;
+import org.jboss.metadata.annotation.creator.Creator;
+import org.jboss.metadata.annotation.creator.Processor;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBossAssemblyDescriptorMetaData;
+import org.jboss.metadata.ejb.jboss.JBossMetaData;
+import org.jboss.metadata.ejb.spec.ApplicationExceptionMetaData;
+import org.jboss.metadata.ejb.spec.ApplicationExceptionsMetaData;
+
+/**
+ * Process an application exception annotation.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: 67165 $
+ */
+public class ApplicationExceptionProcessor extends AbstractFinderUser implements Creator<Class<?>, ApplicationExceptionMetaData>, Processor<JBossMetaData, Class<?>>
+{
+   protected ApplicationExceptionProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+   }
+
+   public ApplicationExceptionMetaData create(Class<?> element)
+   {
+      ApplicationException annotation = finder.getAnnotation(element, ApplicationException.class);
+      if(annotation == null)
+         return null;
+      
+      if(!Exception.class.isAssignableFrom(element))
+         throw new IllegalArgumentException("ApplicationException is only valid on an Exception");
+      
+      ApplicationExceptionMetaData metaData = new ApplicationExceptionMetaData();
+      metaData.setExceptionClass(element.getName());
+      metaData.setRollback(annotation.rollback());
+      
+      return metaData;
+   }
+
+   public void process(JBossMetaData ejbJar, Class<?> type)
+   {
+      ApplicationExceptionMetaData applicationException = create(type);
+      if(applicationException == null)
+         return;
+      
+      if(ejbJar.getAssemblyDescriptor() == null)
+         ejbJar.setAssemblyDescriptor(new JBossAssemblyDescriptorMetaData());
+      if(ejbJar.getAssemblyDescriptor().getApplicationExceptions() == null)
+         ejbJar.getAssemblyDescriptor().setApplicationExceptions(new ApplicationExceptionsMetaData());
+      
+      ejbJar.getAssemblyDescriptor().getApplicationExceptions().add(applicationException);
+   }
+}

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/AroundInvokeProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/AroundInvokeProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/AroundInvokeProcessor.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, 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.annotation.creator.ejb.jboss;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Method;
+
+import javax.interceptor.AroundInvoke;
+
+import org.jboss.metadata.annotation.creator.AbstractFinderUser;
+import org.jboss.metadata.annotation.creator.Creator;
+import org.jboss.metadata.annotation.creator.Processor;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.jboss.metadata.ejb.spec.AroundInvokeMetaData;
+import org.jboss.metadata.ejb.spec.AroundInvokesMetaData;
+
+/**
+ * Process an AroundInvoke annotation.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 67314 $
+ */
+public class AroundInvokeProcessor extends AbstractFinderUser
+   implements Creator<Method, AroundInvokeMetaData>,
+   Processor<JBossSessionBeanMetaData, Method>
+{
+   public AroundInvokeProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+   }
+   
+   public AroundInvokeMetaData create(Method method)
+   {
+      AroundInvoke init = finder.getAnnotation(method, AroundInvoke.class);
+      if(init == null)
+         return null;
+      
+      AroundInvokeMetaData metaData = new AroundInvokeMetaData();
+      String className = method.getDeclaringClass().getName();
+      metaData.setClassName(className);
+      metaData.setMethodName(method.getName());
+      return metaData;
+   }
+   
+   public void process(JBossSessionBeanMetaData bean, Method method)
+   {
+      AroundInvokeMetaData metaData = create(method);
+      if(metaData == null)
+         return;
+
+      AroundInvokesMetaData invokes = bean.getAroundInvokes();
+      if(invokes == null)
+      {
+         invokes = new AroundInvokesMetaData();
+         bean.setAroundInvokes(invokes);
+      }
+      invokes.add(metaData);
+   }
+}

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/DenyAllProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/DenyAllProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/DenyAllProcessor.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,78 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * 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.annotation.creator.ejb.jboss;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Method;
+
+import javax.annotation.security.DenyAll;
+
+import org.jboss.annotation.javaee.Descriptions;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.annotation.creator.AbstractFinderUser;
+import org.jboss.metadata.annotation.creator.Processor;
+import org.jboss.metadata.annotation.creator.ProcessorUtils;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.spec.ExcludeListMetaData;
+import org.jboss.metadata.ejb.spec.MethodMetaData;
+import org.jboss.metadata.ejb.spec.MethodsMetaData;
+
+/**
+ * @DenyAll processor
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 67999 $
+ */
+public class DenyAllProcessor
+   extends AbstractFinderUser
+   implements Processor<ExcludeListMetaData, Method>
+{
+   private static final Logger log = Logger.getLogger(DenyAllProcessor.class);
+   
+   public DenyAllProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+   }
+
+   public void process(ExcludeListMetaData metaData, Method method)
+   {
+      DenyAll deny = finder.getAnnotation(method, DenyAll.class);
+      if(deny == null)
+         return;
+
+      MethodsMetaData methods = metaData.getMethods();
+      if(methods == null)
+      {
+         methods = new MethodsMetaData();
+         metaData.setMethods(methods);
+      }
+      String ejbName = EjbNameThreadLocal.ejbName.get();
+      if(ejbName == null)
+         ejbName = "*";
+      MethodMetaData mmd = ProcessorUtils.createMethod(ejbName, method);
+      Descriptions descriptions = ProcessorUtils.getDescription("@DenyAll for: "+method);
+      mmd.setDescriptions(descriptions);
+      log.trace("add " + mmd);
+      methods.add(mmd);
+   }
+
+}

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/EjbNameThreadLocal.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/EjbNameThreadLocal.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/EjbNameThreadLocal.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * 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.annotation.creator.ejb.jboss;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 67275 $
+ */
+class EjbNameThreadLocal
+{
+   static ThreadLocal<String> ejbName = new ThreadLocal<String>();
+}

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/EntityProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/EntityProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/EntityProcessor.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.annotation.creator.ejb.jboss;
+
+import java.lang.reflect.AnnotatedElement;
+
+import javax.persistence.Entity;
+
+import org.jboss.metadata.annotation.creator.Creator;
+import org.jboss.metadata.annotation.creator.Processor;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBossEntityBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossMetaData;
+
+
+/**
+ * A EntityProcessor.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class EntityProcessor
+   extends AbstractEnterpriseBeanProcessor<JBossEntityBeanMetaData>
+   implements Creator<Class<?>, JBossEntityBeanMetaData>, Processor<JBossMetaData, Class<?>>
+{
+   protected EntityProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+   }
+
+   @Override
+   public JBossEntityBeanMetaData create(Class<?> beanClass)
+   {
+      Entity annotation = finder.getAnnotation(beanClass, Entity.class);
+      if(annotation == null)
+         return null;
+
+      JBossEntityBeanMetaData metaData = new JBossEntityBeanMetaData();
+      if(annotation.name().length() > 0)
+         metaData.setEjbName(annotation.name());
+      else
+         metaData.setEjbName(beanClass.getSimpleName());
+      metaData.setEjbClass(beanClass.getName());
+      return metaData;
+   }
+}

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/InitProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/InitProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/InitProcessor.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,102 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, 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.annotation.creator.ejb.jboss;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Method;
+
+import javax.ejb.Init;
+
+import org.jboss.metadata.annotation.creator.AbstractFinderUser;
+import org.jboss.metadata.annotation.creator.Creator;
+import org.jboss.metadata.annotation.creator.Processor;
+import org.jboss.metadata.annotation.creator.ProcessorUtils;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.jboss.metadata.ejb.spec.InitMethodMetaData;
+import org.jboss.metadata.ejb.spec.InitMethodsMetaData;
+import org.jboss.metadata.ejb.spec.MethodParametersMetaData;
+import org.jboss.metadata.ejb.spec.NamedMethodMetaData;
+import org.jboss.metadata.ejb.spec.SessionType;
+
+/**
+ * Process an init annotation.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 67275 $
+ */
+public class InitProcessor extends AbstractFinderUser implements Creator<Method, InitMethodMetaData>, Processor<JBossSessionBeanMetaData, Method>
+{
+   public InitProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+   }
+   
+   public InitMethodMetaData create(Method method)
+   {
+      Init init = finder.getAnnotation(method, Init.class);
+      if(init == null)
+         return null;
+      
+      InitMethodMetaData metaData = new InitMethodMetaData();
+      NamedMethodMetaData beanMethod = new NamedMethodMetaData();
+      metaData.setBeanMethod(beanMethod);
+      NamedMethodMetaData createMethod = new NamedMethodMetaData();
+      metaData.setCreateMethod(createMethod);
+      
+      String alternativeName = init.value().length() > 0 ? init.value() : method.getName();
+      
+      // Is the init declared on the home interface?
+      if(method.getDeclaringClass().isInterface())
+      {
+         beanMethod.setMethodName(alternativeName);
+         createMethod.setMethodName(method.getName());
+      }
+      else
+      {
+         beanMethod.setMethodName(method.getName());
+         createMethod.setMethodName(alternativeName);
+      }
+      
+      MethodParametersMetaData methodParams = ProcessorUtils.getMethodParameters(method);
+      beanMethod.setMethodParams(methodParams);
+      createMethod.setMethodParams(methodParams);
+      
+      return metaData;
+   }
+   
+   public void process(JBossSessionBeanMetaData bean, Method method)
+   {
+      InitMethodMetaData initMethod = create(method);
+      if(initMethod == null)
+         return;
+      
+      if(bean.getSessionType() != SessionType.Stateful)
+         throw new IllegalArgumentException("Init annotation is only valid on a stateful bean");
+      
+      if(bean.getInitMethods() == null)
+         bean.setInitMethods(new InitMethodsMetaData());
+      
+      bean.getInitMethods().add(initMethod);
+   }
+}

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/InterceptorsProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/InterceptorsProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/InterceptorsProcessor.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,94 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * 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.annotation.creator.ejb.jboss;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Method;
+
+import javax.interceptor.ExcludeClassInterceptors;
+import javax.interceptor.ExcludeDefaultInterceptors;
+import javax.interceptor.Interceptors;
+
+import org.jboss.annotation.javaee.Descriptions;
+import org.jboss.metadata.annotation.creator.AbstractFinderUser;
+import org.jboss.metadata.annotation.creator.Processor;
+import org.jboss.metadata.annotation.creator.ProcessorUtils;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.spec.InterceptorBindingMetaData;
+import org.jboss.metadata.ejb.spec.InterceptorBindingsMetaData;
+import org.jboss.metadata.ejb.spec.InterceptorClassesMetaData;
+import org.jboss.metadata.ejb.spec.MethodParametersMetaData;
+import org.jboss.metadata.ejb.spec.NamedMethodMetaData;
+
+/**
+ * @Interceptors processor
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 67323 $
+ */
+public class InterceptorsProcessor<T extends AnnotatedElement>
+   extends AbstractFinderUser
+   implements Processor<InterceptorBindingsMetaData, T>
+{
+   public InterceptorsProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+   }
+
+   public void process(InterceptorBindingsMetaData metaData, T type)
+   {
+      Interceptors interceptors = finder.getAnnotation(type, Interceptors.class);
+      if(interceptors == null)
+         return;
+      ExcludeClassInterceptors excludeClass = finder.getAnnotation(type, ExcludeClassInterceptors.class);
+      ExcludeDefaultInterceptors excludeDefaults = finder.getAnnotation(type, ExcludeDefaultInterceptors.class);
+
+      Method method = null;
+      if(type instanceof Method)
+         method = (Method) type;
+
+      String ejbName = EjbNameThreadLocal.ejbName.get();
+      InterceptorBindingMetaData interceptor = new InterceptorBindingMetaData();
+      interceptor.setEjbName(ejbName);
+      interceptor.setExcludeClassInterceptors(excludeClass != null);
+      interceptor.setExcludeDefaultInterceptors(excludeDefaults != null);
+      if(method != null)
+      {
+         NamedMethodMetaData namedMethod = new NamedMethodMetaData();
+         namedMethod.setMethodName(method.getName());
+         MethodParametersMetaData methodParams = ProcessorUtils.getMethodParameters(method);
+         namedMethod.setMethodParams(methodParams);
+         interceptor.setMethod(namedMethod);
+      }
+      InterceptorClassesMetaData classes = new InterceptorClassesMetaData();
+      for(Class c : interceptors.value())
+      {
+         classes.add(c.getName());
+      }
+      interceptor.setInterceptorClasses(classes);
+
+      Descriptions descriptions = ProcessorUtils.getDescription("@Interceptors for: "+type);
+      interceptor.setDescriptions(descriptions);
+      metaData.add(interceptor);
+   }
+
+}

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/JBoss50Creator.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/JBoss50Creator.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/JBoss50Creator.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.annotation.creator.ejb.jboss;
+
+import java.lang.reflect.AnnotatedElement;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.jboss.metadata.annotation.creator.AbstractFinderUser;
+import org.jboss.metadata.annotation.creator.Creator;
+import org.jboss.metadata.annotation.creator.Processor;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBoss50MetaData;
+import org.jboss.metadata.ejb.jboss.JBossMetaData;
+
+
+/**
+ * A JBoss50Creator.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBoss50Creator extends AbstractFinderUser
+   implements Creator<Collection<Class<?>>, JBoss50MetaData>
+{
+   private List<Processor<JBossMetaData, Class<?>>> processors;
+
+   public JBoss50Creator(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+      
+      processors = new ArrayList<Processor<JBossMetaData,Class<?>>>();
+      processors.add(new StatefulProcessor(finder));
+      processors.add(new StatelessProcessor(finder));
+      processors.add(new MessageDrivenProcessor(finder));
+      processors.add(new EntityProcessor(finder));
+      processors.add(new ApplicationExceptionProcessor(finder));
+   }
+
+   public JBoss50MetaData create(Collection<Class<?>> classes)
+   {
+      JBoss50MetaData metaData = new JBoss50MetaData();
+      metaData.setVersion("3.0");
+      metaData.setEjbVersion("3.0");
+      
+      for(Class<?> cls : classes)
+      {
+         for(Processor<JBossMetaData, Class<?>> processor : processors)
+         {
+            processor.process(metaData, cls);
+         }
+      }
+
+      return metaData;
+   }
+}

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/LocalHomeProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/LocalHomeProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/LocalHomeProcessor.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, 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.annotation.creator.ejb.jboss;
+
+import java.lang.reflect.AnnotatedElement;
+
+import javax.ejb.EJBLocalHome;
+import javax.ejb.EJBLocalObject;
+import javax.ejb.LocalHome;
+
+import org.jboss.metadata.annotation.creator.Processor;
+import org.jboss.metadata.annotation.creator.ejb.AbstractHomeProcessor;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: 67165 $
+ */
+public class LocalHomeProcessor extends AbstractHomeProcessor implements Processor<JBossSessionBeanMetaData, Class<?>>
+{
+   public LocalHomeProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+   }
+
+   public void process(JBossSessionBeanMetaData metaData, Class<?> type)
+   {
+      LocalHome annotation = finder.getAnnotation(type, LocalHome.class);
+      if(annotation == null)
+         return;
+
+      Class<?> localHome = annotation.value();
+      if(!EJBLocalHome.class.isAssignableFrom(localHome)) 
+         throw new IllegalStateException("Declared EJB 2.1 Home Interface " + localHome.getName() + " does not extend "
+               + EJBLocalHome.class.getName() + " as required by EJB 3.0 Core Specification 4.6.10"); 
+      
+      metaData.setLocalHome(localHome.getName());
+      
+      // Processing the local interface
+      setLocal(metaData, localHome, metaData.isStateless());
+   }
+   
+   private void setLocal(JBossSessionBeanMetaData metaData, Class<?> localHome, boolean isStateless)
+   {
+      Class<?> businessInterface = getCreateReturnSignature(localHome, metaData.isStateless());
+      if(! EJBLocalObject.class.isAssignableFrom(businessInterface))
+         throw new IllegalStateException("EJB 3.0 Core Specification Violation (4.6.9): The session bean’s local interface "+ businessInterface + " must extend the javax.ejb.EJBLocalObject interface.");
+
+      // As the LocalProcessor allows a @Local which extends EjbHomeObject it should not fail on the same interface
+      if(metaData.getLocal() != null  && !metaData.getLocal().equals(businessInterface.getName()))
+         throw new IllegalStateException("2.1 bean " + metaData.getEjbName() + " already has a local interface " + metaData.getLocal() + ", can't add " + businessInterface.getName());
+      
+      metaData.setLocal(businessInterface.getName());
+   }
+}

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/LocalProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/LocalProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/LocalProcessor.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, 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.annotation.creator.ejb.jboss;
+
+import java.lang.reflect.AnnotatedElement;
+
+import javax.ejb.EJBLocalObject;
+import javax.ejb.Local;
+
+import org.jboss.metadata.annotation.creator.AbstractFinderUser;
+import org.jboss.metadata.annotation.creator.Processor;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.jboss.metadata.ejb.spec.BusinessLocalsMetaData;
+import org.jboss.metadata.lang.ClassHelper;
+
+/**
+ * Local annotation processor.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: 67998 $
+ */
+public class LocalProcessor extends AbstractFinderUser implements Processor<JBossSessionBeanMetaData, Class<?>>
+{  
+   public LocalProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+   }
+   
+   protected void addBusinessInterface(JBossSessionBeanMetaData metaData, Class<?> businessInterface)
+   {
+      // Although this is not explicitly allowed by the spec, we accept it
+      // EJB 3 4.6.9
+      if(EJBLocalObject.class.isAssignableFrom(businessInterface))
+      {
+         throw new IllegalStateException("EJB 3.0 Core Specification Violation (4.6.6): The session bean’s business interface "+ businessInterface + " must not extend the javax.ejb.EJBLocalObject interface.");
+      }
+      else
+      {
+         if(metaData.getBusinessLocals() == null)
+            metaData.setBusinessLocals(new BusinessLocalsMetaData());
+         
+         metaData.getBusinessLocals().add(businessInterface.getName());
+      }
+   }
+   
+   public void process(JBossSessionBeanMetaData metaData, Class<?> type)
+   {
+      Local local = finder.getAnnotation(type, Local.class);
+      if(local == null)
+         return;
+      
+      if(type.isInterface())
+      {
+         addBusinessInterface(metaData, type);
+      }
+      else
+      {
+         if(local.value() == null || local.value().length == 0)
+         {
+            Class<?> businessInterface = ClassHelper.getDefaultInterface(type);
+            addBusinessInterface(metaData, businessInterface);
+         }
+         else
+         {
+            for(Class<?> businessInterface : local.value())
+            {
+               addBusinessInterface(metaData, businessInterface);
+            }
+         }
+      }
+   }
+}

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/MessageDrivenProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/MessageDrivenProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/MessageDrivenProcessor.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.annotation.creator.ejb.jboss;
+
+import java.lang.reflect.AnnotatedElement;
+
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+
+import org.jboss.metadata.annotation.creator.ProcessorUtils;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBossMessageDrivenBeanMetaData;
+import org.jboss.metadata.ejb.spec.ActivationConfigMetaData;
+import org.jboss.metadata.ejb.spec.ActivationConfigPropertiesMetaData;
+import org.jboss.metadata.ejb.spec.ActivationConfigPropertyMetaData;
+import org.jboss.metadata.javaee.spec.DescriptionGroupMetaData;
+
+
+/**
+ * A MessageDrivenProcessor.
+ * 
+ * @author Scott.Stark at jboss.org
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class MessageDrivenProcessor extends AbstractEnterpriseBeanProcessor<JBossMessageDrivenBeanMetaData>
+{
+
+   protected MessageDrivenProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+      addMethodProcessor(new TimeoutProcessor(finder));
+   }
+
+   @Override
+   protected JBossMessageDrivenBeanMetaData create(Class<?> beanClass)
+   {
+      MessageDriven annotation = finder.getAnnotation(beanClass, MessageDriven.class);
+      if(annotation == null)
+         return null;
+
+      JBossMessageDrivenBeanMetaData metaData = new JBossMessageDrivenBeanMetaData();
+      metaData.setEjbClass(beanClass.getName());
+      if(annotation.name().length() > 0)
+         metaData.setEjbName(annotation.name());
+      else
+         metaData.setEjbName(beanClass.getSimpleName());
+      if(annotation.description().length() > 0)
+      {
+         DescriptionGroupMetaData dg = ProcessorUtils.getDescriptionGroup(annotation.description());
+         metaData.setDescriptionGroup(dg);
+      }
+      if(annotation.mappedName().length() > 0)
+         metaData.setMappedName(annotation.mappedName());
+      if(annotation.messageListenerInterface() != Object.class)
+         metaData.setMessagingType(annotation.messageListenerInterface().getName());
+      ActivationConfigProperty[] props = annotation.activationConfig();
+      ActivationConfigMetaData config = new ActivationConfigMetaData();
+      ActivationConfigPropertiesMetaData configProps = new ActivationConfigPropertiesMetaData();
+      config.setActivationConfigProperties(configProps);
+      for(ActivationConfigProperty prop : props)
+      {
+         ActivationConfigPropertyMetaData acp = new ActivationConfigPropertyMetaData();
+         acp.setActivationConfigPropertyName(prop.propertyName());
+         acp.setValue(prop.propertyValue());
+         configProps.add(acp);
+      }
+      metaData.setActivationConfig(config);
+      return metaData;
+   }
+}

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/PermitAllProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/PermitAllProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/PermitAllProcessor.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * 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.annotation.creator.ejb.jboss;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Method;
+
+import javax.annotation.security.PermitAll;
+
+import org.jboss.annotation.javaee.Descriptions;
+import org.jboss.metadata.annotation.creator.AbstractFinderUser;
+import org.jboss.metadata.annotation.creator.Processor;
+import org.jboss.metadata.annotation.creator.ProcessorUtils;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.spec.MethodPermissionsMetaData;
+import org.jboss.metadata.ejb.spec.MethodPermissionMetaData;
+import org.jboss.metadata.ejb.spec.MethodMetaData;
+import org.jboss.metadata.ejb.spec.MethodsMetaData;
+import org.jboss.metadata.javaee.spec.EmptyMetaData;
+
+/**
+ * @PermitAll processor
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 67280 $
+ */
+public class PermitAllProcessor<T extends AnnotatedElement>
+   extends AbstractFinderUser
+   implements Processor<MethodPermissionsMetaData, T>
+{
+   public PermitAllProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+   }
+
+   
+   public void process(MethodPermissionsMetaData metaData, T type)
+   {
+      PermitAll permit = finder.getAnnotation(type, PermitAll.class);
+      if(permit == null)
+         return;
+
+      Method method = null;
+      if(type instanceof Method)
+         method = (Method) type;
+
+      String ejbName = EjbNameThreadLocal.ejbName.get();
+      MethodMetaData mmd = ProcessorUtils.createMethod(ejbName, method);
+      MethodPermissionMetaData perm = new MethodPermissionMetaData();
+      MethodsMetaData methods = perm.getMethods();
+      if(methods == null)
+      {
+         methods = new MethodsMetaData();
+         perm.setMethods(methods);
+      }
+      perm.setUnchecked(new EmptyMetaData());
+      Descriptions descriptions = ProcessorUtils.getDescription("@PermitAll for: "+type);
+      mmd.setDescriptions(descriptions);
+      methods.add(mmd);
+      metaData.add(perm);
+   }
+
+}

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/PostActivateMethodProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/PostActivateMethodProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/PostActivateMethodProcessor.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * 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.annotation.creator.ejb.jboss;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Method;
+
+import javax.ejb.PostActivate;
+
+import org.jboss.metadata.annotation.creator.AbstractLifeCycleMethodProcessor;
+import org.jboss.metadata.annotation.creator.Processor;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.jboss.metadata.javaee.spec.LifecycleCallbackMetaData;
+import org.jboss.metadata.javaee.spec.LifecycleCallbacksMetaData;
+
+/**
+ * Translate @PostActivate into LifecycleCallbackMetaData for
+ * SessionBeanMetaData
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 67165 $
+ */
+public class PostActivateMethodProcessor
+   extends AbstractLifeCycleMethodProcessor
+   implements Processor<JBossSessionBeanMetaData, Method>
+{
+   /**
+    * @param finder
+    */
+   public PostActivateMethodProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+   }
+
+   public void process(JBossSessionBeanMetaData metaData, Method element)
+   {
+      PostActivate annotation = finder.getAnnotation(element, PostActivate.class);
+      if(annotation == null)
+         return;
+
+      LifecycleCallbackMetaData callback = super.create(element);
+      LifecycleCallbacksMetaData preDestroys = metaData.getPostActivates();
+      if(preDestroys == null)
+      {
+         preDestroys = new LifecycleCallbacksMetaData();
+         metaData.setPostActivates(preDestroys);
+      }
+      preDestroys.add(callback);
+   }
+
+}

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/PrePassivateMethodProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/PrePassivateMethodProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/PrePassivateMethodProcessor.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * 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.annotation.creator.ejb.jboss;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Method;
+
+import javax.ejb.PrePassivate;
+
+import org.jboss.metadata.annotation.creator.AbstractLifeCycleMethodProcessor;
+import org.jboss.metadata.annotation.creator.Processor;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.jboss.metadata.javaee.spec.LifecycleCallbackMetaData;
+import org.jboss.metadata.javaee.spec.LifecycleCallbacksMetaData;
+
+/**
+ * Translate @PrePassivate into LifecycleCallbackMetaData for
+ * SessionBeanMetaData
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 67165 $
+ */
+public class PrePassivateMethodProcessor
+   extends AbstractLifeCycleMethodProcessor
+   implements Processor<JBossSessionBeanMetaData, Method>
+{
+   /**
+    * @param finder
+    */
+   public PrePassivateMethodProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+   }
+
+   public void process(JBossSessionBeanMetaData metaData, Method element)
+   {
+      PrePassivate annotation = finder.getAnnotation(element, PrePassivate.class);
+      if(annotation == null)
+         return;
+
+      LifecycleCallbackMetaData callback = super.create(element);
+      LifecycleCallbacksMetaData preDestroys = metaData.getPrePassivates();
+      if(preDestroys == null)
+      {
+         preDestroys = new LifecycleCallbacksMetaData();
+         metaData.setPrePassivates(preDestroys);
+      }
+      preDestroys.add(callback);
+   }
+
+}

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/RemoteHomeProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/RemoteHomeProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/RemoteHomeProcessor.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, 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.annotation.creator.ejb.jboss;
+
+import java.lang.reflect.AnnotatedElement;
+
+import javax.ejb.EJBHome;
+import javax.ejb.EJBObject;
+import javax.ejb.RemoteHome;
+
+import org.jboss.metadata.annotation.creator.Processor;
+import org.jboss.metadata.annotation.creator.ejb.AbstractHomeProcessor;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+
+/**
+ * @RemoteHome annotation processor.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 67165 $
+ */
+public class RemoteHomeProcessor extends AbstractHomeProcessor
+   implements Processor<JBossSessionBeanMetaData, Class<?>>
+{  
+   public RemoteHomeProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+   }
+   
+   public void process(JBossSessionBeanMetaData metaData, Class<?> type)
+   {
+      RemoteHome remote = finder.getAnnotation(type, RemoteHome.class);
+      if(remote == null)
+         return;
+
+      Class<?> remoteHome = remote.value();
+      
+      if(!EJBHome.class.isAssignableFrom(remoteHome))
+         throw new IllegalStateException("Declared EJB 2.1 Home Interface " + remoteHome.getName() + " does not extend "
+               + EJBHome.class.getName() + " as required by EJB 3.0 Core Specification 4.6.8"); 
+      
+      metaData.setHome(remoteHome.getName());
+
+      // Processing the remote interface
+      setRemote(metaData, remoteHome, metaData.isStateless());
+   }
+   
+   private void setRemote(JBossSessionBeanMetaData metaData, Class<?> remoteHome, boolean isStateless)
+   {
+      Class<?> businessInterface = getCreateReturnSignature(remoteHome, metaData.isStateless());
+      if(! EJBObject.class.isAssignableFrom(businessInterface))
+         throw new IllegalStateException("EJB 3.0 Core Specification Violation (4.6.7): The session bean’s remote interface "+ businessInterface + " must extend the javax.ejb.EJBObject interface.");
+      
+      // As the RemoteProcessor allows a @Remote which extends EjbObject it should not fail on the same interface
+      if(metaData.getRemote() != null && !metaData.getRemote().equals(businessInterface.getName()))
+         throw new IllegalStateException("2.1 bean " + metaData.getEjbName() + " already has a remote interface " + metaData.getRemote() + ", can't add " + businessInterface.getName());
+         
+      metaData.setRemote(businessInterface.getName());
+   }
+}

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/RemoteProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/RemoteProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/RemoteProcessor.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, 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.annotation.creator.ejb.jboss;
+
+import java.lang.reflect.AnnotatedElement;
+
+import javax.ejb.EJBObject;
+import javax.ejb.Remote;
+
+import org.jboss.metadata.annotation.creator.AbstractFinderUser;
+import org.jboss.metadata.annotation.creator.Processor;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.jboss.metadata.ejb.spec.BusinessRemotesMetaData;
+import org.jboss.metadata.lang.ClassHelper;
+
+/**
+ * Remote annotation processor.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: 67998 $
+ */
+public class RemoteProcessor extends AbstractFinderUser implements Processor<JBossSessionBeanMetaData, Class<?>>
+{  
+   public RemoteProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+   }
+
+   protected void addBusinessInterface(JBossSessionBeanMetaData metaData, Class<?> businessInterface)
+   {
+      // Although this is not explicitly allowed by the spec, we accept it
+      // EJB 3 4.6.7
+      if(EJBObject.class.isAssignableFrom(businessInterface))
+      {
+         throw new IllegalStateException("EJB 3.0 Core Specification Violation (4.6.6): The session bean’s business interface "+ businessInterface + " must not extend the javax.ejb.EJBObject interface.");
+      }
+      else
+      {
+         if(metaData.getBusinessRemotes() == null)
+            metaData.setBusinessRemotes(new BusinessRemotesMetaData());
+         
+         metaData.getBusinessRemotes().add(businessInterface.getName());
+      }
+   }
+   
+   public void process(JBossSessionBeanMetaData metaData, Class<?> type)
+   {
+      Remote remote = finder.getAnnotation(type, Remote.class);
+      if(remote == null)
+         return;
+      
+      if(type.isInterface())
+      {
+         addBusinessInterface(metaData, type);
+      }
+      else
+      {
+         if(remote.value() == null || remote.value().length == 0)
+         {
+            Class<?> businessInterface = ClassHelper.getDefaultInterface(type);
+            addBusinessInterface(metaData, businessInterface);
+         }
+         else
+         {
+            for(Class<?> businessInterface : remote.value())
+            {
+               addBusinessInterface(metaData, businessInterface);
+            }
+         }
+      }
+   }
+}

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/RemoveProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/RemoveProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/RemoveProcessor.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, 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.annotation.creator.ejb.jboss;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Method;
+
+import javax.ejb.Remove;
+
+import org.jboss.metadata.annotation.creator.AbstractFinderUser;
+import org.jboss.metadata.annotation.creator.Creator;
+import org.jboss.metadata.annotation.creator.Processor;
+import org.jboss.metadata.annotation.creator.ProcessorUtils;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.jboss.metadata.ejb.spec.RemoveMethodMetaData;
+import org.jboss.metadata.ejb.spec.RemoveMethodsMetaData;
+import org.jboss.metadata.ejb.spec.MethodParametersMetaData;
+import org.jboss.metadata.ejb.spec.NamedMethodMetaData;
+import org.jboss.metadata.ejb.spec.SessionType;
+
+/**
+ * Process @Remove annotation.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 67275 $
+ */
+public class RemoveProcessor extends AbstractFinderUser
+   implements Creator<Method, RemoveMethodMetaData>,
+   Processor<JBossSessionBeanMetaData, Method>
+{
+   public RemoveProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+   }
+   
+   public RemoveMethodMetaData create(Method method)
+   {
+      Remove remove = finder.getAnnotation(method, Remove.class);
+      if(remove == null)
+         return null;
+      
+      RemoveMethodMetaData metaData = new RemoveMethodMetaData();
+      NamedMethodMetaData beanMethod = new NamedMethodMetaData();
+      beanMethod.setMethodName(method.getName());
+      metaData.setBeanMethod(beanMethod);
+      metaData.setRetainIfException(remove.retainIfException());
+
+      MethodParametersMetaData methodParams = ProcessorUtils.getMethodParameters(method);
+      beanMethod.setMethodParams(methodParams);
+      
+      return metaData;
+   }
+   
+   public void process(JBossSessionBeanMetaData bean, Method method)
+   {
+      RemoveMethodMetaData removeMethod = create(method);
+      if(removeMethod == null)
+         return;
+      
+      if(bean.getSessionType() != SessionType.Stateful)
+         throw new IllegalArgumentException("Remove annotation is only valid on a stateful bean");
+      
+      if(bean.getRemoveMethods() == null)
+         bean.setRemoveMethods(new RemoveMethodsMetaData());
+      
+      bean.getRemoveMethods().add(removeMethod);
+   }
+}

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/RolesAllowedProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/RolesAllowedProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/RolesAllowedProcessor.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,85 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * 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.annotation.creator.ejb.jboss;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Method;
+import java.util.HashSet;
+
+import javax.annotation.security.RolesAllowed;
+
+import org.jboss.annotation.javaee.Descriptions;
+import org.jboss.metadata.annotation.creator.AbstractFinderUser;
+import org.jboss.metadata.annotation.creator.Processor;
+import org.jboss.metadata.annotation.creator.ProcessorUtils;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.spec.MethodPermissionsMetaData;
+import org.jboss.metadata.ejb.spec.MethodPermissionMetaData;
+import org.jboss.metadata.ejb.spec.MethodMetaData;
+import org.jboss.metadata.ejb.spec.MethodsMetaData;
+
+/**
+ * @RolesAllowed processor
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 67280 $
+ */
+public class RolesAllowedProcessor<T extends AnnotatedElement>
+   extends AbstractFinderUser
+   implements Processor<MethodPermissionsMetaData, T>
+{
+   public RolesAllowedProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+   }
+
+   
+   public void process(MethodPermissionsMetaData metaData, T type)
+   {
+      RolesAllowed allowed = finder.getAnnotation(type, RolesAllowed.class);
+      if(allowed == null)
+         return;
+
+      Method method = null;
+      if(type instanceof Method)
+         method = (Method) type;
+
+      String ejbName = EjbNameThreadLocal.ejbName.get();
+      MethodMetaData mmd = ProcessorUtils.createMethod(ejbName, method);
+      MethodPermissionMetaData perm = new MethodPermissionMetaData();
+      MethodsMetaData methods = perm.getMethods();
+      if(methods == null)
+      {
+         methods = new MethodsMetaData();
+         perm.setMethods(methods);
+      }
+      HashSet<String> roles = new HashSet<String>();
+      for(String role : allowed.value())
+         roles.add(role);
+      perm.setRoles(roles);
+      Descriptions descriptions = ProcessorUtils.getDescription("@RolesAllowed for: "+type);
+      mmd.setDescriptions(descriptions);
+      methods.add(mmd);
+      metaData.add(perm);
+   }
+
+}

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/RunAsProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/RunAsProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/RunAsProcessor.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * 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.annotation.creator.ejb.jboss;
+
+import java.lang.reflect.AnnotatedElement;
+
+import javax.annotation.security.RunAs;
+
+import org.jboss.metadata.annotation.creator.AbstractRunAsProcessor;
+import org.jboss.metadata.annotation.creator.Processor;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.spec.SecurityIdentityMetaData;
+import org.jboss.metadata.javaee.spec.RunAsMetaData;
+
+/**
+ * Processor for ejb @RunAs
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 67218 $
+ */
+public class RunAsProcessor extends AbstractRunAsProcessor
+   implements Processor<JBossEnterpriseBeanMetaData, Class>
+{
+   /**
+    * @param finder
+    */
+   public RunAsProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+   }
+
+   public void process(JBossEnterpriseBeanMetaData metaData, Class type)
+   {
+      RunAs annotation = finder.getAnnotation(type, RunAs.class);
+      if(annotation == null)
+         return;
+
+      RunAsMetaData runAs = super.create(type);
+      SecurityIdentityMetaData identity = metaData.getSecurityIdentity();
+      if(identity == null)
+      {
+         identity = new SecurityIdentityMetaData();
+         metaData.setSecurityIdentity(identity);         
+      }
+      identity.setRunAs(runAs);
+   }
+}

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/StatefulProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/StatefulProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/StatefulProcessor.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.annotation.creator.ejb.jboss;
+
+import java.lang.reflect.AnnotatedElement;
+
+import javax.ejb.Stateful;
+
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.jboss.metadata.ejb.spec.SessionType;
+
+
+/**
+ * A StatefulProcessor.
+ * 
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @author Scott.Stark at jboss.org
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class StatefulProcessor extends AbstractSessionBeanProcessor
+{
+
+   protected StatefulProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+
+      addMethodProcessor(new RemoveProcessor(finder));
+      addMethodProcessor(new PostActivateMethodProcessor(finder));
+      addMethodProcessor(new PrePassivateMethodProcessor(finder));
+   }
+
+   @Override
+   public JBossSessionBeanMetaData create(Class<?> beanClass)
+   {
+      Stateful annotation = finder.getAnnotation(beanClass, Stateful.class);
+      if(annotation == null)
+         return null;
+      
+      JBossSessionBeanMetaData beanMetaData = create(beanClass, annotation);
+      beanMetaData.setSessionType(SessionType.Stateful);
+      return beanMetaData;
+   }
+
+   protected JBossSessionBeanMetaData create(Class<?> beanClass, Stateful annotation)
+   {
+      return create(beanClass, annotation.name(), annotation.mappedName(), annotation.description());
+   }
+}

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/StatelessProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/StatelessProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/StatelessProcessor.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.annotation.creator.ejb.jboss;
+
+import java.lang.reflect.AnnotatedElement;
+
+import javax.ejb.Stateless;
+
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.jboss.metadata.ejb.spec.SessionType;
+
+
+/**
+ * A StatelessProcessor.
+ * 
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class StatelessProcessor extends AbstractSessionBeanProcessor
+{
+
+   protected StatelessProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+   }
+
+   @Override
+   public JBossSessionBeanMetaData create(Class<?> beanClass)
+   {
+      Stateless annotation = finder.getAnnotation(beanClass, Stateless.class);
+      if(annotation == null)
+         return null;
+      
+      JBossSessionBeanMetaData beanMetaData = create(beanClass, annotation);
+      beanMetaData.setSessionType(SessionType.Stateless);
+      return beanMetaData;
+   }
+
+   protected JBossSessionBeanMetaData create(Class<?> beanClass, Stateless annotation)
+   {
+      return create(beanClass, annotation.name(), annotation.mappedName(), annotation.description());
+   }
+}

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/TimeoutProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/TimeoutProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/TimeoutProcessor.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, 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.annotation.creator.ejb.jboss;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Method;
+
+import javax.ejb.Timeout;
+
+import org.jboss.metadata.annotation.creator.AbstractFinderUser;
+import org.jboss.metadata.annotation.creator.Processor;
+import org.jboss.metadata.annotation.creator.ProcessorUtils;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.common.ejb.ITimeoutTarget;
+import org.jboss.metadata.ejb.spec.NamedMethodMetaData;
+
+/**
+ * Process @Timeout annotation.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 67275 $
+ */
+public class TimeoutProcessor extends AbstractFinderUser
+   implements Processor<ITimeoutTarget, Method>
+{
+   public TimeoutProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+   }
+   
+   public void process(ITimeoutTarget bean, Method method)
+   {
+      Timeout timeout = finder.getAnnotation(method, Timeout.class);
+      if(timeout == null)
+         return;
+      
+      NamedMethodMetaData timeoutMethod = new NamedMethodMetaData();
+      timeoutMethod.setMethodName(method.getName());
+      timeoutMethod.setMethodParams(ProcessorUtils.getMethodParameters(method));
+      bean.setTimeoutMethod(timeoutMethod);
+   }
+}

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/TransactionAttributeClassProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/TransactionAttributeClassProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/TransactionAttributeClassProcessor.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.annotation.creator.ejb.jboss;
+
+import java.lang.reflect.AnnotatedElement;
+
+import javax.ejb.TransactionAttribute;
+
+import org.jboss.metadata.annotation.creator.Processor;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.spec.ContainerTransactionMetaData;
+
+
+/**
+ * A TransactionAttributeClassProcessor.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class TransactionAttributeClassProcessor<T extends JBossEnterpriseBeanMetaData>
+   extends AbstractTransactionAttributeProcessor<Class<?>, T>
+   implements Processor<T, Class<?>>
+{
+
+   protected TransactionAttributeClassProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+      // TODO Auto-generated constructor stub
+   }
+
+   @Override
+   protected ContainerTransactionMetaData createContainerTransaction(String ejbName, TransactionAttribute annotation, Class<?> element)
+   {
+      ContainerTransactionMetaData containerTransaction = new ContainerTransactionMetaData();
+      containerTransaction.setMethods(createMethods(ejbName, null));
+      containerTransaction.setTransAttribute(createTransAttributeType(annotation));
+      return containerTransaction;
+   }
+}

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/TransactionAttributeMethodProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/TransactionAttributeMethodProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/TransactionAttributeMethodProcessor.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.annotation.creator.ejb.jboss;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Method;
+
+import javax.ejb.TransactionAttribute;
+
+import org.jboss.metadata.annotation.creator.Processor;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.spec.ContainerTransactionMetaData;
+
+
+/**
+ * A TransactionAttributeMethodProcessor.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class TransactionAttributeMethodProcessor<T extends JBossEnterpriseBeanMetaData>
+   extends AbstractTransactionAttributeProcessor<Method, T>
+   implements Processor<T, Method>
+{
+
+   protected TransactionAttributeMethodProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+   }
+
+   @Override
+   protected ContainerTransactionMetaData createContainerTransaction(String ejbName, TransactionAttribute annotation, Method method)
+   {
+      ContainerTransactionMetaData containerTransaction = new ContainerTransactionMetaData();
+      containerTransaction.setMethods(createMethods(ejbName, method));
+      containerTransaction.setTransAttribute(createTransAttributeType(annotation));
+      return containerTransaction;
+   }
+}

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/jboss/AbstractComponentProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/jboss/AbstractComponentProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/jboss/AbstractComponentProcessor.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,367 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * 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.annotation.creator.jboss;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.logging.Logger;
+import org.jboss.metadata.annotation.creator.AbstractFinderUser;
+import org.jboss.metadata.annotation.creator.EJBClassProcessor;
+import org.jboss.metadata.annotation.creator.EJBFieldProcessor;
+import org.jboss.metadata.annotation.creator.EJBMethodProcessor;
+import org.jboss.metadata.annotation.creator.EJBsClassProcessor;
+import org.jboss.metadata.annotation.creator.PersistenceContextClassProcessor;
+import org.jboss.metadata.annotation.creator.PersistenceContextFieldProcessor;
+import org.jboss.metadata.annotation.creator.PersistenceContextMethodProcessor;
+import org.jboss.metadata.annotation.creator.Processor;
+import org.jboss.metadata.annotation.creator.ResourceClassProcessor;
+import org.jboss.metadata.annotation.creator.ResourceFieldProcessor;
+import org.jboss.metadata.annotation.creator.ResourceMethodProcessor;
+import org.jboss.metadata.annotation.creator.ResourcesClassProcessor;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBossEnvironmentRefsGroupMetaData;
+import org.jboss.metadata.javaee.jboss.JBossServiceReferencesMetaData;
+import org.jboss.metadata.javaee.spec.AnnotatedEJBReferencesMetaData;
+import org.jboss.metadata.javaee.spec.EnvironmentRefsGroupMetaData;
+import org.jboss.metadata.javaee.spec.PersistenceContextReferencesMetaData;
+import org.jboss.metadata.javaee.spec.PersistenceUnitReferencesMetaData;
+import org.jboss.metadata.javaee.spec.RemoteEnvironmentRefsGroupMetaData;
+import org.jboss.metadata.javaee.spec.ServiceReferencesMetaData;
+
+/**
+ * A base javaee component processor.
+ * @param MD - the component metadata type
+ * @parma E - the component jndi environment references group type
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 72364 $
+ */
+public abstract class AbstractComponentProcessor<MD>
+   extends AbstractFinderUser
+{
+   private static Logger log = Logger.getLogger(AbstractComponentProcessor.class);
+
+   /** Map<Processor metdata type class, List<Processor for classes>> */
+   protected Map<Class<?>, List<Processor<Object, Class<?>>>> typeProcessors;
+   /** Map<Processor metdata type class, List<Processor for fields>> */
+   protected Map<Class<?>, List<Processor<Object, Field>>> fieldProcessors;
+   /** Map<Processor metdata type class, List<Processor for methods>> */
+   protected Map<Class<?>, List<Processor<Object, Method>>> methodProcessors;
+   /** */
+   protected Set<Class> boundedTypes = new HashSet<Class>();
+
+   /**
+    * @param finder
+    */
+   public AbstractComponentProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+      typeProcessors = new HashMap<Class<?>, List<Processor<Object,Class<?>>>>();
+      fieldProcessors = new HashMap<Class<?>, List<Processor<Object,Field>>>();
+      methodProcessors = new HashMap<Class<?>, List<Processor<Object,Method>>>();
+
+      // Add component environment processors
+      // @Resources/@Resource
+      addMethodProcessor(new ResourceMethodProcessor(finder));
+      addFieldProcessor(new ResourceFieldProcessor(finder));
+      addTypeProcessor(new ResourceClassProcessor(finder));
+      addTypeProcessor(new ResourcesClassProcessor(finder));
+      // @EJBs/@EJB
+      addMethodProcessor(new EJBMethodProcessor(finder));
+      addFieldProcessor(new EJBFieldProcessor(finder));
+      addTypeProcessor(new EJBClassProcessor(finder));
+      addTypeProcessor(new EJBsClassProcessor(finder));
+      // @PersistenceContext
+      addFieldProcessor(new PersistenceContextFieldProcessor(finder));
+      addMethodProcessor(new PersistenceContextMethodProcessor(finder));
+      addTypeProcessor(new PersistenceContextClassProcessor(finder));
+      // @PostConstruct/@PreDestroy
+      addMethodProcessor(new PostConstructMethodProcessor(finder));
+      addMethodProcessor(new PreDestroyMethodProcessor(finder));
+   }
+
+   public void addFieldProcessor(Processor processor)
+   {
+      Class processorType = getProcessorMetaDataType(processor);
+      log.debug("addFieldProcessor: "+processor+", for type: "+processorType);
+      List<Processor<Object, Field>> processors = fieldProcessors.get(processorType);
+      if(processors == null)
+      {
+         processors = new ArrayList<Processor<Object, Field>>();
+         fieldProcessors.put(processorType, processors);
+      }
+      processors.add(processor);
+   }
+
+   public void addMethodProcessor(Processor processor)
+   {
+      Class processorType = getProcessorMetaDataType(processor);
+      log.debug("addMethodProcessor: "+processor+", for type: "+processorType);
+      List<Processor<Object, Method>> processors = methodProcessors.get(processorType);
+      if(processors == null)
+      {
+         processors = new ArrayList<Processor<Object, Method>>();
+         methodProcessors.put(processorType, processors);
+      }
+      processors.add(processor);
+   }
+   public void addTypeProcessor(Processor processor)
+   {
+      Class processorType = getProcessorMetaDataType(processor);
+      log.debug("addTypeProcessor: "+processor+", for type: "+processorType);
+      List<Processor<Object, Class<?>>> processors = typeProcessors.get(processorType);
+      if(processors == null)
+      {
+         processors = new ArrayList<Processor<Object, Class<?>>>();
+         typeProcessors.put(processorType, processors);
+      }
+      processors.add(processor);
+   }
+
+   /**
+    * Process type for remote environment metadata related annotations
+    * @param metaData
+    * @param type
+    */
+   public void process(RemoteEnvironmentRefsGroupMetaData metaData, Class<?> type)
+   {
+      // @Resources/@Resource
+      processClass(metaData, type, JBossEnvironmentRefsGroupMetaData.class);
+
+      // @EJBs/@EJB
+      AnnotatedEJBReferencesMetaData aejbRefs = metaData.getAnnotatedEjbReferences();
+      if(aejbRefs == null)
+      {
+         aejbRefs = new AnnotatedEJBReferencesMetaData();
+         metaData.setAnnotatedEjbReferences(aejbRefs);
+      }
+      processClass(aejbRefs, type);
+
+      // @PersistenceUnit
+      PersistenceUnitReferencesMetaData puRefs = metaData.getPersistenceUnitRefs();
+      if(puRefs == null)
+      {
+         puRefs = new PersistenceUnitReferencesMetaData();
+         metaData.setPersistenceUnitRefs(puRefs);
+      }
+      processClass(puRefs, type);
+      // @WebServiceRefs/@WebServiceRef
+      ServiceReferencesMetaData wsRefs = metaData.getServiceReferences();
+      if(wsRefs == null)
+      {
+         wsRefs = new JBossServiceReferencesMetaData();
+         metaData.setServiceReferences(wsRefs);
+      }
+      processClass(wsRefs, type);
+   }
+   /**
+    * Process type for environment metadata related annotations
+    * @param metaData
+    * @param type
+    */
+   public void process(EnvironmentRefsGroupMetaData metaData, Class<?> type)
+   {
+      this.process((RemoteEnvironmentRefsGroupMetaData)metaData, type);
+
+      // @PersistenceContext
+      PersistenceContextReferencesMetaData pcRefs = metaData.getPersistenceContextRefs();
+      if(pcRefs == null)
+      {
+         pcRefs = new PersistenceContextReferencesMetaData();
+         metaData.setPersistenceContextRefs(pcRefs);
+      }
+      processClass(pcRefs, type);
+   }
+   /**
+    * Process type for component metadata related annotations
+    * @param metaData
+    * @param type
+    */
+   public void process(MD metaData, Class<?> type)
+   {
+      processClass(metaData, type);
+   }
+
+   /**
+    * Process a the cls annotations at the type, method and field levels
+    * into the argument metaData. Only processors registered for the metaData
+    * type will be run.
+    * 
+    * @param <T>
+    * @param metaData
+    * @param cls
+    */
+   protected <T> void processClass(T metaData, Class<?> cls)
+   {
+      Class<?> type = metaData.getClass();
+      boolean trace = log.isTraceEnabled();
+      int processorCount = processClass(metaData, cls, type);
+      if(trace)
+         log.trace("Found "+processorCount+" processors for type: "+type);
+      // See if metaData has a bounded type
+      type = type.getSuperclass();
+      while(boundedTypes.contains(type) == false && type != Object.class)
+      {
+         type = type.getSuperclass();
+      }
+      // 
+      if(type != Object.class)
+      {
+         if(trace)
+            log.trace("Reprocessing class using bounded processor type: "+type);
+         processClass(metaData, cls, type);
+      }
+   }
+   private <T> int processClass(T metaData, Class<?> cls, Class processorType)
+   {
+      boolean trace = log.isTraceEnabled();
+      int processorCount = 0;
+      if(trace)
+         log.trace("processClass for metaData: "+processorType+", class: "+cls);
+
+      List<Processor<Object, Class<?>>> tps = typeProcessors.get(processorType);
+      if(tps != null)
+      {
+         processorCount += tps.size();
+         if(trace)
+            log.trace("typeProcessors("+tps.size()+") for metaData: "+tps);
+         for(Processor<Object, Class<?>> processor : tps)
+         {
+            processor.process(metaData, cls);
+         }
+         
+         for(Class<?> intf : cls.getInterfaces())
+         {
+            for(Processor<Object, Class<?>> processor : tps)
+            {
+               processor.process(metaData, intf);
+            }
+         }
+      }
+      
+      List<Processor<Object, Field>> fps = fieldProcessors.get(processorType);
+      if(fps != null)
+      {
+         processorCount += fps.size();
+         if(trace)
+            log.trace("fieldProcessors("+fps.size()+") for metaData: "+fps);
+         Field[] fields = {};
+         try
+         {
+            fields = cls.getDeclaredFields();
+         }
+         catch(Throwable e)
+         {
+            log.debug("Failed to get DeclaredFields for: "+cls, e);
+         }
+         for(Field field : fields)
+         {
+            for(Processor<Object, Field> processor : fps)
+            {
+               processor.process(metaData, field);
+            }
+         }
+      }
+
+      List<Processor<Object, Method>> mps = methodProcessors.get(processorType);
+      if(mps != null)
+      {
+         processorCount += mps.size();
+         if(trace)
+            log.trace("methodProcessors("+mps.size()+") for metaData: "+mps);
+         Method[] methods = {};
+         try
+         {
+            methods = cls.getDeclaredMethods();
+         }
+         catch(Throwable e)
+         {
+            log.debug("Failed to get DeclaredMethods for: "+cls, e);            
+         }
+         for(Method method : methods)
+         {
+            if(trace)
+               log.trace("process method " + method);
+            for(Processor<Object, Method> processor : mps)
+            {
+               processor.process(metaData, method);
+            }
+         }
+      }
+      
+      if(cls.getSuperclass() != null && cls.getSuperclass() != Object.class)
+         processorCount += processClass(metaData, cls.getSuperclass(), processorType);
+      return processorCount;
+   }
+
+   /**
+    * Determine the Processor<T, ?> T generic processorType class.
+    * 
+    * @param processor
+    * @return The Class for the T parameter type. If this was an upper bound,
+    * this will have been added to the boundedTypes set.
+    */
+   protected Class getProcessorMetaDataType(Processor processor)
+   {
+      // Find the Proccessor<T, ?> interface
+      Type[] interfaces = processor.getClass().getGenericInterfaces();
+      Type processorType = null;
+      for(Type t : interfaces)
+      {
+         ParameterizedType pt = (ParameterizedType) t;
+         Type rawType = pt.getRawType();
+         if((rawType instanceof Class) && ((Class)rawType).getName().equals("org.jboss.metadata.annotation.creator.Processor"))
+         {
+            processorType = t;
+            break;
+         }
+      }
+      if(processorType == null)
+         throw new IllegalStateException("No generic Processor interface found on: "+processor);
+
+      // Get the type of the T parameter
+      ParameterizedType pt = (ParameterizedType) processorType;
+      Type t0 = pt.getActualTypeArguments()[0];
+      Class t = null;
+      if(t0 instanceof Class)
+         t = (Class) t0;
+      else if(t0 instanceof TypeVariable)
+      {
+         TypeVariable tv = (TypeVariable) t0;
+         t = (Class)tv.getBounds()[0];
+         boundedTypes.add(t);
+      }
+      return t;
+   }
+
+}

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/jboss/PostConstructMethodProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/jboss/PostConstructMethodProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/jboss/PostConstructMethodProcessor.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * 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.annotation.creator.jboss;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Method;
+
+import javax.annotation.PostConstruct;
+
+import org.jboss.metadata.annotation.creator.AbstractLifeCycleMethodProcessor;
+import org.jboss.metadata.annotation.creator.Processor;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBossEnvironmentRefsGroupMetaData;
+import org.jboss.metadata.javaee.spec.LifecycleCallbackMetaData;
+import org.jboss.metadata.javaee.spec.LifecycleCallbacksMetaData;
+
+/**
+ * Translate @PostConstruct into LifecycleCallbackMetaData for
+ * EnvironmentRefsGroupMetaData
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 72364 $
+ */
+public class PostConstructMethodProcessor
+   extends AbstractLifeCycleMethodProcessor
+   implements Processor<JBossEnvironmentRefsGroupMetaData, Method>
+{
+   /**
+    * @param finder
+    */
+   public PostConstructMethodProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+   }
+
+   public void process(JBossEnvironmentRefsGroupMetaData metaData, Method element)
+   {
+      PostConstruct annotation = finder.getAnnotation(element, PostConstruct.class);
+      if(annotation == null)
+         return;
+
+      LifecycleCallbackMetaData callback = super.create(element);
+      LifecycleCallbacksMetaData postConstructs = metaData.getPostConstructs();
+      if(postConstructs == null)
+      {
+         postConstructs = new LifecycleCallbacksMetaData();
+         metaData.setPostConstructs(postConstructs);
+      }
+      postConstructs.add(callback);
+   }
+
+}

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/jboss/PreDestroyMethodProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/jboss/PreDestroyMethodProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/jboss/PreDestroyMethodProcessor.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * 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.annotation.creator.jboss;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Method;
+
+import javax.annotation.PreDestroy;
+
+import org.jboss.metadata.annotation.creator.AbstractLifeCycleMethodProcessor;
+import org.jboss.metadata.annotation.creator.Processor;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBossEnvironmentRefsGroupMetaData;
+import org.jboss.metadata.javaee.spec.LifecycleCallbackMetaData;
+import org.jboss.metadata.javaee.spec.LifecycleCallbacksMetaData;
+
+/**
+ * Translate @PreDestroy into LifecycleCallbackMetaData for
+ * EnvironmentRefsGroupMetaData
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 72364 $
+ */
+public class PreDestroyMethodProcessor
+   extends AbstractLifeCycleMethodProcessor
+   implements Processor<JBossEnvironmentRefsGroupMetaData, Method>
+{
+   /**
+    * @param finder
+    */
+   public PreDestroyMethodProcessor(AnnotationFinder<AnnotatedElement> finder)
+   {
+      super(finder);
+   }
+
+   public void process(JBossEnvironmentRefsGroupMetaData metaData, Method element)
+   {
+      PreDestroy annotation = finder.getAnnotation(element, PreDestroy.class);
+      if(annotation == null)
+         return;
+
+      LifecycleCallbackMetaData callback = super.create(element);
+      LifecycleCallbacksMetaData preDestroys = metaData.getPreDestroys();
+      if(preDestroys == null)
+      {
+         preDestroys = new LifecycleCallbacksMetaData();
+         metaData.setPreDestroys(preDestroys);
+      }
+      preDestroys.add(callback);
+   }
+
+}

Modified: projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/InvokerBindingsMetaData.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/InvokerBindingsMetaData.java	2008-05-28 14:59:00 UTC (rev 73747)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/InvokerBindingsMetaData.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -46,4 +46,19 @@
    {
       super("invoker-proxy-binding-name for invoker");
    }
+
+   public void merge(InvokerBindingsMetaData override, InvokerBindingsMetaData original)
+   {
+      super.merge(override, original);
+      if (original != null)
+      {
+         for (InvokerBindingMetaData property : original)
+            add(property);
+      }
+      if (override != null)
+      {
+         for (InvokerBindingMetaData property : override)
+            add(property);
+      }
+   }
 }

Modified: projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/JBossAssemblyDescriptorMetaData.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/JBossAssemblyDescriptorMetaData.java	2008-05-28 14:59:00 UTC (rev 73747)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/JBossAssemblyDescriptorMetaData.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -22,8 +22,6 @@
 package org.jboss.metadata.ejb.jboss;
 
 import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
@@ -32,7 +30,6 @@
 import org.jboss.metadata.ejb.spec.AssemblyDescriptorMetaData;
 import org.jboss.metadata.ejb.spec.ContainerTransactionsMetaData;
 import org.jboss.metadata.ejb.spec.ExcludeListMetaData;
-import org.jboss.metadata.ejb.spec.InterceptorBindingMetaData;
 import org.jboss.metadata.ejb.spec.InterceptorBindingsMetaData;
 import org.jboss.metadata.ejb.spec.MethodPermissionsMetaData;
 import org.jboss.metadata.javaee.spec.MessageDestinationMetaData;
@@ -461,4 +458,94 @@
       AssemblyDescriptorMetaData original = (AssemblyDescriptorMetaData) assembly;
       merge(override, original);
    }
+   
+   public void merge(JBossAssemblyDescriptorMetaData override, JBossAssemblyDescriptorMetaData original)
+   {
+      super.merge(override, original);
+
+      ApplicationExceptionsMetaData originalExceptions = null;
+      SecurityRolesMetaData originalRoles = null;
+      MethodPermissionsMetaData originalPermissions = null;
+      ContainerTransactionsMetaData originalTransactions = null;
+      InterceptorBindingsMetaData originalInterceptors = null;
+      MessageDestinationsMetaData originalDestinations = null;
+      ExcludeListMetaData originalExclude = null; 
+      if(original != null)
+      {
+         originalExceptions = original.applicationExceptions;
+         originalRoles = original.securityRoles;
+         originalPermissions = original.methodPermissions;
+         originalTransactions = original.containerTransactions;
+         originalInterceptors = original.interceptorBindings;
+         originalDestinations = original.messageDestinations;
+         originalExclude = original.excludeList;
+      }
+
+      ApplicationExceptionsMetaData overrideExceptions = null;
+      SecurityRolesMetaData overrideRoles = null;
+      MethodPermissionsMetaData overridePermissions = null;
+      ContainerTransactionsMetaData overrideTransactions = null;
+      InterceptorBindingsMetaData overrideInterceptors = null;
+      MessageDestinationsMetaData overrideDestinations = null;
+      ExcludeListMetaData overrideExclude = null;
+      if(override != null)
+      {
+         overrideExceptions = override.applicationExceptions;
+         overrideRoles = override.securityRoles;
+         overridePermissions = override.methodPermissions;
+         overrideTransactions = override.containerTransactions;
+         overrideInterceptors = override.interceptorBindings;
+         overrideDestinations = override.messageDestinations;
+         overrideExclude = override.excludeList;
+      }
+
+      if(originalExceptions != null || overrideExceptions != null)
+      {
+         if(applicationExceptions == null)
+            applicationExceptions = new ApplicationExceptionsMetaData();
+         applicationExceptions.merge(overrideExceptions, originalExceptions);
+      }
+      
+      if(originalRoles != null || overrideRoles != null)
+      {
+         if(securityRoles == null)
+            securityRoles = new SecurityRolesMetaData();
+         securityRoles.merge(overrideRoles, originalRoles);
+      }
+      
+      if(originalPermissions != null || overridePermissions != null)
+      {
+         if(methodPermissions == null)
+            methodPermissions = new MethodPermissionsMetaData();
+         methodPermissions.merge(overridePermissions, originalPermissions);
+      }
+      
+      if(originalTransactions != null || overrideTransactions != null)
+      {
+         if(containerTransactions == null)
+            containerTransactions = new ContainerTransactionsMetaData();
+         containerTransactions.merge(overrideTransactions, originalTransactions);
+      }
+
+      if(originalInterceptors != null || overrideInterceptors != null)
+      {
+         if(interceptorBindings == null)
+            interceptorBindings = new InterceptorBindingsMetaData();
+         interceptorBindings.merge(overrideInterceptors, originalInterceptors);
+      }
+      
+      if(originalDestinations != null || overrideDestinations != null)
+      {
+         if(messageDestinations == null)
+            messageDestinations = new MessageDestinationsMetaData();
+         messageDestinations.merge(overrideDestinations, originalDestinations);
+      }
+      
+      if(originalExclude != null || overrideExclude != null)
+      {
+         if(excludeList == null)
+            excludeList = new ExcludeListMetaData();
+         excludeList.merge(overrideExclude, originalExclude);
+      }
+   }
 }

Modified: projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/JBossEnterpriseBeanMetaData.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/JBossEnterpriseBeanMetaData.java	2008-05-28 14:59:00 UTC (rev 73747)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/JBossEnterpriseBeanMetaData.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -1754,6 +1754,108 @@
       }
    }
 
+   public void merge(JBossEnterpriseBeanMetaData override, JBossEnterpriseBeanMetaData original)
+   {
+      super.merge(override, original);
+      
+      AnnotationsMetaData originalAnnotations = null;
+      InvokerBindingsMetaData originalInvokers = null;
+      JBossEnvironmentRefsGroupMetaData originalEnv = null;
+      if(original != null)
+      {
+         if(original.aopDomainName != null)
+            aopDomainName = original.aopDomainName;
+         if(original.configurationName != null)
+            configurationName = original.configurationName;
+         if(original.containerName != null)
+            containerName = original.containerName;
+         if(original.ejbClass != null)
+            ejbClass = original.ejbClass;
+         if(original.generatedContainerName != null)
+            generatedContainerName = original.generatedContainerName;
+         if(original.jndiBindingPolicy != null)
+            jndiBindingPolicy = original.jndiBindingPolicy;
+         if(original.localJndiName != null)
+            localJndiName = original.localJndiName;
+         if(original.mappedName != null)
+            mappedName = original.mappedName;
+         if(original.securityDomain != null)
+            securityDomain = original.securityDomain;
+         if(original.securityProxy != null)
+            securityProxy = original.securityProxy;
+
+         // boolean wrapper should be used to differentiate between default and not set values
+         timerPersistence = original.timerPersistence;
+         exceptionOnRollback = original.exceptionOnRollback;
+
+         originalAnnotations = original.annotations;
+         originalInvokers = original.invokers;
+         originalEnv = original.jndiEnvironmentRefsGroup;
+         
+         // not merged currently but overriden
+         if(original.iorSecurityConfig != null)
+            iorSecurityConfig = original.iorSecurityConfig;
+         
+      }
+      
+      AnnotationsMetaData overrideAnnotations = null;
+      InvokerBindingsMetaData overrideInvokers = null;
+      JBossEnvironmentRefsGroupMetaData overrideEnv = null;
+      if(override != null)
+      {         
+         if(override.aopDomainName != null)
+            aopDomainName = override.aopDomainName;
+         if(override.configurationName != null)
+            configurationName = override.configurationName;
+         if(override.containerName != null)
+            containerName = override.containerName;
+         if(override.ejbClass != null)
+            ejbClass = override.ejbClass;
+         if(override.generatedContainerName != null)
+            generatedContainerName = override.generatedContainerName;
+         if(override.jndiBindingPolicy != null)
+            jndiBindingPolicy = override.jndiBindingPolicy;
+         if(override.localJndiName != null)
+            localJndiName = override.localJndiName;
+         if(override.mappedName != null)
+            mappedName = override.mappedName;
+         if(override.securityDomain != null)
+            securityDomain = override.securityDomain;
+         if(override.securityProxy != null)
+            securityProxy = override.securityProxy;
+         timerPersistence = override.timerPersistence;
+         exceptionOnRollback = override.exceptionOnRollback;
+         
+         overrideAnnotations = override.annotations;
+         overrideInvokers = override.invokers;
+         overrideEnv = override.jndiEnvironmentRefsGroup;
+
+         if(override.iorSecurityConfig != null)
+            iorSecurityConfig = override.iorSecurityConfig;
+      }
+      
+      if(originalAnnotations != null || overrideAnnotations != null)
+      {
+         if(annotations == null)
+            annotations = new AnnotationsMetaData();
+         annotations.merge(overrideAnnotations, originalAnnotations);
+      }
+
+      if(originalInvokers != null || overrideInvokers != null)
+      {
+         if(invokers == null)
+            invokers = new InvokerBindingsMetaData();
+         invokers.merge(overrideInvokers, originalInvokers);
+      }
+      
+      if(originalEnv != null || overrideEnv != null)
+      {
+         if(jndiEnvironmentRefsGroup == null)
+            jndiEnvironmentRefsGroup = new JBossEnvironmentRefsGroupMetaData();
+         jndiEnvironmentRefsGroup.merge(overrideEnv, originalEnv);
+      }
+   }
+   
    public void checkValid()
    {
    }

Modified: projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/JBossEnterpriseBeansMetaData.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/JBossEnterpriseBeansMetaData.java	2008-05-28 14:59:00 UTC (rev 73747)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/JBossEnterpriseBeansMetaData.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -21,6 +21,8 @@
 */
 package org.jboss.metadata.ejb.jboss;
 
+import java.util.HashMap;
+
 import javax.xml.bind.annotation.XmlTransient;
 import javax.xml.bind.annotation.XmlType;
 
@@ -187,4 +189,93 @@
          ejb.checkValid();
       }
    }
+   
+   public void merge(JBossEnterpriseBeansMetaData override, JBossEnterpriseBeansMetaData original)
+   {
+      HashMap<String, String> ejbClassToName = new HashMap<String, String>();
+      if(override != null)
+      {
+         if(override.getId() != null)
+            setId(override.getId());
+         for(JBossEnterpriseBeanMetaData bean : override)
+         {
+            String className = bean.getEjbClass();
+            if(className != null)
+            {
+               // Use the unqualified name
+               int dot = className.lastIndexOf('.');
+               if(dot >= 0)
+                  className = className.substring(dot+1);
+               ejbClassToName.put(className, bean.getEjbName());
+            }
+         }         
+      }
+      
+      // first get the original beans without the corresponding override entry
+      if(original != null)
+      {
+         for(JBossEnterpriseBeanMetaData bean : original)
+         {
+            if(override != null)
+            {
+               // This is either the ejb-name or the ejb-class simple name
+               String ejbName = bean.getEjbName();
+               JBossEnterpriseBeanMetaData match = override.get(ejbName);
+               if(match == null)
+               {
+                  // Lookup by the unqualified ejb class
+                  String xmlEjbName = ejbClassToName.get(ejbName);
+                  if(xmlEjbName == null)
+                     add(bean);
+               }
+            }
+            else
+            {
+               add(bean);
+            }
+         }
+      }
+      
+      // Now merge the xml and annotations
+      if(override != null)
+      {
+         for(JBossEnterpriseBeanMetaData bean : override)
+         {
+            JBossEnterpriseBeanMetaData annBean = null;
+            if(original != null)
+            {
+               String name = bean.getEjbName();
+               annBean = original.get(name);
+               if(annBean == null)
+               {
+                  // Lookup by the unqualified ejb class
+                  String className = bean.getEjbClass();
+                  if(className != null)
+                  {
+                     // Use the unqualified name
+                     int dot = className.lastIndexOf('.');
+                     if(dot >= 0)
+                        className = className.substring(dot+1);
+                     annBean = original.get(className);
+                  }
+               }
+            }
+
+            // Merge
+            if(annBean != null)
+            {
+               JBossEnterpriseBeanMetaData mbean;
+               if(bean.isSession())
+                  mbean = new JBossSessionBeanMetaData();
+               else if(bean.isEntity())
+                  mbean = new JBossEntityBeanMetaData();
+               else
+                  mbean = new JBossMessageDrivenBeanMetaData();
+               mbean.merge(bean, annBean);
+            }
+            else
+               add(bean);
+         }
+      }
+   }
 }

Modified: projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/JBossEnvironmentRefsGroupMetaData.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/JBossEnvironmentRefsGroupMetaData.java	2008-05-28 14:59:00 UTC (rev 73747)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/JBossEnvironmentRefsGroupMetaData.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -210,4 +210,25 @@
          this.setPersistenceContextRefs(mergedPcRefs);
       
    }
+   
+   public void merge(JBossEnvironmentRefsGroupMetaData override, JBossEnvironmentRefsGroupMetaData original)
+   {
+      super.merge(override, original, "jboss.xml", null, true);
+      
+      EJBLocalReferencesMetaData originalLocalRefs = null;
+      if(original != null)
+      {
+         originalLocalRefs = original.ejbLocalReferences;
+      }
+      
+      EJBLocalReferencesMetaData overrideLocalRefs = null;
+      if(override != null)
+      {
+         overrideLocalRefs = override.ejbLocalReferences;
+      }
+
+      EJBLocalReferencesMetaData mergedEjbLocalRefs = EJBLocalReferencesMetaData.merge(overrideLocalRefs, originalLocalRefs, null, "jboss.xml");
+      if (mergedEjbLocalRefs != null)
+         this.setEjbLocalReferences(mergedEjbLocalRefs);
+   }
 }

Modified: projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/JBossMetaData.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/JBossMetaData.java	2008-05-28 14:59:00 UTC (rev 73747)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/JBossMetaData.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -805,6 +805,163 @@
       }
    }
 
+   public void merge(JBossMetaData override, JBossMetaData original)
+   {
+      super.merge(override, original);
+
+      JBossAssemblyDescriptorMetaData originalAssembly = null;
+      ResourceManagersMetaData originalResManagers = null;
+      ContainerConfigurationsMetaData originalContainerConfig = null;
+      InvokerProxyBindingsMetaData originalInvokerProxyBindings = null;
+      InterceptorsMetaData originalInterceptors = null;
+      WebservicesMetaData originalWebservices = null;
+      JBossEnterpriseBeansMetaData originalBeans = null;
+      if(original != null)
+      {
+         originalAssembly = original.assemblyDescriptor;
+         originalResManagers = original.resourceManagers;
+         originalContainerConfig = original.containerConfigurations;
+         originalInvokerProxyBindings = original.invokerProxyBindings;
+         originalInterceptors = original.interceptors;
+         originalWebservices = original.webservices;
+         originalBeans = original.enterpriseBeans;
+         
+         if(original.ejbVersion != null)
+            ejbVersion = original.ejbVersion;
+         if(original.metadataComplete)
+            metadataComplete = true;
+         if(original.relationships != null)
+            relationships = original.relationships;
+         if(original.jaccContextID != null)
+            jaccContextID = original.jaccContextID;
+         if(original.jmxName != null)
+            jmxName = original.jmxName;
+         if(original.loaderRepository != null)
+            loaderRepository = original.loaderRepository;         
+         if(original.securityDomain != null)
+            securityDomain = original.securityDomain;         
+         if(original.unauthenticatedPrincipal != null)
+            unauthenticatedPrincipal = original.unauthenticatedPrincipal;
+      }
+
+      JBossAssemblyDescriptorMetaData overrideAssembly = null;
+      ResourceManagersMetaData overrideResManagers = null;
+      ContainerConfigurationsMetaData overrideContainerConfig = null;
+      InvokerProxyBindingsMetaData overrideInvokerProxyBindings = null;
+      InterceptorsMetaData overrideInterceptors = null;
+      WebservicesMetaData overrideWebservices = null;
+      JBossEnterpriseBeansMetaData overrideBeans = null;
+      if(override != null)
+      {
+         overrideAssembly = override.assemblyDescriptor;
+         overrideResManagers = override.resourceManagers;
+         overrideContainerConfig = override.containerConfigurations;
+         overrideInvokerProxyBindings = override.invokerProxyBindings;
+         overrideInterceptors = override.interceptors;
+         overrideWebservices = override.webservices;
+         overrideBeans = override.enterpriseBeans;
+
+         if(override.ejbVersion != null)
+           ejbVersion = override.ejbVersion;
+         if(override.metadataComplete)
+            metadataComplete = true;
+         // TODO: relationships should be merged
+         if(override.relationships != null)
+            relationships = original.relationships;
+         if(override.jaccContextID != null)
+            jaccContextID = override.jaccContextID;
+         if(override.jmxName != null)
+            jmxName = override.jmxName;
+         if(override.loaderRepository != null)
+            loaderRepository = override.loaderRepository;         
+         if(override.securityDomain != null)
+            securityDomain = override.securityDomain;         
+         if(override.unauthenticatedPrincipal != null)
+            unauthenticatedPrincipal = override.unauthenticatedPrincipal;
+         //Ensure that there is no customization of the Unspecified method permissions
+         if(override.excludeMissingMethods == false)
+             this.excludeMissingMethods = false; 
+      }
+      
+      if(assemblyDescriptor == null)
+         assemblyDescriptor = new JBossAssemblyDescriptorMetaData();
+      if(overrideAssembly != null || originalAssembly != null)
+         assemblyDescriptor.merge(overrideAssembly, originalAssembly);
+
+      if(resourceManagers == null)
+         resourceManagers = new ResourceManagersMetaData();
+      if(overrideResManagers != null || originalResManagers != null)
+         resourceManagers.merge(overrideResManagers, originalResManagers);
+
+      if(containerConfigurations == null)
+         containerConfigurations = new ContainerConfigurationsMetaData();
+      if(overrideContainerConfig != null || originalContainerConfig != null)
+         containerConfigurations.merge(overrideContainerConfig, originalContainerConfig);
+      
+      if(invokerProxyBindings == null)
+         invokerProxyBindings = new InvokerProxyBindingsMetaData();
+      if(overrideInvokerProxyBindings != null || originalInvokerProxyBindings != null)
+         invokerProxyBindings.merge(overrideInvokerProxyBindings, originalInvokerProxyBindings);
+
+      if(interceptors == null)
+         interceptors = new InterceptorsMetaData();
+      if(overrideInterceptors != null || originalInterceptors != null)
+         interceptors.merge(overrideInterceptors, originalInterceptors);
+
+      if (overrideWebservices != null || originalWebservices != null)
+      {
+         webservices = new WebservicesMetaData();
+         webservices.merge(overrideWebservices, originalWebservices);
+      }
+
+      if(enterpriseBeans == null)
+      {
+         enterpriseBeans = new JBossEnterpriseBeansMetaData();
+         enterpriseBeans.setJBossMetaData(this);
+      }
+      
+      if(originalBeans != null || overrideBeans != null)
+         enterpriseBeans.merge(overrideBeans, originalBeans);
+      
+      // Update run-as indentity for a run-as-principal
+      if(enterpriseBeans != null)
+      {
+         for(JBossEnterpriseBeanMetaData ejb : enterpriseBeans)
+         {
+            String ejbName = ejb.getEjbName();
+            SecurityIdentityMetaData si = ejb.getSecurityIdentity();
+            String principalName = si != null ? si.getRunAsPrincipal() : null;
+            // Get the run-as primary role
+            String ejbXmlRunAs = null;
+            if(si != null && si.getRunAs() != null)
+               ejbXmlRunAs = si.getRunAs().getRoleName();
+            if (principalName != null)
+            {
+               // Update the run-as indentity to use the principal name
+               if (ejbXmlRunAs == null)
+               {
+                  // Can't make this check since the name may come from an annotation
+                  //throw new IllegalStateException("run-as-principal: " + principalName + " found in jboss.xml but there was no run-as in ejb-jar.xml");
+                  ejbXmlRunAs = "anonymous";
+               }
+               // See if there are any additional roles for this principal
+               Set<String> extraRoles = null;
+               if(getAssemblyDescriptor() != null)
+               {
+                  extraRoles = getAssemblyDescriptor().getSecurityRoleNamesByPrincipal(principalName);
+               }
+               RunAsIdentityMetaData runAsId = new RunAsIdentityMetaData(ejbXmlRunAs, principalName, extraRoles);
+               runAsIdentity.put(ejbName, runAsId);
+            }
+            else if (ejbXmlRunAs != null)
+            {
+               RunAsIdentityMetaData runAsId = new RunAsIdentityMetaData(ejbXmlRunAs, null);
+               runAsIdentity.put(ejbName, runAsId);
+            }
+         }
+      }
+   }
+   
    /**
     * 
     * @return

Modified: projects/metadata/trunk/src/main/java/org/jboss/metadata/javaee/jboss/AnnotationsMetaData.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/javaee/jboss/AnnotationsMetaData.java	2008-05-28 14:59:00 UTC (rev 73747)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/javaee/jboss/AnnotationsMetaData.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -41,4 +41,19 @@
    {
       super("annotation class");
    }
+   
+   public void merge(AnnotationsMetaData override, AnnotationsMetaData original)
+   {
+      super.merge(override, original);
+      if (original != null)
+      {
+         for (AnnotationMetaData property : original)
+            add(property);
+      }
+      if (override != null)
+      {
+         for (AnnotationMetaData property : override)
+            add(property);
+      }
+   }
 }

Modified: projects/metadata/trunk/src/main/java/org/jboss/metadata/javaee/support/AbstractMappedMetaData.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/javaee/support/AbstractMappedMetaData.java	2008-05-28 14:59:00 UTC (rev 73747)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/javaee/support/AbstractMappedMetaData.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -117,7 +117,7 @@
       String key = o.getKey();
       if (key == null)
          throw new IllegalArgumentException("No " + keyName);
-      
+
       if (map == null)
          map = new NonNullLinkedHashMap<String, T>();
       T result = map.put(key, o);

Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/JBossAnnotationEjb3UnitTestCase.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/JBossAnnotationEjb3UnitTestCase.java	                        (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/JBossAnnotationEjb3UnitTestCase.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,617 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.test.metadata.annotation.ejb3;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.lang.reflect.AnnotatedElement;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.ejb.TransactionAttributeType;
+
+import org.jboss.metadata.annotation.creator.ejb.jboss.JBoss50Creator;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.annotation.finder.DefaultAnnotationFinder;
+import org.jboss.metadata.common.ejb.IEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBoss50DTDMetaData;
+import org.jboss.metadata.ejb.jboss.JBoss50MetaData;
+import org.jboss.metadata.ejb.jboss.JBossAssemblyDescriptorMetaData;
+import org.jboss.metadata.ejb.jboss.JBossConsumerBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossEntityBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossMessageDrivenBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossServiceBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.jboss.metadata.ejb.spec.ActivationConfigMetaData;
+import org.jboss.metadata.ejb.spec.ActivationConfigPropertiesMetaData;
+import org.jboss.metadata.ejb.spec.ActivationConfigPropertyMetaData;
+import org.jboss.metadata.ejb.spec.AroundInvokeMetaData;
+import org.jboss.metadata.ejb.spec.AroundInvokesMetaData;
+import org.jboss.metadata.ejb.spec.ContainerTransactionMetaData;
+import org.jboss.metadata.ejb.spec.EjbJar20MetaData;
+import org.jboss.metadata.ejb.spec.EjbJar21MetaData;
+import org.jboss.metadata.ejb.spec.EjbJar30MetaData;
+import org.jboss.metadata.ejb.spec.EjbJar3xMetaData;
+import org.jboss.metadata.ejb.spec.ExcludeListMetaData;
+import org.jboss.metadata.ejb.spec.InitMethodMetaData;
+import org.jboss.metadata.ejb.spec.InitMethodsMetaData;
+import org.jboss.metadata.ejb.spec.InterceptorBindingMetaData;
+import org.jboss.metadata.ejb.spec.InterceptorBindingsMetaData;
+import org.jboss.metadata.ejb.spec.MethodMetaData;
+import org.jboss.metadata.ejb.spec.MethodParametersMetaData;
+import org.jboss.metadata.ejb.spec.MethodPermissionMetaData;
+import org.jboss.metadata.ejb.spec.MethodPermissionsMetaData;
+import org.jboss.metadata.ejb.spec.MethodsMetaData;
+import org.jboss.metadata.ejb.spec.NamedMethodMetaData;
+import org.jboss.metadata.ejb.spec.RemoveMethodMetaData;
+import org.jboss.metadata.ejb.spec.RemoveMethodsMetaData;
+import org.jboss.metadata.ejb.spec.SecurityIdentityMetaData;
+import org.jboss.metadata.ejb.spec.SessionType;
+import org.jboss.metadata.javaee.spec.AnnotatedEJBReferenceMetaData;
+import org.jboss.metadata.javaee.spec.AnnotatedEJBReferencesMetaData;
+import org.jboss.metadata.javaee.spec.LifecycleCallbackMetaData;
+import org.jboss.metadata.javaee.spec.LifecycleCallbacksMetaData;
+import org.jboss.metadata.javaee.spec.RunAsMetaData;
+import org.jboss.metadata.javaee.spec.SecurityRoleMetaData;
+import org.jboss.metadata.javaee.spec.SecurityRolesMetaData;
+import org.jboss.test.metadata.annotation.ejb3.runas.InterMediateBean;
+import org.jboss.test.metadata.javaee.AbstractJavaEEMetaDataTest;
+import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver;
+
+
+/**
+ * A JBossAnnotationEjb3UnitTestCase.
+ * 
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @author Scott.Stark at jboss.org
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBossAnnotationEjb3UnitTestCase extends AbstractJavaEEMetaDataTest
+{
+   public static SchemaBindingResolver initResolver()
+   {
+      DefaultSchemaResolver resolver = new DefaultSchemaResolver();
+
+      resolver.addClassBindingForLocation("ejb-jar_2_0.dtd", EjbJar20MetaData.class);
+      resolver.addClassBindingForLocation("ejb-jar_2_1.xsd", EjbJar21MetaData.class);
+      resolver.addClassBindingForLocation("ejb-jar_3_0.xsd", EjbJar30MetaData.class);
+      resolver.addClassBindingForLocation("jboss_3_0.dtd", JBoss50DTDMetaData.class);
+      resolver.addClassBindingForLocation("jboss_3_2.dtd", JBoss50DTDMetaData.class);
+      resolver.addClassBindingForLocation("jboss_4_0.dtd", JBoss50DTDMetaData.class);
+      resolver.addClassBindingForLocation("jboss_4_2.dtd", JBoss50DTDMetaData.class);
+      resolver.addClassBindingForLocation("jboss_5_0.dtd", JBoss50DTDMetaData.class);
+      resolver.addClassBindingForLocation("jboss_5_0.xsd", JBoss50MetaData.class);
+      // Workaround wildard resolution slowness
+      resolver.addClassBinding("http://www.jboss.com/xml/ns/javaee", JBoss50MetaData.class);
+      return resolver;
+   }
+
+   public JBossAnnotationEjb3UnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testBeans() throws Exception
+   {
+      AnnotationFinder<AnnotatedElement> finder = new DefaultAnnotationFinder<AnnotatedElement>();
+
+      Collection<Class<?>> classes = loadClassesFromCurrentClassDir();
+
+      //enableTrace("org.jboss.metadata.annotation.creator");
+      JBoss50Creator creator = new JBoss50Creator(finder);
+
+      JBoss50MetaData metaData = creator.create(classes);
+
+      assertTrue(metaData.isEJB3x());
+      assertEquals("3.0", metaData.getVersion());
+
+      assertNotNull("no beans defined", metaData.getEnterpriseBeans());
+      assertNotNull("no assembly descriptor defined", metaData.getAssemblyDescriptor());
+
+      // There is a bug in IdMetaDataImpl.hashCode which isn't unique when id is not set.
+      for(ContainerTransactionMetaData transaction : metaData.getAssemblyDescriptor().getContainerTransactions())
+      {
+         System.out.println(transaction);
+      }
+
+      assertEquals(8, metaData.getEnterpriseBeans().size());
+
+      assertMyStatefulBean(metaData.getEnterpriseBean("AnotherName")); // MyStatefulBean
+      assertMyStateless21Bean(metaData.getEnterpriseBean("MyStateless21Bean"));
+      assertMyStatelessBean(metaData.getEnterpriseBean("MyStatelessBean"));
+      assertMyEntity(metaData.getEnterpriseBean("MyEntity"));
+      assertMyMDB(metaData.getEnterpriseBean("MailMDB"));
+
+      JBossAssemblyDescriptorMetaData assembly = metaData.getAssemblyDescriptor();
+      assertNotNull("no application exceptions defined", assembly.getApplicationExceptions());
+      assertEquals(1, assembly.getApplicationExceptions().size());
+      System.out.println(assembly.getContainerTransactionsByEjbName("MyStatelessBean"));
+
+      // @DeclareRoles
+      SecurityRolesMetaData securityRoles = assembly.getSecurityRoles();
+      assertNotNull(securityRoles);
+      assertEquals(2, securityRoles.size());
+      SecurityRoleMetaData role1 = securityRoles.get("Role1");
+      assertNotNull(role1);
+      assertEquals("Role1", role1.getRoleName());
+      SecurityRoleMetaData role2 = securityRoles.get("Role2");
+      assertNotNull(role2);
+      assertEquals("Role2", role2.getRoleName());
+
+      // @DenyAll
+      // cls.getDeclaredMethods is un-ordered, so we must use bestMatch
+      ExcludeListMetaData excludes = assembly.getExcludeList();
+      assertNotNull(excludes);
+      MethodsMetaData excludedMethods = excludes.getMethods();
+      assertEquals(2, excludedMethods.size());
+      MethodMetaData m0 = excludedMethods.bestMatch("denyAll", (Class[]) null, null, null);
+      assertEquals("MyStatelessBean", m0.getEjbName());
+      assertEquals("denyAll", m0.getMethodName());
+      MethodParametersMetaData noargs = new MethodParametersMetaData();
+      assertEquals(noargs, m0.getMethodParams());
+      MethodMetaData m1 = excludedMethods.bestMatch("excluded", (Class[]) null, null, null);;
+      assertEquals("MyStatelessBean", m1.getEjbName());
+      assertEquals("excluded", m1.getMethodName());
+      assertEquals(noargs, m1.getMethodParams());
+
+      // @PermitAll, @RolesAllowed({"AccessRole1", "AccessRole2"})
+      MethodPermissionsMetaData allPerms = assembly.getMethodPermissions();
+      assertEquals(8, allPerms.size());
+      MethodPermissionsMetaData perms = assembly.getMethodPermissionsByEjbName("MyStatelessBean");
+      assertEquals(2, perms.size());
+      MethodPermissionMetaData permitAll = null;
+      MethodPermissionMetaData rolesAllowed = null;
+      for(MethodPermissionMetaData mp : perms)
+      {
+         if(mp.matches("permitAll", null, null))
+            permitAll = mp;
+         if(mp.matches("rolesAllowed", null, null))
+            rolesAllowed = mp;
+      }
+      assertNotNull(permitAll);
+      assertTrue(permitAll.isNotChecked());
+      assertTrue(permitAll.isNotChecked("permitAll", null, null));
+      assertNotNull(rolesAllowed);
+      HashSet<String> roles = new HashSet<String>();
+      roles.add("AccessRole1");
+      roles.add("AccessRole2");
+      assertEquals(roles, rolesAllowed.getRoles());
+
+      // Validate the MyStateless @Interceptors
+      InterceptorBindingsMetaData interceptorBindings = assembly.getInterceptorBindings();
+      assertEquals(2, interceptorBindings.size());
+      InterceptorBindingMetaData ib0 = interceptorBindings.get(0);
+      InterceptorBindingMetaData ib1 = interceptorBindings.get(1);
+      assertEquals("MyStatelessBean", ib0.getEjbName());
+      NamedMethodMetaData ib0Method = ib0.getMethod();
+      if(ib0Method == null)
+      {
+         // The class level @Interceptors
+         assertFalse(ib0.isExcludeClassInterceptors());
+         assertTrue(ib0.isExcludeDefaultInterceptors());
+         assertEquals(TestClassInterceptor.class.getName(),
+               ib0.getInterceptorClasses().iterator().next());
+      }
+      else
+      {
+         // The method level @Interceptors
+         assertTrue(ib0.isExcludeClassInterceptors());
+         assertTrue(ib0.isExcludeDefaultInterceptors());
+         assertEquals(TestMethodInterceptor.class.getName(),
+               ib0.getInterceptorClasses().iterator().next());
+         assertEquals("intercept2", ib0Method.getMethodName());
+      }
+      assertEquals("MyStatelessBean", ib1.getEjbName());
+      NamedMethodMetaData ib1Method = ib1.getMethod();
+      if(ib1Method == null)
+      {
+         // The class level @Interceptors
+         assertFalse(ib1.isExcludeClassInterceptors());
+         assertTrue(ib1.isExcludeDefaultInterceptors());
+         assertEquals(TestClassInterceptor.class.getName(),
+               ib1.getInterceptorClasses().iterator().next());
+      }
+      else
+      {
+         // The method level @Interceptors
+         assertTrue(ib1.isExcludeClassInterceptors());
+         assertTrue(ib1.isExcludeDefaultInterceptors());
+         assertEquals(TestMethodInterceptor.class.getName(),
+               ib1.getInterceptorClasses().iterator().next());
+         assertEquals("intercept2", ib1Method.getMethodName());
+      }
+   }
+
+   /**
+    * Test merging annotation and xml based metadata
+    * @throws Exception
+    */
+   public void testXmlMerge()
+      throws Exception
+   {
+      Class<?>[] beanClasses = {
+            InterMediateBean.class
+      };
+      List<Class<?>> classes = Arrays.asList(beanClasses);
+      AnnotationFinder<AnnotatedElement> finder = new DefaultAnnotationFinder<AnnotatedElement>();
+      JBoss50Creator creator = new JBoss50Creator(finder);
+      JBoss50MetaData annotations = creator.create(classes);
+      EjbJar3xMetaData specMetaData = unmarshal("AnnotationEjb3_testXmlMerge.xml", EjbJar3xMetaData.class, null);
+      JBoss50MetaData dd = new JBoss50MetaData();
+      dd.merge(null, specMetaData);
+      JBossEnterpriseBeanMetaData eb = dd.getEnterpriseBean("InterMediateBean");
+      assertNotNull(eb);
+
+      JBoss50MetaData merged = new JBoss50MetaData();
+      merged.merge(dd, annotations);
+
+      JBossEnterpriseBeanMetaData enterpriseBean = merged.getEnterpriseBean("InterMediateBean");
+      assertNotNull(enterpriseBean);
+      assertInterMediateBean(enterpriseBean);
+   }
+
+   private void assertMyStatefulBean(IEnterpriseBeanMetaData enterpriseBean)
+   {
+      assertTrue(enterpriseBean instanceof JBossSessionBeanMetaData);
+
+      JBossSessionBeanMetaData bean = (JBossSessionBeanMetaData) enterpriseBean;
+      assertEquals(SessionType.Stateful, bean.getSessionType());
+      assertEquals(MyStatefulBean.class.getName(), bean.getEjbClass());
+      assertEquals("AnotherName", bean.getEjbName());
+
+      assertNotNull("bean has no business remotes", bean.getBusinessRemotes());
+      assertEquals(1, bean.getBusinessRemotes().size());
+      assertTrue(bean.getBusinessRemotes().contains(MyStateful.class.getName()));
+      assertEquals(MyStatefulHome.class.getName(), bean.getHome());
+
+      // @EJBs
+      AnnotatedEJBReferencesMetaData ejbRefs = bean.getAnnotatedEjbReferences();
+      assertEquals(2, ejbRefs.size());
+      AnnotatedEJBReferenceMetaData local1 = ejbRefs.get("ejb/local1");
+      assertNotNull(local1);
+      assertEquals("java:/MyLocalSession1", local1.getMappedName());
+      assertEquals("ejb/local1", local1.getEjbRefName());
+      assertEquals("MyLocalSession1", local1.getLink());
+      assertEquals("A reference to MyLocalSession1", local1.getDescriptions().value()[0].value());
+      assertEquals(MyStatelessLocal.class, local1.getBeanInterface());
+      AnnotatedEJBReferenceMetaData local2 = ejbRefs.get("ejb/local2");
+      assertNotNull(local2);
+      assertEquals("java:/MyLocalSession2", local2.getMappedName());
+      assertEquals("ejb/local2", local2.getEjbRefName());
+      assertEquals("local.jar#MyLocalSession1", local2.getLink());
+      assertEquals("A reference to MyLocalSession2", local2.getDescriptions().value()[0].value());
+      assertEquals(MyStatelessLocal.class, local2.getBeanInterface());
+      // @PostConstruct
+      LifecycleCallbacksMetaData postConstructs = bean.getPostConstructs();
+      assertNotNull(postConstructs);
+      assertEquals(1, postConstructs.size());
+      LifecycleCallbackMetaData postConstruct = postConstructs.get(0);
+      assertEquals("setUp", postConstruct.getMethodName());
+      assertEquals(MyStatefulBean.class.getName(), postConstruct.getClassName());
+      // @PreDestroy
+      LifecycleCallbacksMetaData preDestroys = bean.getPreDestroys();
+      assertNotNull(preDestroys);
+      assertEquals(1, preDestroys.size());
+      LifecycleCallbackMetaData preDestroy = preDestroys.get(0);
+      assertEquals("tearDown", preDestroy.getMethodName());
+      assertEquals(MyStatefulBean.class.getName(), preDestroy.getClassName());
+      // @Init
+      InitMethodsMetaData initMethods = bean.getInitMethods();
+      assertNotNull(initMethods);
+      assertEquals(1, initMethods.size());
+      InitMethodMetaData initMethod = initMethods.get(0);
+      assertEquals("init", initMethod.getBeanMethod().getMethodName());
+      // @PostActivate
+      LifecycleCallbacksMetaData postActivates = bean.getPostActivates();
+      assertNotNull(postActivates);
+      assertEquals(1, postActivates.size());
+      LifecycleCallbackMetaData postActivate = postActivates.get(0);
+      assertEquals("activate", postActivate.getMethodName());
+      assertEquals(MyStatefulBean.class.getName(), postActivate.getClassName());
+      // @PrePassivate
+      LifecycleCallbacksMetaData prePassivates = bean.getPrePassivates();
+      assertNotNull(prePassivates);
+      assertEquals(1, prePassivates.size());
+      LifecycleCallbackMetaData prePassivate = prePassivates.get(0);
+      assertEquals("passivate", prePassivate.getMethodName());
+      assertEquals(MyStatefulBean.class.getName(), prePassivate.getClassName());
+      // @Remove
+      RemoveMethodsMetaData removeMethods = bean.getRemoveMethods();
+      assertNotNull(removeMethods);
+      assertEquals(1, removeMethods.size());
+      RemoveMethodMetaData removeMethod = removeMethods.get(0);
+      assertEquals("remove", removeMethod.getBeanMethod().getMethodName());
+   }
+
+   private void assertMyStateless21Bean(IEnterpriseBeanMetaData enterpriseBean)
+   {
+      assertTrue(enterpriseBean instanceof JBossSessionBeanMetaData);
+      JBossSessionBeanMetaData bean = (JBossSessionBeanMetaData) enterpriseBean;
+      assertEquals(SessionType.Stateless, bean.getSessionType());
+      assertEquals(MyStateless21Bean.class.getName(), bean.getEjbClass());
+      assertEquals("MyStateless21Bean", bean.getEjbName());
+
+      assertNull("bean has business locals (instead of local interface)", bean.getBusinessLocals());
+
+      assertEquals(MyStateless21Local.class.getName(), bean.getLocal());
+      assertEquals(MyStateless21Home.class.getName(), bean.getLocalHome());
+   }
+
+   private void assertMyStatelessBean(IEnterpriseBeanMetaData enterpriseBean)
+   {
+      assertTrue(enterpriseBean instanceof JBossSessionBeanMetaData);
+      JBossSessionBeanMetaData bean = (JBossSessionBeanMetaData) enterpriseBean;
+      assertEquals(SessionType.Stateless, bean.getSessionType());
+      assertEquals(MyStatelessBean.class.getName(), bean.getEjbClass());
+      assertEquals("MyStatelessBean", bean.getEjbName());
+
+      assertNotNull("bean has no business locals", bean.getBusinessLocals());
+      assertEquals(1, bean.getBusinessLocals().size());
+      assertTrue(bean.getBusinessLocals().contains(MyStatelessLocal.class.getName()));
+
+      assertNotNull("bean has no container transactions", bean.getContainerTransactions());
+      Iterator<ContainerTransactionMetaData> it = bean.getContainerTransactions().iterator();
+      ContainerTransactionMetaData tx1 = it.next();
+      assertEquals(TransactionAttributeType.NEVER, tx1.getTransAttribute());
+      // TODO: methods
+      ContainerTransactionMetaData tx2 = it.next();
+      assertEquals(TransactionAttributeType.MANDATORY, tx2.getTransAttribute());
+      MethodsMetaData tx2Methods = tx2.getMethods();
+      String[] params = {};
+      tx2Methods.matches("transactionAttributeMandatory", params, null);
+
+      // @EJB
+      AnnotatedEJBReferencesMetaData ejbRefs = bean.getAnnotatedEjbReferences();
+      assertEquals(2, ejbRefs.size());
+      AnnotatedEJBReferenceMetaData injectedField = ejbRefs.get("injectedField");
+      assertNotNull(injectedField);
+      assertEquals(MyStatelessLocal.class, injectedField.getBeanInterface());
+      AnnotatedEJBReferenceMetaData injectedFieldWithOverridenName = ejbRefs.get("overrideName");
+      assertNotNull(injectedFieldWithOverridenName);
+      assertEquals(MyStatelessLocal.class, injectedFieldWithOverridenName.getBeanInterface());
+      // @PostConstruct
+      LifecycleCallbacksMetaData postConstructs = bean.getPostConstructs();
+      assertNotNull(postConstructs);
+      assertEquals(1, postConstructs.size());
+      LifecycleCallbackMetaData postConstruct = postConstructs.get(0);
+      assertEquals("setUp", postConstruct.getMethodName());
+      assertEquals(MyStatelessBean.class.getName(), postConstruct.getClassName());
+      // @PreDestroy
+      LifecycleCallbacksMetaData preDestroys = bean.getPreDestroys();
+      assertNotNull(preDestroys);
+      assertEquals(1, preDestroys.size());
+      LifecycleCallbackMetaData preDestroy = preDestroys.get(0);
+      assertEquals("tearDown", preDestroy.getMethodName());
+      assertEquals(MyStatelessBean.class.getName(), preDestroy.getClassName());
+
+      // @RunAs
+      SecurityIdentityMetaData identity = bean.getSecurityIdentity();
+      assertNotNull(identity);
+      RunAsMetaData runAs = identity.getRunAs();
+      assertNotNull(runAs);
+      assertEquals("InternalUser", runAs.getRoleName());
+
+      // @AroundInvoke
+      AroundInvokesMetaData invokes = bean.getAroundInvokes();
+      assertNotNull(invokes);
+      assertEquals(1, invokes.size());
+      AroundInvokeMetaData aroundInvoke = invokes.get(0);
+      assertEquals(MyStatelessBean.class.getName(), aroundInvoke.getClassName());
+      assertEquals("intercept", aroundInvoke.getMethodName());
+   }
+
+   private void assertMyEntity(IEnterpriseBeanMetaData enterpriseBean)
+   {
+      assertTrue(enterpriseBean instanceof JBossEntityBeanMetaData);
+      JBossEntityBeanMetaData bean = (JBossEntityBeanMetaData) enterpriseBean;
+      assertEquals(MyEntityBean.class.getName(), bean.getEjbClass());
+      assertEquals("MyEntity", bean.getEjbName());
+   }
+
+   private void assertMyMDB(IEnterpriseBeanMetaData enterpriseBean)
+   {
+      assertTrue(enterpriseBean instanceof JBossMessageDrivenBeanMetaData);
+      JBossMessageDrivenBeanMetaData bean = (JBossMessageDrivenBeanMetaData) enterpriseBean;
+      assertEquals(MyMDB.class.getName(), bean.getEjbClass());
+      assertEquals("MailMDB", bean.getEjbName());
+      assertEquals(false, bean.isJMS());
+      assertEquals(IMailListener.class.getName(), bean.getMessagingType());
+      ActivationConfigMetaData config = bean.getActivationConfig();
+      ActivationConfigMetaData expected = new ActivationConfigMetaData();
+      ActivationConfigPropertiesMetaData props = new ActivationConfigPropertiesMetaData();
+      ActivationConfigPropertyMetaData p1 = new ActivationConfigPropertyMetaData();
+      p1.setName("p1");
+      p1.setValue("v1");
+      props.add(p1);
+      ActivationConfigPropertyMetaData p2 = new ActivationConfigPropertyMetaData();
+      p2.setName("p2");
+      p2.setValue("v2");
+      props.add(p2);
+      expected.setActivationConfigProperties(props);
+      assertEquals(expected, config);
+      assertEquals("java:/mdbs/MailMDB", bean.getMappedName());
+   }
+
+   private void assertMyServiceBean(IEnterpriseBeanMetaData enterpriseBean)
+   {
+      assertTrue(enterpriseBean instanceof JBossServiceBeanMetaData);
+
+      //TODO test the different values. This bean is based on MyStatelessSessionBean
+      JBossServiceBeanMetaData bean = (JBossServiceBeanMetaData) enterpriseBean;
+      assertEquals(SessionType.Stateless, bean.getSessionType());
+      assertEquals(MyServiceBean.class.getName(), bean.getEjbClass());
+      assertEquals("MyServiceBean", bean.getEjbName());
+
+      assertNotNull("bean has no business locals", bean.getBusinessLocals());
+      assertEquals(1, bean.getBusinessLocals().size());
+      assertTrue(bean.getBusinessLocals().contains(MyStatelessLocal.class.getName()));
+
+      assertNotNull("bean has no container transactions", bean.getContainerTransactions());
+      Iterator<ContainerTransactionMetaData> it = bean.getContainerTransactions().iterator();
+      ContainerTransactionMetaData tx1 = it.next();
+      assertEquals(TransactionAttributeType.NEVER, tx1.getTransAttribute());
+      // TODO: methods
+      ContainerTransactionMetaData tx2 = it.next();
+      assertEquals(TransactionAttributeType.MANDATORY, tx2.getTransAttribute());
+      MethodsMetaData tx2Methods = tx2.getMethods();
+      String[] params = {};
+      tx2Methods.matches("transactionAttributeMandatory", params, null);
+
+      // @EJB
+      AnnotatedEJBReferencesMetaData ejbRefs = bean.getAnnotatedEjbReferences();
+      assertEquals(2, ejbRefs.size());
+      AnnotatedEJBReferenceMetaData injectedField = ejbRefs.get("injectedField");
+      assertNotNull(injectedField);
+      assertEquals(MyStatelessLocal.class, injectedField.getBeanInterface());
+      AnnotatedEJBReferenceMetaData injectedFieldWithOverridenName = ejbRefs.get("overrideName");
+      assertNotNull(injectedFieldWithOverridenName);
+      assertEquals(MyStatelessLocal.class, injectedFieldWithOverridenName.getBeanInterface());
+      // @PostConstruct
+      LifecycleCallbacksMetaData postConstructs = bean.getPostConstructs();
+      assertNotNull(postConstructs);
+      assertEquals(1, postConstructs.size());
+      LifecycleCallbackMetaData postConstruct = postConstructs.get(0);
+      assertEquals("setUp", postConstruct.getMethodName());
+      assertEquals(MyStatelessBean.class.getName(), postConstruct.getClassName());
+      // @PreDestroy
+      LifecycleCallbacksMetaData preDestroys = bean.getPreDestroys();
+      assertNotNull(preDestroys);
+      assertEquals(1, preDestroys.size());
+      LifecycleCallbackMetaData preDestroy = preDestroys.get(0);
+      assertEquals("tearDown", preDestroy.getMethodName());
+      assertEquals(MyStatelessBean.class.getName(), preDestroy.getClassName());
+
+      // @RunAs
+      SecurityIdentityMetaData identity = bean.getSecurityIdentity();
+      assertNotNull(identity);
+      RunAsMetaData runAs = identity.getRunAs();
+      assertNotNull(runAs);
+      assertEquals("InternalUser", runAs.getRoleName());
+
+      // @AroundInvoke
+      AroundInvokesMetaData invokes = bean.getAroundInvokes();
+      assertNotNull(invokes);
+      assertEquals(1, invokes.size());
+      AroundInvokeMetaData aroundInvoke = invokes.get(0);
+      assertEquals(MyStatelessBean.class.getName(), aroundInvoke.getClassName());
+      assertEquals("intercept", aroundInvoke.getMethodName());
+   }
+
+   private void assertInterMediateBean(JBossEnterpriseBeanMetaData interMediateBean)
+   {
+      // Validate the merged InterMediateBean
+      assertNotNull(interMediateBean);
+      assertEquals("org.jboss.test.metadata.annotation.ejb3.runas.InterMediate", interMediateBean.getEjbClass());
+      assertTrue(interMediateBean instanceof JBossSessionBeanMetaData);
+      JBossSessionBeanMetaData sInterMediateBean = (JBossSessionBeanMetaData) interMediateBean;
+      assertEquals(SessionType.Stateless, sInterMediateBean.getSessionType());
+      SecurityIdentityMetaData identity = sInterMediateBean.getSecurityIdentity();
+      assertNotNull(identity);
+      RunAsMetaData runAs = identity.getRunAs();
+      assertNotNull(runAs);
+      assertEquals("InternalUser", runAs.getRoleName());
+   }
+
+   private void assertMyConsumer(IEnterpriseBeanMetaData enterpriseBean)
+   {
+      //TODO test the different values. This bean is based on MyMDB
+      JBossConsumerBeanMetaData bean = (JBossConsumerBeanMetaData) enterpriseBean;
+      assertEquals(MyConsumer.class.getName(), bean.getEjbClass());
+      assertEquals("MyConsumer", bean.getEjbName());
+      //assertEquals(false, bean.isJMS());
+      //assertEquals(IMailListener.class.getName(), bean.getMessagingType());
+      //ActivationConfigMetaData config = bean.getActivationConfig();
+      ActivationConfigMetaData expected = new ActivationConfigMetaData();
+      ActivationConfigPropertiesMetaData props = new ActivationConfigPropertiesMetaData();
+      ActivationConfigPropertyMetaData p1 = new ActivationConfigPropertyMetaData();
+      p1.setName("p1");
+      p1.setValue("v1");
+      props.add(p1);
+      ActivationConfigPropertyMetaData p2 = new ActivationConfigPropertyMetaData();
+      p2.setName("p2");
+      p2.setValue("v2");
+      props.add(p2);
+      expected.setActivationConfigProperties(props);
+      //assertEquals(expected, config);
+      //assertEquals("java:/mdbs/MailMDB", bean.getMappedName());
+   }
+
+   private Collection<Class<?>> loadClassesFromCurrentClassDir()
+   {
+      return loadClassesFromRelativeClassDir(".");
+   }
+
+   private Collection<Class<?>> loadClassesFromRelativeClassDir(String dir)
+   {
+      // In real life the deployer will pass probably pass a class scanner
+      Collection<Class<?>> classes = new ArrayList<Class<?>>();
+      URL currentClassDirURL = getClass().getResource(dir);
+      File currentDir;
+      try
+      {
+         currentDir = new File(currentClassDirURL.toURI());
+      }
+      catch (URISyntaxException e)
+      {
+         throw new RuntimeException(e);
+      }
+      String classFileNames[] = currentDir.list(new FilenameFilter() {
+         public boolean accept(File dir, String name)
+         {
+            return name.endsWith(".class");
+         }
+      });
+      if(classFileNames == null)
+         throw new RuntimeException("list failed");
+
+      Arrays.sort(classFileNames);
+
+      String packageName;
+      if(dir.indexOf('/') != -1)
+         packageName = dir.replaceAll("\\/", "") + ".";
+      else
+         packageName = ".";
+
+      for(String classFileName : classFileNames)
+      {
+         String className = getClass().getPackage().getName() + packageName + classFileName.substring(0, classFileName.length() - 6);
+         try
+         {
+            classes.add(Class.forName(className));
+         }
+         catch (ClassNotFoundException e)
+         {
+            throw new RuntimeException(e);
+         }
+      }
+      return classes;
+   }
+}

Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/ejb/JBossAssemblyDescriptorOverrideUnitTestCase.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/ejb/JBossAssemblyDescriptorOverrideUnitTestCase.java	                        (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/ejb/JBossAssemblyDescriptorOverrideUnitTestCase.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,346 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.test.metadata.ejb;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.metadata.ejb.jboss.JBoss50MetaData;
+import org.jboss.metadata.ejb.jboss.JBossAssemblyDescriptorMetaData;
+import org.jboss.metadata.ejb.spec.ApplicationExceptionMetaData;
+import org.jboss.metadata.ejb.spec.ApplicationExceptionsMetaData;
+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.MethodsMetaData;
+import org.jboss.metadata.javaee.spec.SecurityRoleMetaData;
+import org.jboss.metadata.javaee.spec.SecurityRolesMetaData;
+
+import junit.framework.TestCase;
+
+
+/**
+ * A JBossAssemblyDescriptorOverrideUnitTestCase.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBossAssemblyDescriptorOverrideUnitTestCase extends TestCase
+{
+   public void testAssemblyAppExceptionsOverride()
+   {
+      // original
+      JBoss50MetaData original = new JBoss50MetaData();
+      JBossAssemblyDescriptorMetaData assembly = new JBossAssemblyDescriptorMetaData();
+      original.setAssemblyDescriptor(assembly);
+      ApplicationExceptionsMetaData exceptions = new ApplicationExceptionsMetaData();
+      assembly.setApplicationExceptions(exceptions);
+      
+      ApplicationExceptionMetaData exc = new ApplicationExceptionMetaData();
+      exc.setExceptionClass("original.only.Exception");
+      exc.setRollback(true);
+      exceptions.add(exc);
+      exc = new ApplicationExceptionMetaData();
+      exc.setExceptionClass("overriden.Exception");
+      exc.setRollback(false);
+      exceptions.add(exc);
+
+      // override
+      JBoss50MetaData override = new JBoss50MetaData();
+      assembly = new JBossAssemblyDescriptorMetaData();
+      override.setAssemblyDescriptor(assembly);
+      exceptions = new ApplicationExceptionsMetaData();
+      assembly.setApplicationExceptions(exceptions);
+      
+      exc = new ApplicationExceptionMetaData();
+      exc.setExceptionClass("override.only.Exception");
+      exc.setRollback(false);
+      exceptions.add(exc);
+      exc = new ApplicationExceptionMetaData();
+      exc.setExceptionClass("overriden.Exception");
+      exc.setRollback(true);
+      exceptions.add(exc);
+      
+      // merge
+      JBoss50MetaData merged = new JBoss50MetaData();
+      merged.merge(override, original);      
+      assembly = merged.getAssemblyDescriptor();
+      assertNotNull(assembly);
+      exceptions = assembly.getApplicationExceptions();
+      assertNotNull(exceptions);
+      assertEquals(3, exceptions.size());
+      
+      exc = exceptions.get("original.only.Exception");
+      assertNotNull(exc);
+      assertEquals("original.only.Exception", exc.getExceptionClass());
+      assertTrue(exc.isRollback());
+      
+      exc = exceptions.get("override.only.Exception");
+      assertNotNull(exc);
+      assertEquals("override.only.Exception", exc.getExceptionClass());
+      assertFalse(exc.isRollback());
+      
+      exc = exceptions.get("overriden.Exception");
+      assertNotNull(exc);
+      assertEquals("overriden.Exception", exc.getExceptionClass());
+      assertTrue(exc.isRollback());
+   }
+
+   public void testAssemblySecurityRolesOverride()
+   {
+      // original
+      JBoss50MetaData original = new JBoss50MetaData();
+      JBossAssemblyDescriptorMetaData assembly = new JBossAssemblyDescriptorMetaData();
+      original.setAssemblyDescriptor(assembly);
+      SecurityRolesMetaData roles = new SecurityRolesMetaData();
+      assembly.setSecurityRoles(roles);
+      
+      SecurityRoleMetaData role = new SecurityRoleMetaData();
+      role.setRoleName("original.only.Role");
+      role.setPrincipals(java.util.Collections.singleton("original"));
+      roles.add(role);
+      role = new SecurityRoleMetaData();
+      role.setRoleName("overriden.Role");
+      HashSet<String> principals = new HashSet<String>();
+      principals.add("original1");
+      principals.add("original2");
+      role.setPrincipals(principals);
+      roles.add(role);
+      
+      // override
+      JBoss50MetaData override = new JBoss50MetaData();
+      assembly = new JBossAssemblyDescriptorMetaData();
+      override.setAssemblyDescriptor(assembly);
+      roles = new SecurityRolesMetaData();
+      assembly.setSecurityRoles(roles);
+      
+      role = new SecurityRoleMetaData();
+      role.setRoleName("override.only.Role");
+      role.setPrincipals(java.util.Collections.singleton("override"));
+      roles.add(role);
+      role = new SecurityRoleMetaData();
+      role.setRoleName("overriden.Role");
+      principals = new HashSet<String>();
+      principals.add("original1");
+      principals.add("override1");
+      principals.add("override2");
+      role.setPrincipals(principals);
+      roles.add(role);
+      
+      // merge
+      JBoss50MetaData merged = new JBoss50MetaData();
+      merged.merge(override, original);      
+      assembly = merged.getAssemblyDescriptor();
+      assertNotNull(assembly);
+      roles = assembly.getSecurityRoles();
+      assertNotNull(roles);
+      assertEquals(3, roles.size());
+      
+      role = roles.get("original.only.Role");
+      assertNotNull(role);
+      assertEquals("original.only.Role", role.getRoleName());
+      assertNotNull(role.getPrincipals());
+      assertEquals(1, role.getPrincipals().size());
+      assertTrue(role.getPrincipals().contains("original"));
+      
+      role = roles.get("override.only.Role");
+      assertNotNull(role);
+      assertEquals("override.only.Role", role.getRoleName());
+      assertNotNull(role.getPrincipals());
+      assertEquals(1, role.getPrincipals().size());
+      assertTrue(role.getPrincipals().contains("override"));
+      
+      role = roles.get("overriden.Role");
+      assertNotNull(role);
+      assertEquals("overriden.Role", role.getRoleName());
+      assertNotNull(role.getPrincipals());
+      // shouldn't there be 3? missing original2?
+      assertEquals(4, role.getPrincipals().size());
+      assertTrue(role.getPrincipals().contains("original1"));
+      assertTrue(role.getPrincipals().contains("original2"));
+      assertTrue(role.getPrincipals().contains("override1"));
+      assertTrue(role.getPrincipals().contains("override2"));
+   }
+   
+   public void testAssemblyMethodPermissionsOverride()
+   {
+      // original
+      JBoss50MetaData original = new JBoss50MetaData();
+      JBossAssemblyDescriptorMetaData assembly = new JBossAssemblyDescriptorMetaData();
+      original.setAssemblyDescriptor(assembly);
+      MethodPermissionsMetaData permissions = new MethodPermissionsMetaData();
+      assembly.setMethodPermissions(permissions);
+
+      // original only
+      MethodsMetaData methods = new MethodsMetaData();
+      MethodMetaData method = new MethodMetaData();
+      method.setEjbName("Original");
+      method.setMethodName("execute");
+      methods.add(method);
+
+      MethodPermissionMetaData permission = new MethodPermissionMetaData();
+      permission.setMethods(methods);
+      permission.setRoles(java.util.Collections.singleton("original"));
+      permissions.add(permission);
+      
+      // mixed original part
+      methods = new MethodsMetaData();
+      method = new MethodMetaData();
+      method.setEjbName("Overriden");
+      method.setMethodName("execute");
+      method.setMethodIntf(MethodInterfaceType.Local);
+      methods.add(method);
+
+      permission = new MethodPermissionMetaData();
+      permission.setMethods(methods);
+      permission.setRoles(java.util.Collections.singleton("original"));
+      permissions.add(permission);
+
+      methods = new MethodsMetaData();
+      method = new MethodMetaData();
+      method.setEjbName("Overriden");
+      method.setMethodName("execute");
+      method.setMethodIntf(MethodInterfaceType.Remote);
+      methods.add(method);
+
+      permission = new MethodPermissionMetaData();
+      permission.setMethods(methods);
+      Set<String> roles = new HashSet<String>();
+      roles.add("original1");
+      roles.add("original2");
+      permission.setRoles(roles);
+      permissions.add(permission);
+
+      // override
+      JBoss50MetaData override = new JBoss50MetaData();
+      assembly = new JBossAssemblyDescriptorMetaData();
+      override.setAssemblyDescriptor(assembly);
+      permissions = new MethodPermissionsMetaData();
+      assembly.setMethodPermissions(permissions);
+      
+      // override only
+      methods = new MethodsMetaData();
+      method = new MethodMetaData();
+      method.setEjbName("Override");
+      method.setMethodName("execute");
+      methods.add(method);
+
+      permission = new MethodPermissionMetaData();
+      permission.setMethods(methods);
+      permission.setRoles(java.util.Collections.singleton("override"));
+      permissions.add(permission);
+
+      // mixed override part
+      methods = new MethodsMetaData();
+      method = new MethodMetaData();
+      method.setEjbName("Overriden");
+      method.setMethodName("execute");
+      method.setMethodIntf(MethodInterfaceType.LocalHome);
+      methods.add(method);
+
+      permission = new MethodPermissionMetaData();
+      permission.setMethods(methods);
+      permission.setRoles(java.util.Collections.singleton("override"));
+      permissions.add(permission);
+
+      methods = new MethodsMetaData();
+      method = new MethodMetaData();
+      method.setEjbName("Overriden");
+      method.setMethodName("execute");
+      method.setMethodIntf(MethodInterfaceType.Remote);
+      methods.add(method);
+
+      permission = new MethodPermissionMetaData();
+      permission.setMethods(methods);
+      roles = new HashSet<String>();
+      roles.add("override1");
+      roles.add("override2");
+      permission.setRoles(roles);
+      permissions.add(permission);
+
+      // merge
+      JBoss50MetaData merged = new JBoss50MetaData();
+      merged.merge(override, original);      
+      assembly = merged.getAssemblyDescriptor();
+      assertNotNull(assembly);
+      permissions = assembly.getMethodPermissions();
+      assertNotNull(permissions);
+      assertEquals(6, permissions.size());
+
+      for(MethodPermissionMetaData perm : permissions)
+      {
+         methods = perm.getMethods();
+         assertNotNull(methods);
+         assertEquals(1, methods.size());
+         method = methods.get(0);
+         assertNotNull(method);
+         assertEquals("execute", method.getMethodName());
+         roles = perm.getRoles();
+         assertNotNull(roles);
+         
+         String ejbName = method.getEjbName();
+         if("Original".equals(ejbName))
+         {
+            assertEquals(1, roles.size());
+            assertTrue(roles.contains("original"));
+         }
+         else if("Override".equals(ejbName))
+         {
+            assertEquals(1, roles.size());
+            assertTrue(roles.contains("override"));
+         }
+         else if("Overriden".equals(ejbName))
+         {
+            MethodInterfaceType methodIntf = method.getMethodIntf();
+            if(MethodInterfaceType.Local == methodIntf)
+            {
+               assertEquals(1, roles.size());
+               assertTrue(roles.contains("original"));               
+            }
+            else if(MethodInterfaceType.LocalHome == methodIntf)
+            {
+               assertEquals(1, roles.size());
+               assertTrue(roles.contains("override"));
+            }
+            else if(MethodInterfaceType.Remote == methodIntf)
+            {
+               assertEquals(2, roles.size());
+               if(roles.contains("original1"))
+                  assertTrue(roles.contains("original2"));
+               else if(roles.contains("override1"))
+                  assertTrue(roles.contains("override2"));
+               else
+                  fail("roles didn't contain neither original1 nor override1");
+            }
+            else
+            {
+               fail("Unexpected method interface type: " + methodIntf);
+            }
+         }
+         else
+         {
+            fail("Unexpected ejb-name: " + ejbName);
+         }
+      }
+   }   
+}

Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/ejb/JBossEnterpriseBeanOverrideUnitTestCase.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/ejb/JBossEnterpriseBeanOverrideUnitTestCase.java	                        (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/ejb/JBossEnterpriseBeanOverrideUnitTestCase.java	2008-05-28 15:19:20 UTC (rev 73748)
@@ -0,0 +1,360 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.test.metadata.ejb;
+
+import java.beans.BeanInfo;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.Set;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+
+import org.jboss.metadata.ejb.jboss.IORSecurityConfigMetaData;
+import org.jboss.metadata.ejb.jboss.InvokerBindingMetaData;
+import org.jboss.metadata.ejb.jboss.InvokerBindingsMetaData;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossEnvironmentRefsGroupMetaData;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.jboss.metadata.javaee.jboss.AnnotationMetaData;
+import org.jboss.metadata.javaee.jboss.AnnotationsMetaData;
+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.util.Classes;
+
+
+/**
+ * A JBossEnterpriseBeanOverrideUnitTestCase.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBossEnterpriseBeanOverrideUnitTestCase extends TestCase
+{
+   private static final Object[] EMPTY_ARR = new Object[]{};
+
+   /**
+    * Test the simpleProperties method for consistency of the values being set and compared
+    */
+   public void testSimplePropertiesMethod() throws Exception
+   {
+      BeanInfo beanInfo = Introspector.getBeanInfo(JBossSessionBeanMetaData.class);
+      PropertyDescriptor[] props = beanInfo.getPropertyDescriptors();
+      Set<String> ignoreNames = Collections.singleton("name");
+
+      JBossSessionBeanMetaData original = new JBossSessionBeanMetaData();
+      simpleProperties(props, original, true, true, ignoreNames);
+      simpleProperties(props, original, true, false, ignoreNames);
+
+      JBossSessionBeanMetaData override = new JBossSessionBeanMetaData();
+      simpleProperties(props, override, false, true, ignoreNames);
+      simpleProperties(props, override, false, false, ignoreNames);
+      
+      try
+      {
+         simpleProperties(props, override, true, false, ignoreNames);
+         fail("override passed for original");
+      }
+      catch(AssertionFailedError e)
+      {
+         // expected
+      }
+   }
+   
+   public void testSimplePropertiesOfEnterpriseBean() throws Exception
+   {
+      BeanInfo beanInfo = Introspector.getBeanInfo(JBossEnterpriseBeanMetaData.class);
+      PropertyDescriptor[] props = beanInfo.getPropertyDescriptors();
+      Set<String> ignoreNames = Collections.singleton("name");
+      
+      JBossSessionBeanMetaData original = new JBossSessionBeanMetaData();
+      simpleProperties(props, original, true, true, ignoreNames);
+
+      // merge only original
+      JBossSessionBeanMetaData merged = new JBossSessionBeanMetaData();
+      merged.merge(null, original);
+      simpleProperties(props, merged, true, false, ignoreNames);
+
+      // merge with override
+      JBossSessionBeanMetaData override = new JBossSessionBeanMetaData();
+      simpleProperties(props, override, false, true, ignoreNames);      
+      merged = new JBossSessionBeanMetaData();
+      merged.merge(override, original);
+      simpleProperties(props, merged, false, false, ignoreNames);
+   }
+
+   
+   /**
+    * Initializes or asserts properties of java.lang.String, primitive and wrapper types.
+    * If original is true then the generated property values are for the original object,
+    * otherwise - for the override.
+    * If init is true the object is initialized,
+    * otherwise the property values are compared to the expected values.
+    */
+   private void simpleProperties(PropertyDescriptor[] props, Object o, boolean original, boolean init, Set<String> ignoreNames) throws Exception
+   {
+      for (PropertyDescriptor prop : props)
+      {
+         if(ignoreNames.contains(prop.getName()))
+            continue;
+         
+         Class<?> propertyType = prop.getPropertyType();
+         boolean isString = java.lang.String.class.equals(propertyType);
+         boolean isPrimitive = propertyType.isPrimitive();
+         Method writeMethod = prop.getWriteMethod();
+         if (writeMethod == null /*&& prop.getReadMethod() != null*/
+               || !(isPrimitive || Classes.isPrimitiveWrapper(propertyType) || isString))
+            continue;
+      
+         Object propValue;
+         if(isString)
+         {
+            propValue = (original ? "original_" : "override_") + prop.getName();
+         }
+         else
+         {
+            Class wrapper = propertyType;
+            if(isPrimitive)
+               wrapper = Classes.getPrimitiveWrapper(propertyType);
+            if(wrapper.equals(Boolean.class))
+               propValue = original ? "false" : "true";
+            else
+               propValue = original ? "0" : "1";
+            
+            Method method = wrapper.getMethod("valueOf", new Class[]{String.class});
+            propValue = method.invoke(null, new Object[]{propValue});
+         }
+
+         if(init)
+         {
+            writeMethod.invoke(o, new Object[]{propValue});
+         }
+         else
+         {
+            Method readMethod = prop.getReadMethod();
+            if(readMethod == null)
+            {
+               if(propertyType.equals(Boolean.class))
+                  readMethod = Classes.getAttributeGetter(o.getClass(), prop.getName());
+               if(readMethod == null)
+                  fail("Read-method not found for " + prop.getName() + " in " + o.getClass());
+            }
+            assertEquals(prop.getName(), propValue, readMethod.invoke(o, EMPTY_ARR));
+         }
+      }
+   }
+
+   public void testAnnotations() throws Exception
+   {
+      JBossSessionBeanMetaData original = new JBossSessionBeanMetaData();
+      original.setEjbName("session");
+
+      AnnotationsMetaData annotations = new AnnotationsMetaData();
+      original.setAnnotations(annotations);
+      AnnotationMetaData annotation = new AnnotationMetaData();
+      annotation.setAnnotationClass("annotation1");
+      annotation.setAnnotationImplementationClass(annotation.getAnnotationClass() + "Original");
+      annotations.add(annotation);
+      annotation = new AnnotationMetaData();
+      annotation.setAnnotationClass("annotation2");
+      annotation.setAnnotationImplementationClass(annotation.getAnnotationClass() + "Original");
+      annotations.add(annotation);
+      
+      JBossSessionBeanMetaData override = new JBossSessionBeanMetaData();
+      override.setEjbName("session");
+      annotations = new AnnotationsMetaData();
+      override.setAnnotations(annotations);
+      annotation = new AnnotationMetaData();
+      annotation.setAnnotationClass("annotation2");
+      annotation.setAnnotationImplementationClass(annotation.getAnnotationClass() + "Override");
+      annotations.add(annotation);
+      annotation = new AnnotationMetaData();
+      annotation.setAnnotationClass("annotation3");
+      annotation.setAnnotationImplementationClass(annotation.getAnnotationClass() + "Override");
+      annotations.add(annotation);
+      
+      JBossSessionBeanMetaData merged = new JBossSessionBeanMetaData();
+      merged.merge(override, original);
+      annotations = merged.getAnnotations();
+      assertNotNull(annotations);
+      assertEquals(3, annotations.size());
+      annotation = annotations.get("annotation1");
+      assertNotNull(annotation);
+      assertEquals(annotation.getAnnotationClass() + "Original", annotation.getAnnotationImplementationClass());
+      annotation = annotations.get("annotation2");
+      assertNotNull(annotation);
+      assertEquals(annotation.getAnnotationClass() + "Override", annotation.getAnnotationImplementationClass());
+      annotation = annotations.get("annotation3");
+      assertNotNull(annotation);
+      assertEquals(annotation.getAnnotationClass() + "Override", annotation.getAnnotationImplementationClass());
+   }
+   
+   public void testInvokers() throws Exception
+   {
+      JBossSessionBeanMetaData original = new JBossSessionBeanMetaData();
+      original.setEjbName("session");
+
+      InvokerBindingsMetaData invokers = new InvokerBindingsMetaData();
+      InvokerBindingMetaData invoker = new InvokerBindingMetaData();
+      invoker.setInvokerProxyBindingName("invoker1");
+      invoker.setJndiName(invoker.getInvokerProxyBindingName() + "Original");
+      invokers.add(invoker);
+      invoker = new InvokerBindingMetaData();
+      invoker.setInvokerProxyBindingName("invoker2");
+      invoker.setJndiName(invoker.getInvokerProxyBindingName() + "Original");
+      invokers.add(invoker);
+      original.setInvokerBindings(invokers);
+      
+      JBossSessionBeanMetaData override = new JBossSessionBeanMetaData();
+      override.setEjbName("session");
+
+      invokers = new InvokerBindingsMetaData();
+      invoker = new InvokerBindingMetaData();
+      invoker.setInvokerProxyBindingName("invoker2");
+      invoker.setJndiName(invoker.getInvokerProxyBindingName() + "Override");
+      invokers.add(invoker);
+      invoker = new InvokerBindingMetaData();
+      invoker.setInvokerProxyBindingName("invoker3");
+      invoker.setJndiName(invoker.getInvokerProxyBindingName() + "Override");
+      invokers.add(invoker);
+      override.setInvokerBindings(invokers);
+
+
+      JBossSessionBeanMetaData merged = new JBossSessionBeanMetaData();
+      merged.merge(override, original);
+      invokers = merged.getInvokerBindings();
+      assertNotNull(invokers);
+      assertEquals(3, invokers.size());
+      invoker = invokers.get("invoker1");
+      assertNotNull(invoker);
+      assertEquals(invoker.getInvokerProxyBindingName() + "Original", invoker.getJndiName());
+      invoker = invokers.get("invoker2");
+      assertNotNull(invoker);
+      assertEquals(invoker.getInvokerProxyBindingName() + "Override", invoker.getJndiName());
+      invoker = invokers.get("invoker3");
+      assertNotNull(invoker);
+      assertEquals(invoker.getInvokerProxyBindingName() + "Override", invoker.getJndiName());
+   }
+
+   public void testIORSecurityConfig() throws Exception
+   {
+      JBossSessionBeanMetaData original = new JBossSessionBeanMetaData();
+      original.setEjbName("session");
+      original.setIorSecurityConfig(new IORSecurityConfigMetaData());
+      
+      JBossSessionBeanMetaData override = new JBossSessionBeanMetaData();
+      override.setEjbName("session");
+      override.setIorSecurityConfig(new IORSecurityConfigMetaData());
+
+      JBossSessionBeanMetaData merged = new JBossSessionBeanMetaData();
+      merged.merge(override, original);
+      assertTrue(override.getIorSecurityConfig() == merged.getIorSecurityConfig());
+   }
+   
+   public void testEnvironmentRefsGroup() throws Exception
+   {
+      JBossSessionBeanMetaData original = new JBossSessionBeanMetaData();
+      original.setEjbName("session");
+
+      JBossEnvironmentRefsGroupMetaData originalEnv = new JBossEnvironmentRefsGroupMetaData();
+      original.setJndiEnvironmentRefsGroup(originalEnv);
+      originalEnv.setAnnotatedEjbReferences(new AnnotatedEJBReferencesMetaData());
+      
+      EJBLocalReferencesMetaData localRefs = new EJBLocalReferencesMetaData();
+      EJBLocalReferenceMetaData localRef = new EJBLocalReferenceMetaData();
+      localRef.setEjbRefName("localRef1");
+      localRef.setJndiName(localRef.getEjbRefName() + "Original");
+      localRefs.add(localRef);
+      localRef = new EJBLocalReferenceMetaData();
+      localRef.setEjbRefName("localRef2");
+      localRef.setJndiName(localRef.getEjbRefName() + "Original");
+      localRefs.add(localRef);
+      originalEnv.setEjbLocalReferences(localRefs);
+      
+      EJBReferencesMetaData ejbRefs = new EJBReferencesMetaData();
+      EJBReferenceMetaData ejbRef = new EJBReferenceMetaData();
+      ejbRef.setEjbRefName("ejbRef1");
+      ejbRef.setJndiName(ejbRef.getEjbRefName() + "Original");
+      ejbRefs.add(ejbRef);
+      ejbRef = new EJBReferenceMetaData();
+      ejbRef.setEjbRefName("ejbRef2");
+      ejbRef.setJndiName(ejbRef.getEjbRefName() + "Original");
+      ejbRefs.add(ejbRef);
+      originalEnv.setEjbReferences(ejbRefs);
+      
+      // override
+      JBossSessionBeanMetaData override = new JBossSessionBeanMetaData();
+      override.setEjbName("session");
+      JBossEnvironmentRefsGroupMetaData overrideEnv = new JBossEnvironmentRefsGroupMetaData();
+      override.setJndiEnvironmentRefsGroup(overrideEnv);
+      overrideEnv.setAnnotatedEjbReferences(new AnnotatedEJBReferencesMetaData());
+
+      localRefs = new EJBLocalReferencesMetaData();
+      localRef = new EJBLocalReferenceMetaData();
+      localRef.setEjbRefName("localRef2");
+      localRef.setJndiName(localRef.getEjbRefName() + "Override");
+      localRefs.add(localRef);
+      overrideEnv.setEjbLocalReferences(localRefs);
+      
+      ejbRefs = new EJBReferencesMetaData();
+      ejbRef = new EJBReferenceMetaData();
+      ejbRef.setEjbRefName("ejbRef2");
+      ejbRef.setJndiName(ejbRef.getEjbRefName() + "Override");
+      ejbRefs.add(ejbRef);
+      overrideEnv.setEjbReferences(ejbRefs);
+      
+      // merged
+      JBossSessionBeanMetaData merged = new JBossSessionBeanMetaData();
+      merged.merge(override, original);
+      JBossEnvironmentRefsGroupMetaData mergedEnv = (JBossEnvironmentRefsGroupMetaData) merged.getJndiEnvironmentRefsGroup();
+      assertNotNull(mergedEnv);
+      
+      // I am not sure whether it makes sense
+      assertTrue(originalEnv.getAnnotatedEjbReferences() == mergedEnv.getAnnotatedEjbReferences());
+
+      // local refs
+      localRefs = mergedEnv.getEjbLocalReferences();
+      assertNotNull(localRefs);
+      assertEquals(2, localRefs.size());
+      localRef = localRefs.get("localRef1");
+      assertNotNull(localRef);
+      assertEquals(localRef.getEjbRefName() + "Original", localRef.getJndiName());
+      localRef = localRefs.get("localRef2");
+      assertNotNull(localRef);
+      assertEquals(localRef.getEjbRefName() + "Override", localRef.getJndiName());
+      
+      ejbRefs = mergedEnv.getEjbReferences();
+      assertNotNull(ejbRefs);
+      assertEquals(2, ejbRefs.size());
+      ejbRef = ejbRefs.get("ejbRef1");
+      assertNotNull(ejbRef);
+      assertEquals(ejbRef.getEjbRefName() + "Original", ejbRef.getJndiName());
+      ejbRef = ejbRefs.get("ejbRef2");
+      assertNotNull(ejbRef);
+      assertEquals(ejbRef.getEjbRefName() + "Override", ejbRef.getJndiName());
+   }
+}




More information about the jboss-cvs-commits mailing list