[jboss-cvs] JBossAS SVN: r80468 - in projects/jboss-mdr/branches/Branch_2_0: src/main/java/org/jboss/annotation/factory and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Nov 4 05:50:26 EST 2008
Author: alesj
Date: 2008-11-04 05:50:26 -0500 (Tue, 04 Nov 2008)
New Revision: 80468
Added:
projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/annotation/factory/support/Name.java
projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/annotation/factory/support/NameDefaults.java
projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/annotation/factory/support/NameImpl.java
Modified:
projects/jboss-mdr/branches/Branch_2_0/pom.xml
projects/jboss-mdr/branches/Branch_2_0/src/main/java/org/jboss/annotation/factory/AnnotationProxy.java
projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/ContainerTest.java
projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/annotation/factory/support/Complex.java
projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/annotation/factory/test/AnnotationCreatorTest.java
Log:
Port trunk changes to branch.
Modified: projects/jboss-mdr/branches/Branch_2_0/pom.xml
===================================================================
--- projects/jboss-mdr/branches/Branch_2_0/pom.xml 2008-11-04 10:49:29 UTC (rev 80467)
+++ projects/jboss-mdr/branches/Branch_2_0/pom.xml 2008-11-04 10:50:26 UTC (rev 80468)
@@ -97,7 +97,7 @@
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-common-core</artifactId>
- <version>2.2.8.GA</version>
+ <version>2.2.9.GA</version>
</dependency>
<!-- Test dependencies -->
<dependency>
Modified: projects/jboss-mdr/branches/Branch_2_0/src/main/java/org/jboss/annotation/factory/AnnotationProxy.java
===================================================================
--- projects/jboss-mdr/branches/Branch_2_0/src/main/java/org/jboss/annotation/factory/AnnotationProxy.java 2008-11-04 10:49:29 UTC (rev 80467)
+++ projects/jboss-mdr/branches/Branch_2_0/src/main/java/org/jboss/annotation/factory/AnnotationProxy.java 2008-11-04 10:50:26 UTC (rev 80468)
@@ -22,35 +22,72 @@
package org.jboss.annotation.factory;
import java.io.Serializable;
+import java.lang.reflect.Array;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
+import java.lang.reflect.UndeclaredThrowableException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Collections;
import java.util.Map;
+import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.config.plugins.property.PropertyConfiguration;
+import org.jboss.config.spi.Configuration;
+import org.jboss.util.JBossObject;
+import org.jboss.util.Objects;
+
/**
* InvocationHandler implementation for creating an annotation proxy.
*
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
* @author <a href="mailto:kabir.khan at jboss.org">Kabir Khan</a>
- * @version $Revision$
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
*/
public class AnnotationProxy implements InvocationHandler, Serializable
{
private static final long serialVersionUID = 1;
- @SuppressWarnings("unchecked")
- private Map map;
+ private static Configuration configuration;
+
+ static
+ {
+ configuration = AccessController.doPrivileged(new PrivilegedAction<Configuration>()
+ {
+ public Configuration run()
+ {
+ return new PropertyConfiguration();
+ }
+ });
+ }
+
private Class<?> annotationType;
+ private transient BeanInfo beanInfo;
+ private Map<String, Object> map;
@SuppressWarnings("unchecked")
public AnnotationProxy(Class<?> annotationType, Map valueMap)
{
+ if (annotationType == null)
+ throw new IllegalArgumentException("Null annotation type.");
this.annotationType = annotationType;
- map = valueMap;
+ this.map = valueMap != null ? valueMap : Collections.<String, Object>emptyMap();
}
- public Object invoke(Object proxy, Method method, Object[] args)
- throws Throwable
+ /**
+ * Get bean info.
+ *
+ * @return the annotation's bean info
+ */
+ protected BeanInfo getBeanInfo()
{
+ if (beanInfo == null)
+ beanInfo = configuration.getBeanInfo(annotationType);
+
+ return beanInfo;
+ }
+
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+ {
String name = method.getName();
if ("equals".equals(name))
{
@@ -68,15 +105,6 @@
{
return annotationType;
}
-
- /*
- Object obj = map.get(method.getName());
- if (!method.getReturnType().equals(obj.getClass()))
- {
- System.err.println("***** " + method.toString() + " has bad return type: " + obj.getClass().getName());
- }
- return obj;
- */
return map.get(name);
}
@@ -93,25 +121,47 @@
if (obj == null)
return Boolean.FALSE;
- Class[] intfs = proxy.getClass().getInterfaces();
- if (intfs[0].isAssignableFrom(obj.getClass()) == false)
+ if (annotationType.isInstance(obj) == false)
{
return Boolean.FALSE;
}
+
try
{
- Proxy.getInvocationHandler(obj);
+ for (String key : map.keySet())
+ {
+ Object value = getValue(key);
+ Object other = getBeanInfo().getProperty(obj, key);
+ if (Objects.isArray(value))
+ {
+ if (Objects.isArray(other) == false)
+ return Boolean.FALSE;
+
+ int length = Array.getLength(value);
+ if (length != Array.getLength(other))
+ return Boolean.FALSE;
+
+ for (int i = 0; i < length; i++)
+ {
+ if (JBossObject.equals(Array.get(value, i), Array.get(other, i)) == false)
+ return Boolean.FALSE;
+ }
+ }
+ else if (JBossObject.equals(value, other) == false)
+ return Boolean.FALSE;
+ }
}
- catch (Exception ex)
+ catch (Throwable t)
{
- return Boolean.FALSE;
+ throw new UndeclaredThrowableException(t);
}
+
return Boolean.TRUE;
}
private Object doHashCode()
{
- return new Integer(map.hashCode());
+ return map.hashCode();
}
/**
@@ -121,8 +171,7 @@
* @return an instance implementing the annotation
* @throws Exception for any error
*/
- @SuppressWarnings("unchecked")
- public static Object createProxy(Map map, Class<?> annotation) throws Exception
+ public static Object createProxy(Map<String, Object> map, Class<?> annotation) throws Exception
{
AnnotationProxy proxyHandler = new AnnotationProxy(annotation, map);
return java.lang.reflect.Proxy.newProxyInstance(annotation.getClassLoader(), new Class[]{annotation}, proxyHandler);
Modified: projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/ContainerTest.java
===================================================================
--- projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/ContainerTest.java 2008-11-04 10:49:29 UTC (rev 80467)
+++ projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/ContainerTest.java 2008-11-04 10:50:26 UTC (rev 80468)
@@ -21,9 +21,14 @@
*/
package org.jboss.test;
+import java.lang.reflect.Array;
+
+import org.jboss.util.Objects;
+import org.jboss.util.JBossObject;
+
/**
* A ContainerTest.
- *
+ *
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @version $Revision: 69888 $
*/
@@ -31,17 +36,17 @@
{
/**
* Create a new ContainerTest.
- *
+ *
* @param name the test name
*/
public ContainerTest(String name)
{
super(name);
}
-
+
/**
* Default setup with security manager enabled
- *
+ *
* @param clazz the class
* @return the delegate
* @throws Exception for any error
@@ -52,4 +57,9 @@
//delegate.enableSecurity = true;
return delegate;
}
+
+ protected static void assertArrays(Object value, Object other)
+ {
+ assertTrue(Objects.equals(value, other));
+ }
}
Modified: projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/annotation/factory/support/Complex.java
===================================================================
--- projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/annotation/factory/support/Complex.java 2008-11-04 10:49:29 UTC (rev 80467)
+++ projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/annotation/factory/support/Complex.java 2008-11-04 10:50:26 UTC (rev 80468)
@@ -51,4 +51,6 @@
Class<?> clazz();
MyEnum enumVal();
+
+ int[] primitiveArray();
}
Copied: projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/annotation/factory/support/Name.java (from rev 80466, projects/jboss-mdr/trunk/src/test/java/org/jboss/test/annotation/factory/support/Name.java)
===================================================================
--- projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/annotation/factory/support/Name.java (rev 0)
+++ projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/annotation/factory/support/Name.java 2008-11-04 10:50:26 UTC (rev 80468)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.test.annotation.factory.support;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface Name
+{
+ public String type() default "";
+ public String subtype() default "";
+}
Copied: projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/annotation/factory/support/NameDefaults.java (from rev 80466, projects/jboss-mdr/trunk/src/test/java/org/jboss/test/annotation/factory/support/NameDefaults.java)
===================================================================
--- projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/annotation/factory/support/NameDefaults.java (rev 0)
+++ projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/annotation/factory/support/NameDefaults.java 2008-11-04 10:50:26 UTC (rev 80468)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.test.annotation.factory.support;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+ at Name(type="type", subtype="subtype")
+public class NameDefaults
+{
+ @Name(type="", subtype="")
+ public static class NAME_CLASS {}
+ @Name(type="", subtype="")
+ public static class NAME_CLASS2 {}
+ /** The ManagementComponent uninitialized default */
+ public static final Name COMP_TYPE = defaultNameType();
+ /**
+ * The unitialized/default ManagementComponent value
+ * @return The unitialized/default ManagementComponent value
+ */
+ public static synchronized Name defaultNameType()
+ {
+ Name name = NAME_CLASS.class.getAnnotation(Name.class);
+ return name;
+ }
+
+}
Copied: projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/annotation/factory/support/NameImpl.java (from rev 80466, projects/jboss-mdr/trunk/src/test/java/org/jboss/test/annotation/factory/support/NameImpl.java)
===================================================================
--- projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/annotation/factory/support/NameImpl.java (rev 0)
+++ projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/annotation/factory/support/NameImpl.java 2008-11-04 10:50:26 UTC (rev 80468)
@@ -0,0 +1,81 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, 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.annotation.factory.support;
+
+import java.lang.annotation.Annotation;
+
+import org.jboss.util.JBossObject;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class NameImpl implements Name
+{
+ private String type = "";
+ private String subtype = "";
+
+ public NameImpl()
+ {
+ }
+
+ public NameImpl(String type, String subtype)
+ {
+ if (type != null)
+ this.type = type;
+ if (subtype != null)
+ this.subtype = subtype;
+ }
+
+ public String type()
+ {
+ return type;
+ }
+
+ public String subtype()
+ {
+ return subtype;
+ }
+
+ public Class<? extends Annotation> annotationType()
+ {
+ return Name.class;
+ }
+
+ public int hashCode()
+ {
+ return type.hashCode() + subtype.hashCode();
+ }
+
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof Name == false)
+ return false;
+
+ Name name = (Name)obj;
+ return JBossObject.equals(type, name.type()) && JBossObject.equals(subtype, name.subtype());
+ }
+
+ public String toString()
+ {
+ return "@" + annotationType().getName() + "(type=" + type + ", subtype=" + subtype + ")";
+ }
+}
Modified: projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/annotation/factory/test/AnnotationCreatorTest.java
===================================================================
--- projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/annotation/factory/test/AnnotationCreatorTest.java 2008-11-04 10:49:29 UTC (rev 80467)
+++ projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/annotation/factory/test/AnnotationCreatorTest.java 2008-11-04 10:50:26 UTC (rev 80468)
@@ -29,14 +29,18 @@
import org.jboss.test.ContainerTest;
import org.jboss.test.annotation.factory.support.Complex;
import org.jboss.test.annotation.factory.support.MyEnum;
+import org.jboss.test.annotation.factory.support.Name;
+import org.jboss.test.annotation.factory.support.NameDefaults;
import org.jboss.test.annotation.factory.support.Simple;
import org.jboss.test.annotation.factory.support.SimpleValue;
+import org.jboss.test.annotation.factory.support.NameImpl;
/**
*
* @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
* @version $Revision$
*/
+
public abstract class AnnotationCreatorTest extends ContainerTest
{
public AnnotationCreatorTest(String name)
@@ -79,7 +83,7 @@
public void testComplex() throws Exception
{
- String expr = "@org.jboss.test.annotation.factory.support.Complex(ch='a', string=\"Test123\", flt=9.9, dbl=123456789.99, shrt=1, lng=987654321, integer=123, bool=true, annotation=@org.jboss.test.annotation.factory.support.SimpleValue(\"Yes\"), array={\"Test\", \"123\"}, clazz=java.lang.Long.class, enumVal=org.jboss.test.annotation.factory.support.MyEnum.TWO)";
+ String expr = "@org.jboss.test.annotation.factory.support.Complex(ch='a', string=\"Test123\", flt=9.9, dbl=123456789.99, shrt=1, lng=987654321, integer=123, bool=true, annotation=@org.jboss.test.annotation.factory.support.SimpleValue(\"Yes\"), array={\"Test\", \"123\"}, clazz=java.lang.Long.class, enumVal=org.jboss.test.annotation.factory.support.MyEnum.TWO, primitiveArray={1,2,3})";
Annotation annotation = (Annotation)AnnotationCreator.createAnnotation(expr, Complex.class);
assertEquals(Complex.class, annotation.annotationType());
Complex complex = (Complex)annotation;
@@ -95,12 +99,13 @@
assertEquals("Yes", complex.annotation().value());
assertEquals(new String[]{"Test", "123"}, complex.array());
assertEquals(MyEnum.TWO, complex.enumVal());
+ assertArrays(new int[]{1, 2, 3}, complex.primitiveArray());
}
public void testComplexWithPropertyReplacement() throws Exception
{
String expr = "@org.jboss.test.annotation.factory.support.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})";
+ "lng=${lng}, integer=${integer}, bool=${bool}, annotation=${annotation}, array=${array}, clazz=${clazz}, enumVal=${enumVal}, primitiveArray=${primitiveArray})";
System.setProperty("ch", "a");
System.setProperty("string", "Test123");
@@ -114,8 +119,8 @@
System.setProperty("array", "{\"Test\", \"123\"}");
System.setProperty("clazz", "java.lang.Long.class");
System.setProperty("enumVal", "org.jboss.test.annotation.factory.support.MyEnum.TWO");
+ System.setProperty("primitiveArray", "{1, 2, 3}");
-
Annotation annotation = (Annotation)AnnotationCreator.createAnnotation(expr, Complex.class, true);
assertEquals(Complex.class, annotation.annotationType());
Complex complex = (Complex)annotation;
@@ -131,11 +136,12 @@
assertEquals("Yes", complex.annotation().value());
assertEquals(new String[]{"Test", "123"}, complex.array());
assertEquals(MyEnum.TWO, complex.enumVal());
+ assertArrays(new int[]{1, 2, 3}, complex.primitiveArray());
}
public void testSerializable() throws Exception
{
- String expr = "@org.jboss.test.annotation.factory.support.Complex(ch='a', string=\"Test123\", flt=9.9, dbl=123456789.99, shrt=1, lng=987654321, integer=123, bool=true, annotation=@org.jboss.test.annotation.factory.support.SimpleValue(\"Yes\"), array={\"Test\", \"123\"}, clazz=java.lang.Long.class, enumVal=org.jboss.test.annotation.factory.support.MyEnum.TWO)";
+ String expr = "@org.jboss.test.annotation.factory.support.Complex(ch='a', string=\"Test123\", flt=9.9, dbl=123456789.99, shrt=1, lng=987654321, integer=123, bool=true, annotation=@org.jboss.test.annotation.factory.support.SimpleValue(\"Yes\"), array={\"Test\", \"123\"}, clazz=java.lang.Long.class, enumVal=org.jboss.test.annotation.factory.support.MyEnum.TWO, primitiveArray={1,2,3})";
Annotation annotation = (Annotation)AnnotationCreator.createAnnotation(expr, Complex.class);
assertInstanceOf(annotation, Serializable.class);
byte[] bytes = serialize((Serializable)annotation);
@@ -155,4 +161,38 @@
{
}
}
+
+ public void testEquals()
+ throws Exception
+ {
+ String expr = "@"+Name.class.getName() + "(type=\"type\",subtype=\"subtype\")";
+ Name n0 = (Name) AnnotationCreator.createAnnotation(expr, Name.class);
+ getLog().debug("n0: "+n0);
+ Name n1 = NameDefaults.class.getAnnotation(Name.class);
+ getLog().debug("n1: "+n1);
+ assertEquals(n0, n1);
+ assertEquals(n1, n0);
+
+ Name defaultName = NameDefaults.defaultNameType();
+ getLog().debug("defaultName: "+defaultName);
+ // The jdk annotation should not equal the defaultName
+ assertFalse(n1+" != "+defaultName, n1.equals(defaultName));
+ assertFalse(defaultName+" != "+n1, defaultName.equals(n1));
+ // The AnnotationCreator annotation should not equal the defaultName
+ assertFalse(n0+" != "+defaultName, n0.equals(defaultName));
+ assertFalse(defaultName+" != "+n0, defaultName.equals(n0));
+
+ Name n2 = new NameImpl("type", "subtype");
+ getLog().debug("n2: " + n2);
+ assertEquals(n0, n2);
+ assertEquals(n2, n0);
+ assertEquals(n1, n2);
+ assertEquals(n2, n1);
+
+ Name n3 = new NameImpl();
+ assertFalse(n0 + "!=" + n3, n0.equals(n3));
+ assertFalse(n3 + "!=" + n0, n3.equals(n0));
+ assertFalse(n1 + "!=" + n3, n1.equals(n3));
+ assertFalse(n3 + "!=" + n1, n3.equals(n1));
+ }
}
More information about the jboss-cvs-commits
mailing list