[Jboss-cvs] JBossAS SVN: r55512 - in trunk/ejb3/src: main/org/jboss/annotation/ejb main/org/jboss/ejb3 main/org/jboss/ejb3/metamodel resources/schema resources/test/circulardependency/META-INF test/org/jboss/ejb3/test/strictpool

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Aug 10 21:16:28 EDT 2006


Author: bdecoste
Date: 2006-08-10 21:16:24 -0400 (Thu, 10 Aug 2006)
New Revision: 55512

Added:
   trunk/ejb3/src/main/org/jboss/ejb3/metamodel/XmlAnnotation.java
Modified:
   trunk/ejb3/src/main/org/jboss/annotation/ejb/PoolClassImpl.java
   trunk/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java
   trunk/ejb3/src/main/org/jboss/ejb3/metamodel/EnterpriseBean.java
   trunk/ejb3/src/main/org/jboss/ejb3/metamodel/EnterpriseBeans.java
   trunk/ejb3/src/main/org/jboss/ejb3/metamodel/JBossDDObjectFactory.java
   trunk/ejb3/src/resources/schema/jboss_5_0.xsd
   trunk/ejb3/src/resources/test/circulardependency/META-INF/jboss.xml
   trunk/ejb3/src/test/org/jboss/ejb3/test/strictpool/MDBInvoker.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/strictpool/OverrideStrictlyPooledSessionBean.java
Log:
added generic <annotation> element to jboss.xml for adding any annotation type via xml

Modified: trunk/ejb3/src/main/org/jboss/annotation/ejb/PoolClassImpl.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/annotation/ejb/PoolClassImpl.java	2006-08-11 01:15:42 UTC (rev 55511)
+++ trunk/ejb3/src/main/org/jboss/annotation/ejb/PoolClassImpl.java	2006-08-11 01:16:24 UTC (rev 55512)
@@ -29,9 +29,9 @@
  */
 public class PoolClassImpl implements PoolClass
 {
-   private Class value;
-   private int maxSize = 30;
-   private long timeout = Long.MAX_VALUE;
+   public Class value;
+   public int maxSize = 30;
+   public long timeout = Long.MAX_VALUE;
 
    public PoolClassImpl()
    {
@@ -71,4 +71,15 @@
    {
       return PoolClass.class;
    }
+   
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[PoolClassImpl:");
+      sb.append("value=").append(value);
+      sb.append(", maxSize=").append(maxSize);
+      sb.append(", timeout=").append(timeout);
+      sb.append("]");
+      return sb.toString();
+   }
 }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java	2006-08-11 01:15:42 UTC (rev 55511)
+++ trunk/ejb3/src/main/org/jboss/ejb3/Ejb3DescriptorHandler.java	2006-08-11 01:16:24 UTC (rev 55512)
@@ -21,6 +21,8 @@
  */
 package org.jboss.ejb3;
 
+import java.lang.reflect.Field;
+
 import javassist.bytecode.ClassFile;
 import org.jboss.annotation.IgnoreDependency;
 import org.jboss.annotation.IgnoreDependencyImpl;
@@ -116,6 +118,7 @@
 import org.jboss.ejb3.metamodel.RemoveMethod;
 import org.jboss.ejb3.metamodel.SecurityIdentity;
 import org.jboss.ejb3.metamodel.SessionEnterpriseBean;
+import org.jboss.ejb3.metamodel.XmlAnnotation;
 import org.jboss.ejb3.service.ServiceContainer;
 import org.jboss.ejb3.stateful.StatefulContainer;
 import org.jboss.ejb3.stateless.StatelessContainer;
@@ -1059,6 +1062,8 @@
          addDependencies(container, enterpriseBean);
 
          addPoolAnnotations(container, enterpriseBean);
+         
+         addXmlAnnotations(container, enterpriseBean);
 
          if (enterpriseBean instanceof SessionEnterpriseBean)
          {
@@ -1108,7 +1113,54 @@
          addClassAnnotation(container, PoolClass.class, poolAnnotation);
       }
    }
