[jboss-cvs] JBossAS SVN: r80349 - in projects/metadata/trunk/src: test/java/org/jboss/test/metadata and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Nov 2 13:41:58 EST 2008


Author: ALRubinger
Date: 2008-11-02 13:41:56 -0500 (Sun, 02 Nov 2008)
New Revision: 80349

Added:
   projects/metadata/trunk/src/main/java/org/jboss/metadata/process/processor/ejb/jboss/SetExplicitLocalJndiNameProcessor.java
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta143/
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta143/MyLocal.java
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta143/MyLocalBean.java
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta143/unit/
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta143/unit/LocalBindingSetsLocalJndiNameTestCase.java
Modified:
   projects/metadata/trunk/src/main/java/org/jboss/metadata/process/processor/ejb/jboss/JBossMetaDataValidatorChainProcessor.java
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta117/unit/BindingsWithNoAssociatedBusinessInterfaceTestCase.java
Log:
[JBMETA-143] Add and test SetExplicitLocalJndiNameProcessor

Modified: projects/metadata/trunk/src/main/java/org/jboss/metadata/process/processor/ejb/jboss/JBossMetaDataValidatorChainProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/process/processor/ejb/jboss/JBossMetaDataValidatorChainProcessor.java	2008-11-02 17:37:01 UTC (rev 80348)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/process/processor/ejb/jboss/JBossMetaDataValidatorChainProcessor.java	2008-11-02 18:41:56 UTC (rev 80349)
@@ -47,7 +47,7 @@
    private static final Logger log = Logger.getLogger(JBossMetaDataValidatorChainProcessor.class);
 
    @SuppressWarnings("unchecked")
-   public static final JBossMetaDataValidatorChainProcessor INSTANCE = new JBossMetaDataValidatorChainProcessor();
+   public static final JBossMetaDataValidatorChainProcessor<JBossMetaData> INSTANCE = new JBossMetaDataValidatorChainProcessor<JBossMetaData>();
 
    // --------------------------------------------------------------------------------||
    // Required Implementations -------------------------------------------------------||

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/process/processor/ejb/jboss/SetExplicitLocalJndiNameProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/process/processor/ejb/jboss/SetExplicitLocalJndiNameProcessor.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/process/processor/ejb/jboss/SetExplicitLocalJndiNameProcessor.java	2008-11-02 18:41:56 UTC (rev 80349)
@@ -0,0 +1,123 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.process.processor.ejb.jboss;
+
+import java.util.List;
+
+import org.jboss.logging.Logger;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeansMetaData;
+import org.jboss.metadata.ejb.jboss.JBossMetaData;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.jboss.metadata.ejb.jboss.LocalBindingMetaData;
+import org.jboss.metadata.process.ProcessingException;
+import org.jboss.metadata.process.processor.JBossMetaDataProcessor;
+
+/**
+ * SetExplicitLocalJndiNameProcessor
+ * 
+ * Processor to set the default local JNDI name
+ * as specified by @LocalBinding.jndiName
+ * upon metadata
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class SetExplicitLocalJndiNameProcessor<T extends JBossMetaData> implements JBossMetaDataProcessor<T>
+{
+
+   // --------------------------------------------------------------------------------||
+   // Class Members ------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   private static final Logger log = Logger.getLogger(SetExplicitLocalJndiNameProcessor.class);
+
+   /**
+    * Convenience instance
+    */
+   @SuppressWarnings("unchecked")
+   public static final SetExplicitLocalJndiNameProcessor INSTANCE = new SetExplicitLocalJndiNameProcessor();
+
+   // --------------------------------------------------------------------------------||
+   // Required Implementations -------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /* (non-Javadoc)
+    * @see org.jboss.metadata.process.processor.JBossMetaDataProcessor#process(org.jboss.metadata.ejb.jboss.JBossMetaData)
+    */
+   public T process(T metadata) throws ProcessingException
+   {
+      // Sanity check
+      assert metadata != null : "Specified metadata was null";
+
+      // Get EJBs
+      JBossEnterpriseBeansMetaData ejbs = metadata.getEnterpriseBeans();
+
+      // For each EJB
+      for (JBossEnterpriseBeanMetaData ejb : ejbs)
+      {
+
+         // Only applies to Session beans
+         if (!ejb.isSession())
+         {
+            continue;
+         }
+
+         // Cast
+         JBossSessionBeanMetaData smd = (JBossSessionBeanMetaData) ejb;
+
+         // Get @LocalBindings
+         List<LocalBindingMetaData> localBindings = smd.getLocalBindings();
+
+         // If not specified, continue to next bean
+         if (localBindings == null || localBindings.size() == 0)
+         {
+            continue;
+         }
+
+         // For now, we just support 1 LocalBinding
+         assert localBindings.size() == 1 : "Currently only 1 @LocalBinding is supported for EJB " + smd.getName();
+
+         // Grab the top @LocalBinding
+         LocalBindingMetaData localBinding = localBindings.get(0);
+
+         // Get the JNDI Name
+         String localJndiName = localBinding.getJndiName();
+         assert localJndiName != null && localJndiName.length() > 0 : "@LocalBinding.jndiName must be specified for EJB "
+               + smd.getName();
+
+         // Set the local JNDI Name
+         smd.setLocalJndiName(localJndiName);
+
+         // Log
+         if (log.isTraceEnabled())
+         {
+            log.trace("Found and set @LocalBinding.jndiName for EJB " + smd.getName() + " to " + localJndiName);
+         }
+      }
+
+      // Return
+      return metadata;
+
+   }
+
+}

