[jboss-cvs] JBossAS SVN: r78756 - in projects/aop/trunk/aop: src/main/org/jboss/aop/introduction and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Sep 22 11:01:32 EDT 2008


Author: kabir.khan at jboss.com
Date: 2008-09-22 11:01:32 -0400 (Mon, 22 Sep 2008)
New Revision: 78756

Added:
   projects/aop/trunk/aop/src/resources/test/annotationproperty/
   projects/aop/trunk/aop/src/resources/test/annotationproperty/annotations-aop.xml
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationproperty/
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationproperty/AnnotationPropertyReplacementTestCase.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationproperty/Complex.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationproperty/MyEnum.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationproperty/POJO.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationproperty/SimpleValue.java
Modified:
   projects/aop/trunk/aop/base-tests.xml
   projects/aop/trunk/aop/src/main/org/jboss/aop/introduction/AnnotationIntroduction.java
Log:
[JBAOP-650] Support use of system properties in created annotations

Modified: projects/aop/trunk/aop/base-tests.xml
===================================================================
--- projects/aop/trunk/aop/base-tests.xml	2008-09-22 14:38:29 UTC (rev 78755)
+++ projects/aop/trunk/aop/base-tests.xml	2008-09-22 15:01:32 UTC (rev 78756)
@@ -111,6 +111,11 @@
          <param name="test" value="introduction"/>
          <param name="aop.xml" value="${source.res}/test/introduction/introduction-aop.xml"/>
       </antcall>
+      <antcall target="${test-target}" inheritRefs="true">
+         <param name="test" value="annotationproperty"/>
+         <param name="no.xml" value="true"/>
+         <param name="use.annotations" value="false"/>
+      </antcall>
    </target>
 
    <target name="help">

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/introduction/AnnotationIntroduction.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/introduction/AnnotationIntroduction.java	2008-09-22 14:38:29 UTC (rev 78755)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/introduction/AnnotationIntroduction.java	2008-09-22 15:01:32 UTC (rev 78756)
@@ -26,12 +26,15 @@
 import javassist.CtField;
 import javassist.CtMethod;
 import org.jboss.aop.Advisor;
+import org.jboss.aop.AspectManager;
 import org.jboss.annotation.factory.ast.ASTAnnotation;
 import org.jboss.annotation.factory.ast.AnnotationParser;
 import org.jboss.annotation.factory.ast.ParseException;
 import org.jboss.aop.pointcut.AnnotationMatcher;
 import org.jboss.aop.pointcut.ast.ASTStart;
 import org.jboss.aop.pointcut.ast.TypeExpressionParser;
+import org.jboss.aop.util.logging.AOPLogger;
+import org.jboss.util.StringPropertyReplacer;
 
 import java.io.StringReader;
 import java.lang.reflect.Constructor;
