[jboss-cvs] JBossAS SVN: r76209 - in projects/ejb3/trunk: common/src/main/java/org/jboss/ejb3/common/lang and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jul 24 21:51:58 EDT 2008


Author: ALRubinger
Date: 2008-07-24 21:51:58 -0400 (Thu, 24 Jul 2008)
New Revision: 76209

Added:
   projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/lang/SerializableMethod.java
Modified:
   projects/ejb3/trunk/common/jboss-ejb3-common-client.xml
   projects/ejb3/trunk/common/pom.xml
   projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/plugin/mc/Ejb3McRegistrar.java
   projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/spi/Ejb3Registrar.java
   projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/spi/Ejb3RegistrarLocator.java
   projects/ejb3/trunk/test/pom.xml
   projects/ejb3/trunk/test/src/main/java/org/jboss/ejb3/test/common/MetaDataHelper.java
Log:
[EJBTHREE-1345] Development in EJB3 Common and EJB3 Dev for EJB3 Proxy

Modified: projects/ejb3/trunk/common/jboss-ejb3-common-client.xml
===================================================================
--- projects/ejb3/trunk/common/jboss-ejb3-common-client.xml	2008-07-25 01:50:04 UTC (rev 76208)
+++ projects/ejb3/trunk/common/jboss-ejb3-common-client.xml	2008-07-25 01:51:58 UTC (rev 76209)
@@ -16,6 +16,7 @@
       <directory>target/classes</directory>
       <outputDirectory></outputDirectory>
       <includes>
