[jboss-cvs] JBossAS SVN: r64532 - in projects/microcontainer/trunk: deployers-impl/src/tests/org/jboss/test/deployers/managed/support and 7 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Aug 10 03:37:17 EDT 2007
Author: scott.stark at jboss.org
Date: 2007-08-10 03:37:16 -0400 (Fri, 10 Aug 2007)
New Revision: 64532
Added:
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/SecurityDeployment.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/support/MockProfileService.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/test/DeployerManagedDeploymentUnitTestCase.java
projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObjectID.java
projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObjectRef.java
Removed:
projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementComponentRef.java
Modified:
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/ConnMetaData.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/MCFDeployer.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/SecMetaData.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/test/DeployerManagedObjectUnitTestCase.java
projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/Fields.java
projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedObject.java
projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedProperty.java
projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObject.java
projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementProperty.java
projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/factory/ManagedObjectFactory.java
projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedObjectImpl.java
projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedPropertyImpl.java
projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/factory/AbstractManagedObjectFactoryTest.java
Log:
JBMICROCONT-181, checkpoint current progress.
Modified: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/ConnMetaData.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/ConnMetaData.java 2007-08-10 06:20:25 UTC (rev 64531)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/ConnMetaData.java 2007-08-10 07:37:16 UTC (rev 64532)
@@ -25,6 +25,7 @@
import java.util.Properties;
import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementObjectID;
import org.jboss.managed.api.annotation.ManagementProperty;
import org.jboss.managed.plugins.WritethroughManagedPropertyImpl;
@@ -114,6 +115,7 @@
}
@ManagementProperty(name="security-domain", managed=true)
+ @ManagementObjectID(name="java:/jaas/DefaultDS", type="SecurityDomain")
public SecMetaData getSecurityMetaData()
{
return securityMetaData;
Modified: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/MCFDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/MCFDeployer.java 2007-08-10 06:20:25 UTC (rev 64531)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/MCFDeployer.java 2007-08-10 07:37:16 UTC (rev 64532)
@@ -1,21 +1,27 @@
package org.jboss.test.deployers.deployer.support;
-import java.util.Set;
+import java.io.Serializable;
+import java.util.Map;
import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
import org.jboss.deployers.spi.deployer.managed.ManagedDeploymentCreator;
+import org.jboss.deployers.spi.deployer.managed.ManagedObjectCreator;
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.managed.api.ManagedDeployment;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.managed.plugins.factory.ManagedObjectFactoryBuilder;
public class MCFDeployer
extends AbstractSimpleRealDeployer<DSMetaData>
- implements ManagedDeploymentCreator
+ implements ManagedDeploymentCreator,
+ ManagedObjectCreator
{
- public MCFDeployer(Class<DSMetaData> input)
+ public MCFDeployer()
{
- super(input);
+ super(DSMetaData.class);
}
@Override
@@ -24,6 +30,23 @@
{
}
+ public void build(DeploymentUnit unit, Map<String, ManagedObject> managedObjects)
+ throws DeploymentException
+ {
+ ManagedObjectFactory factory = ManagedObjectFactoryBuilder.create();
+ Map<String, Object> attachments = unit.getAttachments();
+ for(Object metaData : attachments.values() )
+ {
+ if( metaData instanceof Serializable )
+ {
+ Serializable smetaData = Serializable.class.cast(metaData);
+ ManagedObject mo = factory.initManagedObject(smetaData, null, null);
+ if (mo != null)
+ managedObjects.put(mo.getName(), mo);
+ }
+ }
+ }
+
public ManagedDeployment build(DeploymentUnit unit)
{
ManagedDeployment md = null;
Modified: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/SecMetaData.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/SecMetaData.java 2007-08-10 06:20:25 UTC (rev 64531)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/SecMetaData.java 2007-08-10 07:37:16 UTC (rev 64532)
@@ -2,7 +2,8 @@
import java.io.Serializable;
-import org.jboss.managed.api.annotation.ManagementComponentRef;
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementObjectRef;
import org.jboss.managed.api.annotation.ManagementProperty;
/**
@@ -10,6 +11,7 @@
* @author Scott.Stark at jboss.org
* @version $Revision$
*/
+ at ManagementObject
public class SecMetaData implements Serializable
{
private static final long serialVersionUID = 1;
@@ -25,7 +27,7 @@
* @return
*/
@ManagementProperty(name="domain-name")
- @ManagementComponentRef
+ @ManagementObjectRef(type="SecurityDomain")
public String getDomain()
{
return domain;
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/SecurityDeployment.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/SecurityDeployment.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/SecurityDeployment.java 2007-08-10 07:37:16 UTC (rev 64532)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.deployers.deployer.support;
+
+import java.io.Serializable;
+
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementObjectID;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+ at ManagementObject
+public class SecurityDeployment implements Serializable
+{
+ private static final long serialVersionUID = 1;
+ private String domain;
+
+ @ManagementObjectID(type="SecurityDomain")
+ public String getDomainName()
+ {
+ return domain;
+ }
+ public void setDomainName(String name)
+ {
+ this.domain = name;
+ }
+}
Property changes on: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/SecurityDeployment.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/support/MockProfileService.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/support/MockProfileService.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/support/MockProfileService.java 2007-08-10 07:37:16 UTC (rev 64532)
@@ -0,0 +1,108 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.deployers.managed.support;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.logging.Logger;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.annotation.ManagementObjectRef;
+import org.jboss.managed.plugins.factory.AbstractManagedObjectFactory;
+
+/**
+ * Mock profile service for testing implementation details.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class MockProfileService
+{
+ private static final Logger log = Logger.getLogger(MockProfileService.class);
+
+ /** id/type key to ManagedObject map */
+ private Map<String, ManagedObject> moRegistry = new HashMap<String, ManagedObject>();
+
+ private Map<String, List<ManagedProperty>> unresolvedRefs = new HashMap<String, List<ManagedProperty>>();
+
+ /**
+ *
+ * @param mo
+ */
+ public void processManagedObject(ManagedObject mo)
+ {
+ String key = mo.getName() + "/" + mo.getNameType();
+ log.info("ID for ManagedObject: "+key+", attachmentName: "+mo.getAttachmentName());
+ ManagedObject prevMO = moRegistry.put(key, mo);
+ if( prevMO != null )
+ log.warn("Duplicate mo for key: "+key+", prevMO: "+prevMO);
+
+ // Check for unresolved refs
+ List<ManagedProperty> referers = unresolvedRefs.get(key);
+ if (referers != null)
+ {
+ for(ManagedProperty prop : referers)
+ {
+ prop.setTargetManagedObject(mo);
+ }
+ referers.clear();
+ }
+
+ // Scan for @ManagementObjectRef
+ for(ManagedProperty prop : mo.getProperties())
+ {
+ ManagementObjectRef ref = (ManagementObjectRef) prop.getAnnotations().get(ManagementObjectRef.class.getName());
+ if ( ref != null )
+ {
+ String targetKey = ref.name() + "/" + ref.type();
+ ManagedObject target = moRegistry.get(targetKey);
+ if (target != null)
+ {
+ prop.setTargetManagedObject(target);
+ }
+ else
+ {
+ referers = (List<ManagedProperty>) unresolvedRefs.get(targetKey);
+ if (referers == null)
+ {
+ referers = new ArrayList<ManagedProperty>();
+ unresolvedRefs.put(targetKey, referers);
+ }
+ referers.add(prop);
+ }
+ }
+ if (prop.getMetaType() == AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE)
+ {
+ ManagedObject propMO = (ManagedObject) prop.getValue();
+ processManagedObject(propMO);
+ }
+ }
+ }
+
+ public Map<String, List<ManagedProperty>> getUnresolvedRefs()
+ {
+ return unresolvedRefs;
+ }
+}
Property changes on: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/support/MockProfileService.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/test/DeployerManagedDeploymentUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/test/DeployerManagedDeploymentUnitTestCase.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/test/DeployerManagedDeploymentUnitTestCase.java 2007-08-10 07:37:16 UTC (rev 64532)
@@ -0,0 +1,154 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, 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.deployers.managed.test;
+
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.plugins.attachments.AttachmentsImpl;
+import org.jboss.deployers.spi.attachments.MutableAttachments;
+import org.jboss.deployers.spi.attachments.PredeterminedManagedObjectAttachments;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.reflect.plugins.ClassInfoImpl;
+import org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactoryImpl;
+import org.jboss.reflect.spi.AnnotationValue;
+import org.jboss.reflect.spi.MethodInfo;
+import org.jboss.test.deployers.AbstractDeployerTest;
+import org.jboss.test.deployers.deployer.support.ConnMetaData;
+import org.jboss.test.deployers.deployer.support.DSMetaData;
+import org.jboss.test.deployers.deployer.support.LocalDataSourceMetaData;
+import org.jboss.test.deployers.deployer.support.MCFDeployer;
+import org.jboss.test.deployers.deployer.support.SecMetaData;
+import org.jboss.test.deployers.deployer.support.SecurityDeployment;
+import org.jboss.test.deployers.deployer.support.XADataSourceMetaData;
+import org.jboss.test.deployers.managed.support.MockProfileService;
+import org.jboss.test.deployers.managed.support.TestManagedObjectDeployer;
+
+/**
+ * ManagedDeployment unit tests.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class DeployerManagedDeploymentUnitTestCase extends AbstractDeployerTest
+{
+ private MCFDeployer deployer = new MCFDeployer();
+
+ public static Test suite()
+ {
+ return new TestSuite(DeployerManagedObjectUnitTestCase.class);
+ }
+
+ public DeployerManagedDeploymentUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testAnnotationScan()
+ throws Exception
+ {
+ ManagedObjectFactory mof = ManagedObjectFactory.getInstance();
+ ManagedObject mo = mof.createManagedObject(DSMetaData.class);
+
+ Set<ManagedProperty> props = mo.getProperties();
+ assertEquals(2, props.size());
+
+ }
+
+ public void testManagedDeployment()
+ throws Exception
+ {
+ MockProfileService ps = new MockProfileService();
+ DeployerClient main = getMainDeployer();
+
+ // Deploy a datasource
+ Deployment ctx1 = createSimpleDeployment("deployment1");
+ DSMetaData dsmd = new DSMetaData();
+ LocalDataSourceMetaData ds = new LocalDataSourceMetaData();
+ ds.setJndiName("java:DefaultDS1");
+ ds.setMaxSize(100);
+ ds.setMinSize(10);
+ ds.setPassword("password1".toCharArray());
+ ds.setUsername("username1");
+ SecMetaData smd = new SecMetaData();
+ smd.setDomain("java:/jaas/domain1");
+ ds.setSecurityMetaData(smd);
+
+ XADataSourceMetaData xads = new XADataSourceMetaData();
+ xads.setJndiName("java:DefaultXADS2");
+ ds.setMaxSize(100);
+ ds.setMinSize(10);
+ ds.setPassword("password2".toCharArray());
+ ds.setUsername("username2");
+ xads.setXaDataSourceClass("org.jboss.xa.SomeXADS");
+ xads.setXaResourceTimeout(300);
+ xads.setSecurityMetaData(smd);
+
+ ArrayList<ConnMetaData> deployments = new ArrayList<ConnMetaData>();
+ deployments.add(ds);
+ deployments.add(xads);
+ dsmd.setDeployments(deployments);
+
+ MutableAttachments a1 = (MutableAttachments) ctx1.getPredeterminedManagedObjects();
+ a1.addAttachment(DSMetaData.class, dsmd);
+ main.addDeployment(ctx1);
+
+ // Deploy a security domain
+ Deployment ctx2 = createSimpleDeployment("deployment2");
+ MutableAttachments a2 = (MutableAttachments) ctx2.getPredeterminedManagedObjects();
+ SecurityDeployment sd = new SecurityDeployment();
+ a2.addAttachment(SecurityDeployment.class, sd);
+ main.addDeployment(ctx2);
+ main.process();
+
+ //
+ Map<String, ManagedObject> mds1 = main.getManagedObjects("deployment1");
+ log.info("deployment1 ManagedObjects: " + mds1);
+ for(ManagedObject mo : mds1.values())
+ ps.processManagedObject(mo);
+ Map<String, List<ManagedProperty>> unresolvedRefs = ps.getUnresolvedRefs();
+ log.info("unresolvedRefs: "+unresolvedRefs);
+
+ Map<String, ManagedObject> mds2 = main.getManagedObjects("deployment2");
+ log.info("deployment2 ManagedObjects: " +mds2);
+ for(ManagedObject mo : mds2.values())
+ ps.processManagedObject(mo);
+
+ //
+ }
+
+ protected DeployerClient getMainDeployer()
+ {
+ return createMainDeployer(deployer);
+ }
+}
Property changes on: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/test/DeployerManagedDeploymentUnitTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Modified: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/test/DeployerManagedObjectUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/test/DeployerManagedObjectUnitTestCase.java 2007-08-10 06:20:25 UTC (rev 64531)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/test/DeployerManagedObjectUnitTestCase.java 2007-08-10 07:37:16 UTC (rev 64532)
@@ -169,10 +169,9 @@
ArrayMetaType valueType = value.getMetaType();
assertEquals(AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE, valueType.getElementType());
- Object[] values = value.getValue();
- assertEquals(1, values.length);
+ assertEquals(1, value.getLength());
// Validate the ConnMetaData ManagedObject
- ManagedObject localConnMO = ManagedObject.class.cast(values[0]);
+ ManagedObject localConnMO = ManagedObject.class.cast(value.getValue(0));
assertEquals(ConnMetaData.class.getName(), localConnMO.getName());
props = localConnMO.getProperties();
assertEquals(8, props.size());
@@ -202,7 +201,7 @@
deployments.add(ds);
deployments.add(xads);
dsmd.setDeployments(deployments);
- ManagedObject mo = mof.initManagedObject(dsmd);
+ ManagedObject mo = mof.initManagedObject(dsmd, null, null);
// Validate the expected properties
Set<ManagedProperty> props = mo.getProperties();
@@ -230,11 +229,10 @@
ArrayMetaType valueType = value.getMetaType();
assertEquals(AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE, valueType.getElementType());
- Object[] values = value.getValue();
- assertEquals(2, values.length);
+ assertEquals(2, value.getLength());
ManagedObject localConnMO = null;
ManagedObject xaConnMO = null;
- for(Object md : values)
+ for(Object md : value)
{
ManagedObject tmpMO = ManagedObject.class.cast(md);
if (tmpMO.getName().equals(LocalDataSourceMetaData.class.getName()))
Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/Fields.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/Fields.java 2007-08-10 06:20:25 UTC (rev 64531)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/Fields.java 2007-08-10 07:37:16 UTC (rev 64532)
@@ -59,10 +59,14 @@
/** The mandatory */
String MANDATORY = "mandatory";
- // TODO other standard fields here
/** The PropertyInfo info for the ManagedObject attachment */
String PROPERTY_INFO = "propertyInfo";
+ /** The annotations associated with the property */
+ String ANNOTATIONS = "annotations";
+
+ // TODO other standard fields here
+
/**
* Get a field with the given name
*
Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedObject.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedObject.java 2007-08-10 06:20:25 UTC (rev 64531)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedObject.java 2007-08-10 07:37:16 UTC (rev 64532)
@@ -22,33 +22,43 @@
package org.jboss.managed.api;
import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.util.Map;
import java.util.Set;
-import org.jboss.metatype.api.types.Name;
-
/**
* ManagedObject.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Scott.Stark at jboss.org
* @version $Revision: 1.1 $
*/
public interface ManagedObject extends Serializable
{
/**
- * Get the attachment name
- *
- * @return the name
+ * Get the external name by which the ManagedObject is known
+ * @see {@linkplain ManagementObject#name}}
+ * @see {@linkplain ManagementObjectID#name}}
+ * @return
*/
String getName();
-
/**
- * Get the external name by which the ManagedObject
- * @see {@linkplain ManagedObjectRegistry}}
+ * Get the external name type/qualifier.
+ * @see {@linkplain ManagementObject#type}
+ * @see {@linkplain ManagementObjectID#type}
* @return
*/
- Name getExternalName();
+ String getNameType();
/**
+ * Get the attachment name
+ * @see {@linkplain ManagementObject#attachmentName}}
+ *
+ * @return the name
+ */
+ String getAttachmentName();
+
+ /**
* Get the underlying object
*
* @return the underlying object
@@ -56,6 +66,12 @@
Serializable getAttachment();
/**
+ * Get the annotations associated with the property
+ * @return the annotations associated with the property
+ */
+ public Map<String, Annotation> getAnnotations();
+
+ /**
* Get the property names
*
* @return the property names
Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedProperty.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedProperty.java 2007-08-10 06:20:25 UTC (rev 64531)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedProperty.java 2007-08-10 07:37:16 UTC (rev 64532)
@@ -22,6 +22,8 @@
package org.jboss.managed.api;
import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.util.Map;
import java.util.Set;
import org.jboss.metatype.api.types.MetaType;
@@ -31,18 +33,28 @@
* ManagedProperty.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Scott.Stark at jboss.org
* @version $Revision: 1.1 $
*/
public interface ManagedProperty extends Serializable
{
/**
- * Get the managed object
+ * Get the managed object the property is associated with.
*
* @return the managed object
*/
ManagedObject getManagedObject();
-
+
/**
+ * Get the ManagedObject
+ * @see {@linkplain ManagementObjectRef}
+ * @return the ManagedObject the property references, null
+ * if there is no reference or its unresolved.
+ */
+ ManagedObject getTargetManagedObject();
+ void setTargetManagedObject(ManagedObject target);
+
+ /**
* Get the fields
*
* @return the fields
@@ -99,6 +111,12 @@
MetaType getMetaType();
/**
+ * Get the annotations associated with the property
+ * @return the annotations associated with the property
+ */
+ Map<String, Annotation> getAnnotations();
+
+ /**
* Get the value
*
* @return the value
Deleted: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementComponentRef.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementComponentRef.java 2007-08-10 06:20:25 UTC (rev 64531)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementComponentRef.java 2007-08-10 07:37:16 UTC (rev 64532)
@@ -1,40 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, 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.managed.api.annotation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Indicates a property that references another ManagedComponent
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
- at Target({ElementType.METHOD})
- at Retention(RetentionPolicy.RUNTIME)
-public @interface ManagementComponentRef
-{
- String name() default "";
-}
Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObject.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObject.java 2007-08-10 06:20:25 UTC (rev 64531)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObject.java 2007-08-10 07:37:16 UTC (rev 64532)
@@ -26,22 +26,44 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+import org.jboss.managed.api.Fields;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.annotation.ManagementProperty.NULL_CONSTRAINTS;
+import org.jboss.managed.api.annotation.ManagementProperty.NULL_FIELDS_FACTORY;
+import org.jboss.managed.api.annotation.ManagementProperty.NULL_PROPERTY_FACTORY;
+import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulatorFactory;
+
/**
- * ManagementObject.
+ * ManagementObject annotation for describing ManagedObjects.
+ * @see {@linkplain ManagedObject}
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Scott.Stark at jboss.org
* @version $Revision: 1.1 $
*/
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface ManagementObject
{
- /** The name */
+ /** The name used for ManagementObjectRef resolution */
String name() default ManagementConstants.GENERATED;
-
+ /** The name type used for ManagementObjectRef resolution */
+ String type() default "";
+ /** The metadata attachment name for the ManagedObject */
+ String attachmentName() default "";
+
/** What properties to include */
ManagementProperties properties() default ManagementProperties.ALL;
/** The exposed operations */
ManagementOperation[] operations() default {};
+
+ /** The class to use for the ManagedProperty implementation */
+ Class<? extends ManagedProperty> propertyFactory() default NULL_PROPERTY_FACTORY.class;
+ /** The class to use for the ManagedProperty Fields implementation */
+ Class<? extends Fields> fieldsFactory() default NULL_FIELDS_FACTORY.class;
+ /** The constraints, allowed values populator factory */
+ Class<? extends ManagedPropertyConstraintsPopulatorFactory> constraintsFactory()
+ default NULL_CONSTRAINTS.class;
+
}
Added: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObjectID.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObjectID.java (rev 0)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObjectID.java 2007-08-10 07:37:16 UTC (rev 64532)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.managed.api.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * An annotation that identifies a ManagedObject key/type
+ * qualifier source.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+ at Target({ElementType.TYPE, ElementType.METHOD})
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface ManagementObjectID
+{
+ /** An explicit ManagedObject name. If empty, the name is
+ * taken from the annotated property.
+ */
+ String name() default "";
+ /** A qualifier for the name that provides a context to
+ * identify the type or scope of the ManagedObject name.
+ */
+ String type() default "";
+}
Property changes on: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObjectID.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Copied: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObjectRef.java (from rev 64319, projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementComponentRef.java)
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObjectRef.java (rev 0)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObjectRef.java 2007-08-10 07:37:16 UTC (rev 64532)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.managed.api.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Indicates a property that references another ManagedObject
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+ at Target({ElementType.METHOD})
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface ManagementObjectRef
+{
+ /** An explicit ManagedObject name. If empty, the name is
+ * taken from the annotated property.
+ * @see {@linkplain ManagedObject#getExternalName()}
+ */
+ String name() default "";
+ /** A qualifier for the name that provides a context to
+ * identify the type or scope of the ManagedObject name.
+ * @see {@linkplain ManagedObject#getExternalNameType()}
+ */
+ String type() default "";
+}
Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementProperty.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementProperty.java 2007-08-10 06:20:25 UTC (rev 64531)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementProperty.java 2007-08-10 07:37:16 UTC (rev 64532)
@@ -65,7 +65,7 @@
/** The views this property should be used in */
ViewUse[] use() default {ViewUse.RUNTIME};
- /** */
+ /** The class to use for the ManagedProperty implementation */
Class<? extends ManagedProperty> propertyFactory() default NULL_PROPERTY_FACTORY.class;
/** The class to use for the ManagedProperty Fields implementation */
Class<? extends Fields> fieldsFactory() default NULL_FIELDS_FACTORY.class;
Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/factory/ManagedObjectFactory.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/factory/ManagedObjectFactory.java 2007-08-10 06:20:25 UTC (rev 64531)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/factory/ManagedObjectFactory.java 2007-08-10 07:37:16 UTC (rev 64532)
@@ -52,10 +52,17 @@
* Create a managed object from the given object
*
* @param object the object
+ * @param name - the name of the managed object. If null, the name will
+ * be derived from the object annotations or attachment name.
+ * @param type - the name of the managed object. If null, the name will
+ * be derived from the object annotations or default to "".
+ *
+ * @see ManagementObjectID
+ *
* @return the managed object
* @throws IllegalArgumentException for a null object
*/
- public abstract ManagedObject initManagedObject(Serializable object);
+ public abstract ManagedObject initManagedObject(Serializable object, String name, String nameType);
/**
* Create a shell managed object from the given class
Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedObjectImpl.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedObjectImpl.java 2007-08-10 06:20:25 UTC (rev 64531)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedObjectImpl.java 2007-08-10 07:37:16 UTC (rev 64532)
@@ -22,33 +22,40 @@
package org.jboss.managed.plugins;
import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import org.jboss.managed.api.ManagedObject;
import org.jboss.managed.api.ManagedOperation;
import org.jboss.managed.api.ManagedProperty;
-import org.jboss.metatype.api.types.Name;
/**
* ManagedObjectImpl.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Scott.Stark at jboss.org
* @version $Revision: 1.1 $
*/
public class ManagedObjectImpl implements ManagedObject
{
/** The serialVersionUID */
- private static final long serialVersionUID = -2588364350006686542L;
+ private static final long serialVersionUID = 2L;
+ /** The object name used for ManagementRef resolution */
+ private String name;
+ /** The name type/qualifier used for ManagementRef resolution */
+ private String nameType;
/** The attachment name */
- private String name;
- /** */
- private Name externalName;
+ private String attachmentName;
/** The attachment */
private Serializable attachment;
-
+ /** The object annotations <Class name, Annotation> */
+ private Map<String, Annotation> annotations = Collections.emptyMap();
/** The properties */
private Set<ManagedProperty> properties;
/** The operations */
@@ -57,7 +64,7 @@
/**
* Create a new ManagedObjectImpl
*
- * @param name the attachment name
+ * @param name - The object name used for ManagementRef resolution
*/
public ManagedObjectImpl(String name)
{
@@ -67,7 +74,7 @@
/**
* Create a new ManagedObjectImpl
*
- * @param name the attachment name
+ * @param name - The object name used for ManagementRef resolution
* @param properties the properties
*/
public ManagedObjectImpl(String name, Set<ManagedProperty> properties)
@@ -78,7 +85,7 @@
/**
* Create a new ManagedObjectImpl
*
- * @param name the attachment name
+ * @param name - The object name used for ManagementRef resolution
* @param properties the properties
* @param operations the operations
*/
@@ -91,7 +98,7 @@
/**
* Create a new ManagedObjectImpl
*
- * @param name the attachment name
+ * @param name - The object name used for ManagementRef resolution
* @param properties the properties
* @param operations the operations
* @param attachment the attachment
@@ -113,12 +120,13 @@
/**
* Create a new ManagedObjectImpl
*
- * @param name the attachment name
- * @param externalName - the ManagedObjectRegistry name
+ * @param name - The object name used for ManagementRef resolution
+ * @param nameType - The name type/qualifier used for ManagementRef resolution
+ * @param attachmentName the attachment name
* @param properties the properties
* @param attachment the attachment
*/
- public ManagedObjectImpl(String name, Name externalName,
+ public ManagedObjectImpl(String name, String nameType, String attachmentName,
Set<ManagedProperty> properties, Serializable attachment)
{
if (name == null)
@@ -127,7 +135,8 @@
throw new IllegalArgumentException("Null properties");
this.name = name;
- this.externalName = externalName;
+ this.nameType = nameType;
+ this.attachmentName = attachmentName;
this.properties = properties;
setAttachment(attachment);
}
@@ -136,16 +145,45 @@
{
return name;
}
+ public void setName(String name)
+ {
+ this.name = name;
+ }
- public Name getExternalName()
+ public String getNameType()
{
- return externalName;
+ return nameType;
}
- public void setExternalName(Name externalName)
+ public void setNameType(String nameType)
{
- this.externalName = externalName;
+ this.nameType = nameType;
}
+ public String getAttachmentName()
+ {
+ return attachmentName;
+ }
+ public void setAttachmentName(String attachmentName)
+ {
+ this.attachmentName = attachmentName;
+ }
+
+ /**
+ * Get the annotations associated with the property
+ * @return the annotations associated with the property
+ */
+ public Map<String, Annotation> getAnnotations()
+ {
+ return annotations;
+ }
+ public void setAnnotations(Map<String, Annotation> annotations)
+ {
+ if (this.annotations.isEmpty())
+ this.annotations = new HashMap<String, Annotation>();
+ this.annotations.clear();
+ this.annotations.putAll(annotations);
+ }
+
public Set<String> getPropertyNames()
{
Set<String> result = new HashSet<String>(properties.size());
Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedPropertyImpl.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedPropertyImpl.java 2007-08-10 06:20:25 UTC (rev 64531)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedPropertyImpl.java 2007-08-10 07:37:16 UTC (rev 64532)
@@ -26,6 +26,8 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.util.Map;
import java.util.Set;
import org.jboss.managed.api.Fields;
@@ -56,6 +58,8 @@
/** The managed object */
private ManagedObject managedObject;
+ /** The managed object target for a ManagementObjectRef */
+ private ManagedObject targetManagedObject;
/** The fields */
private Fields fields;
@@ -117,6 +121,15 @@
this.managedObject = managedObject;
}
+ public ManagedObject getTargetManagedObject()
+ {
+ return targetManagedObject;
+ }
+ public void setTargetManagedObject(ManagedObject target)
+ {
+ this.targetManagedObject = target;
+ }
+
public Fields getFields()
{
return fields;
@@ -186,6 +199,20 @@
}
+ /**
+ * Get the annotations associated with the property
+ * @return the annotations associated with the property
+ */
+ public Map<String, Annotation> getAnnotations()
+ {
+ Object set = getField(Fields.ANNOTATIONS, Object.class);
+ return (Map<String, Annotation>) set;
+ }
+ public void setAnnotations(Map<String, Annotation> annotations)
+ {
+ setField(Fields.ANNOTATIONS, (Serializable) annotations);
+ }
+
public MetaType getMetaType()
{
return getField(Fields.META_TYPE, MetaType.class);
Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java 2007-08-10 06:20:25 UTC (rev 64531)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java 2007-08-10 07:37:16 UTC (rev 64532)
@@ -22,6 +22,7 @@
package org.jboss.managed.plugins.factory;
import java.io.Serializable;
+import java.lang.annotation.Annotation;
import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor;
import java.security.AccessController;
@@ -29,6 +30,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@@ -46,6 +48,8 @@
import org.jboss.managed.api.ManagedOperation.Impact;
import org.jboss.managed.api.annotation.ManagementConstants;
import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementObjectID;
+import org.jboss.managed.api.annotation.ManagementObjectRef;
import org.jboss.managed.api.annotation.ManagementOperation;
import org.jboss.managed.api.annotation.ManagementProperties;
import org.jboss.managed.api.annotation.ManagementProperty;
@@ -123,13 +127,19 @@
}
@Override
- public ManagedObject initManagedObject(Serializable object)
+ public ManagedObject initManagedObject(Serializable object,
+ String name, String nameType)
{
if (object == null)
throw new IllegalArgumentException("Null object");
Class<? extends Serializable> clazz = object.getClass();
ManagedObject result = createSkeletonManagedObject(clazz);
+ if (result == null )
+ {
+ log.debug("Null ManagedObject created for: "+clazz);
+ return null;
+ }
ManagedObjectPopulator<Serializable> populator = getPopulator(clazz);
populator.populateManagedObject(result, object);
@@ -152,7 +162,9 @@
*
* @param <T> the type
* @param clazz the clazz
- * @return the skeleton managed object
+ * @return the skeleton managed object, null if clazz is not
+ * marked as a ManagementObject.
+ * @see {@linkplain ManagementObject}
*/
protected <T extends Serializable> ManagedObject createSkeletonManagedObject(Class<T> clazz)
{
@@ -161,11 +173,16 @@
ManagedObjectBuilder builder = getBuilder(clazz);
ManagedObject result = builder.buildManagedObject(clazz);
- if (result == null)
- throw new IllegalStateException("Builder returned null object: " + builder);
return result;
}
+ /**
+ * The ManagedObjectBuilder.buildManagedObject implementation. This is based
+ * on the org.jboss.managed.api.annotation.* package annotations.
+ * @param clazz -
+ * @return the ManagementObject if clazz is properly annotated, null if
+ * it does not have a ManagementObject annotation.
+ */
public ManagedObject buildManagedObject(Class<? extends Serializable> clazz)
{
BeanInfo beanInfo = configuration.getBeanInfo(clazz);
@@ -178,18 +195,43 @@
return null;
}
- String name = ManagementConstants.GENERATED;
+ HashMap<String, Annotation> moAnnotations = new HashMap<String, Annotation>();
+ moAnnotations.put(ManagementObject.class.getName(), managementObject);
+ ManagementObjectID moID = classInfo.getUnderlyingAnnotation(ManagementObjectID.class);
+ if (moID != null)
+ moAnnotations.put(ManagementObjectID.class.getName(), moID);
+
+ // Process the ManagementObject fields
+ String name = classInfo.getName();
+ String nameType = null;
+ String attachmentName = classInfo.getName();
+ Class<? extends Fields> moFieldsFactory = null;
+ Class<? extends ManagedPropertyConstraintsPopulatorFactory> moConstraintsFactory = null;
+ Class<? extends ManagedProperty> moPropertyFactory = null;
if (managementObject != null)
+ {
name = managementObject.name();
- if (ManagementConstants.GENERATED.equals(name))
- name = classInfo.getName();
-
+ if (name.length() == 0 || name.equals(ManagementConstants.GENERATED))
+ name = classInfo.getName();
+ nameType = managementObject.type();
+ if (nameType.length() == 0)
+ nameType = null;
+ attachmentName = managementObject.attachmentName();
+ if (attachmentName.length() == 0)
+ attachmentName = classInfo.getName();
+ // ManagementObject level default factory classes
+ moFieldsFactory = managementObject.fieldsFactory();
+ moConstraintsFactory = managementObject.constraintsFactory();
+ moPropertyFactory = managementObject.propertyFactory();
+ }
+
ManagementProperties propertyType = ManagementProperties.ALL;
if (managementObject != null)
propertyType = managementObject.properties();
-
+
+ // Build the ManagedProperties
Set<ManagedProperty> properties = new HashSet<ManagedProperty>();
-
+
Set<PropertyInfo> propertyInfos = beanInfo.getProperties();
if (propertyInfos != null && propertyInfos.isEmpty() == false)
{
@@ -200,6 +242,15 @@
continue;
ManagementProperty managementProperty = propertyInfo.getUnderlyingAnnotation(ManagementProperty.class);
+ ManagementObjectID id = propertyInfo.getUnderlyingAnnotation(ManagementObjectID.class);
+ ManagementObjectRef ref = propertyInfo.getUnderlyingAnnotation(ManagementObjectRef.class);
+ HashMap<String, Annotation> propAnnotations = new HashMap<String, Annotation>();
+ if (managementProperty != null)
+ propAnnotations.put(ManagementProperty.class.getName(), managementProperty);
+ if (id != null)
+ propAnnotations.put(ManagementObjectID.class.getName(), id);
+ if (ref != null)
+ propAnnotations.put(ManagementObjectRef.class.getName(), ref);
// Check for a simple property
boolean includeProperty = (propertyType == ManagementProperties.ALL);
@@ -211,7 +262,9 @@
Fields fields = null;
if (managementProperty != null)
{
- Class<? extends Fields> factory = managementProperty.fieldsFactory();
+ Class<? extends Fields> factory = moFieldsFactory;
+ if (factory == ManagementProperty.NULL_FIELDS_FACTORY.class)
+ factory = managementProperty.fieldsFactory();
if (factory != ManagementProperty.NULL_FIELDS_FACTORY.class)
{
try
@@ -279,11 +332,18 @@
metaType = metaTypeFactory.resolve(propertyInfo.getType());
}
fields.setField(Fields.META_TYPE, metaType);
+ if (propAnnotations.isEmpty() == false)
+ fields.setField(Fields.ANNOTATIONS, propAnnotations);
// Delegate others (legal values, min/max etc.) to the constraints factory
try
{
- Class<? extends ManagedPropertyConstraintsPopulatorFactory> factoryClass = managementProperty.constraintsFactory();
+ Class<? extends ManagedPropertyConstraintsPopulatorFactory> factoryClass = moConstraintsFactory;
+ if (factoryClass == ManagementProperty.NULL_CONSTRAINTS.class)
+ {
+ if (managementProperty != null)
+ factoryClass = managementProperty.constraintsFactory();
+ }
ManagedPropertyConstraintsPopulatorFactory factory = factoryClass.newInstance();
ManagedPropertyConstraintsPopulator populator = factory.newInstance();
if (populator != null)
@@ -291,14 +351,15 @@
}
catch(Exception e)
{
-
+ log.debug("Failed to populate constraints for: "+propertyInfo, e);
}
-
ManagedProperty property = null;
if (managementProperty != null)
{
- Class<? extends ManagedProperty> factory = managementProperty.propertyFactory();
+ Class<? extends ManagedProperty> factory = moPropertyFactory;
+ if (factory == ManagementProperty.NULL_PROPERTY_FACTORY.class)
+ factory = managementProperty.propertyFactory();
if (factory != ManagementProperty.NULL_PROPERTY_FACTORY.class)
{
property = getManagedProperty(factory, fields);
@@ -331,8 +392,14 @@
}
ManagedObjectImpl result = new ManagedObjectImpl(name, properties);
+ result.setAnnotations(moAnnotations);
+ if (nameType != null)
+ result.setNameType(nameType);
+ if (attachmentName != null)
+ result.setAttachmentName(attachmentName);
for (ManagedProperty property : properties)
{
+ // FIXME: this either needs to be passed in via the factory or setter added to ManagedProperty
ManagedPropertyImpl managedPropertyImpl = (ManagedPropertyImpl) property;
managedPropertyImpl.setManagedObject(result);
}
@@ -450,7 +517,11 @@
{
if (value instanceof Serializable == false)
throw new IllegalStateException("Object is not serializable: " + value.getClass().getName());
- ManagedObject mo = initManagedObject((Serializable) value);
+ // Look for a ManagementObjectID
+ ManagementObjectID id = (ManagementObjectID) property.getAnnotations().get(ManagementObjectID.class.getName());
+ String moName = (id != null ? id.name() : value.getClass().getName());
+ String moNameType = (id != null ? id.type() : "");
+ ManagedObject mo = initManagedObject((Serializable) value, moName, moNameType);
return new GenericValueSupport(MANAGED_OBJECT_META_TYPE, mo);
}
else if (propertyType.isArray())
@@ -464,7 +535,7 @@
ArrayList<ManagedObject> tmp = new ArrayList<ManagedObject>();
for(Object element : cvalue)
{
- ManagedObject mo = initManagedObject((Serializable) element);
+ ManagedObject mo = initManagedObject((Serializable) element, null, null);
tmp.add(mo);
}
ManagedObject[] mos = new ManagedObject[tmp.size()];
@@ -477,6 +548,12 @@
return metaValueFactory.create(value, propertyInfo.getType());
}
+ /**
+ *
+ * @param methodInfo
+ * @param opAnnotation
+ * @return
+ */
protected ManagedOperation getManagedOperation(MethodInfo methodInfo,
ManagementOperation opAnnotation)
{
Modified: projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/factory/AbstractManagedObjectFactoryTest.java
===================================================================
--- projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/factory/AbstractManagedObjectFactoryTest.java 2007-08-10 06:20:25 UTC (rev 64531)
+++ projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/factory/AbstractManagedObjectFactoryTest.java 2007-08-10 07:37:16 UTC (rev 64532)
@@ -89,7 +89,7 @@
*/
protected ManagedObject initManagedObject(Serializable object)
{
- ManagedObject result = managedObjectFactory.initManagedObject(object);
+ ManagedObject result = managedObjectFactory.initManagedObject(object, null, null);
getLog().debug("Inited managed: " + result + " for object=" + Strings.defaultToString(object));
return result;
}
More information about the jboss-cvs-commits
mailing list