[jboss-cvs] JBossAS SVN: r64445 - in projects/microcontainer/trunk: deployers-impl/src/tests/org/jboss/test/deployers/managed/test and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Aug 3 02:37:48 EDT 2007
Author: scott.stark at jboss.org
Date: 2007-08-03 02:37:48 -0400 (Fri, 03 Aug 2007)
New Revision: 64445
Added:
projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/WritethroughManagedPropertyImpl.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/XADataSourceMetaData.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/annotation/ManagementProperty.java
projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
Log:
Add Fields and ManagedProperty factory values to the ManagementProperty annotation and a WritethroughManagedPropertyImpl that writes values back to the attachment bean using the PropertyInfo.
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-03 04:14:14 UTC (rev 64444)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/ConnMetaData.java 2007-08-03 06:37:48 UTC (rev 64445)
@@ -24,10 +24,9 @@
import java.io.Serializable;
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;
+import org.jboss.managed.plugins.WritethroughManagedPropertyImpl;
/**
* Test connection factory like metadata.
@@ -48,7 +47,8 @@
private Properties connProperties;
private SecMetaData securityMetaData;
- @ManagementProperty(name="datasource-type", constraintsFactory=AllowedDsTypes.class)
+ @ManagementProperty(name="datasource-type", constraintsFactory=AllowedDsTypes.class,
+ propertyFactory=WritethroughManagedPropertyImpl.class)
public String getConnType()
{
return connType;
@@ -58,7 +58,7 @@
this.connType = connType;
}
- @ManagementProperty(name="jndi-name")
+ @ManagementProperty(name="jndi-name", propertyFactory=WritethroughManagedPropertyImpl.class)
public String getJndiName()
{
return jndiName;
@@ -67,7 +67,7 @@
{
this.jndiName = jndiName;
}
- @ManagementProperty(name="max-size")
+ @ManagementProperty(name="max-size", propertyFactory=WritethroughManagedPropertyImpl.class)
public int getMaxSize()
{
return maxSize;
@@ -76,7 +76,7 @@
{
this.maxSize = maxSize;
}
- @ManagementProperty(name="min-size")
+ @ManagementProperty(name="min-size", propertyFactory=WritethroughManagedPropertyImpl.class)
public int getMinSize()
{
return minSize;
@@ -85,7 +85,7 @@
{
this.minSize = minSize;
}
- @ManagementProperty
+ @ManagementProperty(propertyFactory=WritethroughManagedPropertyImpl.class)
public char[] getPassword()
{
return password;
@@ -94,7 +94,7 @@
{
this.password = password;
}
- @ManagementProperty
+ @ManagementProperty(propertyFactory=WritethroughManagedPropertyImpl.class)
public String getUsername()
{
return username;
@@ -103,7 +103,7 @@
{
this.username = username;
}
- @ManagementProperty(name="connection-properties")
+ @ManagementProperty(name="connection-properties", propertyFactory=WritethroughManagedPropertyImpl.class)
public Properties getConnProperties()
{
return connProperties;
Modified: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/XADataSourceMetaData.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/XADataSourceMetaData.java 2007-08-03 04:14:14 UTC (rev 64444)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/XADataSourceMetaData.java 2007-08-03 06:37:48 UTC (rev 64445)
@@ -21,6 +21,9 @@
*/
package org.jboss.test.deployers.deployer.support;
+import org.jboss.managed.api.annotation.ManagementProperty;
+import org.jboss.managed.plugins.WritethroughManagedPropertyImpl;
+
/**
*
* @author Scott.Stark at jboss.org
@@ -37,6 +40,7 @@
{
}
+ @ManagementProperty(propertyFactory=WritethroughManagedPropertyImpl.class)
public String getXaDataSourceClass()
{
return xaDataSourceClass;
@@ -47,6 +51,7 @@
this.xaDataSourceClass = xaDataSourceClass;
}
+ @ManagementProperty(propertyFactory=WritethroughManagedPropertyImpl.class)
public int getXaResourceTimeout()
{
return xaResourceTimeout;
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-03 04:14:14 UTC (rev 64444)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/managed/test/DeployerManagedObjectUnitTestCase.java 2007-08-03 06:37:48 UTC (rev 64445)
@@ -23,7 +23,6 @@
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@@ -38,7 +37,6 @@
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;
@@ -278,6 +276,36 @@
assertNotNull(secDomain);
MetaType secDomainType = secDomain.getMetaType();
assertEquals(AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE, secDomainType);
+
+ ManagedProperty jndiName = propsMap.get("jndi-name");
+ assertNotNull(jndiName);
+ ManagedProperty password = propsMap.get("password");
+ assertNotNull(password);
+ ManagedProperty connProperties = propsMap.get("connection-properties");
+ assertNotNull(connProperties);
+ ManagedProperty username = propsMap.get("username");
+ assertNotNull(username);
+ ManagedProperty maxSize = propsMap.get("max-size");
+ assertNotNull(maxSize);
+ ManagedProperty minSize = propsMap.get("min-size");
+ assertNotNull(minSize);
+
+ // Validate setting the properties
+ displayName.setValue("testDSMetaDataManagedObjectFactoryInit");
+ jndiName.setValue("java:TestDS");
+ password.setValue("password".toCharArray());
+ username.setValue("username");
+ minSize.setValue(new Integer(10));
+ maxSize.setValue(new Integer(100));
+
+ Object attachment = xaConnMO.getAttachment();
+ assertTrue("attachment is a XADataSourceMetaData("+attachment+")", attachment instanceof XADataSourceMetaData);
+ XADataSourceMetaData xaDS = XADataSourceMetaData.class.cast(attachment);
+ assertEquals("jndiName", "java:TestDS", xaDS.getJndiName());
+ assertEquals("password", "password", new String(xaDS.getPassword()));
+ assertEquals("username", "username", xaDS.getUsername());
+ assertEquals("minSize", 10, xaDS.getMinSize());
+ assertEquals("maxSize", 100, xaDS.getMaxSize());
}
protected DeployerClient getMainDeployer()
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-03 04:14:14 UTC (rev 64444)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementProperty.java 2007-08-03 06:37:48 UTC (rev 64445)
@@ -26,6 +26,8 @@
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.spi.factory.ManagedPropertyConstraintsPopulator;
import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulatorFactory;
@@ -63,16 +65,20 @@
/** The views this property should be used in */
ViewUse[] use() default {ViewUse.RUNTIME};
+ /** */
+ 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 DEFAULT.class;
+ default NULL_CONSTRAINTS.class;
/**
* Used in {@link ManagementProperty#constraintsFactory()} to
* signal that the factory be inferred from the type
* of the property.
*/
- static final class DEFAULT
+ public static final class NULL_CONSTRAINTS
implements ManagedPropertyConstraintsPopulatorFactory
{
public ManagedPropertyConstraintsPopulator newInstance()
@@ -80,5 +86,21 @@
return null;
}
}
+ /**
+ * Used in {@link ManagementProperty#fieldsFactory()} to
+ * indicate that no Fields factory is defined.
+ */
+ public static abstract class NULL_FIELDS_FACTORY
+ implements Fields
+ {
+ }
+ /**
+ * Used in {@link ManagementProperty#fieldsFactory()} to
+ * indicate that no Fields factory is defined.
+ */
+ public static abstract class NULL_PROPERTY_FACTORY
+ implements ManagedProperty
+ {
+ }
}
Added: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/WritethroughManagedPropertyImpl.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/WritethroughManagedPropertyImpl.java (rev 0)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/WritethroughManagedPropertyImpl.java 2007-08-03 06:37:48 UTC (rev 64445)
@@ -0,0 +1,85 @@
+/*
+ * 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 java.io.Serializable;
+import java.lang.reflect.UndeclaredThrowableException;
+
+import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.managed.api.Fields;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.metatype.api.values.MetaValue;
+
+/**
+ * An extension of
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class WritethroughManagedPropertyImpl extends ManagedPropertyImpl
+{
+ private static final long serialVersionUID = 1;
+
+ public WritethroughManagedPropertyImpl(String name)
+ {
+ super(name);
+ }
+ public WritethroughManagedPropertyImpl(Fields fields)
+ {
+ super(fields);
+ }
+ public WritethroughManagedPropertyImpl(ManagedObject managedObject, Fields fields)
+ {
+ super(managedObject, fields);
+ }
+
+ /**
+ * Write the value back to the attachment if there is a PropertyInfo
+ * in the Fields.PROPERTY_INFO field.
+ * TODO: this ignored MetaValues as the tests pass in the corresponding
+ * primative
+ */
+ @Override
+ public void setField(String name, Serializable value)
+ {
+ super.setField(name, value);
+ // Skip MetaValues
+ if( (value instanceof MetaValue) )
+ return;
+
+ // Write the value back to the attachment if there is a PropertyInfo
+ PropertyInfo info = super.getField(Fields.PROPERTY_INFO, PropertyInfo.class);
+ if (info != null)
+ {
+ Object bean = getManagedObject().getAttachment();
+ try
+ {
+ info.set(bean, value);
+ }
+ catch(Throwable t)
+ {
+ throw new UndeclaredThrowableException(t);
+ }
+ }
+ }
+
+
+}
Property changes on: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/WritethroughManagedPropertyImpl.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-03 04:14:14 UTC (rev 64444)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java 2007-08-03 06:37:48 UTC (rev 64445)
@@ -23,6 +23,7 @@
import java.io.Serializable;
import java.lang.ref.WeakReference;
+import java.lang.reflect.Constructor;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
@@ -36,6 +37,7 @@
import org.jboss.beans.info.spi.PropertyInfo;
import org.jboss.config.plugins.property.PropertyConfiguration;
import org.jboss.config.spi.Configuration;
+import org.jboss.logging.Logger;
import org.jboss.managed.api.Fields;
import org.jboss.managed.api.ManagedObject;
import org.jboss.managed.api.ManagedOperation;
@@ -79,6 +81,8 @@
public class AbstractManagedObjectFactory extends ManagedObjectFactory
implements ManagedObjectBuilder, ManagedObjectPopulator<Serializable>
{
+ private static final Logger log = Logger.getLogger(AbstractManagedObjectFactory.class);
+
/** The configuration */
private static final Configuration configuration;
@@ -201,7 +205,24 @@
if (includeProperty)
{
- Fields fields = new DefaultFieldsImpl();
+ Fields fields = null;
+ if (managementProperty != null)
+ {
+ Class<? extends Fields> factory = managementProperty.fieldsFactory();
+ if (factory != ManagementProperty.NULL_FIELDS_FACTORY.class)
+ {
+ try
+ {
+ fields = factory.newInstance();
+ }
+ catch (Exception e)
+ {
+ log.debug("Failed to created Fields", e);
+ }
+ }
+ }
+ if (fields == null)
+ fields = new DefaultFieldsImpl();
if( propertyInfo instanceof Serializable )
{
@@ -269,13 +290,24 @@
{
}
+
- ManagedPropertyImpl property = new ManagedPropertyImpl(fields);
+ ManagedProperty property = null;
+ if (managementProperty != null)
+ {
+ Class<? extends ManagedProperty> factory = managementProperty.propertyFactory();
+ if (factory != ManagementProperty.NULL_PROPERTY_FACTORY.class)
+ {
+ property = getManagedProperty(factory, fields);
+ }
+ }
+ if (property == null)
+ property = new ManagedPropertyImpl(fields);
properties.add(property);
}
}
}
-
+
/* TODO: Operations. In general the bean metadata does not contain
operation information.
*/
@@ -504,4 +536,27 @@
return Collection.class.cast(value);
return null;
}
+
+ /**
+ * Look for ctor(Fields)
+ * @param factory - the ManagedProperty implementation class
+ * @param fields - the fields to pass to the ctor
+ * @return
+ */
+ protected ManagedProperty getManagedProperty(Class<? extends ManagedProperty> factory, Fields fields)
+ {
+ ManagedProperty property = null;
+ try
+ {
+ Class[] sig = {Fields.class};
+ Constructor<? extends ManagedProperty> ctor = factory.getConstructor(sig);
+ Object[] args = {fields};
+ property = ctor.newInstance(args);
+ }
+ catch(Exception e)
+ {
+ log.debug("Failed to create ManagedProperty", e);
+ }
+ return property;
+ }
}
More information about the jboss-cvs-commits
mailing list