+        <include>org/jboss/ejb3/common/lang/SerializableMethod.class</include>
         <include>org/jboss/ejb3/common/registrar/spi/**</include>
         <include>org/jboss/ejb3/common/string/StringUtils.class</include>
       </includes>

Modified: projects/ejb3/trunk/common/pom.xml
===================================================================
--- projects/ejb3/trunk/common/pom.xml	2008-07-25 01:50:04 UTC (rev 76208)
+++ projects/ejb3/trunk/common/pom.xml	2008-07-25 01:51:58 UTC (rev 76209)
@@ -4,7 +4,7 @@
   <parent>
     <artifactId>jboss-ejb3-build</artifactId>
     <groupId>org.jboss.ejb3</groupId>
-    <version>0.13.10</version>
+    <version>0.13.11-SNAPSHOT</version>
     <relativePath>../build/pom.xml</relativePath>
   </parent>
 

Copied: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/lang/SerializableMethod.java (from rev 76062, projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/lang/SerializableMethod.java)
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/lang/SerializableMethod.java	                        (rev 0)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/lang/SerializableMethod.java	2008-07-25 01:51:58 UTC (rev 76209)
@@ -0,0 +1,405 @@
+/*
+ * 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.ejb3.common.lang;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * SerializableMethod
+ * 
+ * A Serializable view of an Invoked Method, providing
+ * overridden implementations of hashCode, equals, and toString
+ * 
+ * JIRA: EJBTHREE-1269
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class SerializableMethod implements Serializable
+{
+   // ------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------||
+   // ------------------------------------------------------------------------------||
+
+   private static final long serialVersionUID = 1L;
+
+   // ------------------------------------------------------------------------------||
+   // Instance Members -------------------------------------------------------------||
+   // ------------------------------------------------------------------------------||
+
+   /**
+    * The name of the method
+    */
+   private String name;
+
+   /**
+    * Fully-qualified declaring class name of the method
+    */
+   private String declaringClassName;
+
+   /**
+    * Fully-qualified final (child) class name of the method, may have inherited the method
+    */
+   private String actualClassName;
+
+   /**
+    * Fully-qualfied class name of the return type of the method
+    */
+   private String returnType;
+
+   /**
+    * Array of fully-qualified class names of arguments, in order
+    */
+   private String[] argumentTypes;
+
+   // ------------------------------------------------------------------------------||
+   // Constructors -----------------------------------------------------------------||
+   // ------------------------------------------------------------------------------||
+   
+   /**
+    * Constructor
+    * 
+    * Creates a Serializable Method View, using the declaring class
+    * of the specified method as the actual class
+    * 
+    * @param method The method this view represents
+    */
+   public SerializableMethod(Method method)
+   {
+      this(method, method.getDeclaringClass());
+   }
+
+   /**
+    * Constructor
+    * 
+    * Creates a Serializable Method View, allowing for
+    * an alternate "actual class" defining the method in 
+    * addition to the declaring class
+    * 
+    * @param method The method this view represents
+    * @param actualClass The class to which this method is associated, 
+    *   may be a child of the class declaring the method
+    */
+   public SerializableMethod(Method method, Class<?> actualClass)
+   {
+      // Pass to alternate constructor
+      this(method, actualClass.getName());
+   }
+   
+   /**
+    * Constructor
+    * 
+    * Creates a Serializable Method View, allowing for
+    * an alternate "actual class" defining the method in 
+    * addition to the declaring class
+    * 
+    * @param method The method this view represents
+    * @param actualClass The name of the class to which this method is associated, 
+    *   may be a child of the class declaring the method
+    */
+   public SerializableMethod(Method method, String actualClassName)
+   {
+      // Set properties
+      this.setName(method.getName());
+      this.setDeclaringClassName(method.getDeclaringClass().getName());
+      this.setActualClassName(actualClassName);
+      this.setReturnType(method.getReturnType().getName());
+      Class<?>[] paramTypes = method.getParameterTypes();
+      List<String> paramTypesString = new ArrayList<String>();
+      if (paramTypes != null)
+      {
+         for (Class<?> paramType : paramTypes)
+         {
+            paramTypesString.add(paramType.getName());
+         }
+      }
+      this.setArgumentTypes(paramTypesString.toArray(new String[]
+      {}));
+   }
+
+   // ------------------------------------------------------------------------------||
+   // Overridden Implementations ---------------------------------------------------||
+   // ------------------------------------------------------------------------------||
+
+   @Override
+   public boolean equals(Object obj)
+   {
+      // If not an instance of SerializableMethod
+      if (!(obj instanceof SerializableMethod))
+      {
+         // Different types, we can't be equal
+         return false;
+      }
+
+      // Cast
+      SerializableMethod other = SerializableMethod.class.cast(obj);
+
+      // We're equal if all properties are equal
+      return this.getDeclaringClassName().equals(other.getDeclaringClassName())
+            && this.getName().equals(other.getName())
+            && Arrays.equals(this.getArgumentTypes(), other.getArgumentTypes())
+            && this.getActualClassName().equals(other.getActualClassName());
+   }
+
+   @Override
+   public int hashCode()
+   {
+      // toString is unique, use it
+      return this.toString().hashCode();
+   }
+
+   @Override
+   public String toString()
+   {
+      // Initialize
+      StringBuffer sb = new StringBuffer();
+
+      // Construct
+      sb.append(this.getActualClassName());
+      sb.append(": ");
+      sb.append(this.getDeclaringClassName());
+      sb.append('.');
+      sb.append(this.getName());
+      sb.append('(');
+      int count = 0;
+      for (String argType : this.getArgumentTypes())
+      {
+         count++;
+         sb.append(argType);
+         if (count < this.getArgumentTypes().length)
+         {
+            sb.append(',');
+         }
+      }
+      sb.append(')');
+
+      // Return
+      return sb.toString();
+   }
+
+   // ------------------------------------------------------------------------------||
+   // Functional Methods -----------------------------------------------------------||
+   // ------------------------------------------------------------------------------||
+
+   /**
+    * Obtains the Method described by this view, using the
+    * TCL
+    * 
+    * @return
+    */
+   public Method toMethod()
+   {
+      return this.toMethod(Thread.currentThread().getContextClassLoader());
+   }
+
+   /**
+    * Obtains the Method described by this view, using the
+    * ClassLoader specified
+    * 
+    * @param cl
+    * @return
+    */
+   public Method toMethod(ClassLoader cl)
+   {
+      // Load the Class described by the Method
+      Class<?> invokingClass = this.getClassType(cl);
+
+      // Load the argument types
+      List<Object> argTypesList = new ArrayList<Object>();
+      for (String argTypeName : this.getArgumentTypes())
+      {
+         Class<?> argType = this.getClassFromName(argTypeName, cl);
+         argTypesList.add(argType);
+      }
+      Class<?>[] argTypes = argTypesList.toArray(new Class<?>[]
+      {});
+
+      // Obtain the Method
+      String methodName = this.getName();
+      Method invokedMethod = null;
+      try
+      {
+         invokedMethod = invokingClass.getMethod(methodName, argTypes);
+      }
+      catch (NoSuchMethodException nsme)
+      {
+         throw new RuntimeException("Method " + this + " does not exist in " + invokingClass.getName(), nsme);
+      }
+
+      // Return
+      return invokedMethod;
+   }
+
+   /**
+    * Obtains the Class described by this view, using the
+    * TCL
+    * 
+    * @return
+    */
+   public Class<?> getClassType()
+   {
+      return this.getClassType(Thread.currentThread().getContextClassLoader());
+   }
+
+   /**
+    * Obtains the Class described by this view, using the
+    * specified ClassLoader
+    * 
+    * @param cl
+    * @return
+    */
+   public Class<?> getClassType(ClassLoader cl)
+   {
+      // Obtain
+      Class<?> clazz = this.getClassFromName(this.getDeclaringClassName(), cl);
+
+      // Return 
+      return clazz;
+   }
+
+   /**
+    * Returns the class associated with the given name
+    * 
+    * @param name
+    * @param cl
+    * @return
+    */
+   protected Class<?> getClassFromName(String name, ClassLoader cl)
+   {
+      // Perform assertions
+      assert cl != null : ClassLoader.class.getSimpleName() + "must be defined.";
+
+      /*
+       * Handle Primitives
+       */
+      if (name.equals(void.class.getName()))
+      {
+         return void.class;
+      }
+      if (name.equals(byte.class.getName()))
+      {
+         return byte.class;
+      }
+      if (name.equals(short.class.getName()))
+      {
+         return short.class;
+      }
+      if (name.equals(int.class.getName()))
+      {
+         return int.class;
+      }
+      if (name.equals(long.class.getName()))
+      {
+         return long.class;
+      }
+      if (name.equals(char.class.getName()))
+      {
+         return char.class;
+      }
+      if (name.equals(boolean.class.getName()))
+      {
+         return boolean.class;
+      }
+      if (name.equals(float.class.getName()))
+      {
+         return float.class;
+      }
+      if (name.equals(double.class.getName()))
+      {
+         return double.class;
+      }
+
+      // Load the Class described by the Method
+      Class<?> clazz = null;
+
+      try
+      {
+         clazz = cl.loadClass(name);
+      }
+      catch (ClassNotFoundException cnfe)
+      {
+         throw new RuntimeException("Specified calling class, " + name + " could not be found for " + cl, cnfe);
+      }
+
+      // Return
+      return clazz;
+   }
+
+   // ------------------------------------------------------------------------------||
+   // Accessors / Mutators ---------------------------------------------------------||
+   // ------------------------------------------------------------------------------||
+
+   public String getDeclaringClassName()
+   {
+      return declaringClassName;
+   }
+
+   public void setDeclaringClassName(String className)
+   {
+      this.declaringClassName = className;
+   }
+
+   public String getReturnType()
+   {
+      return returnType;
+   }
+
+   public void setReturnType(String returnType)
+   {
+      this.returnType = returnType;
+   }
+
+   public String[] getArgumentTypes()
+   {
+      return argumentTypes;
+   }
+
+   public void setArgumentTypes(String[] argumentTypes)
+   {
+      this.argumentTypes = argumentTypes;
+   }
+
+   public String getName()
+   {
+      return name;
+   }
+
+   public void setName(String name)
+   {
+      this.name = name;
+   }
+
+   public String getActualClassName()
+   {
+      return actualClassName;
+   }
+
+   public void setActualClassName(String actualClassName)
+   {
+      this.actualClassName = actualClassName;
+   }
+
+}

