[jboss-cvs] JBossAS SVN: r81520 - in projects/jboss-man/branches/Branch_2_0: managed/src/main/java/org/jboss/managed/plugins and 9 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Nov 24 22:53:54 EST 2008


Author: scott.stark at jboss.org
Date: 2008-11-24 22:53:54 -0500 (Mon, 24 Nov 2008)
New Revision: 81520

Added:
   projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/support/ObjectNameBean.java
   projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/test/PropertyMetaMapperUnitTestCase.java
   projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/annotations/MetaMappingFactory.java
   projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/
   projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/ObjectNameMetaMapper.java
   projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/ObjectNameMetaMapperFactory.java
   projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/PropertiesObjectNameMetaMapper.java
   projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/StringObjectNameMetaMapper.java
   projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/spi/values/MetaMapperFactory.java
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/plugins/ManagedPropertyImpl.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/test/java/org/jboss/test/managed/factory/AbstractManagedObjectFactoryTest.java
   projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/test/SimpleManagedObjectFactoryUnitTestCase.java
   projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/values/PropertiesMetaValue.java
Log:
JBMAN-47, meta mapper factory and object name mappers

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-25 03:49:03 UTC (rev 81519)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java	2008-11-25 03:53:54 UTC (rev 81520)
@@ -154,14 +154,14 @@
     * 
     * @return the minimum value
     */
-   Comparable<?> getMinimumValue();
+   Comparable<? extends MetaValue> getMinimumValue();
 
    /**
     * Get the miximum value
     * 
     * @return the maximum value
     */
-   Comparable<?> getMaximumValue();
+   Comparable<? extends MetaValue> getMaximumValue();
 
    /**
     * Check whether this is a valid value
@@ -169,7 +169,7 @@
     * @param value the value
     * @return null for a valid value, an error message otherwise
     */
-   String checkValidValue(Serializable value);
+   String checkValidValue(MetaValue value);
    
    /**
     * Whether the property is mandatory

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-25 03:49:03 UTC (rev 81519)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/ManagedPropertyImpl.java	2008-11-25 03:53:54 UTC (rev 81520)
@@ -325,7 +325,7 @@
       setField(Fields.LEGAL_VALUES, (Serializable)values);
    }
 
-   public Comparable<?> getMinimumValue()
+   public Comparable<? extends MetaValue> getMinimumValue()
    {
       return getField(Fields.MINIMUM_VALUE, Comparable.class);
    }
@@ -335,14 +335,15 @@
     * 
     * @param value the value
     */
-   public void setMinimumValue(Comparable<?> value)
+   public void setMinimumValue(Comparable<? extends MetaValue> value)
    {
       setField(Fields.MINIMUM_VALUE, (Serializable)value);
    }
 
-   public Comparable<?> getMaximumValue()
+   public Comparable<? extends MetaValue> getMaximumValue()
    {
-      return getField(Fields.MAXIMUM_VALUE, Comparable.class);
+      Comparable<? extends MetaValue> field = getField(Fields.MAXIMUM_VALUE, Comparable.class);
+      return field;
    }
 
    /**
@@ -350,12 +351,12 @@
     * 
     * @param value the value
     */
-   public void setMaximumValue(Comparable<?> value)
+   public void setMaximumValue(Comparable<? extends MetaValue> value)
    {
       setField(Fields.MAXIMUM_VALUE, (Serializable)value);
    }
 
