[jboss-cvs] JBossAS SVN: r81467 - in projects/jboss-man/branches/Branch_2_0: managed/src/main/java/org/jboss/managed/api/annotation and 11 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Nov 24 03:41:56 EST 2008
Author: scott.stark at jboss.org
Date: 2008-11-24 03:41:56 -0500 (Mon, 24 Nov 2008)
New Revision: 81467
Added:
projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/annotation/ConstraintsPopulatorFactory.java
projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/annotation/FieldsFactory.java
projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/annotation/ManagementPropertyFactory.java
projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/support/mcf/ConnectionFactoryProperty.java
projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/support/mcf/MCFPropertyMetaDataMapper.java
projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/types/PropertiesMetaType.java
projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/values/PropertiesMetaValue.java
projects/jboss-man/branches/Branch_2_0/metatype/src/test/java/org/jboss/test/metatype/types/support/BeanMetaMapper.java
projects/jboss-man/branches/Branch_2_0/metatype/src/test/java/org/jboss/test/metatype/types/support/MetaMappingUsage.java
Modified:
projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/DeploymentTemplateInfo.java
projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/Fields.java
projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/ManagedObject.java
projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java
projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/annotation/ManagementObject.java
projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/annotation/ManagementProperty.java
projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/BasicDeploymentTemplateInfo.java
projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/DelegateManagedObjectImpl.java
projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/ManagedObjectImpl.java
projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/ManagedPropertyImpl.java
projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractInstanceClassFactory.java
projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/factory/DeploymentTemplateInfoFactory.java
projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/support/mcf/LocalDSInstanceClassFactory.java
projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/support/mcf/ManagedConnectionFactoryDeploymentMetaData.java
projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/support/mcf/NonXADataSourceDeploymentMetaData.java
projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/test/AbstractManagedObjectFactoryUnitTestCase.java
projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/annotations/MetaMapping.java
projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/types/MapCompositeMetaType.java
projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/types/MetaType.java
projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/values/MetaValueFactory.java
projects/jboss-man/branches/Branch_2_0/metatype/src/test/java/org/jboss/test/metatype/types/factory/test/CompositeMetaTypeFactoryUnitTestCase.java
projects/jboss-man/branches/Branch_2_0/metatype/src/test/java/org/jboss/test/metatype/types/test/MetaTypeUnitTestCase.java
projects/jboss-man/branches/Branch_2_0/metatype/src/test/java/org/jboss/test/metatype/values/factory/test/CompositeValueFactoryUnitTestCase.java
Log:
JBMAN-43, JBMAN-45, refactor the server side factory fields in the annotations to transient attachments
Modified: projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/DeploymentTemplateInfo.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/DeploymentTemplateInfo.java 2008-11-24 00:25:49 UTC (rev 81466)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/DeploymentTemplateInfo.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -57,4 +57,10 @@
* for use by the deployment template.
*/
public Map<String, ManagedProperty> getProperties();
+
+ /**
+ *
+ * @return
+ */
+ public DeploymentTemplateInfo copy();
}
Modified: projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/Fields.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/Fields.java 2008-11-24 00:25:49 UTC (rev 81466)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/Fields.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -73,6 +73,9 @@
/** The ViewUses */
String VIEW_USE = "viewUse";
+ /** The removed flag */
+ String REMOVED = "removed";
+
// TODO other standard fields here
/**
Modified: projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/ManagedObject.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/ManagedObject.java 2008-11-24 00:25:49 UTC (rev 81466)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/ManagedObject.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -72,4 +72,38 @@
* @return the parent if one exists, null otherwise
*/
public ManagedObject getParent();
+
+ /**
+ * Get a transient attachment from the property.
+ *
+ * @see #setTransientAttachment(String, Object)
+ *
+ * @param name the name
+ * @return the attachment
+ */
+ Object getTransientAttachment(String name);
+
+ /**
+ * Get an attachment from the property,
+ * uses the expected type as both the name
+ * and to cast the resulting object.
+ *
+ * @param <T> the expected type
+ * @param expectedType the expected type
+ * @return the attachment
+ * @throws ClassCastException when the object is not of the expected type
+ */
+ <T> T getTransientAttachment(Class<T> expectedType);
+
+ /**
+ * Set an transient attachment against the property. A transient attachment
+ * is one that will not be available to clients of the property, typically
+ * admin tools. Such attachments are used by the server side where the
+ * underlying metadata to which the property is
+ *
+ * @param name the name
+ * @param attachment the attachment, pass null to remove an attachment
+ * @throws IllegalArgumentException for a null name
+ */
+ void setTransientAttachment(String name, Object attachment);
}
Modified: projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java 2008-11-24 00:25:49 UTC (rev 81466)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -177,4 +177,49 @@
* @return true when mandatory
*/
boolean isMandatory();
+
+ /**
+ * Whether the property has been marked as removed from its ManagedObject.
+ * @return true is the property has been removed.
+ */
+ boolean isRemoved();
+ /**
+ * Set whether a property has been marked as removed from its ManagedObject.
+ * @param flag - true is the property has been removed, false if not.
+ */
+ void setRemoved(boolean flag);
+
+ /**
+ * Get a transient attachment from the property.
+ *
+ * @see #setTransientAttachment(String, Object)
+ *
+ * @param name the name
+ * @return the attachment
+ */
+ Object getTransientAttachment(String name);
+
+ /**
+ * Get an attachment from the property,
+ * uses the expected type as both the name
+ * and to cast the resulting object.
+ *
+ * @param <T> the expected type
+ * @param expectedType the expected type
+ * @return the attachment
+ * @throws ClassCastException when the object is not of the expected type
+ */
+ <T> T getTransientAttachment(Class<T> expectedType);
+
+ /**
+ * Set an transient attachment against the property. A transient attachment
+ * is one that will not be available to clients of the property, typically
+ * admin tools. Such attachments are used by the server side where the
+ * underlying metadata to which the property is
+ *
+ * @param name the name
+ * @param attachment the attachment, pass null to remove an attachment
+ * @throws IllegalArgumentException for a null name
+ */
+ void setTransientAttachment(String name, Object attachment);
}
Added: projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/annotation/ConstraintsPopulatorFactory.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/annotation/ConstraintsPopulatorFactory.java (rev 0)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/annotation/ConstraintsPopulatorFactory.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.spi.factory.ManagedPropertyConstraintsPopulatorFactory;
+
+/**
+ * An annotation describing the ManagedPropertyConstraintsPopulatorFactory
+ * for a property.
+ * This can be used on fields,methods for an individual property, or on a type
+ * to specify the default factory for all properties in a managed object.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+ at Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface ConstraintsPopulatorFactory
+{
+ /** The constraints, allowed values populator factory */
+ Class<? extends ManagedPropertyConstraintsPopulatorFactory> value();
+}
Added: projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/annotation/FieldsFactory.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/annotation/FieldsFactory.java (rev 0)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/annotation/FieldsFactory.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.Fields;
+
+/**
+ * An annotation for describing the Fields class to use for a ManagedProperty.
+ * This can be used on fields,methods for an individual property, or on a type
+ * to specify the default factory for all properties in a managed object.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+ at Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface FieldsFactory
+{
+ /** The class to use for the ManagedProperty Fields implementation */
+ Class<? extends Fields> value();
+}
Modified: projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/annotation/ManagementObject.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/annotation/ManagementObject.java 2008-11-24 00:25:49 UTC (rev 81466)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/annotation/ManagementObject.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -27,21 +27,13 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.jboss.managed.api.Fields;
-import org.jboss.managed.api.ManagedObject;
-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 annotation for describing ManagedObjects.
* {@linkplain ManagedObject}
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @author Scott.Stark at jboss.org
- * @version $Revision: 1.1 $
+ * @version $Revision$
*/
@Inherited
@Target({ElementType.TYPE})
@@ -88,12 +80,13 @@
*/
ManagementOperation[] operations() default {};
- /** The class to use for the ManagedProperty implementation */
+/*
+ // 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 */
+ // The class to use for the ManagedProperty Fields implementation
Class<? extends Fields> fieldsFactory() default NULL_FIELDS_FACTORY.class;
- /** The constraints, allowed values populator factory */
+ // The constraints, allowed values populator factory
Class<? extends ManagedPropertyConstraintsPopulatorFactory> constraintsFactory()
default NULL_CONSTRAINTS.class;
-
+*/
}
Property changes on: projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/annotation/ManagementObject.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Modified: projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/annotation/ManagementProperty.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/annotation/ManagementProperty.java 2008-11-24 00:25:49 UTC (rev 81466)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/annotation/ManagementProperty.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -21,19 +21,12 @@
*/
package org.jboss.managed.api.annotation;
-import java.io.Serializable;
-import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
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.InstanceClassFactory;
-import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulator;
-import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulatorFactory;
-
/**
* ManagementProperty annotation for describing a ManagedProperty
*
@@ -43,6 +36,7 @@
*/
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
+ at Inherited
public @interface ManagementProperty
{
/** The description */
@@ -73,50 +67,4 @@
/** Strings describing free form association to admin views (Ports, Networks, ...} */
String[] adminViews() 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;
- /** The constraints, allowed values populator factory */
- Class<? extends InstanceClassFactory<? extends Serializable>> marshallerFactory() default NULL_MARSHALLER_FACTORY.class;
-
- /**
- * Used in {@link ManagementProperty#constraintsFactory()} to
- * signal that the factory be inferred from the type
- * of the property.
- */
- public static final class NULL_CONSTRAINTS implements ManagedPropertyConstraintsPopulatorFactory
- {
- public ManagedPropertyConstraintsPopulator newInstance()
- {
- 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#propertyFactory()} to
- * indicate that no ManagedProperty factory is defined.
- */
- public static abstract class NULL_PROPERTY_FACTORY implements ManagedProperty
- {
- }
-
- /**
- * Used in {@link ManagementProperty#propertyFactory()} to
- * indicate that no ManagedProperty factory is defined.
- */
- public static abstract class NULL_MARSHALLER_FACTORY implements InstanceClassFactory<Serializable>
- {
- }
}
Added: projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/annotation/ManagementPropertyFactory.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/annotation/ManagementPropertyFactory.java (rev 0)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/annotation/ManagementPropertyFactory.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.ManagedProperty;
+
+/**
+ * An annotation describing the implementation class for a ManagedProperty.
+ * This can be used on fields,methods for an individual property, or on a type
+ * to specify the default factory for all properties in a managed object.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+ at Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface ManagementPropertyFactory
+{
+ /** The class to use for the ManagedProperty implementation */
+ Class<? extends ManagedProperty> value();
+}
Modified: projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/BasicDeploymentTemplateInfo.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/BasicDeploymentTemplateInfo.java 2008-11-24 00:25:49 UTC (rev 81466)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/BasicDeploymentTemplateInfo.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -95,6 +95,12 @@
this.properties.put(property.getName(), property);
}
+
+ public DeploymentTemplateInfo copy()
+ {
+ return null;
+ }
+
public String toString()
{
StringBuilder tmp = new StringBuilder(super.toString());
Modified: projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/DelegateManagedObjectImpl.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/DelegateManagedObjectImpl.java 2008-11-24 00:25:49 UTC (rev 81466)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/DelegateManagedObjectImpl.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -31,7 +31,7 @@
import org.jboss.managed.api.ManagedProperty;
/**
- *
+ * A delegating
* @author Scott.Stark at jboss.org
* @version $Revision$
*/
@@ -99,4 +99,20 @@
{
return delegate.getParent();
}
+
+ public <T> T getTransientAttachment(Class<T> expectedType)
+ {
+ return delegate.getTransientAttachment(expectedType);
+ }
+
+ public Object getTransientAttachment(String name)
+ {
+ return delegate.getTransientAttachment(name);
+ }
+
+ public void setTransientAttachment(String name, Object attachment)
+ {
+ delegate.setTransientAttachment(name, attachment);
+ }
+
}
Modified: projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/ManagedObjectImpl.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/ManagedObjectImpl.java 2008-11-24 00:25:49 UTC (rev 81466)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/ManagedObjectImpl.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -65,8 +65,9 @@
private ManagedObject parent;
/** The runtime component name */
private transient Object componentName;
+ /** The transient attachments map */
+ private transient Map<String, Object> transientAttachments;
-
/**
* Create a new ManagedObjectImpl
*
@@ -277,6 +278,31 @@
this.componentName = name;
}
+
+ public <T> T getTransientAttachment(Class<T> expectedType)
+ {
+ T tvalue = null;
+ Object value = getTransientAttachment(expectedType.getName());
+ if(value != null)
+ tvalue = expectedType.cast(value);
+ return tvalue;
+ }
+
+ public Object getTransientAttachment(String name)
+ {
+ Object value = null;
+ if(transientAttachments != null)
+ value = transientAttachments.get(name);
+ return value;
+ }
+
+ public synchronized void setTransientAttachment(String name, Object attachment)
+ {
+ if(transientAttachments == null)
+ transientAttachments = new HashMap<String, Object>();
+ transientAttachments.put(name, attachment);
+ }
+
@Override
public boolean equals(Object obj)
{
Modified: projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/ManagedPropertyImpl.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/ManagedPropertyImpl.java 2008-11-24 00:25:49 UTC (rev 81466)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/ManagedPropertyImpl.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -27,6 +27,7 @@
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.annotation.Annotation;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@@ -44,7 +45,8 @@
* ManagedProperty.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
*/
public class ManagedPropertyImpl implements ManagedProperty
{
@@ -70,6 +72,8 @@
/** The property name */
private transient String name;
+ /** The transient attachments map */
+ private transient Map<String, Object> transientAttachments;
/**
* Create a new ManagedProperty that is not associated to
@@ -378,6 +382,51 @@
setField(Fields.MANDATORY, null);
}
+ public boolean isRemoved()
+ {
+ Boolean result = getField(Fields.REMOVED, Boolean.class);
+ if (result == null)
+ return false;
+ return result;
+ }
+
+ /**
+ * Set whether the property is removed
+ *
+ * @param flag true for removed
+ */
+ public void setRemoved(boolean flag)
+ {
+ if (flag)
+ setField(Fields.REMOVED, flag);
+ else
+ setField(Fields.REMOVED, null);
+ }
+
+ public <T> T getTransientAttachment(Class<T> expectedType)
+ {
+ T tvalue = null;
+ Object value = getTransientAttachment(expectedType.getName());
+ if(value != null)
+ tvalue = expectedType.cast(value);
+ return tvalue;
+ }
+
+ public Object getTransientAttachment(String name)
+ {
+ Object value = null;
+ if(transientAttachments != null)
+ value = transientAttachments.get(name);
+ return value;
+ }
+
+ public synchronized void setTransientAttachment(String name, Object attachment)
+ {
+ if(transientAttachments == null)
+ transientAttachments = new HashMap<String, Object>();
+ transientAttachments.put(name, attachment);
+ }
+
@Override
public String toString()
{
Property changes on: projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/ManagedPropertyImpl.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Modified: projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractInstanceClassFactory.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractInstanceClassFactory.java 2008-11-24 00:25:49 UTC (rev 81466)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractInstanceClassFactory.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -52,6 +52,7 @@
import org.jboss.metatype.api.values.MetaValue;
import org.jboss.metatype.api.values.MetaValueFactory;
import org.jboss.metatype.plugins.values.DefaultMetaValueFactory;
+import org.jboss.metatype.spi.values.MetaMapper;
import org.jboss.reflect.spi.TypeInfo;
import org.jboss.util.NotImplementedException;
@@ -217,6 +218,15 @@
return null;
MetaType propertyType = property.getMetaType();
+ // Look for a MetaMapper
+ MetaMapper metaMapper = property.getTransientAttachment(MetaMapper.class);
+ if(metaMapper != null)
+ {
+ MetaValue mvalue = metaMapper.createMetaValue(propertyType, value);
+ return mvalue;
+ }
+
+ // Otherwise use the MetaValueFactory
if (AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE == propertyType)
{
return getManagedObjectValue(beanInfo, property, metaData, value);
@@ -378,7 +388,12 @@
{
String name = getPropertyName(property);
PropertyInfo propertyInfo = beanInfo.getProperty(name);
-
+ // Look for a property MetaMapper
+ MetaMapper metaMapper = property.getTransientAttachment(MetaMapper.class);
+ if(metaMapper != null)
+ {
+ return metaMapper.unwrapMetaValue(value);
+ }
return metaValueFactory.unwrap(value, propertyInfo.getType());
}
Modified: projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java 2008-11-24 00:25:49 UTC (rev 81466)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -45,6 +45,8 @@
import org.jboss.managed.api.MutableManagedObject;
import org.jboss.managed.api.ManagedOperation.Impact;
import org.jboss.managed.api.annotation.AnnotationDefaults;
+import org.jboss.managed.api.annotation.ConstraintsPopulatorFactory;
+import org.jboss.managed.api.annotation.FieldsFactory;
import org.jboss.managed.api.annotation.ManagementComponent;
import org.jboss.managed.api.annotation.ManagementConstants;
import org.jboss.managed.api.annotation.ManagementDeployment;
@@ -55,6 +57,7 @@
import org.jboss.managed.api.annotation.ManagementParameter;
import org.jboss.managed.api.annotation.ManagementProperties;
import org.jboss.managed.api.annotation.ManagementProperty;
+import org.jboss.managed.api.annotation.ManagementPropertyFactory;
import org.jboss.managed.api.annotation.ManagementRuntimeRef;
import org.jboss.managed.api.factory.ManagedObjectFactory;
import org.jboss.managed.plugins.DefaultFieldsImpl;
@@ -70,12 +73,14 @@
import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulator;
import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulatorFactory;
import org.jboss.metadata.spi.MetaData;
+import org.jboss.metatype.api.annotations.MetaMapping;
import org.jboss.metatype.api.types.ArrayMetaType;
import org.jboss.metatype.api.types.CollectionMetaType;
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.MetaValueFactory;
+import org.jboss.metatype.spi.values.MetaMapper;
import org.jboss.reflect.spi.AnnotatedInfo;
import org.jboss.reflect.spi.ClassInfo;
import org.jboss.reflect.spi.MethodInfo;
@@ -471,9 +476,15 @@
moAnnotations.put(ManagementComponent.class.getName(), mc);
}
// ManagementObject level default factory classes
- moFieldsFactory = managementObject.fieldsFactory();
- moConstraintsFactory = managementObject.constraintsFactory();
- moPropertyFactory = managementObject.propertyFactory();
+ FieldsFactory ff = getAnnotation(FieldsFactory.class, classInfo, metaData);
+ if(ff != null)
+ moFieldsFactory = ff.value();
+ ConstraintsPopulatorFactory cpf = getAnnotation(ConstraintsPopulatorFactory.class, classInfo, metaData);
+ if(cpf != null)
+ moConstraintsFactory = cpf.value();
+ ManagementPropertyFactory mpf = getAnnotation(ManagementPropertyFactory.class, classInfo, metaData);
+ if(mpf != null)
+ moPropertyFactory = mpf.value();
}
if (trace)
@@ -558,22 +569,20 @@
if (includeProperty)
{
Fields fields = null;
- if (managementProperty != null)
+ Class<? extends Fields> factory = moFieldsFactory;
+ FieldsFactory ff = getAnnotation(FieldsFactory.class, propertyInfo, metaData);
+ if(ff != null)
+ factory = ff.value();
+ if (factory != null)
{
- Class<? extends Fields> factory = moFieldsFactory;
- if (factory == ManagementProperty.NULL_FIELDS_FACTORY.class)
- factory = managementProperty.fieldsFactory();
- if (factory != ManagementProperty.NULL_FIELDS_FACTORY.class)
+ try
{
- try
- {
- fields = factory.newInstance();
- }
- catch (Exception e)
- {
- log.debug("Failed to created Fields", e);
- }
+ fields = factory.newInstance();
}
+ catch (Exception e)
+ {
+ log.debug("Failed to created Fields", e);
+ }
}
if (fields == null)
fields = new DefaultFieldsImpl();
@@ -623,22 +632,44 @@
if (managementProperty != null)
managed = managementProperty.managed();
- MetaType metaType;
- if (managed)
+ // The managed property type
+ MetaType metaType = null;
+ MetaMapper<?> metaMapper = null;
+ MetaMapping metaMapping = getAnnotation(MetaMapping.class, propertyInfo, metaData);
+ if(metaMapping != null)
{
- TypeInfo typeInfo = propertyInfo.getType();
- if(typeInfo.isArray())
- metaType = new ArrayMetaType(1, MANAGED_OBJECT_META_TYPE);
- else if (typeInfo.isCollection())
- metaType = new CollectionMetaType(typeInfo.getName(), MANAGED_OBJECT_META_TYPE);
- else
- metaType = MANAGED_OBJECT_META_TYPE;
+ // Use the mapping for the type
+ Class<? extends MetaMapper<?>> mapperClass = metaMapping.value();
+ try
+ {
+ metaMapper = mapperClass.newInstance();
+ metaType = metaMapper.getMetaType();
+ }
+ catch(Exception e)
+ {
+ log.debug("Failed to create MetaMapper: "+metaMapping, e);
+ }
}
- else
+ // Determine meta type based on property type
+ if(metaType == null)
{
- metaType = metaTypeFactory.resolve(propertyInfo.getType());
+ if (managed)
+ {
+ TypeInfo typeInfo = propertyInfo.getType();
+ if(typeInfo.isArray())
+ metaType = new ArrayMetaType(1, MANAGED_OBJECT_META_TYPE);
+ else if (typeInfo.isCollection())
+ metaType = new CollectionMetaType(typeInfo.getName(), MANAGED_OBJECT_META_TYPE);
+ else
+ metaType = MANAGED_OBJECT_META_TYPE;
+ }
+ else
+ {
+ metaType = metaTypeFactory.resolve(propertyInfo.getType());
+ }
}
fields.setField(Fields.META_TYPE, metaType);
+ // Property annotations
if (propAnnotations.isEmpty() == false)
fields.setField(Fields.ANNOTATIONS, propAnnotations);
@@ -646,15 +677,16 @@
try
{
Class<? extends ManagedPropertyConstraintsPopulatorFactory> factoryClass = moConstraintsFactory;
- if (factoryClass == ManagementProperty.NULL_CONSTRAINTS.class)
+ ConstraintsPopulatorFactory cpf = getAnnotation(ConstraintsPopulatorFactory.class, propertyInfo, metaData);
+ if(cpf != null)
+ factoryClass = cpf.value();
+ if(factoryClass != null)
{
- if (managementProperty != null)
- factoryClass = managementProperty.constraintsFactory();
+ ManagedPropertyConstraintsPopulatorFactory mpcpf = factoryClass.newInstance();
+ ManagedPropertyConstraintsPopulator populator = mpcpf.newInstance();
+ if (populator != null)
+ populator.populateManagedProperty(clazz, propertyInfo, fields);
}
- ManagedPropertyConstraintsPopulatorFactory factory = factoryClass.newInstance();
- ManagedPropertyConstraintsPopulator populator = factory.newInstance();
- if (populator != null)
- populator.populateManagedProperty(clazz, propertyInfo, fields);
}
catch(Exception e)
{
@@ -662,18 +694,19 @@
}
ManagedProperty property = null;
- if (managementProperty != null)
- {
- 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);
- }
+ Class<? extends ManagedProperty> mpClass = moPropertyFactory;
+ ManagementPropertyFactory mpf = getAnnotation(ManagementPropertyFactory.class, propertyInfo, metaData);
+ if (mpf != null)
+ mpClass = mpf.value();
+ if (mpClass != null)
+ property = getManagedProperty(mpClass, fields);
// we should have write-through by default
// use factory to change this default behavior
if (property == null)
property = createDefaultManagedProperty(fields);
+ // Pass the MetaMapper as an attachment
+ if(metaMapper != null)
+ property.setTransientAttachment(MetaMapper.class.getName(), metaMapper);
properties.add(property);
}
else if (trace)
Modified: projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/factory/DeploymentTemplateInfoFactory.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/factory/DeploymentTemplateInfoFactory.java 2008-11-24 00:25:49 UTC (rev 81466)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/factory/DeploymentTemplateInfoFactory.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -36,8 +36,11 @@
import org.jboss.managed.api.Fields;
import org.jboss.managed.api.ManagedObject;
import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.annotation.ConstraintsPopulatorFactory;
+import org.jboss.managed.api.annotation.FieldsFactory;
import org.jboss.managed.api.annotation.ManagementConstants;
import org.jboss.managed.api.annotation.ManagementProperty;
+import org.jboss.managed.api.annotation.ManagementPropertyFactory;
import org.jboss.managed.plugins.BasicDeploymentTemplateInfo;
import org.jboss.managed.plugins.DefaultFieldsImpl;
import org.jboss.managed.plugins.WritethroughManagedPropertyImpl;
@@ -182,20 +185,18 @@
propAnnotations.put(ManagementProperty.class.getName(), managementProperty);
Fields fields = null;
- if (managementProperty != null)
+ FieldsFactory factory = propertyInfo.getUnderlyingAnnotation(FieldsFactory.class);
+ if (factory != null)
{
- Class<? extends Fields> factory = managementProperty.fieldsFactory();
- if (factory != ManagementProperty.NULL_FIELDS_FACTORY.class)
+ try
{
- try
- {
- fields = factory.newInstance();
- }
- catch (Exception e)
- {
- log.debug("Failed to created Fields", e);
- }
+ Class<? extends Fields> fieldClass = factory.value();
+ fields = fieldClass.newInstance();
}
+ catch (Exception e)
+ {
+ log.debug("Failed to created Fields", e);
+ }
}
if (fields == null)
fields = new DefaultFieldsImpl();
@@ -267,13 +268,17 @@
// 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)
+ ConstraintsPopulatorFactory cpf = propertyInfo.getUnderlyingAnnotation(ConstraintsPopulatorFactory.class);
+ if(factory != null)
{
- Class<?> clazz = propertyInfo.getBeanInfo().getClassInfo().getType();
- populator.populateManagedProperty(clazz, propertyInfo, fields);
+ Class<? extends ManagedPropertyConstraintsPopulatorFactory> factoryClass = cpf.value();
+ ManagedPropertyConstraintsPopulatorFactory pfactory = factoryClass.newInstance();
+ ManagedPropertyConstraintsPopulator populator = pfactory.newInstance();
+ if (populator != null)
+ {
+ Class<?> clazz = propertyInfo.getBeanInfo().getClassInfo().getType();
+ populator.populateManagedProperty(clazz, propertyInfo, fields);
+ }
}
}
catch(Exception e)
@@ -281,11 +286,11 @@
log.debug("Failed to populate constraints for: "+propertyInfo, e);
}
- if (managementProperty != null)
+ ManagementPropertyFactory mpf = propertyInfo.getUnderlyingAnnotation(ManagementPropertyFactory.class);
+ if (mpf != null)
{
- Class<? extends ManagedProperty> factory = managementProperty.propertyFactory();
- if (factory != ManagementProperty.NULL_PROPERTY_FACTORY.class)
- property = AbstractManagedObjectFactory.createManagedProperty(factory, fields);
+ Class<? extends ManagedProperty> factoryClass = mpf.value();
+ property = AbstractManagedObjectFactory.createManagedProperty(factoryClass, fields);
}
// we should have write-through by default
// use factory to change this default behavior
Added: projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/support/mcf/ConnectionFactoryProperty.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/support/mcf/ConnectionFactoryProperty.java (rev 0)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/support/mcf/ConnectionFactoryProperty.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -0,0 +1,124 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.managed.factory.support.mcf;
+
+import java.io.ObjectStreamException;
+import java.io.Serializable;
+
+import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.managed.api.Fields;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.managed.plugins.ManagedPropertyImpl;
+import org.jboss.managed.spi.factory.InstanceClassFactory;
+import org.jboss.metatype.api.types.MapCompositeMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.MetaValue;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class ConnectionFactoryProperty extends ManagedPropertyImpl
+{
+ private static final long serialVersionUID = 1;
+ private ManagedObjectFactory moFactory;
+ private MapCompositeMetaType type;
+
+ public ConnectionFactoryProperty(String s)
+ {
+ super(s);
+ }
+
+ public ConnectionFactoryProperty(Fields fields)
+ {
+ super(fields);
+ type = new MapCompositeMetaType(SimpleMetaType.STRING);
+ setField(Fields.META_TYPE, null);
+ }
+
+ public ConnectionFactoryProperty(ManagedObject managedObject, Fields fields)
+ {
+ super(managedObject, fields);
+ type = new MapCompositeMetaType(SimpleMetaType.STRING);
+ setField(Fields.META_TYPE, null);
+ }
+
+ public MetaType getMetaType()
+ {
+ return type;
+ }
+
+ public void setField(String fieldName, Serializable value)
+ {
+ if(Fields.META_TYPE.equals(fieldName))
+ value = type;
+ super.setField(fieldName, value);
+ }
+
+ /**
+ * Write the value back to the attachment if there is a PropertyInfo
+ * in the Fields.PROPERTY_INFO field.
+ */
+ @Override
+ @SuppressWarnings("unchecked")
+ public void setValue(MetaValue value)
+ {
+ super.setValue(value);
+
+ PropertyInfo propertyInfo = getField(Fields.PROPERTY_INFO, PropertyInfo.class);
+ if (propertyInfo != null)
+ {
+ Object attachment = getManagedObject().getAttachment();
+ if (attachment != null)
+ {
+ MetaValue metaValue = value;
+ InstanceClassFactory icf = getMOFactory().getInstanceClassFactory(attachment.getClass());
+ BeanInfo beanInfo = propertyInfo.getBeanInfo();
+ icf.setValue(beanInfo, this, attachment, metaValue);
+ }
+ }
+ }
+
+ private ManagedObjectFactory getMOFactory()
+ {
+ if(moFactory == null)
+ moFactory = ManagedObjectFactory.getInstance();
+ return moFactory;
+ }
+
+ /**
+ * Expose only plain ManangedPropertyImpl.
+ *
+ * @return simpler ManagedPropertyImpl
+ * @throws java.io.ObjectStreamException for any error
+ */
+ private Object writeReplace() throws ObjectStreamException
+ {
+ ManagedPropertyImpl managedProperty = new ManagedPropertyImpl(getManagedObject(), getFields());
+ managedProperty.setTargetManagedObject(getTargetManagedObject());
+ return managedProperty;
+ }
+
+}
\ No newline at end of file
Modified: projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/support/mcf/LocalDSInstanceClassFactory.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/support/mcf/LocalDSInstanceClassFactory.java 2008-11-24 00:25:49 UTC (rev 81466)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/support/mcf/LocalDSInstanceClassFactory.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -85,6 +85,21 @@
}
value = mapValue;
}
+ else if("config-property".equals(property.getName()))
+ {
+ MapCompositeValueSupport mapValue = new MapCompositeValueSupport(SimpleMetaType.STRING);
+ List<ManagedConnectionFactoryPropertyMetaData> list = attachment.getManagedConnectionFactoryProperties();
+ if(list != null)
+ {
+ for(ManagedConnectionFactoryPropertyMetaData prop : list)
+ {
+ mapValue.put("name", SimpleValueSupport.wrap(prop.getName()));
+ mapValue.put("value", SimpleValueSupport.wrap(prop.getValue()));
+ mapValue.put("type", SimpleValueSupport.wrap("java.lang.String"));
+ }
+ }
+ value = mapValue;
+ }
else
{
value = super.getValue(beanInfo, property, metaData, attachment);
@@ -116,6 +131,20 @@
}
unwrapValue = list;
}
+ else if("config-property".equals(property.getName()))
+ {
+ List<ManagedConnectionFactoryPropertyMetaData> list = new ArrayList<ManagedConnectionFactoryPropertyMetaData>();
+ for(String name : mapValue.getMetaType().keySet())
+ {
+ ManagedConnectionFactoryPropertyMetaData prop = new ManagedConnectionFactoryPropertyMetaData();
+ prop.setName(name);
+ String svalue = (String) getMetaValueFactory().unwrap(mapValue.get(name));
+ prop.setValue(svalue);
+ prop.setType("java.lang.String");
+ list.add(prop);
+ }
+ unwrapValue = list;
+ }
return unwrapValue;
}
}
Added: projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/support/mcf/MCFPropertyMetaDataMapper.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/support/mcf/MCFPropertyMetaDataMapper.java (rev 0)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/support/mcf/MCFPropertyMetaDataMapper.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.managed.factory.support.mcf;
+
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.jboss.metatype.api.types.CollectionMetaType;
+import org.jboss.metatype.api.types.MapCompositeMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.CollectionValue;
+import org.jboss.metatype.api.values.CollectionValueSupport;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.MapCompositeValueSupport;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.metatype.spi.values.MetaMapper;
+
+/**
+ * A MetaMapper for ManagedConnectionFactoryPropertyMetaData
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class MCFPropertyMetaDataMapper extends MetaMapper<Collection<ManagedConnectionFactoryPropertyMetaData>>
+{
+ CollectionMetaType type;
+
+ public MCFPropertyMetaDataMapper()
+ {
+ MapCompositeMetaType etype = new MapCompositeMetaType(SimpleMetaType.STRING);
+ etype.addItem("name", "the name of the bean");
+ etype.addItem("value", "the string value of the bean");
+ etype.addItem("type", "the type name of the value");
+ type = new CollectionMetaType("java.util.List", etype);
+ }
+
+ @Override
+ public MetaType getMetaType()
+ {
+ return type;
+ }
+ @Override
+ public Type mapToType()
+ {
+ return ManagedConnectionFactoryPropertyMetaData.class;
+ }
+
+ @Override
+ public MetaValue createMetaValue(MetaType metaType, Collection<ManagedConnectionFactoryPropertyMetaData> list)
+ {
+ ArrayList<MetaValue> values = new ArrayList<MetaValue>();
+ for(ManagedConnectionFactoryPropertyMetaData mcfpmd : list)
+ {
+ MapCompositeValueSupport metaValue = new MapCompositeValueSupport(SimpleMetaType.STRING);
+ metaValue.put("name", SimpleValueSupport.wrap(mcfpmd.getName()));
+ metaValue.put("value", SimpleValueSupport.wrap(mcfpmd.getValue()));
+ metaValue.put("type", SimpleValueSupport.wrap(mcfpmd.getType()));
+ values.add(metaValue);
+ }
+ MetaValue[] elements = new MetaValue[values.size()];
+ values.toArray(elements);
+ CollectionValueSupport cvalue = new CollectionValueSupport(type, elements);
+ return cvalue;
+ }
+
+ @Override
+ public Collection<ManagedConnectionFactoryPropertyMetaData> unwrapMetaValue(MetaValue metaValue)
+ {
+ CollectionValue cvalue = (CollectionValue) metaValue;
+ MetaValue[] elements = cvalue.getElements();
+ ArrayList<ManagedConnectionFactoryPropertyMetaData> values = new ArrayList<ManagedConnectionFactoryPropertyMetaData>();
+ if(elements != null)
+ {
+ for(MetaValue mv : elements)
+ {
+ CompositeValue cv = (CompositeValue) mv;
+ ManagedConnectionFactoryPropertyMetaData bean = new ManagedConnectionFactoryPropertyMetaData();
+ SimpleValue name = (SimpleValue) cv.get("name");
+ SimpleValue value = (SimpleValue) cv.get("value");
+ SimpleValue type = (SimpleValue) cv.get("value");
+ bean.setName((String) name.getValue());
+ bean.setValue((String) value.getValue());
+ bean.setType((String) type.getValue());
+ values.add(bean);
+ }
+ }
+ return values;
+ }
+}
Property changes on: projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/support/mcf/MCFPropertyMetaDataMapper.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Modified: projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/support/mcf/ManagedConnectionFactoryDeploymentMetaData.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/support/mcf/ManagedConnectionFactoryDeploymentMetaData.java 2008-11-24 00:25:49 UTC (rev 81466)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/support/mcf/ManagedConnectionFactoryDeploymentMetaData.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -36,6 +36,7 @@
import org.jboss.managed.api.annotation.ManagementObject;
import org.jboss.managed.api.annotation.ManagementProperty;
+import org.jboss.managed.api.annotation.ManagementPropertyFactory;
@@ -263,6 +264,10 @@
*
* @return the managedConnectionFactoryProperties.
*/
+ @ManagementProperty(name="config-property",
+ description="The connection factory property info", managed=true,
+ includeInTemplate=true)
+ @ManagementPropertyFactory(ConnectionFactoryProperty.class)
public List<ManagedConnectionFactoryPropertyMetaData> getManagedConnectionFactoryProperties()
{
return managedConnectionFactoryProperties;
Modified: projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/support/mcf/NonXADataSourceDeploymentMetaData.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/support/mcf/NonXADataSourceDeploymentMetaData.java 2008-11-24 00:25:49 UTC (rev 81466)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/support/mcf/NonXADataSourceDeploymentMetaData.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -10,6 +10,9 @@
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementProperty;
+import org.jboss.managed.api.annotation.ManagementPropertyFactory;
+import org.jboss.metatype.api.annotations.MetaMapping;
@XmlAccessorType(XmlAccessType.FIELD)
@ManagementObject
@@ -57,9 +60,13 @@
}
@Override
+ @ManagementProperty(name="config-property",
+ description="The connection factory property info", managed=true,
+ includeInTemplate=true)
+ @ManagementPropertyFactory(ConnectionFactoryProperty.class)
+ @MetaMapping(MCFPropertyMetaDataMapper.class)
public List<ManagedConnectionFactoryPropertyMetaData> getManagedConnectionFactoryProperties()
{
-
List<ManagedConnectionFactoryPropertyMetaData> properties = super.getManagedConnectionFactoryProperties();
ManagedConnectionFactoryPropertyMetaData property = null;
Modified: projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/test/AbstractManagedObjectFactoryUnitTestCase.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/test/AbstractManagedObjectFactoryUnitTestCase.java 2008-11-24 00:25:49 UTC (rev 81466)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/test/AbstractManagedObjectFactoryUnitTestCase.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -46,9 +46,14 @@
import org.jboss.metadata.plugins.loader.memory.MemoryMetaDataLoader;
import org.jboss.metadata.spi.MetaData;
import org.jboss.metadata.spi.retrieval.MetaDataRetrievalToMetaDataBridge;
+import org.jboss.metatype.api.types.CollectionMetaType;
+import org.jboss.metatype.api.types.MapCompositeMetaType;
+import org.jboss.metatype.api.types.MetaType;
import org.jboss.metatype.api.values.CollectionValue;
+import org.jboss.metatype.api.values.CompositeValue;
import org.jboss.metatype.api.values.GenericValue;
import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
import org.jboss.metatype.api.values.SimpleValueSupport;
import org.jboss.test.managed.factory.AbstractManagedObjectFactoryTest;
import org.jboss.test.managed.factory.support.ManagementObjectChangedName;
@@ -71,12 +76,14 @@
import org.jboss.test.managed.factory.support.deployment.JmsDestinations;
import org.jboss.test.managed.factory.support.deployment.QueueDestination;
import org.jboss.test.managed.factory.support.deployment.SecurityDomain;
+import org.jboss.test.managed.factory.support.mcf.ConnectionFactoryProperty;
import org.jboss.test.managed.factory.support.mcf.DBMSMetaData;
import org.jboss.test.managed.factory.support.mcf.DataSourceConnectionPropertyMetaData;
import org.jboss.test.managed.factory.support.mcf.LocalDSInstanceClassFactory;
import org.jboss.test.managed.factory.support.mcf.LocalDataSourceDeploymentMetaData;
import org.jboss.test.managed.factory.support.mcf.ManagedConnectionFactoryDeploymentGroup;
import org.jboss.test.managed.factory.support.mcf.ManagedConnectionFactoryDeploymentMetaData;
+import org.jboss.test.managed.factory.support.mcf.ManagedConnectionFactoryPropertyMetaData;
import org.jboss.test.managed.factory.support.mcf.NoTxConnectionFactoryDeploymentMetaData;
import org.jboss.test.managed.factory.support.mcf.NoTxICF;
import org.jboss.test.managed.factory.support.mcf.SecurityMetaData;
@@ -272,6 +279,10 @@
assertEquals("jboss:test=testTransformer", managedObject.getComponentName());
}
+ /**
+ * Test the
+ * @throws Exception
+ */
public void testMCFHierarchy()
throws Exception
{
@@ -303,7 +314,44 @@
ManagedProperty domainName = secDomainMO.getProperty("domain");
assertNotNull("security-domain.MO.domain", domainName);
assertEquals(SimpleValueSupport.wrap("java:/jaas/SomeDomain"), domainName.getValue());
+ }
+ /**
+ * Test the custom ConnectionFactoryProperty used for the config-property of
+ * ManagedConnectionFactoryDeploymentMetaData
+ * @throws Exception
+ */
+ public void testManagedConnectionFactoryPropertyMetaData()
+ throws Exception
+ {
+ ManagedConnectionFactoryDeploymentGroup mcf = initMCFDG();
+ ManagedObjectFactory mof = getMOF();
+ LocalDSInstanceClassFactory dsicf = new LocalDSInstanceClassFactory();
+ mof.addInstanceClassFactory(dsicf);
+ ManagedObject mcfMO = mof.initManagedObject(mcf, "ManagedConnectionFactoryDeploymentGroup", null);
+ ManagedProperty deployments = mcfMO.getProperty("deployments");
+ Object dvalue = deployments.getValue();
+ assertTrue(dvalue.getClass()+"", dvalue instanceof CollectionValue);
+ CollectionValue cv = (CollectionValue) dvalue;
+ assertEquals(1, cv.getSize());
+ Object cv0 = cv.iterator().next();
+ assertTrue(cv0 instanceof GenericValue);
+ GenericValue gv0 = (GenericValue) cv0;
+ assertTrue(gv0.getValue() instanceof ManagedObject);
+ ManagedObject mo = (ManagedObject) gv0.getValue();
+ assertEquals(LocalDataSourceDeploymentMetaData.class.getName(), mo.getAttachmentName());
+
+ ManagedProperty cpMP = mo.getProperty("config-property");
+ assertNotNull("config-property", cpMP);
+ assertTrue("config-property("+cpMP+") isa ConnectionFactoryProperty", cpMP instanceof ConnectionFactoryProperty);
+ MetaType type = cpMP.getMetaType();
+ assertTrue("config-property type("+type+") is MapCompositeMetaType", type instanceof MapCompositeMetaType);
+ MetaValue value = cpMP.getValue();
+ assertTrue("config-property("+value+") MapCompositeMetaType.isValue", value instanceof CompositeValue);
+ CompositeValue cvalue = (CompositeValue) value;
+ SimpleValue connectionPropertiesValue = (SimpleValue) cvalue.get("value");
+ assertEquals("cp1-name=cp1-value\ncp2-name=cp2-value", connectionPropertiesValue.getValue().toString().trim());
+ assertEquals(SimpleValueSupport.wrap("java.lang.String"), cvalue.get("type"));
}
public void testKernelDeployment()
@@ -400,6 +448,18 @@
cp1, cp2
};
lds.setDataSourceConnectionProperties(Arrays.asList(cps));
+ List<ManagedConnectionFactoryPropertyMetaData> mcps = new ArrayList<ManagedConnectionFactoryPropertyMetaData>();
+ ManagedConnectionFactoryPropertyMetaData mcp1 = new ManagedConnectionFactoryPropertyMetaData();
+ mcp1.setName("mcp1-name");
+ mcp1.setValue("mcp1-value");
+ mcp1.setType("java.lang.String");
+ mcps.add(mcp1);
+ ManagedConnectionFactoryPropertyMetaData mcp2 = new ManagedConnectionFactoryPropertyMetaData();
+ mcp2.setName("mcp2-name");
+ mcp2.setValue("mcp2-value");
+ mcp2.setType("java.lang.String");
+ mcps.add(mcp2);
+ lds.setManagedConnectionFactoryProperties(mcps);
lds.setDriverClass("org.jboss.jdbc.SomeDriver");
lds.setExceptionSorterClassName("org.jboss.jdbc.SomeExceptionSorter");
String[] depends = {"jboss:service=Naming", "jboss:service=Hypersonic,database=localDB"};
Modified: projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/annotations/MetaMapping.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/annotations/MetaMapping.java 2008-11-24 00:25:49 UTC (rev 81466)
+++ projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/annotations/MetaMapping.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -32,9 +32,10 @@
* MetaMapper.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
*/
- at Target({ElementType.TYPE})
+ at Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface MetaMapping
{
Property changes on: projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/annotations/MetaMapping.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Modified: projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/types/MapCompositeMetaType.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/types/MapCompositeMetaType.java 2008-11-24 00:25:49 UTC (rev 81466)
+++ projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/types/MapCompositeMetaType.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -59,13 +59,22 @@
}
/**
- *
- * @param itemName
+ * Add an item
+ * @param itemName - the name of the item
*/
public void addItem(String itemName)
{
- super.addItem(itemName, itemName, valueType);
+ addItem(itemName, itemName, valueType);
}
+ /**
+ * Add an item along with its description
+ * @param itemName - the name of the item
+ * @param itemDescription - the description of the item
+ */
+ public void addItem(String itemName, String itemDescription)
+ {
+ super.addItem(itemName, itemDescription, valueType);
+ }
@Override
public boolean equals(Object obj)
Modified: projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/types/MetaType.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/types/MetaType.java 2008-11-24 00:25:49 UTC (rev 81466)
+++ projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/types/MetaType.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -28,6 +28,7 @@
import java.util.Collections;
import java.util.Date;
import java.util.List;
+import java.util.Properties;
import org.jboss.metatype.api.values.ArrayValue;
import org.jboss.metatype.api.values.CompositeValue;
@@ -61,6 +62,7 @@
* java.lang.Date<br>
* java.math.BigDecimal<br>
* java.math.BigInteger<br>
+ * java.util.Properties<br>
* {@link Name}<br>
* {@link SimpleValue}<br>
* {@link EnumValue}<br>
@@ -84,6 +86,7 @@
Date.class.getName(),
BigDecimal.class.getName(),
BigInteger.class.getName(),
+ Properties.class.getName(),
Name.class.getName(),
SimpleValue.class.getName(),
EnumValue.class.getName(),
Added: projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/types/PropertiesMetaType.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/types/PropertiesMetaType.java (rev 0)
+++ projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/types/PropertiesMetaType.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.metatype.api.types;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.jboss.metatype.api.values.PropertiesMetaValue;
+
+
+/**
+ * A MetaType for java.util.Properties
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class PropertiesMetaType extends AbstractMetaType
+{
+ private static final long serialVersionUID = 1;
+ public static final PropertiesMetaType INSTANCE = new PropertiesMetaType();
+ /** A mapping from known property names to description */
+ private Map<String, String> propertyNameDescriptions = Collections.emptyMap();
+
+ public PropertiesMetaType()
+ {
+ this(Properties.class.getName());
+ }
+ public PropertiesMetaType(String description)
+ {
+ super(Properties.class.getName(), description);
+ }
+ public PropertiesMetaType(String description, Map<String, String> propertyNameDescriptions)
+ {
+ super(Properties.class.getName(), description);
+ this.propertyNameDescriptions = propertyNameDescriptions;
+ }
+
+ public void addProperty(String name, String description)
+ {
+ if(propertyNameDescriptions.size() == 0)
+ propertyNameDescriptions = new HashMap<String,String>();
+ propertyNameDescriptions.put(name, description);
+ }
+
+ public boolean isProperty(String name)
+ {
+ return propertyNameDescriptions.containsKey(name);
+ }
+ public String getDescription(String name)
+ {
+ return propertyNameDescriptions.get(name);
+ }
+ @Override
+ public boolean isValue(Object obj)
+ {
+ return obj instanceof PropertiesMetaValue;
+ }
+}
Modified: projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/values/MetaValueFactory.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/values/MetaValueFactory.java 2008-11-24 00:25:49 UTC (rev 81466)
+++ projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/values/MetaValueFactory.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -23,6 +23,7 @@
import java.lang.reflect.Type;
+import org.jboss.metatype.api.types.MetaType;
import org.jboss.metatype.plugins.values.MetaValueFactoryBuilder;
import org.jboss.metatype.spi.values.MetaValueBuilder;
import org.jboss.reflect.spi.TypeInfo;
@@ -119,4 +120,5 @@
* @return meta value's value
*/
public abstract Object unwrap(MetaValue metaValue, TypeInfo type);
+
}
Added: projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/values/PropertiesMetaValue.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/values/PropertiesMetaValue.java (rev 0)
+++ projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/values/PropertiesMetaValue.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -0,0 +1,97 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.metatype.api.values;
+
+import java.util.Properties;
+
+import org.jboss.metatype.api.types.PropertiesMetaType;
+
+/**
+ * A mapping from the jdk Properties to a MetaValue
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class PropertiesMetaValue extends Properties
+ implements MetaValue
+{
+ private static final long serialVersionUID = 1;
+ private PropertiesMetaType type;
+
+ /**
+ * Build a PropertiesMetaValue from a Properties by copying all key/value
+ * pairs from props into the new PropertiesMetaValue.
+ *
+ * @param props - the Properties to copy
+ * @return PropertiesMetaValue
+ */
+ public static PropertiesMetaValue wrap(Properties props)
+ {
+ PropertiesMetaValue value = new PropertiesMetaValue();
+ value.putAll(props);
+ return value;
+ }
+
+ /**
+ * Creates an empty PropertiesMetaValue
+ */
+ public PropertiesMetaValue()
+ {
+ }
+ /**
+ * Create a PropertiesMetaValue with props as the defaults. If you want to
+ * create a PropertiesMetaValue with only the key/value pairs of props use
+ * {@link #wrap(Properties)}.
+ *
+ * @param props - default properties
+ */
+ public PropertiesMetaValue(Properties props)
+ {
+ this(props, PropertiesMetaType.INSTANCE);
+ }
+ /**
+ * Create a PropertiesMetaValue with props as the defaults. If you want to
+ * create a PropertiesMetaValue with only the key/value pairs of props use
+ * {@link #wrap(Properties)}.
+ *
+ * @param props - default properties
+ * @param type - the properties
+ */
+ public PropertiesMetaValue(Properties props, PropertiesMetaType type)
+ {
+ super(props);
+ this.type = type;
+ }
+
+ public PropertiesMetaType getMetaType()
+ {
+ return type;
+ }
+
+ @Override
+ public MetaValue clone()
+ {
+ PropertiesMetaValue clone = new PropertiesMetaValue();
+ clone.putAll(this);
+ return clone;
+ }
+
+}
Modified: projects/jboss-man/branches/Branch_2_0/metatype/src/test/java/org/jboss/test/metatype/types/factory/test/CompositeMetaTypeFactoryUnitTestCase.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/metatype/src/test/java/org/jboss/test/metatype/types/factory/test/CompositeMetaTypeFactoryUnitTestCase.java 2008-11-24 00:25:49 UTC (rev 81466)
+++ projects/jboss-man/branches/Branch_2_0/metatype/src/test/java/org/jboss/test/metatype/types/factory/test/CompositeMetaTypeFactoryUnitTestCase.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -44,6 +44,7 @@
import org.jboss.test.metatype.types.factory.support.TestRecursiveComposite;
import org.jboss.test.metatype.types.factory.support.TestRenamedCompositeItem;
import org.jboss.test.metatype.types.factory.support.TestSimpleComposite;
+import org.jboss.test.metatype.types.support.MetaMappingUsage;
/**
* CompositeMetaTypeFactoryUnitTestCase.
@@ -165,10 +166,24 @@
CompositeMetaType result = assertInstanceOf(resolve(propertiesType), CompositeMetaType.class);
MapCompositeMetaType expected = new MapCompositeMetaType(SimpleMetaType.STRING);
testComposite(expected, result);
-
}
/**
+ * A test of the MetaMapping annotation controlling the MetaType of a Type
+ */
+ public void testMetaMappingComposite()
+ throws Exception
+ {
+ Type type = MetaMappingUsage.class;
+ MapCompositeMetaType result = assertInstanceOf(resolve(type), MapCompositeMetaType.class);
+ MapCompositeMetaType expected = new MapCompositeMetaType(SimpleMetaType.STRING);
+ expected.addItem("name");
+ expected.addItem("value");
+ expected.addItem("type");
+ testComposite(expected, result);
+ }
+
+ /**
* Illustrate the expected type when type does not contain the
* generic parameter type information.
*
Added: projects/jboss-man/branches/Branch_2_0/metatype/src/test/java/org/jboss/test/metatype/types/support/BeanMetaMapper.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/metatype/src/test/java/org/jboss/test/metatype/types/support/BeanMetaMapper.java (rev 0)
+++ projects/jboss-man/branches/Branch_2_0/metatype/src/test/java/org/jboss/test/metatype/types/support/BeanMetaMapper.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.metatype.types.support;
+
+import java.lang.reflect.Type;
+
+import org.jboss.metatype.api.types.MapCompositeMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.MapCompositeValueSupport;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.metatype.spi.values.MetaMapper;
+
+/**
+ * A MetaMapper implementation for the MetaMappingUsage bean that converts
+ * to from a MapCompositeMetaType
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class BeanMetaMapper extends MetaMapper<MetaMappingUsage>
+{
+ MapCompositeMetaType type;
+
+ public BeanMetaMapper()
+ {
+ type = new MapCompositeMetaType(SimpleMetaType.STRING);
+ type.addItem("name", "the name of the bean");
+ type.addItem("value", "the string value of the bean");
+ type.addItem("type", "the type name of the value");
+ }
+
+ @Override
+ public MetaType getMetaType()
+ {
+ return type;
+ }
+ @Override
+ public Type mapToType()
+ {
+ return BeanMetaMapper.class;
+ }
+
+ @Override
+ public MetaValue createMetaValue(MetaType metaType, MetaMappingUsage object)
+ {
+ MapCompositeValueSupport metaValue = new MapCompositeValueSupport(SimpleMetaType.STRING);
+ metaValue.put("name", SimpleValueSupport.wrap(object.getName()));
+ metaValue.put("value", SimpleValueSupport.wrap(object.getValue()));
+ metaValue.put("type", SimpleValueSupport.wrap(object.getType()));
+ return metaValue;
+ }
+
+ @Override
+ public MetaMappingUsage unwrapMetaValue(MetaValue metaValue)
+ {
+ MetaMappingUsage bean = new MetaMappingUsage();
+ CompositeValue cv = (CompositeValue) metaValue;
+ SimpleValue name = (SimpleValue) cv.get("name");
+ SimpleValue value = (SimpleValue) cv.get("value");
+ SimpleValue type = (SimpleValue) cv.get("value");
+ bean.setName((String) name.getValue());
+ bean.setValue((String) value.getValue());
+ bean.setType((String) type.getValue());
+ return bean;
+ }
+
+}
Added: projects/jboss-man/branches/Branch_2_0/metatype/src/test/java/org/jboss/test/metatype/types/support/MetaMappingUsage.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/metatype/src/test/java/org/jboss/test/metatype/types/support/MetaMappingUsage.java (rev 0)
+++ projects/jboss-man/branches/Branch_2_0/metatype/src/test/java/org/jboss/test/metatype/types/support/MetaMappingUsage.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.metatype.types.support;
+
+import org.jboss.metatype.api.annotations.MetaMapping;
+
+/**
+ * A javabean with a MetaMapping
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+ at MetaMapping(BeanMetaMapper.class)
+public class MetaMappingUsage
+{
+ private String name;
+ private String value;
+ private String type;
+
+ public String getName()
+ {
+ return name;
+ }
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+ public String getValue()
+ {
+ return value;
+ }
+ public void setValue(String value)
+ {
+ this.value = value;
+ }
+ public String getType()
+ {
+ return type;
+ }
+ public void setType(String type)
+ {
+ this.type = type;
+ }
+}
Modified: projects/jboss-man/branches/Branch_2_0/metatype/src/test/java/org/jboss/test/metatype/types/test/MetaTypeUnitTestCase.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/metatype/src/test/java/org/jboss/test/metatype/types/test/MetaTypeUnitTestCase.java 2008-11-24 00:25:49 UTC (rev 81466)
+++ projects/jboss-man/branches/Branch_2_0/metatype/src/test/java/org/jboss/test/metatype/types/test/MetaTypeUnitTestCase.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -25,6 +25,7 @@
import java.math.BigInteger;
import java.util.Date;
import java.util.List;
+import java.util.Properties;
import junit.framework.Test;
@@ -75,7 +76,7 @@
public void testAllowedClasses() throws Exception
{
List<String> allowedClassNames = MetaType.ALLOWED_CLASSNAMES;
- assertEquals(20, allowedClassNames.size());
+ assertEquals(21, allowedClassNames.size());
checkMetaType(allowedClassNames, Void.class);
checkMetaType(allowedClassNames, Boolean.class);
checkMetaType(allowedClassNames, Character.class);
@@ -96,6 +97,7 @@
checkMetaType(allowedClassNames, ArrayValue.class);
checkMetaType(allowedClassNames, CompositeValue.class);
checkMetaType(allowedClassNames, TableValue.class);
+ checkMetaType(allowedClassNames, Properties.class);
}
/**
Modified: projects/jboss-man/branches/Branch_2_0/metatype/src/test/java/org/jboss/test/metatype/values/factory/test/CompositeValueFactoryUnitTestCase.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/metatype/src/test/java/org/jboss/test/metatype/values/factory/test/CompositeValueFactoryUnitTestCase.java 2008-11-24 00:25:49 UTC (rev 81466)
+++ projects/jboss-man/branches/Branch_2_0/metatype/src/test/java/org/jboss/test/metatype/values/factory/test/CompositeValueFactoryUnitTestCase.java 2008-11-24 08:41:56 UTC (rev 81467)
@@ -38,6 +38,7 @@
import org.jboss.metatype.api.values.MetaValue;
import org.jboss.metatype.api.values.SimpleValueSupport;
import org.jboss.metatype.plugins.types.MutableCompositeMetaType;
+import org.jboss.test.metatype.types.support.MetaMappingUsage;
import org.jboss.test.metatype.values.factory.support.TestIgnoredCompositeItem;
import org.jboss.test.metatype.values.factory.support.TestRecursiveComposite;
import org.jboss.test.metatype.values.factory.support.TestRenamedCompositeItem;
@@ -206,4 +207,27 @@
getLog().debug("Composite Value: " + actual);
assertEquals(expected, actual);
}
+
+ /**
+ * A test of the MetaMapping annotation controlling the MetaType of a Type
+ */
+ public void testMetaMappingComposite()
+ throws Exception
+ {
+ Type type = MetaMappingUsage.class;
+ MetaMappingUsage values = new MetaMappingUsage();
+ values.setName("testMetaMappingComposite");
+ values.setType("java.lang.String");
+ values.setValue("testMetaMappingComposite-value");
+
+ MapCompositeValueSupport expected = new MapCompositeValueSupport(SimpleMetaType.STRING);
+ expected.put("name", SimpleValueSupport.wrap("testMetaMappingComposite"));
+ expected.put("type", SimpleValueSupport.wrap("java.lang.String"));
+ expected.put("value", SimpleValueSupport.wrap("testMetaMappingComposite-value"));
+
+ MetaValue result = createMetaValue(values, type);
+ CompositeValue actual = assertInstanceOf(result, CompositeValue.class);
+ getLog().debug("Composite Value: " + actual);
+ assertEquals(expected, actual);
+ }
}
More information about the jboss-cvs-commits
mailing list