Modified: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta117/unit/BindingsWithNoAssociatedBusinessInterfaceTestCase.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta117/unit/BindingsWithNoAssociatedBusinessInterfaceTestCase.java	2008-11-02 17:37:01 UTC (rev 80348)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta117/unit/BindingsWithNoAssociatedBusinessInterfaceTestCase.java	2008-11-02 18:41:56 UTC (rev 80349)
@@ -100,7 +100,7 @@
       // Make the metadata
       JBoss50MetaData md = creator.create(classes);
 
-      // Run the Validation Processor
+      // Run the Validator
       try
       {
          JBossMetaDataValidatorChainProcessor.INSTANCE.process(md);

Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta143/MyLocal.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta143/MyLocal.java	                        (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta143/MyLocal.java	2008-11-02 18:41:56 UTC (rev 80349)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.jbmeta143;
+
+/**
+ * MyLocal
+ * 
+ * A test local business interface declaring a local JNDI binding name
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface MyLocal
+{
+   /**
+    * Local JNDI Target
+    */
+   String JNDI_NAME = "OverriddenLocalJndiName";
+}

Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta143/MyLocalBean.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta143/MyLocalBean.java	                        (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta143/MyLocalBean.java	2008-11-02 18:41:56 UTC (rev 80349)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.jbmeta143;
+
+import javax.ejb.Local;
+import javax.ejb.Stateless;
+
+import org.jboss.ejb3.annotation.LocalBinding;
+
+/**
+ * MyLocalBean
+ * 
+ * A test SLSB declaring an explicit Local JNDI Binding
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Stateless
+ at Local(MyLocal.class)
+ at LocalBinding(jndiBinding = MyLocal.JNDI_NAME)
+public class MyLocalBean implements MyLocal
+{
+
+}

Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta143/unit/LocalBindingSetsLocalJndiNameTestCase.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta143/unit/LocalBindingSetsLocalJndiNameTestCase.java	                        (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta143/unit/LocalBindingSetsLocalJndiNameTestCase.java	2008-11-02 18:41:56 UTC (rev 80349)
@@ -0,0 +1,102 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.jbmeta143.unit;
+
+import java.lang.reflect.AnnotatedElement;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import junit.framework.TestCase;
+
+import org.jboss.logging.Logger;
+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.ejb.jboss.JBoss50MetaData;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.process.processor.JBossMetaDataProcessor;
+import org.jboss.metadata.process.processor.ejb.jboss.SetExplicitLocalJndiNameProcessor;
+import org.jboss.test.metadata.jbmeta143.MyLocal;
+import org.jboss.test.metadata.jbmeta143.MyLocalBean;
+
+/**
+ * LocalBindingSetsLocalJndiNameTestCase
+ * 
+ * Tests that an EJB with @LocalBinding.jndiBinding
+ * declared has the local JNDI Name set in the metadata
+ * 
+ * JBMETA-117
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class LocalBindingSetsLocalJndiNameTestCase extends TestCase
+{
+   // -------------------------------------------------------------------||
+   // Class Members -----------------------------------------------------||
+   // -------------------------------------------------------------------||
+
+   private static final Logger log = Logger.getLogger(LocalBindingSetsLocalJndiNameTestCase.class);
+
+   // -------------------------------------------------------------------||
+   // Tests -------------------------------------------------------------||
+   // -------------------------------------------------------------------||
+
+   /**
+    * Tests that an EJB with a @LocalBinding declared has a local
+    * JNDI name set in metadata
+    */
+   @SuppressWarnings("unchecked")
+   public void testLocalBindingDeclaredSetsLocalJndiName() throws Throwable
+   {
+      // Set up EJB Impl class
+      final Class<?> ejbImplClass = MyLocalBean.class;
+
+      /*
+       * Set up a JBoss Metadata Creator
+       */
+
+      // Make an annotation finder
+      AnnotationFinder<AnnotatedElement> finder = new DefaultAnnotationFinder<AnnotatedElement>();
+
+      // Configure to scan the test EJB
+      Collection<Class<?>> classes = new ArrayList<Class<?>>();
+      classes.add(ejbImplClass);
+      JBoss50Creator creator = new JBoss50Creator(finder);
+
+      // Make the metadata
+      JBoss50MetaData md = creator.create(classes);
+
+      // Create and run the processor on the metadata
+      JBossMetaDataProcessor<JBoss50MetaData> processor = SetExplicitLocalJndiNameProcessor.INSTANCE;
+      md = processor.process(md);
+
+      // Get the EJB
+      JBossEnterpriseBeanMetaData ejb = md.getEnterpriseBean(MyLocalBean.class.getSimpleName());
+
+      // Ensure JNDI name is set up as expected
+      String expectedLocalJndiName = MyLocal.JNDI_NAME;
+      TestCase.assertEquals("@LocalBinding.jndiName should result in metadata local JNDI name to be set",
+            expectedLocalJndiName, ejb.getLocalJndiName());
+   }
+
+}




More information about the jboss-cvs-commits mailing list