[jboss-cvs] JBossAS SVN: r97853 - in projects/jboss-jca/trunk/deployers/src: test/java/org/jboss/jca/test/deployers/spec and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Dec 15 12:40:03 EST 2009
Author: jesper.pedersen
Date: 2009-12-15 12:40:03 -0500 (Tue, 15 Dec 2009)
New Revision: 97853
Modified:
projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/Annotations.java
projects/jboss-jca/trunk/deployers/src/test/java/org/jboss/jca/test/deployers/spec/RarTestCase.java
projects/jboss-jca/trunk/deployers/src/test/java/org/jboss/jca/test/deployers/spec/rars/ra16annoconfprop/TestManagedConnectionFactory.java
Log:
[JBJCA-241] [JBJCA-242] Additional @ConfigProperty support
Modified: projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/Annotations.java
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/Annotations.java 2009-12-15 17:38:38 UTC (rev 97852)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/Annotations.java 2009-12-15 17:40:03 UTC (rev 97853)
@@ -25,6 +25,8 @@
import org.jboss.jca.fungal.deployers.DeployException;
import java.lang.reflect.Array;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
@@ -69,6 +71,7 @@
import org.jboss.metadata.rar.spec.TransactionSupportMetaData;
import org.jboss.papaki.Annotation;
import org.jboss.papaki.AnnotationRepository;
+import org.jboss.papaki.AnnotationType;
/**
* The annotation processor for JCA 1.6
@@ -536,10 +539,21 @@
if (trace)
log.trace("Processing: " + configProperty);
+ // Ignore config-property which has ignore=true
+ if (configProperty.ignore())
+ return md;
+
ConfigPropertyMetaData cfgMeta = new ConfigPropertyMetaData();
- cfgMeta.setName(annotation.getMemberName());
+ cfgMeta.setName(getConfigPropertyName(annotation));
cfgMeta.setValue(configProperty.defaultValue());
- cfgMeta.setType(configProperty.type().getName());
+ if (!Object.class.equals(configProperty.type()))
+ {
+ cfgMeta.setType(configProperty.type().getName());
+ }
+ else
+ {
+ cfgMeta.setType(getConfigPropertyType(annotation));
+ }
cfgMeta.setIgnore(configProperty.ignore());
String[] description = configProperty.description();
@@ -893,4 +907,103 @@
}
}
+ /**
+ * Get the config-property-name for an annotation
+ * @param annotation The annotation
+ * @return The name
+ * @exception ClassNotFoundException Thrown if a class cannot be found
+ * @exception NoSuchFieldException Thrown if a field cannot be found
+ * @exception NoSuchMethodException Thrown if a method cannot be found
+ */
+ private String getConfigPropertyName(Annotation annotation)
+ throws ClassNotFoundException, NoSuchFieldException, NoSuchMethodException
+ {
+ if (AnnotationType.FIELD.equals(annotation.getType()))
+ {
+ return annotation.getMemberName();
+ }
+ else if (AnnotationType.METHOD.equals(annotation.getType()))
+ {
+ String name = annotation.getMemberName();
+
+ if (name.startsWith("set"))
+ {
+ name = name.substring(3);
+ }
+ else if (name.startsWith("get"))
+ {
+ name = name.substring(3);
+ }
+ else if (name.startsWith("is"))
+ {
+ name = name.substring(2);
+ }
+
+ if (name.length() > 1)
+ {
+ return Character.toLowerCase(name.charAt(0)) + name.substring(1);
+ }
+ else
+ {
+ return Character.toString(Character.toLowerCase(name.charAt(0)));
+ }
+ }
+
+ throw new IllegalArgumentException("Unknown annotation: " + annotation);
+ }
+
+ /**
+ * Get the config-property-type for an annotation
+ * @param annotation The annotation
+ * @return The fully qualified classname
+ * @exception ClassNotFoundException Thrown if a class cannot be found
+ * @exception NoSuchFieldException Thrown if a field cannot be found
+ * @exception NoSuchMethodException Thrown if a method cannot be found
+ */
+ private String getConfigPropertyType(Annotation annotation)
+ throws ClassNotFoundException, NoSuchFieldException, NoSuchMethodException
+ {
+ if (AnnotationType.FIELD.equals(annotation.getType()))
+ {
+ ClassLoader cl = SecurityActions.getThreadContextClassLoader();
+ Class clz = Class.forName(annotation.getClassName(), true, cl);
+ Field field = clz.getDeclaredField(annotation.getMemberName());
+
+ return field.getType().getName();
+ }
+ else if (AnnotationType.METHOD.equals(annotation.getType()))
+ {
+ ClassLoader cl = SecurityActions.getThreadContextClassLoader();
+ Class clz = Class.forName(annotation.getClassName(), true, cl);
+
+ Class[] parameters = null;
+
+ if (annotation.getParameterTypes() != null)
+ {
+ parameters = new Class[annotation.getParameterTypes().length];
+
+ for (int i = 0; i < annotation.getParameterTypes().length; i++)
+ {
+ String parameter = annotation.getParameterTypes()[i];
+ parameters[i] = Class.forName(parameter, true, cl);
+ }
+ }
+
+ Method method = clz.getDeclaredMethod(annotation.getMemberName(), parameters);
+
+ if (void.class.equals(method.getReturnType()))
+ {
+ if (parameters != null && parameters.length > 0)
+ {
+ return parameters[0].getName();
+ }
+ }
+ else
+ {
+ return method.getReturnType().getName();
+ }
+ }
+
+ throw new IllegalArgumentException("Unknown annotation: " + annotation);
+ }
}
Modified: projects/jboss-jca/trunk/deployers/src/test/java/org/jboss/jca/test/deployers/spec/RarTestCase.java
===================================================================
--- projects/jboss-jca/trunk/deployers/src/test/java/org/jboss/jca/test/deployers/spec/RarTestCase.java 2009-12-15 17:38:38 UTC (rev 97852)
+++ projects/jboss-jca/trunk/deployers/src/test/java/org/jboss/jca/test/deployers/spec/RarTestCase.java 2009-12-15 17:40:03 UTC (rev 97853)
@@ -563,6 +563,30 @@
}
/**
+ * ra16annoconfprop.rar
+ * @throws Throwable throwable exception
+ */
+ @Test
+ public void testRa16annoconfprop() throws Throwable
+ {
+ URL archive = getURL("ra16annoconfprop.rar");
+
+ try
+ {
+ embedded.deploy(archive);
+ }
+ catch (Throwable t)
+ {
+ log.error(t.getMessage(), t);
+ fail(t.getMessage());
+ }
+ finally
+ {
+ embedded.undeploy(archive);
+ }
+ }
+
+ /**
* ra16asso.rar
* @throws Throwable throwable exception
*/
Modified: projects/jboss-jca/trunk/deployers/src/test/java/org/jboss/jca/test/deployers/spec/rars/ra16annoconfprop/TestManagedConnectionFactory.java
===================================================================
--- projects/jboss-jca/trunk/deployers/src/test/java/org/jboss/jca/test/deployers/spec/rars/ra16annoconfprop/TestManagedConnectionFactory.java 2009-12-15 17:38:38 UTC (rev 97852)
+++ projects/jboss-jca/trunk/deployers/src/test/java/org/jboss/jca/test/deployers/spec/rars/ra16annoconfprop/TestManagedConnectionFactory.java 2009-12-15 17:40:03 UTC (rev 97853)
@@ -37,19 +37,70 @@
@ConfigProperty(type = String.class, defaultValue = "JCA")
private String myStringProperty;
+ @ConfigProperty
+ private String myOtherStringProperty;
+
+ private String myMethodStringProperty;
+
/**
- * @param myStringProperty the myStringProperty to set
+ * Constructor
*/
+ public TestManagedConnectionFactory()
+ {
+ }
+
+ /**
+ * Set the MyStringProperty value
+ * @param myStringProperty The value
+ */
public void setMyStringProperty(String myStringProperty)
{
this.myStringProperty = myStringProperty;
}
/**
- * @return the myStringProperty
+ * Get the MyStringProperty value
+ * @return The value
*/
public String getMyStringProperty()
{
return myStringProperty;
}
+
+ /**
+ * Set the MyOtherStringProperty value
+ * @param value The value
+ */
+ public void setMyOtherStringProperty(String value)
+ {
+ this.myOtherStringProperty = value;
+ }
+
+ /**
+ * Get the MyOtherStringProperty value
+ * @return The value
+ */
+ public String getMyOtherStringProperty()
+ {
+ return myOtherStringProperty;
+ }
+
+ /**
+ * Set the MyMethodStringProperty value
+ * @param value The value
+ */
+ @ConfigProperty
+ public void setMyMethodStringProperty(String value)
+ {
+ this.myMethodStringProperty = value;
+ }
+
+ /**
+ * Get the MyMethodStringProperty value
+ * @return The value
+ */
+ public String getMyMethodStringProperty()
+ {
+ return myMethodStringProperty;
+ }
}
More information about the jboss-cvs-commits
mailing list