[jboss-cvs] JBossAS SVN: r84389 - in projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed: plugins/factory and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Feb 18 11:05:26 EST 2009
Author: scott.stark at jboss.org
Date: 2009-02-18 11:05:26 -0500 (Wed, 18 Feb 2009)
New Revision: 84389
Modified:
projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/annotation/ManagementObjectID.java
projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectPopulator.java
projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/factory/Utility.java
Log:
JBMAN-55, Add prefix, suffix attributes to @ManagementObjectID
JBMAN-54, getAnnotation needs to build proper signature for MetaData
Modified: projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/annotation/ManagementObjectID.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/annotation/ManagementObjectID.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/annotation/ManagementObjectID.java 2009-02-18 16:05:26 UTC (rev 84389)
@@ -45,4 +45,14 @@
* identify the type or scope of the ManagedObject name.
*/
String type() default AnnotationDefaults.EMPTY_STRING;
+ /**
+ * A fixed prefix to prepend to the annotated property value when
+ * name() is empty.
+ */
+ String prefix() default AnnotationDefaults.EMPTY_STRING;
+ /**
+ * A fixed suffix to append to the annotated property value when
+ * name() is empty.
+ */
+ String suffix() default AnnotationDefaults.EMPTY_STRING;
}
Modified: projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java 2009-02-18 16:05:26 UTC (rev 84389)
@@ -75,6 +75,9 @@
import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulator;
import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulatorFactory;
import org.jboss.metadata.spi.MetaData;
+import org.jboss.metadata.spi.signature.FieldSignature;
+import org.jboss.metadata.spi.signature.MethodSignature;
+import org.jboss.metadata.spi.signature.Signature;
import org.jboss.metatype.api.annotations.MetaMapping;
import org.jboss.metatype.api.annotations.MetaMappingFactory;
import org.jboss.metatype.api.types.ArrayMetaType;
@@ -422,7 +425,9 @@
* @param metaData - the optional metadata repository accessor used to query
* for management annotation overrides/additions to the clazz
* @return the ManagementObject if clazz is properly annotated, null if
- * it does not have a ManagementObject annotation on the class or metaData
+ * it does not have a ManagementObject annotation on the class or metaData.
+ * The BeanInfo used by this method is stored as a transient attachment
+ * under the BeanInfo.class.getName() ket.
*/
@SuppressWarnings("unchecked")
public ManagedObject buildManagedObject(Class<?> clazz, MetaData metaData)
@@ -440,6 +445,13 @@
return null;
}
+ // If a targetInterface exists, rebuild the BeanInfo from that
+ Class<?> targetInterface = managementObject.targetInterface();
+ if(targetInterface != Object.class)
+ {
+ beanInfo = getBeanInfo(targetInterface);
+ classInfo = beanInfo.getClassInfo();
+ }
HashMap<String, Annotation> moAnnotations = new HashMap<String, Annotation>();
moAnnotations.put(ManagementObject.class.getName(), managementObject);
ManagementDeployment mnagementDeployment = getAnnotation(ManagementDeployment.class, classInfo, metaData);
@@ -771,6 +783,7 @@
result.setOperations(operations);
for (ManagedProperty property : properties)
property.setManagedObject(result);
+ result.setTransientAttachment(BeanInfo.class.getName(), beanInfo);
return result;
}
@@ -956,6 +969,39 @@
if(metaData != null)
{
annotation = metaData.getAnnotation(annotationType);
+ if(annotation == null && info instanceof MethodInfo)
+ {
+ MethodInfo mi = (MethodInfo) info;
+ Signature mis = Signature.getSignature(mi);
+ MetaData imetaData = metaData.getComponentMetaData(mis);
+ if (imetaData != null)
+ annotation = imetaData.getAnnotation(annotationType);
+ }
+ if (annotation == null && info instanceof PropertyInfo)
+ {
+ PropertyInfo pi = (PropertyInfo) info;
+ if(pi.getGetter() != null)
+ {
+ Signature mis = new MethodSignature(pi.getGetter());
+ MetaData imetaData = metaData.getComponentMetaData(mis);
+ if (imetaData != null)
+ annotation = imetaData.getAnnotation(annotationType);
+ }
+ if(annotation == null && pi.getSetter() != null)
+ {
+ Signature mis = new MethodSignature(pi.getSetter());
+ MetaData imetaData = metaData.getComponentMetaData(mis);
+ if (imetaData != null)
+ annotation = imetaData.getAnnotation(annotationType);
+ }
+ if(annotation == null && pi.getFieldInfo() != null)
+ {
+ Signature fis = new FieldSignature(pi.getFieldInfo());
+ MetaData imetaData = metaData.getComponentMetaData(fis);
+ if (imetaData != null)
+ annotation = imetaData.getAnnotation(annotationType);
+ }
+ }
if(annotation != null)
log.trace("Loaded "+annotationType+" from MetaData");
}
@@ -963,4 +1009,38 @@
annotation = info.getUnderlyingAnnotation(annotationType);
return annotation;
}
+
+ /**
+ * Build up a BeanInfo from the interface class and all interfaces it
+ * implements.
+ *
+ * @param iface - the interface for the managed object
+ * @return the full BeanInfo for the iface
+ */
+ protected BeanInfo getBeanInfo(Class<?> iface)
+ {
+ BeanInfo ifaceBI = configuration.getBeanInfo(iface);
+ Class<?>[] superIfaces = iface.getInterfaces();
+ if(superIfaces != null && superIfaces.length > 0)
+ {
+ // Combine all properties
+ Set<PropertyInfo> allProps = new HashSet<PropertyInfo>(ifaceBI.getProperties());
+ // Combine all operations
+ Set<MethodInfo> allMethods = new HashSet<MethodInfo>(ifaceBI.getMethods());
+ for(Class<?> superIface : superIfaces)
+ {
+ BeanInfo cBI = configuration.getBeanInfo(superIface);
+ Set<PropertyInfo> props = cBI.getProperties();
+ if(props != null)
+ allProps.addAll(props);
+ Set<MethodInfo> methods = cBI.getMethods();
+ if(methods != null)
+ allMethods.addAll(methods);
+ }
+
+ ifaceBI.setProperties(allProps);
+ ifaceBI.setMethods(allMethods);
+ }
+ return ifaceBI;
+ }
}
Modified: projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectPopulator.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectPopulator.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectPopulator.java 2009-02-18 16:05:26 UTC (rev 84389)
@@ -187,7 +187,10 @@
{
throw new IllegalStateException(e);
}
- BeanInfo beanInfo = configuration.getBeanInfo(moClass);
+
+ BeanInfo beanInfo = managedObject.getTransientAttachment(BeanInfo.class);
+ if(beanInfo == null)
+ beanInfo = configuration.getBeanInfo(moClass);
Object componentName = null;
Map<String, ManagedProperty> properties = managedObject.getProperties();
@@ -224,7 +227,8 @@
continue;
}
SimpleValue svalue = (SimpleValue) value;
- String name = "" + svalue.getValue();
+ String name = id.prefix() + svalue.getValue() + id.suffix();
+ log.debug("Created name: "+name+" from property: "+property.getName());
managedObject.setName(name);
}
ManagementRuntimeRef runtimeRef = getAnnotation(ManagementRuntimeRef.class, annotations, metaData);
Modified: projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/factory/Utility.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/factory/Utility.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/factory/Utility.java 2009-02-18 16:05:26 UTC (rev 84389)
@@ -27,10 +27,10 @@
import org.jboss.metadata.spi.MetaData;
/**
- * Common untility methods used by the factory plugins.
+ * Common utility methods used by the factory plugins.
*
* @author Scott.Stark at jboss.org
- * @version $Revision:$
+ * @version $Revision$
*/
public class Utility
{
Property changes on: projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/factory/Utility.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
More information about the jboss-cvs-commits
mailing list