+   
+   private void addXmlAnnotations(EJBContainer container,
+         EnterpriseBean enterpriseBean) throws Exception
+   {
+      Iterator xmlAnnotations = enterpriseBean.getXmlAnnotations().iterator();
+      while (xmlAnnotations.hasNext())
+      {
+         XmlAnnotation xmlAnnotation = (XmlAnnotation)xmlAnnotations.next();
 
+         Class annotationClass = di.getClassLoader().loadClass(xmlAnnotation.getAnnotationClass());
+         Class annotationImplementationClass = di.getClassLoader().loadClass(xmlAnnotation.getAnnotationImplementationClass());
+         Object annotation = annotationImplementationClass.newInstance();
+         
+         Iterator properties = xmlAnnotation.getProperties().iterator();
+         while (properties.hasNext())
+         {
+            NameValuePair property = (NameValuePair)properties.next();
+            Field field = annotationImplementationClass.getDeclaredField(property.getName());
+            setAnnotationPropertyField(field, annotation, property.getValue());
+         }
+            
+         if (xmlAnnotation.getInjectionTarget() == null)
+         {
+            addClassAnnotation(container, annotationClass, annotation);
+         } 
+         else
+         {
+            Method method = new Method();
+            method.setMethodName(xmlAnnotation.getInjectionTarget().getTargetName());
+            addAnnotations(annotationClass, annotation, container, method);
+         }
+      }
+   }
+   
+   protected void setAnnotationPropertyField(Field field, Object annotation, String value) throws Exception
+   {
+      if (field.getType() == String.class)
+         field.set(annotation, value);
+      else if (field.getType() == Long.class)
+         field.setLong(annotation, Long.parseLong(value));
+      else if (field.getType() == Integer.class)
+         field.setInt(annotation, Integer.parseInt(value));
+      else if (field.getType() == Class.class)
+         field.set(annotation, di.getClassLoader().loadClass(value));
+      else if (field.getType() == Boolean.class)
+         field.setBoolean(annotation, Boolean.parseBoolean(value));
+   }
+
    private void addCacheAnnotations(EJBContainer container,
          SessionEnterpriseBean enterpriseBean) throws Exception
    {

Modified: trunk/ejb3/src/main/org/jboss/ejb3/metamodel/EnterpriseBean.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/metamodel/EnterpriseBean.java	2006-08-11 01:15:42 UTC (rev 55511)
+++ trunk/ejb3/src/main/org/jboss/ejb3/metamodel/EnterpriseBean.java	2006-08-11 01:16:24 UTC (rev 55512)
@@ -87,9 +87,21 @@
    private Collection<String> dependencies = new HashSet<String>();
 
    private Collection<InjectionTarget> ignoreDependencies = new HashSet<InjectionTarget>();
+   
+   private Collection<XmlAnnotation> xmlAnnotations = new HashSet<XmlAnnotation>();
 
    private PoolConfig poolConfig = null;
+   
+   public void addXmlAnnotation(XmlAnnotation annotation)
+   {
+      xmlAnnotations.add(annotation);
+   }
 
+   public Collection<XmlAnnotation> getXmlAnnotations()
+   {
+      return xmlAnnotations;
+   }
+
    public void setPoolConfig(PoolConfig poolConfig)
    {
       this.poolConfig = poolConfig;

Modified: trunk/ejb3/src/main/org/jboss/ejb3/metamodel/EnterpriseBeans.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/metamodel/EnterpriseBeans.java	2006-08-11 01:15:42 UTC (rev 55511)
+++ trunk/ejb3/src/main/org/jboss/ejb3/metamodel/EnterpriseBeans.java	2006-08-11 01:16:24 UTC (rev 55512)
@@ -83,6 +83,11 @@
       currentEjb.addJndiRef(ref);
    }
    
+   public void addXmlAnnotation(XmlAnnotation xmlAnnotation)
+   {
+      currentEjb.addXmlAnnotation(xmlAnnotation);
+   }
+   
    public void addRemoteBinding(RemoteBinding binding)
    {
       currentEjb.addRemoteBinding(binding);

Modified: trunk/ejb3/src/main/org/jboss/ejb3/metamodel/JBossDDObjectFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/metamodel/JBossDDObjectFactory.java	2006-08-11 01:15:42 UTC (rev 55511)
+++ trunk/ejb3/src/main/org/jboss/ejb3/metamodel/JBossDDObjectFactory.java	2006-08-11 01:16:24 UTC (rev 55512)
@@ -171,6 +171,10 @@
       {
          child = new Producer(true);
       }
+      else if (localName.equals("annotation"))
+      {
+         child = new XmlAnnotation();
+      }
       else if (localName.equals("ignore-dependency"))
       {
          child = new InjectionTarget();
@@ -202,6 +206,10 @@
       {
          child = new InjectionTarget();
       }
+      else if (localName.equals("annotation"))
+      {
+         child = new XmlAnnotation();
+      }
       else if (localName.equals("remote-binding"))
       {
          child = new RemoteBinding();
@@ -310,6 +318,10 @@
       {
          child = new MethodAttributes();
       }
+      else if (localName.equals("annotation"))
+      {
+         child = new XmlAnnotation();
+      }
       else if (localName.equals("ignore-dependency"))
       {
          child = new InjectionTarget();
@@ -352,6 +364,36 @@
       return child;
    }
    
+   public Object newChild(XmlAnnotation parent,
+         UnmarshallingContext navigator, String namespaceURI, String localName,
+         Attributes attrs)
+   {
+      Object child = null;
+   
+      if (localName.equals("injection-target"))
+      {
+         child = new InjectionTarget();
+      }
+      else if (localName.equals("property"))
+      {
+         child = new NameValuePair();
+      }
+      
+      return child;
+   }
+   
+   public void addChild(XmlAnnotation parent, NameValuePair property,
+         UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addProperty(property);
+   }
+   
+   public void addChild(XmlAnnotation parent, InjectionTarget injectionTarget,
+         UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.setInjectionTarget(injectionTarget);
+   }
+   
    public void addChild(EnterpriseBeans parent, ActivationConfig config,
                         UnmarshallingContext navigator, String namespaceURI, String localName)
    {
@@ -413,45 +455,36 @@
       parent.setMethodAttributes(attributes);
    }
    
-   /**
-    * Called when parsing character is complete.
-    */
    public void addChild(EnterpriseBeans parent, RemoteBinding binding,
                         UnmarshallingContext navigator, String namespaceURI, String localName)
    {
       parent.addRemoteBinding(binding);
    }
    
-   /**
-    * Called when parsing character is complete.
-    */
    public void addChild(EnterpriseBeans parent, InjectionTarget ignoreDependency,
                         UnmarshallingContext navigator, String namespaceURI, String localName)
    {
       parent.addIgnoreDependency(ignoreDependency);
    }
    
-   /**
-    * Called when parsing character is complete.
-    */
+   public void addChild(EnterpriseBeans parent, XmlAnnotation xmlAnnotation,
+                        UnmarshallingContext navigator, String namespaceURI, String localName)
+   {
+      parent.addXmlAnnotation(xmlAnnotation);
+   }
+   
    public void addChild(MethodAttributes parent, Method method,
                         UnmarshallingContext navigator, String namespaceURI, String localName)
    {
       parent.addMethod(method);
    }
    
-   /**
-    * Called when parsing character is complete.
-    */
    public void addChild(Consumer parent, CurrentMessage message,
                         UnmarshallingContext navigator, String namespaceURI, String localName)
    {
       parent.setCurrentMessage(message);
    }
    
-   /**
-    * Called when parsing character is complete.
-    */
    public void addChild(Consumer parent, PoolConfig config,
                         UnmarshallingContext navigator, String namespaceURI, String localName)
    {
@@ -683,25 +716,32 @@
       parent.updateResourceEnvRef(ref);
    }
    
-   /**
-    * Called when a child element with simple content is read for DD.
-    */
+   public void setValue(XmlAnnotation xmlAnnotation, UnmarshallingContext navigator,
+         String namespaceURI, String localName, String value)
+   {
+      if (localName.equals("annotation-class"))
+      {
+         xmlAnnotation.setAnnotationClass(value);
+      }
+      else if (localName.equals("annotation-implementation-class"))
+      {
+         xmlAnnotation.setAnnotationImplementationClass(value);
+      }
+   }
+   
    public void setValue(NameValuePair property, UnmarshallingContext navigator,
                         String namespaceURI, String localName, String value)
    {
-      if (localName.equals("activation-config-property-name") || localName.equals("message-driven-config-property-name"))
+      if (localName.equals("activation-config-property-name") || localName.equals("message-driven-config-property-name")  || localName.equals("property-name"))
       {
          property.setName(value);
       }
-      else if (localName.equals("activation-config-property-value") || localName.equals("message-driven-config-property-value"))
+      else if (localName.equals("activation-config-property-value") || localName.equals("message-driven-config-property-value") || localName.equals("property-value"))
       {
          property.setValue(value);
       }
    }
    
-   /**
-    * Called when a child element with simple content is read for DD.
-    */
    public void setValue(ResourceManager manager, UnmarshallingContext navigator,
                         String namespaceURI, String localName, String value)
    {
@@ -715,9 +755,6 @@
       }
    }
    
-   /**
-    * Called when a child element with simple content is read for DD.
-    */
    public void setValue(MessageDestination destination, UnmarshallingContext navigator,
                         String namespaceURI, String localName, String value)
    {

Added: trunk/ejb3/src/main/org/jboss/ejb3/metamodel/XmlAnnotation.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/metamodel/XmlAnnotation.java	2006-08-11 01:15:42 UTC (rev 55511)
+++ trunk/ejb3/src/main/org/jboss/ejb3/metamodel/XmlAnnotation.java	2006-08-11 01:16:24 UTC (rev 55512)
@@ -0,0 +1,93 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.metamodel;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.jboss.metamodel.descriptor.InjectionTarget;
+import org.jboss.metamodel.descriptor.NameValuePair;
+
+
+/**
+ * Represents an <annotation> element of the jboss.xml deployment descriptor
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public class XmlAnnotation
+{
+   private InjectionTarget injectionTarget = null;
+   private String annotationClass = null;
+   private String annotationImplementationClass = null;
+   private Collection<NameValuePair> properties = new HashSet<NameValuePair>();
+   
+   public Collection<NameValuePair> getProperties()
+   {
+      return properties;
+   }
+   
+   public void addProperty(NameValuePair property)
+   {
+      properties.add(property);
+   }
+
+   public String getAnnotationClass()
+   {
+      return annotationClass;
+   }
+
+   public void setAnnotationClass(String annotationClass)
+   {
+      this.annotationClass = annotationClass;
+   }
+   
+   public String getAnnotationImplementationClass()
+   {
+      return annotationImplementationClass;
+   }
+
+   public void setAnnotationImplementationClass(String annotationImplementationClass)
+   {
+      this.annotationImplementationClass = annotationImplementationClass;
+   }
+   
+   public InjectionTarget getInjectionTarget()
+   {
+      return injectionTarget;
+   }
+   
+   public void setInjectionTarget(InjectionTarget injectionTarget)
+   {
+      this.injectionTarget = injectionTarget;
+   }
+
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer(100);
+      sb.append("[");
+      sb.append("annotationClass=").append(annotationClass);
+      sb.append(", injectionTarget=").append(injectionTarget);
+      sb.append("]");
+      return sb.toString();
+   }
+
+}

Modified: trunk/ejb3/src/resources/schema/jboss_5_0.xsd
===================================================================
(Binary files differ)

Modified: trunk/ejb3/src/resources/test/circulardependency/META-INF/jboss.xml
===================================================================
--- trunk/ejb3/src/resources/test/circulardependency/META-INF/jboss.xml	2006-08-11 01:15:42 UTC (rev 55511)
+++ trunk/ejb3/src/resources/test/circulardependency/META-INF/jboss.xml	2006-08-11 01:16:24 UTC (rev 55512)
@@ -8,12 +8,14 @@
    <enterprise-beans>
       <session>
          <ejb-name>StatelessBean2</ejb-name>
-         <ignore-dependency>
+         <annotation>
+            <annotation-class>org.jboss.annotation.IgnoreDependency</annotation-class>
+            <annotation-implementation-class>org.jboss.annotation.IgnoreDependencyImpl</annotation-implementation-class>
             <injection-target>
                <injection-target-class>org.jboss.ejb3.test.circulardependecy.StatelessBean2</injection-target-class>
                <injection-target-name>stateless</injection-target-name>
             </injection-target>
-         </ignore-dependency>
+         </annotation>
       </session>
    </enterprise-beans>
 </jboss>

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/strictpool/MDBInvoker.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/strictpool/MDBInvoker.java	2006-08-11 01:15:42 UTC (rev 55511)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/strictpool/MDBInvoker.java	2006-08-11 01:16:24 UTC (rev 55512)
@@ -72,8 +72,8 @@
          }
          else
          {
-            TextMessage tm = (TextMessage) reply;
-            System.out.println(tm.getText());
+            Message tm = (Message) reply;
+            System.out.println(tm);
          }
          sender.close();
          receiver.close();

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/strictpool/OverrideStrictlyPooledSessionBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/strictpool/OverrideStrictlyPooledSessionBean.java	2006-08-11 01:15:42 UTC (rev 55511)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/strictpool/OverrideStrictlyPooledSessionBean.java	2006-08-11 01:16:24 UTC (rev 55512)
@@ -34,7 +34,7 @@
  * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
  */
 @Stateless
- at PoolClass (value=org.jboss.ejb3.test.strictpool.BogusPool.class, maxSize=0, timeout=0)
+ at PoolClass(value=org.jboss.ejb3.test.strictpool.BogusPool.class, maxSize=0, timeout=0)
 @Remote(StrictlyPooledSession.class)
 public class OverrideStrictlyPooledSessionBean implements StrictlyPooledSession
 {




More information about the jboss-cvs-commits mailing list