@@ -46,6 +49,8 @@
  */
 public class AnnotationIntroduction
 {
+   final static AOPLogger logger = AOPLogger.getLogger(AnnotationIntroduction.class);
+   
    public static AnnotationIntroduction createMethodAnnotationIntroduction(String methodExpr, String annotationExpr, boolean invisible)
    {
       String expr = "method(" + methodExpr + ")";
@@ -85,11 +90,17 @@
    private AnnotationIntroduction(String expr, String annotationExpr, boolean invisible)
    {
       this.invisible = invisible;
-      originalAnnotationExpr = annotationExpr;
+      //TODO: Remove property replacement once jboss-mdr > 2.0.0.CR1 is out
+      originalAnnotationExpr = StringPropertyReplacer.replaceProperties(annotationExpr);
       originalExpression = expr;
       try
       {
-         AnnotationParser parser = new AnnotationParser(new StringReader(annotationExpr));
+         //TODO: Remove once jboss-mdr > 2.0.0.CR1 is out
+         if (AspectManager.verbose && logger.isTraceEnabled())
+         {
+            logger.trace("Creating annotation from " + originalAnnotationExpr);
+         }
+         AnnotationParser parser = new AnnotationParser(new StringReader(originalAnnotationExpr));
          org.jboss.annotation.factory.ast.ASTStart start = parser.Start();
          annotation = (ASTAnnotation) start.jjtGetChild(0);
       }

Added: projects/aop/trunk/aop/src/resources/test/annotationproperty/annotations-aop.xml
===================================================================
--- projects/aop/trunk/aop/src/resources/test/annotationproperty/annotations-aop.xml	                        (rev 0)
+++ projects/aop/trunk/aop/src/resources/test/annotationproperty/annotations-aop.xml	2008-09-22 15:01:32 UTC (rev 78756)
@@ -0,0 +1,9 @@
+<aop>
+   <prepare expr="all(org.jboss.test.aop.annotationproperty.POJO)"/>
+   <annotation-introduction expr="class(org.jboss.test.aop.annotationproperty.POJO)">
+      @org.jboss.test.aop.annotationproperty.SimpleValue("${value1}")
+   </annotation-introduction>
+   <annotation expr="class(org.jboss.test.aop.annotationproperty.POJO)">
+      @org.jboss.test.aop.annotationproperty.Complex(ch='${ch}', string="${string}", flt=${flt}, dbl=${dbl}, shrt=${shrt}, lng=${lng}, integer=${integer}, bool=${bool}, annotation=${annotation}, array=${array}, clazz=${clazz}, enumVal=${enumVal})
+   </annotation>
+</aop>
\ No newline at end of file

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationproperty/AnnotationPropertyReplacementTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationproperty/AnnotationPropertyReplacementTestCase.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationproperty/AnnotationPropertyReplacementTestCase.java	2008-09-22 15:01:32 UTC (rev 78756)
@@ -0,0 +1,120 @@
+/*
+  * 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.test.aop.annotationproperty;
+
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import org.jboss.aop.Advised;
+import org.jboss.aop.Advisor;
+import org.jboss.aop.AspectXmlLoader;
+import org.jboss.test.AbstractTestDelegate;
+import org.jboss.test.aop.AOPTestDelegate;
+import org.jboss.test.aop.AOPTestWithSetup;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ * @author <a href="mailto:kabir.khan at jboss.org">Kabir Khan</a>
+ * @version $Revision: 75505 $
+ */
+public class AnnotationPropertyReplacementTestCase extends AOPTestWithSetup
+{
+   public static void main(String[] args)
+   {
+      TestRunner.run(suite());
+   }
+
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite("AOPTester");
+      suite.addTestSuite(AnnotationPropertyReplacementTestCase.class);
+      return suite;
+   }
+
+   public AnnotationPropertyReplacementTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static AbstractTestDelegate getDelegate(Class<?> clazz) throws Exception
+   {
+      //Don't use security with this test
+      return new AOPTestDelegate(clazz);
+   }
+   
+   public void testPropertyReplacement() throws Exception
+   {
+      AccessController.doPrivileged(new PrivilegedAction<Object>() {
+
+         public Object run()
+         {
+            //Properties for the @SimpleValue
+            System.setProperty("value1", "Test");
+            
+            //Properties for the @Complex
+            System.setProperty("ch", "a");
+            System.setProperty("string", "Test123");
+            System.setProperty("flt", "9.9");
+            System.setProperty("dbl", "123456789.99");
+            System.setProperty("shrt", "1");
+            System.setProperty("lng", "987654321");
+            System.setProperty("integer", "123");
+            System.setProperty("bool", "true");
+            System.setProperty("annotation", "@org.jboss.test.aop.annotationproperty.SimpleValue(\"Yes\")");
+            System.setProperty("array", "{\"Test\", \"123\"}");
+            System.setProperty("clazz", "java.lang.Long.class");
+            System.setProperty("enumVal", "org.jboss.test.aop.annotationproperty.MyEnum.TWO");
+            return null;
+         }});
+      
+      URL url = getURLRelativeToProjectRoot("/src/resources/test/annotationproperty/annotations-aop.xml");
+      AspectXmlLoader.deployXML(url);
+      
+      POJO pojo = new POJO();
+      Advisor advisor = ((Advised)pojo)._getAdvisor();
+
+      SimpleValue value = advisor.resolveTypedAnnotation(SimpleValue.class);
+      assertNotNull(value);
+      assertEquals(SimpleValue.class, value.annotationType());
+      assertEquals("Test", value.value());
+
+      Complex complex = advisor.resolveTypedAnnotation(Complex.class);
+      assertNotNull(complex);
+      assertEquals(Complex.class, complex.annotationType());
+      assertEquals('a', complex.ch());
+      assertEquals("Test123", complex.string());
+      assertEquals(9,9, complex.flt());
+      assertEquals(123456789.99, complex.dbl());
+      assertEquals(1, complex.shrt());
+      assertEquals(987654321, complex.lng());
+      assertEquals(123, complex.integer());
+      assertEquals(true, complex.bool());
+      assertEquals(Long.class, complex.clazz());
+      assertEquals("Yes", complex.annotation().value());
+      assertEquals(new String[]{"Test", "123"}, complex.array());
+   }
+}
+

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationproperty/Complex.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationproperty/Complex.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationproperty/Complex.java	2008-09-22 15:01:32 UTC (rev 78756)
@@ -0,0 +1,58 @@
+/*
+* 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.test.aop.annotationproperty;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 69888 $
+ */
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface Complex 
+{
+   char ch();
+
+   String string();
+
+   float flt();
+
+   double dbl();
+
+   short shrt();
+
+   long lng();
+
+   int integer();
+
+   boolean bool();
+
+   SimpleValue annotation();
+
+   String[] array();
+
+   Class<?> clazz();
+
+   MyEnum enumVal();
+}

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationproperty/MyEnum.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationproperty/MyEnum.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationproperty/MyEnum.java	2008-09-22 15:01:32 UTC (rev 78756)
@@ -0,0 +1,34 @@
+/*
+  * 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.test.aop.annotationproperty;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 46363 $
+ */
+
+public enum MyEnum
+{
+   ONE, TWO;
+}

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationproperty/POJO.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationproperty/POJO.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationproperty/POJO.java	2008-09-22 15:01:32 UTC (rev 78756)
@@ -0,0 +1,32 @@
+/*
+* 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.aop.annotationproperty;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class POJO
+{
+
+}

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationproperty/SimpleValue.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationproperty/SimpleValue.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/annotationproperty/SimpleValue.java	2008-09-22 15:01:32 UTC (rev 78756)
@@ -0,0 +1,36 @@
+/*
+* 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.test.aop.annotationproperty;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 46363 $
+ */
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface SimpleValue
+{
+   String value();
+}




More information about the jboss-cvs-commits mailing list