[jboss-cvs] JBossAS SVN: r64435 - in projects/microcontainer/trunk: deployers-impl/src/tests/org/jboss/test/deployers/managed/test and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Aug 2 17:42:19 EDT 2007
Author: scott.stark at jboss.org
Date: 2007-08-02 17:42:19 -0400 (Thu, 02 Aug 2007)
New Revision: 64435
Added:
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/AllowedDsTypes.java
projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementOperation.java
projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedOperationImpl.java
projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/ManagedPropertyConstraintsPopulator.java
projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/ManagedPropertyConstraintsPopulatorFactory.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/DSMetaData.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/ManagedObject.java
projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedOperation.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/plugins/ManagedObjectImpl.java
projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
Log:
Update for ManagedOperation support, property contraints and arrays of ManagedObjects.
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/AllowedDsTypes.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/AllowedDsTypes.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/AllowedDsTypes.java 2007-08-02 21:42:19 UTC (rev 64435)
@@ -0,0 +1,62 @@
+/*
+ * 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.util.HashSet;
+
+import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.managed.api.Fields;
+import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulator;
+import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulatorFactory;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+
+/**
+ * Contraints populator for the ConnMetaData datasource-type
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class AllowedDsTypes
+ implements ManagedPropertyConstraintsPopulatorFactory,
+ ManagedPropertyConstraintsPopulator
+{
+ public static HashSet<MetaValue> values = new HashSet<MetaValue>();
+ static
+ {
+ values.add(SimpleValueSupport.wrap("local-tx-datasource"));
+ values.add(SimpleValueSupport.wrap("no-tx-datasource"));
+ values.add(SimpleValueSupport.wrap("xa-datasource"));
+ values.add(SimpleValueSupport.wrap("no-tx-connection-factory"));
+ values.add(SimpleValueSupport.wrap("tx-connection-factory"));
+ }
+
+ public void populateManagedProperty(Class attachmentClass, PropertyInfo info, Fields fields)
+ {
+ fields.setField(Fields.LEGAL_VALUES, values);
+ }
+
+ public ManagedPropertyConstraintsPopulator newInstance()
+ {
+ return this;
+ }
+
+}
Property changes on: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/AllowedDsTypes.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
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-02 19:27:56 UTC (rev 64434)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/ConnMetaData.java 2007-08-02 21:42:19 UTC (rev 64435)
@@ -25,7 +25,9 @@
import java.util.Properties;
import org.jboss.managed.api.annotation.ManagementComponent;
+import org.jboss.managed.api.annotation.ManagementObject;
import org.jboss.managed.api.annotation.ManagementProperty;
+import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulatorFactory;
/**
* Test connection factory like metadata.
@@ -33,17 +35,29 @@
* @author Scott.Stark at jboss.org
* @version $Revision$
*/
+ at ManagementObject
public class ConnMetaData implements Serializable
{
private static final long serialVersionUID = 1;
private int minSize;
private int maxSize;
+ private String connType;
private String jndiName;
private String username;
private char[] password;
private Properties connProperties;
private SecMetaData securityMetaData;
+ @ManagementProperty(name="datasource-type", constraintsFactory=AllowedDsTypes.class)
+ public String getConnType()
+ {
+ return connType;
+ }
+ public void setConnType(String connType)
+ {
+ this.connType = connType;
+ }
+
@ManagementProperty(name="jndi-name")
public String getJndiName()
{
@@ -99,7 +113,7 @@
this.connProperties = connProperties;
}
- @ManagementComponent(name="security-domain")
+ @ManagementProperty(name="security-domain", managed=true)
public SecMetaData getSecurityMetaData()
{
return securityMetaData;
Modified: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/DSMetaData.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/DSMetaData.java 2007-08-02 19:27:56 UTC (rev 64434)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/DSMetaData.java 2007-08-02 21:42:19 UTC (rev 64435)
@@ -28,6 +28,7 @@
import org.jboss.managed.api.annotation.ManagementComponent;
import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementProperties;
import org.jboss.managed.api.annotation.ManagementProperty;
/**
@@ -36,14 +37,20 @@
* @author Scott.Stark at jboss.org
* @version $Revision$
*/
- at ManagementObject
+ at ManagementObject(properties=ManagementProperties.EXPLICIT)
public class DSMetaData implements Serializable
{
private static final long serialVersionUID = 1;
private String diplayName;
+ private List<String> aliases = new ArrayList<String>();
private List<ConnMetaData> deployments = new ArrayList<ConnMetaData>();
- @ManagementProperty(name="display-name", use={})
+ public DSMetaData()
+ {
+ deployments.add(new ConnMetaData());
+ }
+
+ @ManagementProperty(name="display-name", description="display name of DS deployment", use={})
public String getDiplayName()
{
return diplayName;
@@ -54,15 +61,24 @@
this.diplayName = diplayName;
}
+ public List<String> getAliases()
+ {
+ return aliases;
+ }
+ public void setAliases(List<String> aliases)
+ {
+ this.aliases = aliases;
+ }
+
public void addManagedConnectionFactoryDeployment(ConnMetaData deployment)
{
this.deployments.add(deployment);
}
- @ManagementComponent
+ @ManagementProperty(description="The DS connection factories", managed=true)
public List<ConnMetaData> getDeployments()
{
- return Collections.unmodifiableList(deployments);
+ return deployments;
}
}
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-02 19:27:56 UTC (rev 64434)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/test/DeployerManagedObjectUnitTestCase.java 2007-08-02 21:42:19 UTC (rev 64435)
@@ -21,7 +21,10 @@
*/
package org.jboss.test.deployers.managed.test;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -30,7 +33,18 @@
import org.jboss.deployers.client.spi.Deployment;
import org.jboss.deployers.spi.attachments.MutableAttachments;
import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.managed.plugins.factory.AbstractManagedObjectFactory;
+import org.jboss.metatype.api.types.ArrayMetaType;
+import org.jboss.metatype.api.types.GenericMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.ArrayValue;
+import org.jboss.metatype.api.values.MetaValue;
import org.jboss.test.deployers.AbstractDeployerTest;
+import org.jboss.test.deployers.deployer.support.AllowedDsTypes;
+import org.jboss.test.deployers.deployer.support.DSMetaData;
import org.jboss.test.deployers.managed.support.TestAttachment;
import org.jboss.test.deployers.managed.support.TestManagedObjectDeployer;
import org.jboss.util.graph.Graph;
@@ -117,7 +131,60 @@
assertEquals("changedString1", mo.getProperty("string1").getValue());
assertEquals("initialString2", mo.getProperty("string2").getValue());
}
-
+
+ /**
+ * Validate the ManagedObject for DSMetaData
+ *
+ */
+ public void testDSMetaDataManagedObjectFactory()
+ {
+ ManagedObjectFactory mof = ManagedObjectFactory.getInstance();
+ ManagedObject mo = mof.createManagedObject(DSMetaData.class);
+
+ // Validate the expected properties
+ Set<ManagedProperty> props = mo.getProperties();
+ assertEquals(2, props.size());
+ HashMap<String, ManagedProperty> propsMap = new HashMap<String, ManagedProperty>();
+ for(ManagedProperty prop : props)
+ {
+ propsMap.put(prop.getName(), prop);
+ }
+ log.info("DSMetaData properties: "+props);
+
+ // display-name
+ ManagedProperty displayName = propsMap.get("display-name");
+ assertNotNull(displayName);
+ assertEquals("display name of DS deployment", displayName.getDescription());
+ assertEquals(SimpleMetaType.STRING, displayName.getMetaType());
+
+ // deployments
+ ManagedProperty deployments = propsMap.get("deployments");
+ assertNotNull(deployments);
+ assertEquals("The DS connection factories", deployments.getDescription());
+ MetaType deploymentsType = new ArrayMetaType(1, AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE);
+ assertEquals(deploymentsType, deployments.getMetaType());
+ ArrayValue value = ArrayValue.class.cast(deployments.getValue());
+ ArrayMetaType valueType = value.getMetaType();
+ assertEquals(AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE, valueType.getElementType());
+
+ Object[] values = value.getValue();
+ assertEquals(1, values.length);
+ // Validate the ConnMetaData ManagedObject
+ ManagedObject connMO = ManagedObject.class.cast(values[0]);
+ props = connMO.getProperties();
+ assertEquals(8, props.size());
+ propsMap.clear();
+ for(ManagedProperty prop : props)
+ {
+ propsMap.put(prop.getName(), prop);
+ }
+ log.info("ConnMetaData properties: "+props);
+ ManagedProperty dsType = propsMap.get("datasource-type");
+ assertNotNull(dsType);
+ Set<MetaValue> dsTypeValues = dsType.getLegalValues();
+ assertTrue(dsTypeValues.containsAll(AllowedDsTypes.values));
+ }
+
protected DeployerClient getMainDeployer()
{
return createMainDeployer(deployer);
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-02 19:27:56 UTC (rev 64434)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedObject.java 2007-08-02 21:42:19 UTC (rev 64435)
@@ -24,6 +24,8 @@
import java.io.Serializable;
import java.util.Set;
+import org.jboss.metatype.api.types.Name;
+
/**
* ManagedObject.
*
@@ -38,8 +40,15 @@
* @return the name
*/
String getName();
-
+
/**
+ * Get the external name by which the ManagedObject
+ * @see {@linkplain ManagedObjectRegistry}}
+ * @return
+ */
+ Name getExternalName();
+
+ /**
* Get the underlying object
*
* @return the underlying object
@@ -67,4 +76,11 @@
* @return the properties
*/
Set<ManagedProperty> getProperties();
+
+ /**
+ * Get the operations
+ *
+ * @return the operations
+ */
+ Set<ManagedOperation> getOperations();
}
Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedOperation.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedOperation.java 2007-08-02 19:27:56 UTC (rev 64434)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedOperation.java 2007-08-02 21:42:19 UTC (rev 64435)
@@ -76,10 +76,10 @@
* signature array is returned if the operation takes no arguments.
* @return parameter information for the operation arguments.
*/
- public ManagedParameter[] getSignature();
+ public ManagedParameter[] getParameters();
/**
- * Invoker the operation given its parameter values.
+ * Invoke the operation given its parameter values.
*
* @param param the varags for the operation parameters.
* @return the MetaValue for the result.
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-02 19:27:56 UTC (rev 64434)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObject.java 2007-08-02 21:42:19 UTC (rev 64435)
@@ -36,9 +36,12 @@
@Retention(RetentionPolicy.RUNTIME)
public @interface ManagementObject
{
- /** The object name */
+ /** The name */
String name() default ManagementConstants.GENERATED;
/** What properties to include */
ManagementProperties properties() default ManagementProperties.ALL;
+
+ /** The exposed operations */
+ ManagementOperation[] operations() default {};
}
Added: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementOperation.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementOperation.java (rev 0)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementOperation.java 2007-08-02 21:42:19 UTC (rev 64435)
@@ -0,0 +1,52 @@
+/*
+ * 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;
+
+import org.jboss.managed.api.ManagedOperation.Impact;
+
+/**
+ * An annotation for describing a ManagedOperation
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+ at Target({ElementType.METHOD})
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface ManagementOperation
+{
+ /** The runtime target for the operation. TODO: how is this resolved? */
+ String target() ;
+ /** The name of the operation */
+ String name();
+ /** The detyped signature (ala jmx) of the operation */
+ String[] signature() default {};
+
+ /** The description */
+ String description() default ManagementConstants.GENERATED;
+ /** The side-effect impact of invoking the operation */
+ Impact impact() default Impact.Unknown;
+}
Property changes on: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementOperation.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
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-02 19:27:56 UTC (rev 64434)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementProperty.java 2007-08-02 21:42:19 UTC (rev 64435)
@@ -26,11 +26,12 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulator;
+import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulatorFactory;
+
/**
* ManagementProperty annotation for describing a ManagedProperty
*
- * TODO: Need more info on meta-type such as constraints, allowed values.
- *
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @author Scott.Stark at jboss.org
* @version $Revision$
@@ -62,4 +63,22 @@
/** The views this property should be used in */
ViewUse[] use() default {ViewUse.RUNTIME};
+ /** The constraints, allowed values populator factory */
+ Class<? extends ManagedPropertyConstraintsPopulatorFactory> constraintsFactory()
+ default DEFAULT.class;
+
+ /**
+ * Used in {@link ManagementProperty#constraintsFactory()} to
+ * signal that the factory be inferred from the type
+ * of the property.
+ */
+ static final class DEFAULT
+ implements ManagedPropertyConstraintsPopulatorFactory
+ {
+ public ManagedPropertyConstraintsPopulator newInstance()
+ {
+ return null;
+ }
+ }
+
}
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-02 19:27:56 UTC (rev 64434)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedObjectImpl.java 2007-08-02 21:42:19 UTC (rev 64435)
@@ -26,7 +26,9 @@
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.
@@ -41,13 +43,17 @@
/** The attachment name */
private String name;
-
+ /** */
+ private Name externalName;
+
/** The attachment */
private Serializable attachment;
/** The properties */
private Set<ManagedProperty> properties;
-
+ /** The operations */
+ private Set<ManagedOperation> operations;
+
/**
* Create a new ManagedObjectImpl
*
@@ -55,11 +61,7 @@
*/
public ManagedObjectImpl(String name)
{
- if (name == null)
- throw new IllegalArgumentException("Null name");
-
- this.name = name;
- properties = new HashSet<ManagedProperty>();
+ this(name, new HashSet<ManagedProperty>(), new HashSet<ManagedOperation>(), null);
}
/**
@@ -70,6 +72,33 @@
*/
public ManagedObjectImpl(String name, Set<ManagedProperty> properties)
{
+ this(name, properties, new HashSet<ManagedOperation>(), null);
+ }
+
+ /**
+ * Create a new ManagedObjectImpl
+ *
+ * @param name the attachment name
+ * @param properties the properties
+ * @param operations the operations
+ */
+ public ManagedObjectImpl(String name, Set<ManagedProperty> properties,
+ HashSet<ManagedOperation> operations)
+ {
+ this(name, properties, operations, null);
+ }
+
+ /**
+ * Create a new ManagedObjectImpl
+ *
+ * @param name the attachment name
+ * @param properties the properties
+ * @param operations the operations
+ * @param attachment the attachment
+ */
+ public ManagedObjectImpl(String name, Set<ManagedProperty> properties,
+ HashSet<ManagedOperation> operations, Serializable attachment)
+ {
if (name == null)
throw new IllegalArgumentException("Null name");
if (properties == null)
@@ -77,16 +106,20 @@
this.name = name;
this.properties = properties;
+ this.operations = operations;
+ setAttachment(attachment);
}
-
+
/**
* Create a new ManagedObjectImpl
*
* @param name the attachment name
+ * @param externalName - the ManagedObjectRegistry name
* @param properties the properties
* @param attachment the attachment
*/
- public ManagedObjectImpl(String name, Set<ManagedProperty> properties, Serializable attachment)
+ public ManagedObjectImpl(String name, Name externalName,
+ Set<ManagedProperty> properties, Serializable attachment)
{
if (name == null)
throw new IllegalArgumentException("Null name");
@@ -94,15 +127,25 @@
throw new IllegalArgumentException("Null properties");
this.name = name;
+ this.externalName = externalName;
this.properties = properties;
setAttachment(attachment);
}
-
+
public String getName()
{
return name;
}
+ public Name getExternalName()
+ {
+ return externalName;
+ }
+ public void setExternalName(Name externalName)
+ {
+ this.externalName = externalName;
+ }
+
public Set<String> getPropertyNames()
{
Set<String> result = new HashSet<String>(properties.size());
@@ -144,6 +187,11 @@
this.attachment = attachment;
}
+ public Set<ManagedOperation> getOperations()
+ {
+ return operations;
+ }
+
@Override
public boolean equals(Object obj)
{
Added: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedOperationImpl.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedOperationImpl.java (rev 0)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedOperationImpl.java 2007-08-02 21:42:19 UTC (rev 64435)
@@ -0,0 +1,120 @@
+/*
+ * 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.plugins;
+
+import org.jboss.managed.api.ManagedOperation;
+import org.jboss.managed.api.ManagedParameter;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.MetaValue;
+
+/**
+ * A default implementation of ManagedOperation
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class ManagedOperationImpl implements ManagedOperation
+{
+ private static final long serialVersionUID = 1;
+ private String description;
+ private Impact impact;
+ private String name;
+ private ManagedParameter[] parameters;
+ private MetaType returnType;
+
+
+ public ManagedOperationImpl(String name, String description)
+ {
+ this(description, name, Impact.Unknown, new ManagedParameter[0], SimpleMetaType.VOID);
+ }
+ public ManagedOperationImpl(String name, String description, Impact impact,
+ ManagedParameter[] parameters, MetaType returnType)
+ {
+ super();
+ this.description = description;
+ this.impact = impact;
+ this.name = name;
+ this.parameters = parameters;
+ this.returnType = returnType;
+ }
+
+ public String getDescription()
+ {
+ return description;
+ }
+
+ public void setDescription(String description)
+ {
+ this.description = description;
+ }
+
+ public Impact getImpact()
+ {
+ return impact;
+ }
+
+ public void setImpact(Impact impact)
+ {
+ this.impact = impact;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public ManagedParameter[] getParameters()
+ {
+ return parameters;
+ }
+
+ public void setParameters(ManagedParameter[] parameters)
+ {
+ this.parameters = parameters;
+ }
+
+ public MetaType getReturnType()
+ {
+ return returnType;
+ }
+
+ public void setReturnType(MetaType returnType)
+ {
+ this.returnType = returnType;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.managed.api.ManagedOperation#invoke(MetaValue[])
+ */
+ public Object invoke(MetaValue... param)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Property changes on: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedOperationImpl.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
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-02 19:27:56 UTC (rev 64434)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java 2007-08-02 21:42:19 UTC (rev 64435)
@@ -25,6 +25,9 @@
import java.lang.ref.WeakReference;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@@ -35,24 +38,36 @@
import org.jboss.config.spi.Configuration;
import org.jboss.managed.api.Fields;
import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedOperation;
+import org.jboss.managed.api.ManagedParameter;
import org.jboss.managed.api.ManagedProperty;
+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.ManagementOperation;
import org.jboss.managed.api.annotation.ManagementProperties;
import org.jboss.managed.api.annotation.ManagementProperty;
import org.jboss.managed.api.factory.ManagedObjectFactory;
import org.jboss.managed.plugins.DefaultFieldsImpl;
import org.jboss.managed.plugins.ManagedObjectImpl;
+import org.jboss.managed.plugins.ManagedOperationImpl;
import org.jboss.managed.plugins.ManagedPropertyImpl;
import org.jboss.managed.spi.factory.ManagedObjectBuilder;
import org.jboss.managed.spi.factory.ManagedObjectPopulator;
+import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulator;
+import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulatorFactory;
+import org.jboss.metatype.api.types.ArrayMetaType;
import org.jboss.metatype.api.types.GenericMetaType;
import org.jboss.metatype.api.types.MetaType;
import org.jboss.metatype.api.types.MetaTypeFactory;
+import org.jboss.metatype.api.values.ArrayValueSupport;
import org.jboss.metatype.api.values.GenericValueSupport;
import org.jboss.metatype.api.values.MetaValue;
import org.jboss.metatype.api.values.MetaValueFactory;
import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.reflect.spi.MethodInfo;
+import org.jboss.reflect.spi.ParameterInfo;
+import org.jboss.reflect.spi.TypeInfo;
/**
* AbstractManagedObjectFactory.
@@ -149,9 +164,13 @@
BeanInfo beanInfo = configuration.getBeanInfo(clazz);
ClassInfo classInfo = beanInfo.getClassInfo();
- // TODO: should this be skipped if there is no ManagementObject annotation?
ManagementObject managementObject = classInfo.getUnderlyingAnnotation(ManagementObject.class);
-
+ if( managementObject == null )
+ {
+ // Skip the ManagedObject creation
+ return null;
+ }
+
String name = ManagementConstants.GENERATED;
if (managementObject != null)
name = managementObject.name();
@@ -172,13 +191,14 @@
// Ignore the "class" property
if ("class".equals(propertyInfo.getName()))
continue;
-
+
ManagementProperty managementProperty = propertyInfo.getUnderlyingAnnotation(ManagementProperty.class);
+ // Check for a simple property
boolean includeProperty = (propertyType == ManagementProperties.ALL);
if (managementProperty != null)
includeProperty = (managementProperty.ignored() == false);
-
+
if (includeProperty)
{
Fields fields = new DefaultFieldsImpl();
@@ -220,7 +240,11 @@
MetaType metaType;
if (managed)
{
- metaType = MANAGED_OBJECT_META_TYPE;
+ TypeInfo typeInfo = propertyInfo.getType();
+ if( typeInfo.isArray() || typeInfo.isCollection() )
+ metaType = new ArrayMetaType(1, MANAGED_OBJECT_META_TYPE);
+ else
+ metaType = MANAGED_OBJECT_META_TYPE;
}
else
{
@@ -228,7 +252,19 @@
}
fields.setField(Fields.META_TYPE, metaType);
- // TODO others (legal values, min/max etc.)
+ // Delegate others (legal values, min/max etc.) to the constraints factory
+ try
+ {
+ Class<? extends ManagedPropertyConstraintsPopulatorFactory> factoryClass = managementProperty.constraintsFactory();
+ ManagedPropertyConstraintsPopulatorFactory factory = factoryClass.newInstance();
+ ManagedPropertyConstraintsPopulator populator = factory.newInstance();
+ if (populator != null)
+ populator.populateManagedProperty(clazz, propertyInfo, fields);
+ }
+ catch(Exception e)
+ {
+
+ }
ManagedPropertyImpl property = new ManagedPropertyImpl(fields);
properties.add(property);
@@ -236,13 +272,31 @@
}
}
+ /* TODO: Operations. In general the bean metadata does not contain
+ operation information.
+ */
+ Set<ManagedOperation> operations = new HashSet<ManagedOperation>();
+
+ Set<MethodInfo> methodInfos = beanInfo.getMethods();
+ if (methodInfos != null && methodInfos.isEmpty() == false)
+ {
+ for (MethodInfo methodInfo : methodInfos)
+ {
+ ManagementOperation managementOp = methodInfo.getUnderlyingAnnotation(ManagementOperation.class);
+ if (managementOp == null)
+ continue;
+
+ ManagedOperation op = getManagedOperation(methodInfo, managementOp);
+ operations.add(op);
+ }
+ }
+
ManagedObjectImpl result = new ManagedObjectImpl(name, properties);
for (ManagedProperty property : properties)
{
ManagedPropertyImpl managedPropertyImpl = (ManagedPropertyImpl) property;
managedPropertyImpl.setManagedObject(result);
}
-
return result;
}
@@ -319,7 +373,10 @@
*/
protected MetaValue getValue(BeanInfo beanInfo, ManagedProperty property, Serializable object)
{
- String name = property.getName();
+ // First look to the mapped name
+ String name = property.getMappedName();
+ if (name == null)
+ property.getName();
PropertyInfo propertyInfo = beanInfo.getProperty(name);
if (propertyInfo == null)
@@ -346,17 +403,63 @@
if (value == null)
return null;
- if (MANAGED_OBJECT_META_TYPE == property.getMetaType())
+ MetaType propertyType = property.getMetaType();
+ if (MANAGED_OBJECT_META_TYPE == propertyType)
{
if (value instanceof Serializable == false)
throw new IllegalStateException("Object is not serializable: " + value.getClass().getName());
ManagedObject mo = initManagedObject((Serializable) value);
return new GenericValueSupport(MANAGED_OBJECT_META_TYPE, mo);
}
+ else if (propertyType.isArray())
+ {
+ ArrayMetaType arrayType = ArrayMetaType.class.cast(propertyType);
+ if (MANAGED_OBJECT_META_TYPE == arrayType.getElementType())
+ {
+ Collection cvalue = getAsCollection(value);
+ ArrayMetaType moType = new ArrayMetaType(1, MANAGED_OBJECT_META_TYPE);
+ ArrayValueSupport moArrayValue = new ArrayValueSupport(moType);
+ ArrayList<ManagedObject> tmp = new ArrayList<ManagedObject>();
+ for(Object element : cvalue)
+ {
+ ManagedObject mo = initManagedObject((Serializable) element);
+ tmp.add(mo);
+ }
+ ManagedObject[] mos = new ManagedObject[tmp.size()];
+ tmp.toArray(mos);
+ moArrayValue.setValue(mos);
+ return moArrayValue;
+ }
+ }
return metaValueFactory.create(value, propertyInfo.getType());
}
-
+
+ protected ManagedOperation getManagedOperation(MethodInfo methodInfo,
+ ManagementOperation opAnnotation)
+ {
+ String name = methodInfo.getName();
+ String description = opAnnotation.description();
+ Impact impact = opAnnotation.impact();
+ ParameterInfo[] params = methodInfo.getParameters();
+ TypeInfo returnInfo = methodInfo.getReturnType();
+ MetaType returnType = metaTypeFactory.resolve(returnInfo);
+ ArrayList<ManagedParameter> mparams = new ArrayList<ManagedParameter>();
+ if( params != null )
+ {
+ for(ParameterInfo param : params)
+ {
+
+ }
+ }
+ ManagedParameter[] parameters = new ManagedParameter[mparams.size()];
+ mparams.toArray(parameters);
+
+ ManagedOperationImpl op = new ManagedOperationImpl(name, description, impact,
+ parameters, returnType);
+ return op;
+ }
+
/**
* Get the builder for a class
*
@@ -388,4 +491,13 @@
return (ManagedObjectPopulator) builder;
return this;
}
+
+ protected Collection getAsCollection(Object value)
+ {
+ if( value.getClass().isArray() )
+ return Arrays.asList(value);
+ else if (value instanceof Collection)
+ return Collection.class.cast(value);
+ return null;
+ }
}
Added: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/ManagedPropertyConstraintsPopulator.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/ManagedPropertyConstraintsPopulator.java (rev 0)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/ManagedPropertyConstraintsPopulator.java 2007-08-02 21:42:19 UTC (rev 64435)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, 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.spi.factory;
+
+import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.managed.api.Fields;
+
+/**
+ * Plugin for the ManagedProperty fields constraint related info.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public interface ManagedPropertyConstraintsPopulator
+{
+ /** Populate the ManagedProperty fields constraint related info.
+ * @param attachmentClass - the attachment class the property is
+ * associated with
+ * @param info - the PropertyInfo for the attachment class property
+ * @param fields - the fields to add the constraints to
+ */
+ public void populateManagedProperty(Class attachmentClass, PropertyInfo info, Fields fields);
+}
Property changes on: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/ManagedPropertyConstraintsPopulator.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Added: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/ManagedPropertyConstraintsPopulatorFactory.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/ManagedPropertyConstraintsPopulatorFactory.java (rev 0)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/ManagedPropertyConstraintsPopulatorFactory.java 2007-08-02 21:42:19 UTC (rev 64435)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, 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.spi.factory;
+
+/**
+ * Stateless factory for obtaining
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public interface ManagedPropertyConstraintsPopulatorFactory
+{
+ ManagedPropertyConstraintsPopulator newInstance();
+}
Property changes on: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/ManagedPropertyConstraintsPopulatorFactory.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
More information about the jboss-cvs-commits
mailing list