-   public String checkValidValue(Serializable value)
+   public String checkValidValue(MetaValue value)
    {
       // TODO check min/max/etc.
       return null;

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-25 03:49:03 UTC (rev 81519)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java	2008-11-25 03:53:54 UTC (rev 81520)
@@ -74,6 +74,7 @@
 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.annotations.MetaMappingFactory;
 import org.jboss.metatype.api.types.ArrayMetaType;
 import org.jboss.metatype.api.types.CollectionMetaType;
 import org.jboss.metatype.api.types.GenericMetaType;
@@ -81,6 +82,7 @@
 import org.jboss.metatype.api.types.MetaTypeFactory;
 import org.jboss.metatype.api.values.MetaValueFactory;
 import org.jboss.metatype.spi.values.MetaMapper;
+import org.jboss.metatype.spi.values.MetaMapperFactory;
 import org.jboss.reflect.spi.AnnotatedInfo;
 import org.jboss.reflect.spi.ClassInfo;
 import org.jboss.reflect.spi.MethodInfo;
@@ -636,6 +638,24 @@
                MetaType metaType = null;
                MetaMapper<?> metaMapper = null;
                MetaMapping metaMapping = getAnnotation(MetaMapping.class, propertyInfo, metaData);
+               MetaMappingFactory metaMappingFactory = getAnnotation(MetaMappingFactory.class, propertyInfo, metaData);
+               if(metaMappingFactory != null)
+               {
+                  Class<? extends MetaMapperFactory<?>> mmfClass = metaMappingFactory.value();
+                  try
+                  {
+                     MetaMapperFactory<?> mmf = mmfClass.newInstance();
+                     String[] args = metaMappingFactory.args();
+                     if(args.length > 0)
+                        metaMapper = mmf.newInstance(args);
+                     else
+                        metaMapper = mmf.newInstance();
+                  }
+                  catch(Exception e)
+                  {
+                     log.debug("Failed to create MetaMapperFactory: "+metaMappingFactory, e);
+                  }
+               }
                if(metaMapping != null)
                {
                   // Use the mapping for the type
@@ -643,13 +663,15 @@
                   try
                   {
                      metaMapper = mapperClass.newInstance();
-                     metaType = metaMapper.getMetaType();
                   }
                   catch(Exception e)
                   {
                      log.debug("Failed to create MetaMapper: "+metaMapping, e);
                   }
                }
+               if(metaMapper != null)
+                  metaType = metaMapper.getMetaType();
+
                // Determine meta type based on property type
                if(metaType == null)
                {

Modified: projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/AbstractManagedObjectFactoryTest.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/AbstractManagedObjectFactoryTest.java	2008-11-25 03:49:03 UTC (rev 81519)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/AbstractManagedObjectFactoryTest.java	2008-11-25 03:53:54 UTC (rev 81520)
@@ -74,7 +74,7 @@
     * @param object the object
     * @return the managed object
     */
-   protected ManagedObject initManagedObject(Serializable object)
+   protected ManagedObject initManagedObject(Object object)
    {
       ManagedObject result = getMOF().initManagedObject(object, null, null);
       getLog().debug("Inited managed: " + result + " for object=" + Strings.defaultToString(object));

Added: projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/support/ObjectNameBean.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/support/ObjectNameBean.java	                        (rev 0)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/support/ObjectNameBean.java	2008-11-25 03:53:54 UTC (rev 81520)
@@ -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.managed.factory.support;
+
+import javax.management.ObjectName;
+
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementProperty;
+import org.jboss.metatype.api.annotations.MetaMapping;
+import org.jboss.metatype.api.annotations.MetaMappingFactory;
+import org.jboss.metatype.plugins.values.mappers.ObjectNameMetaMapper;
+import org.jboss.metatype.plugins.values.mappers.ObjectNameMetaMapperFactory;
+import org.jboss.metatype.plugins.values.mappers.PropertiesObjectNameMetaMapper;
+import org.jboss.metatype.plugins.values.mappers.StringObjectNameMetaMapper;
+
+/**
+ * Test bean for validating MetaMapping on managed properties
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+ at ManagementObject
+public class ObjectNameBean
+{
+   private ObjectName nameAsString;
+   private ObjectName nameAsComposite;
+   private ObjectName nameAsCompositeFixedKeys;
+   private ObjectName nameAsProperties;
+
+   @ManagementProperty()
+   @MetaMapping(StringObjectNameMetaMapper.class)
+   public ObjectName getNameAsString()
+   {
+      return nameAsString;
+   }
+   public void setNameAsString(ObjectName nameAsString)
+   {
+      this.nameAsString = nameAsString;
+   }
+
+   @ManagementProperty()
+   @MetaMapping(ObjectNameMetaMapper.class)
+   public ObjectName getNameAsComposite()
+   {
+      return nameAsComposite;
+   }
+   public void setNameAsComposite(ObjectName nameAsComposite)
+   {
+      this.nameAsComposite = nameAsComposite;
+   }
+
+   @ManagementProperty()
+   @MetaMapping(PropertiesObjectNameMetaMapper.class)
+   public ObjectName getNameAsProperties()
+   {
+      return nameAsProperties;
+   }
+   public void setNameAsProperties(ObjectName nameAsProperties)
+   {
+      this.nameAsProperties = nameAsProperties;
+   }
+   @ManagementProperty()
+   @MetaMappingFactory(value=ObjectNameMetaMapperFactory.class, args={"key1", "The first key", "key2", "The second key"})
+   public ObjectName getNameAsCompositeFixedKeys()
+   {
+      return nameAsCompositeFixedKeys;
+   }
+   public void setNameAsCompositeFixedKeys(ObjectName nameAsCompositeFixedKeys)
+   {
+      this.nameAsCompositeFixedKeys = nameAsCompositeFixedKeys;
+   }   
+}


Property changes on: projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/support/ObjectNameBean.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision

Added: projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/test/PropertyMetaMapperUnitTestCase.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/test/PropertyMetaMapperUnitTestCase.java	                        (rev 0)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/test/PropertyMetaMapperUnitTestCase.java	2008-11-25 03:53:54 UTC (rev 81520)
@@ -0,0 +1,121 @@
+/*
+ * 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.test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.ObjectName;
+
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.metatype.api.types.CompositeMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.PropertiesMetaType;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.MapCompositeValueSupport;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.PropertiesMetaValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.metatype.spi.values.MetaMapper;
+import org.jboss.test.managed.factory.AbstractManagedObjectFactoryTest;
+import org.jboss.test.managed.factory.support.ObjectNameBean;
+
+/**
+ * Tests of specifying a MetaMapper on managed properties
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class PropertyMetaMapperUnitTestCase extends AbstractManagedObjectFactoryTest
+{
+
+   public PropertyMetaMapperUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testObjectNameBean()
+      throws Exception
+   {
+      ObjectNameBean bean = new ObjectNameBean();
+      bean.setNameAsString(new ObjectName("testObjectNameBean:key1=value1,key2=value2"));
+      bean.setNameAsComposite(new ObjectName("nameAsComposite:key1=value1,key2=value2"));
+      bean.setNameAsCompositeFixedKeys(new ObjectName("nameAsCompositeFixedKeys:key1=value1,key2=value2"));
+      bean.setNameAsProperties(new ObjectName("nameAsProperties:key1=value1,key2=value2"));
+
+      // A String type for ObjectName
+      ManagedObject managedObject = super.initManagedObject(bean);
+      ManagedProperty nameAsString = managedObject.getProperty("nameAsString");
+      assertTrue(nameAsString.getTransientAttachment(MetaMapper.class) != null);
+      MetaType nameAsStringType = nameAsString.getMetaType();
+      assertEquals(SimpleMetaType.STRING, nameAsStringType);
+      nameAsString.setValue(SimpleValueSupport.wrap("testObjectNameBean-update:key1=value1,key2=value2"));
+      ObjectName nameAsStringON = bean.getNameAsString();
+      assertEquals("testObjectNameBean-update", nameAsStringON.getDomain());
+
+      // A CompositeMetaType for ObjectName
+      ManagedProperty nameAsComposite = managedObject.getProperty("nameAsComposite");
+      assertTrue(nameAsComposite.getTransientAttachment(MetaMapper.class) != null);
+      MetaType nameAsCompositeType = nameAsComposite.getMetaType();
+      assertTrue(nameAsCompositeType instanceof CompositeMetaType);
+      Map<String, MetaValue> map = new HashMap<String, MetaValue>();
+      map.put("domain", SimpleValueSupport.wrap("nameAsComposite-update"));
+      map.put("key1", SimpleValueSupport.wrap("value1"));
+      map.put("key2", SimpleValueSupport.wrap("value2"));
+      map.put("key3", SimpleValueSupport.wrap("value3"));
+      MapCompositeValueSupport value = new MapCompositeValueSupport(map, SimpleMetaType.STRING);
+      nameAsComposite.setValue(value);
+      ObjectName nameAsCompositeON = bean.getNameAsComposite();
+      assertEquals("nameAsComposite-update:key1=value1,key2=value2,key3=value3", nameAsCompositeON.getCanonicalName());
+
+      // A CompositeMetaType for ObjectName
+      ManagedProperty nameAsCompositeFixedKeys = managedObject.getProperty("nameAsCompositeFixedKeys");
+      assertTrue(nameAsCompositeFixedKeys.getTransientAttachment(MetaMapper.class) != null);
+      MetaType nameAsCompositeFixedKeysType = nameAsCompositeFixedKeys.getMetaType();
+      assertTrue(nameAsCompositeFixedKeysType instanceof CompositeMetaType);
+      CompositeMetaType nameAsCompositeFixedKeysCMT = (CompositeMetaType) nameAsCompositeFixedKeysType;
+      assertEquals("The first key", nameAsCompositeFixedKeysCMT.getDescription("key1"));
+      assertEquals("The second key", nameAsCompositeFixedKeysCMT.getDescription("key2"));
+      map = new HashMap<String, MetaValue>();
+      map.put("domain", SimpleValueSupport.wrap("nameAsCompositeFixedKeys-update"));
+      map.put("key1", SimpleValueSupport.wrap("value1"));
+      map.put("key2", SimpleValueSupport.wrap("value2"));
+      map.put("key3", SimpleValueSupport.wrap("value3"));
+      value = new MapCompositeValueSupport(map, SimpleMetaType.STRING);
+      nameAsCompositeFixedKeys.setValue(value);
+      ObjectName nameAsCompositeFixedKeysON = bean.getNameAsCompositeFixedKeys();
+      assertEquals("nameAsCompositeFixedKeys-update:key1=value1,key2=value2,key3=value3", nameAsCompositeFixedKeysON.getCanonicalName());
+
+      ManagedProperty nameAsProperties = managedObject.getProperty("nameAsProperties");
+      assertTrue(nameAsProperties.getTransientAttachment(MetaMapper.class) != null);
+      MetaType nameAsPropertiesType = nameAsProperties.getMetaType();
+      assertTrue(nameAsPropertiesType instanceof PropertiesMetaType);
+      PropertiesMetaValue props = new PropertiesMetaValue();
+      props.put("domain", "nameAsProperties-update");
+      props.put("key1", "value1");
+      props.put("key2", "value2");
+      props.put("key3", "value3");
+      nameAsProperties.setValue(props);
+      ObjectName nameAsPropertiesON = bean.getNameAsProperties();
+      assertEquals("nameAsProperties-update:key1=value1,key2=value2,key3=value3", nameAsPropertiesON.getCanonicalName());
+   }
+}

Modified: projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/test/SimpleManagedObjectFactoryUnitTestCase.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/test/SimpleManagedObjectFactoryUnitTestCase.java	2008-11-25 03:49:03 UTC (rev 81519)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/test/SimpleManagedObjectFactoryUnitTestCase.java	2008-11-25 03:53:54 UTC (rev 81520)
@@ -38,7 +38,8 @@
  * SimpleManagedObjectFactoryUnitTestCase.
  * 
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
  */
 public class SimpleManagedObjectFactoryUnitTestCase extends AbstractManagedObjectFactoryTest
 {


Property changes on: projects/jboss-man/branches/Branch_2_0/managed/src/test/java/org/jboss/test/managed/factory/test/SimpleManagedObjectFactoryUnitTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision

Added: projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/annotations/MetaMappingFactory.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/annotations/MetaMappingFactory.java	                        (rev 0)
+++ projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/annotations/MetaMappingFactory.java	2008-11-25 03:53:54 UTC (rev 81520)
@@ -0,0 +1,42 @@
+/*
+ * 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.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.jboss.metatype.spi.values.MetaMapperFactory;
+
+/**
+ * An annotation for specifying a MetaMapperFactory
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+ at Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface MetaMappingFactory
+{
+   Class<? extends MetaMapperFactory<?>> value();
+   String[] args() default {};
+}


Property changes on: projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/annotations/MetaMappingFactory.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision

Modified: 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	2008-11-25 03:49:03 UTC (rev 81519)
+++ projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/api/values/PropertiesMetaValue.java	2008-11-25 03:53:54 UTC (rev 81520)
@@ -21,6 +21,7 @@
  */
 package org.jboss.metatype.api.values;
 
+import java.util.Map;
 import java.util.Properties;
 
 import org.jboss.metatype.api.types.PropertiesMetaType;
@@ -43,7 +44,7 @@
     * @param props - the Properties to copy
     * @return PropertiesMetaValue
     */
-   public static PropertiesMetaValue wrap(Properties props)
+   public static PropertiesMetaValue wrap(Map<String,String> props)
    {
       PropertiesMetaValue value = new PropertiesMetaValue();
       value.putAll(props);

Added: projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/ObjectNameMetaMapper.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/ObjectNameMetaMapper.java	                        (rev 0)
+++ projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/ObjectNameMetaMapper.java	2008-11-25 03:53:54 UTC (rev 81520)
@@ -0,0 +1,125 @@
+/*
+ * 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.plugins.values.mappers;
+
+import java.lang.reflect.Type;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.management.ObjectName;
+
+import org.jboss.metatype.api.types.CompositeMetaType;
+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.plugins.types.MutableCompositeMetaType;
+import org.jboss.metatype.spi.values.MetaMapper;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class ObjectNameMetaMapper extends MetaMapper<ObjectName>
+{
+   CompositeMetaType type;
+
+   public ObjectNameMetaMapper()
+   {
+      type = new MutableCompositeMetaType(ObjectName.class.getName(), "JMX ObjectName");
+   }
+   public ObjectNameMetaMapper(String... args)
+   {
+      MutableCompositeMetaType mcmt = new MutableCompositeMetaType(ObjectName.class.getName(), "JMX ObjectName");
+      if(((args.length %2) == 0) == false)
+         throw new IllegalStateException("args counts must be 2*n for n key,key-description pairs");
+      mcmt.addItem("domain", "the object name domain", SimpleMetaType.STRING);
+      for(int n = 0; n < args.length; n += 2)
+      {
+         String key = args[n];
+         String description = args[n+1];
+         mcmt.addItem(key, description, SimpleMetaType.STRING);
+      }
+      mcmt.freeze();
+      type = mcmt;
+   }
+
+   @Override
+   public MetaType getMetaType()
+   {
+      return type;
+   }
+
+   @Override
+   public Type mapToType()
+   {
+      return ObjectName.class;
+   }
+
+   @Override
+   public MetaValue createMetaValue(MetaType metaType, ObjectName object)
+   {
+      String domain = object.getDomain();
+      Map<String, String> props = object.getKeyPropertyList();
+      Map<String, MetaValue> metaProps = new HashMap<String, MetaValue>();
+      metaProps.put("domain", SimpleValueSupport.wrap(domain));
+      for(Entry<String,String> entry : props.entrySet())
+      {
+         metaProps.put(entry.getKey(), SimpleValueSupport.wrap(entry.getValue()));
+      }
+      MapCompositeValueSupport map = new MapCompositeValueSupport(metaProps, SimpleMetaType.STRING);
+      return map;
+   }
+
+   @Override
+   public ObjectName unwrapMetaValue(MetaValue metaValue)
+   {
+      CompositeValue cv = (CompositeValue) metaValue;
+      String domain = null;
+      Hashtable<String, String> props = new Hashtable<String, String>();
+      for(String key : cv.getMetaType().itemSet())
+      {
+         SimpleValue svalue = (SimpleValue) cv.get(key);
+         String value = (String) svalue.getValue();
+         if(key.equalsIgnoreCase("domain"))
+            domain = value;
+         else
+            props.put(key, value);
+      }
+
+      try
+      {
+         ObjectName name = new ObjectName(domain, props);
+         return name;
+      }
+      catch(Exception e)
+      {
+         throw new IllegalArgumentException("Failed to build ObjectName from MetaValue: "+metaValue, e);
+      }
+   }
+
+}

Added: projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/ObjectNameMetaMapperFactory.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/ObjectNameMetaMapperFactory.java	                        (rev 0)
+++ projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/ObjectNameMetaMapperFactory.java	2008-11-25 03:53:54 UTC (rev 81520)
@@ -0,0 +1,47 @@
+/*
+ * 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.plugins.values.mappers;
+
+import javax.management.ObjectName;
+
+import org.jboss.metatype.spi.values.MetaMapper;
+import org.jboss.metatype.spi.values.MetaMapperFactory;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class ObjectNameMetaMapperFactory
+   implements MetaMapperFactory<ObjectName>
+{
+
+   public MetaMapper<ObjectName> newInstance()
+   {
+      return new ObjectNameMetaMapper();
+   }
+
+   public MetaMapper<ObjectName> newInstance(String... args)
+   {
+      return new ObjectNameMetaMapper(args);
+   }
+
+}

Added: projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/PropertiesObjectNameMetaMapper.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/PropertiesObjectNameMetaMapper.java	                        (rev 0)
+++ projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/PropertiesObjectNameMetaMapper.java	2008-11-25 03:53:54 UTC (rev 81520)
@@ -0,0 +1,109 @@
+/*
+ * 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.plugins.values.mappers;
+
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.ObjectName;
+
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.PropertiesMetaType;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.PropertiesMetaValue;
+import org.jboss.metatype.spi.values.MetaMapper;
+
+/**
+ * An ObjectName MetaMapper that maps to a PropertiesMetaType/PropertiesMetaValue
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class PropertiesObjectNameMetaMapper extends MetaMapper<ObjectName>
+{
+   PropertiesMetaType type;
+
+   public PropertiesObjectNameMetaMapper()
+   {
+      this((String)null);
+   }
+   public PropertiesObjectNameMetaMapper(String... args)
+   {
+      Map<String, String> propertyNameDescriptions = Collections.emptyMap();
+      if(args != null)
+      {
+         if(((args.length %2) == 0) == false)
+            throw new IllegalStateException("args counts must be 2*n for n key,key-description pairs");
+         propertyNameDescriptions = new HashMap<String,String>();
+         propertyNameDescriptions.put("domain", "the object name domain");
+         for(int n = 0; n < args.length; n += 2)
+         {
+            String key = args[n];
+            String description = args[n+1];
+            propertyNameDescriptions.put(key, description);
+         }
+      }
+
+      type = new PropertiesMetaType("java.util.Properties", propertyNameDescriptions);
+   }
+
+   @Override
+   public MetaType getMetaType()
+   {
+      return type;
+   }
+
+   @Override
+   public Type mapToType()
+   {
+      return ObjectName.class;
+   }
+
+   @Override
+   public MetaValue createMetaValue(MetaType metaType, ObjectName object)
+   {
+      String domain = object.getDomain();
+      Map<String, String> props = object.getKeyPropertyList();
+      PropertiesMetaValue map = PropertiesMetaValue.wrap(props);
+      map.put("domain", domain);
+      return map;
+   }
+
+   @Override
+   public ObjectName unwrapMetaValue(MetaValue metaValue)
+   {
+      PropertiesMetaValue map = (PropertiesMetaValue) metaValue;
+      String domain = (String) map.remove("domain");
+
+      try
+      {
+         ObjectName name = new ObjectName(domain, map);
+         return name;
+      }
+      catch(Exception e)
+      {
+         throw new IllegalArgumentException("Failed to build ObjectName from MetaValue: "+metaValue, e);
+      }
+   }
+
+}


Property changes on: projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/PropertiesObjectNameMetaMapper.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision

Added: projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/StringObjectNameMetaMapper.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/StringObjectNameMetaMapper.java	                        (rev 0)
+++ projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/StringObjectNameMetaMapper.java	2008-11-25 03:53:54 UTC (rev 81520)
@@ -0,0 +1,78 @@
+/*
+ * 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.plugins.values.mappers;
+
+import java.lang.reflect.Type;
+
+import javax.management.ObjectName;
+
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.SimpleMetaType;
+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 mapper for String forms of javax.management.ObjectName values to a
+ * SimpleMetaType.STRING/SimpleValue
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class StringObjectNameMetaMapper extends MetaMapper<ObjectName>
+{
+
+   @Override
+   public MetaType getMetaType()
+   {
+      return SimpleMetaType.STRING;
+   }
+   @Override
+   public Type mapToType()
+   {
+      return ObjectName.class;
+   }
+
+   @Override
+   public MetaValue createMetaValue(MetaType metaType, ObjectName object)
+   {
+      String str = object.getCanonicalName();
+      return SimpleValueSupport.wrap(str);
+   }
+
+   @Override
+   public ObjectName unwrapMetaValue(MetaValue metaValue)
+   {
+      SimpleValue sv = (SimpleValue) metaValue;
+      String str = sv.getValue().toString();
+      try
+      {
+         return new ObjectName(str);
+      }
+      catch(Exception e)
+      {
+         throw new IllegalArgumentException(e);
+      }
+   }
+
+}


Property changes on: projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/StringObjectNameMetaMapper.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision

Added: projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/spi/values/MetaMapperFactory.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/spi/values/MetaMapperFactory.java	                        (rev 0)
+++ projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/spi/values/MetaMapperFactory.java	2008-11-25 03:53:54 UTC (rev 81520)
@@ -0,0 +1,44 @@
+/*
+ * 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.spi.values;
+
+/**
+ * A factory interface for creating MetaMappers
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public interface MetaMapperFactory<T>
+{
+   /**
+    * Create a MetaMapper instance
+    * @return the MetaMapper
+    */
+   MetaMapper<T> newInstance();
+   /**
+    * Create a MetaMapper instance using the specified String[]
+    * @param args - String[] for use by the factory
+    * @return the MetaMapper
+    * @throws IllegalArgumentException if the args is invalid
+    */
+   MetaMapper<T> newInstance(String...args);
+}


Property changes on: projects/jboss-man/branches/Branch_2_0/metatype/src/main/java/org/jboss/metatype/spi/values/MetaMapperFactory.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision




More information about the jboss-cvs-commits mailing list