Modified: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/plugin/mc/Ejb3McRegistrar.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/plugin/mc/Ejb3McRegistrar.java	2008-07-25 01:50:04 UTC (rev 76208)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/plugin/mc/Ejb3McRegistrar.java	2008-07-25 01:51:58 UTC (rev 76209)
@@ -104,6 +104,40 @@
       log.debug("Returning from name \"" + name + "\": " + target);
       return target;
    }
+   
+   /**
+    * Obtains the value bound at the specified name, 
+    * throwing NotBoundException if there is nothing
+    * bound at the key.  The value returned will be automatically
+    * casted to the specified type.
+    * 
+    * @param <T>
+    * @param name
+    * @param type
+    * @return
+    * @throws NotBoundException
+    */
+   public <T> T lookup(Object name, Class<T> type) throws NotBoundException
+   {
+      // Obtain object
+      Object obj = this.lookup(name);
+      
+      // Cast
+      T returned = null;
+      try
+      {
+         returned = type.cast(obj);
+      }
+      catch(ClassCastException cce)
+      {
+         throw new RuntimeException("Value returned from key \"" + name
+               + "\" in Object Store was not of expected type " + type + ", but was instead "
+               + obj.getClass().getName());
+      }
+      
+      // Return
+      return returned;
+   }
 
    /**
     * Binds the specified value to the key of specified name, 

Modified: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/spi/Ejb3Registrar.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/spi/Ejb3Registrar.java	2008-07-25 01:50:04 UTC (rev 76208)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/spi/Ejb3Registrar.java	2008-07-25 01:51:58 UTC (rev 76209)
@@ -45,6 +45,20 @@
    Object lookup(Object name) throws NotBoundException;
 
    /**
+    * Obtains the value bound at the specified name, 
+    * throwing NotBoundException if there is nothing
+    * bound at the key.  The value returned will be automatically
+    * casted to the specified type.
+    * 
+    * @param <T>
+    * @param name
+    * @param type
+    * @return
+    * @throws NotBoundException
+    */
+   <T> T lookup(Object name, Class<T> type) throws NotBoundException;
+
+   /**
     * Binds the specified value to the key of specified name, 
     * throwing a DuplicateBindException in the case the
     * name is not unique

Modified: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/spi/Ejb3RegistrarLocator.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/spi/Ejb3RegistrarLocator.java	2008-07-25 01:50:04 UTC (rev 76208)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/registrar/spi/Ejb3RegistrarLocator.java	2008-07-25 01:51:58 UTC (rev 76209)
@@ -114,6 +114,27 @@
    }
 
    /**
+    * Unbinds the current Ejb3Registrar implementation
+    * as the registrar of record 
+    * 
+    * @param registrar
+    * @throws NotBoundException
+    */
+   public synchronized static void unbindRegistrar() throws NotBoundException
+   {
+      // Ensure bound
+      if (!isRegistrarBound())
+      {
+         throw new NotBoundException(Ejb3Registrar.class.getSimpleName() + " is not bound, cannot unbind");
+      }
+
+      // Unbind Registrar
+      Ejb3Registrar reg = Ejb3RegistrarLocator.instance.getRegistrar();
+      log.debug("Unbinding " + Ejb3Registrar.class.getSimpleName() + ": " + reg);
+      Ejb3RegistrarLocator.instance.registrar = null;
+   }
+
+   /**
     * Returns whether or not the Ejb3Registrar 
     * has been bound to this Process
     * 

Modified: projects/ejb3/trunk/test/pom.xml
===================================================================
--- projects/ejb3/trunk/test/pom.xml	2008-07-25 01:50:04 UTC (rev 76208)
+++ projects/ejb3/trunk/test/pom.xml	2008-07-25 01:51:58 UTC (rev 76209)
@@ -4,7 +4,7 @@
   <parent>
     <artifactId>jboss-ejb3-build</artifactId>
     <groupId>org.jboss.ejb3</groupId>
-    <version>0.13.10</version>
+    <version>0.13.11-SNAPSHOT</version>
     <relativePath>../build/pom.xml</relativePath>
   </parent>
 

Modified: projects/ejb3/trunk/test/src/main/java/org/jboss/ejb3/test/common/MetaDataHelper.java
===================================================================
--- projects/ejb3/trunk/test/src/main/java/org/jboss/ejb3/test/common/MetaDataHelper.java	2008-07-25 01:50:04 UTC (rev 76208)
+++ projects/ejb3/trunk/test/src/main/java/org/jboss/ejb3/test/common/MetaDataHelper.java	2008-07-25 01:51:58 UTC (rev 76209)
@@ -22,17 +22,25 @@
 package org.jboss.ejb3.test.common;
 
 import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
+import javax.annotation.Resource;
+import javax.ejb.SessionContext;
+
+import org.jboss.annotation.javaee.Descriptions;
 import org.jboss.logging.Logger;
+import org.jboss.metadata.annotation.creator.ProcessorUtils;
 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.JBossAssemblyDescriptorMetaData;
 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.jboss.JBossSessionBeanMetaData;
 import org.jboss.metadata.ejb.jboss.RemoteBindingMetaData;
@@ -40,6 +48,11 @@
 import org.jboss.metadata.ejb.jboss.jndipolicy.plugins.JBossSessionPolicyDecorator;
 import org.jboss.metadata.ejb.spec.BusinessLocalsMetaData;
 import org.jboss.metadata.ejb.spec.BusinessRemotesMetaData;
+import org.jboss.metadata.javaee.spec.ResourceEnvironmentReferenceMetaData;
+import org.jboss.metadata.javaee.spec.ResourceEnvironmentReferencesMetaData;
+import org.jboss.metadata.javaee.spec.ResourceInjectionTargetMetaData;
+import org.jboss.metadata.javaee.spec.ResourceReferenceMetaData;
+import org.jboss.metadata.javaee.spec.ResourceReferencesMetaData;
 
 /**
  * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
@@ -95,6 +108,28 @@
          remoteBindings.add(remoteBinding);
          beanMetaDataDelegate.setRemoteBindings(remoteBindings);
       }
+      
+//      // Mock up @Resource field-level annotation
+//      //TODO Remove when handled by JBoss50Creator
+//      // http://www.jboss.com/index.html?module=bb&op=viewtopic&t=139578
+//      Field[] fields = beanImplClass.getFields();
+//      for (Field field : fields)
+//      {
+//         Resource resource = field.getAnnotation(Resource.class);
+//         if (resource != null)
+//         {
+//            Class<?> type = field.getType();
+//            if (type.equals(SessionContext.class))
+//            {
+//               ResourceReferenceMetaData ref = createResourceEnvRef(resource, field);
+//               JBossEnvironmentRefsGroupMetaData jndiEnvRefs = new JBossEnvironmentRefsGroupMetaData();
+//               jndiEnvRefs.setResourceReferences(new ResourceReferencesMetaData());
+//               beanMetaDataDelegate.setJndiEnvironmentRefsGroup(jndiEnvRefs);
+//               ResourceReferencesMetaData refs = beanMetaDataDelegate.getResourceReferences();
+//               refs.add(ref);
+//            }
+//         }
+//      }
 
       // Use a Session JNDI Binding Policy for the metadata
       JBossSessionPolicyDecorator beanMetaData = new JBossSessionPolicyDecorator(beanMetaDataDelegate,
@@ -144,4 +179,56 @@
 
       return beanMetaData;
    }
+
+   /*
+    * DEPRECATED Below this marker
+    */
+   
+   @Deprecated
+   protected static ResourceReferenceMetaData createResourceEnvRef(Resource annotation, Field element)
+   {
+      ResourceReferenceMetaData ref = new ResourceReferenceMetaData();
+      String name = annotation.name();
+      if (name.length() == 0)
+         name = getName(element);
+      if (annotation.mappedName().length() > 0)
+         ref.setMappedName(annotation.mappedName());
+      if (annotation.type() != Object.class)
+         ref.setType(annotation.type().getName());
+      else
+         ref.setType(getType(element));
+      Descriptions descriptions = ProcessorUtils.getDescription(annotation.description());
+      if (descriptions != null)
+         ref.setDescriptions(descriptions);
+
+      String injectionName = getInjectionName(element);
+      Set<ResourceInjectionTargetMetaData> injectionTargets = ProcessorUtils
+            .getInjectionTargets(injectionName, element);
+      if (injectionTargets != null)
+         ref.setInjectionTargets(injectionTargets);
+
+      return ref;
+   }
+   
+   @Deprecated
+   protected static String getName(Field element)
+   {
+      String name = element.getName();
+      return name;
+   }
+   @Deprecated
+   protected static String getInjectionName(Field element)
+   {
+      return element.getName();
+   }
+   @Deprecated
+   protected static String getType(Field element)
+   {
+      return element.getType().getName();
+   }
+   @Deprecated
+   protected static String getDeclaringClass(Field element)
+   {
+      return element.getDeclaringClass().getName();
+   }
 }




More information about the jboss-cvs-commits mailing list