[jboss-cvs] JBossAS SVN: r85721 - in projects/jboss-man/branches/Branch_2_1/metatype/src: main/java/org/jboss/metatype/plugins/values/mappers and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Mar 11 03:19:23 EDT 2009


Author: scott.stark at jboss.org
Date: 2009-03-11 03:19:22 -0400 (Wed, 11 Mar 2009)
New Revision: 85721

Added:
   projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/plugins/types/ObjectNameTypeBuilder.java
   projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/PropertiesCompositeObjectNameMetaMapper.java
   projects/jboss-man/branches/Branch_2_1/metatype/src/test/java/org/jboss/test/metatype/values/factory/test/ObjectNameUnitTestCase.java
Log:
JBMAN-63, ObjectName handling

Added: projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/plugins/types/ObjectNameTypeBuilder.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/plugins/types/ObjectNameTypeBuilder.java	                        (rev 0)
+++ projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/plugins/types/ObjectNameTypeBuilder.java	2009-03-11 07:19:22 UTC (rev 85721)
@@ -0,0 +1,59 @@
+/*
+ * 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.types;
+
+import javax.management.ObjectName;
+
+import org.jboss.metatype.api.types.CompositeMetaType;
+import org.jboss.metatype.api.types.ImmutableCompositeMetaType;
+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.spi.types.MetaTypeBuilder;
+
+/**
+ * A type builder for the javax.management.ObjectName type
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class ObjectNameTypeBuilder implements MetaTypeBuilder
+{
+   /** The singleton instance */
+   public static final ObjectNameTypeBuilder INSTANCE = new ObjectNameTypeBuilder();
+   
+   /** The MetaType for Class */
+   public static final CompositeMetaType META_TYPE = new ImmutableCompositeMetaType(
+       ObjectName.class.getName(), 
+       ObjectName.class.getName(), 
+       new String[] { "domain", "keyPropertyList" }, 
+       new String[] { "The domain name", "The unordered set of keys and associated values" },
+       new MetaType[] { SimpleMetaType.STRING, PropertiesMetaType.INSTANCE }
+   );
+
+   public MetaType buildMetaType()
+   {
+      // TODO Auto-generated method stub
+      return META_TYPE;
+   }
+
+}

Added: projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/PropertiesCompositeObjectNameMetaMapper.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/PropertiesCompositeObjectNameMetaMapper.java	                        (rev 0)
+++ projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/PropertiesCompositeObjectNameMetaMapper.java	2009-03-11 07:19:22 UTC (rev 85721)
@@ -0,0 +1,95 @@
+/*
+ * 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.Hashtable;
+
+import javax.management.ObjectName;
+
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.CompositeValueSupport;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.PropertiesMetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.metatype.plugins.types.ObjectNameTypeBuilder;
+import org.jboss.metatype.spi.values.MetaMapper;
+
+/**
+ * A MetaMapper for ObjectName to CompositeValue using domain, keyPropertyList
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class PropertiesCompositeObjectNameMetaMapper extends MetaMapper<ObjectName>
+{
+
+   @Override
+   public MetaType getMetaType()
+   {
+      return ObjectNameTypeBuilder.META_TYPE;
+   }
+   @Override
+   public Type mapToType()
+   {
+      return ObjectName.class;
+   }
+
+   @Override
+   public MetaValue createMetaValue(MetaType metaType, ObjectName object)
+   {
+      String[] itemNames = {"domain", "keyPropertyList"};
+      PropertiesMetaValue keyValues = new PropertiesMetaValue();
+      for(Object key : object.getKeyPropertyList().keySet())
+      {
+         Object value = object.getKeyProperty((String)key);
+         keyValues.put(key, value);
+      }
+      MetaValue[] itemValues = {SimpleValueSupport.wrap(object.getDomain()), };
+      CompositeValueSupport mv = new CompositeValueSupport(ObjectNameTypeBuilder.META_TYPE,
+            itemNames, itemValues);
+      return mv;
+   }
+
+   @Override
+   public ObjectName unwrapMetaValue(MetaValue metaValue)
+   {
+      CompositeValue compositeValue = (CompositeValue) metaValue;
+      SimpleValue domain = (SimpleValue) compositeValue.get("domain");
+      String domainUnwrap = domain.toString();
+      MetaValue keys = compositeValue.get("keyPropertyList");
+      Hashtable keysUnwrap = null;
+      if(keys instanceof PropertiesMetaValue)
+         keysUnwrap = (PropertiesMetaValue) keys;
+      try
+      {
+         ObjectName name = new ObjectName(domainUnwrap, keysUnwrap);
+         return name;
+      }
+      catch(Exception e)
+      {
+         throw new IllegalArgumentException(e);
+      }
+   }
+
+}

Added: projects/jboss-man/branches/Branch_2_1/metatype/src/test/java/org/jboss/test/metatype/values/factory/test/ObjectNameUnitTestCase.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/metatype/src/test/java/org/jboss/test/metatype/values/factory/test/ObjectNameUnitTestCase.java	                        (rev 0)
+++ projects/jboss-man/branches/Branch_2_1/metatype/src/test/java/org/jboss/test/metatype/values/factory/test/ObjectNameUnitTestCase.java	2009-03-11 07:19:22 UTC (rev 85721)
@@ -0,0 +1,96 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.values.factory.test;
+
+import java.util.Hashtable;
+
+import javax.management.ObjectName;
+
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.PropertiesMetaValue;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class ObjectNameUnitTestCase extends AbstractMetaValueFactoryTest
+{
+
+   public ObjectNameUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   /**
+    * Test ObjectName(String, Hashtable)
+    * @throws Exception
+    */
+   public void testObjectNameMVCreation()
+      throws Exception
+   {
+      Hashtable keys = new Hashtable();
+      keys.put("key1", "value1");
+      keys.put("key1", "value1");
+      ObjectName on = new ObjectName("testObjectNameMVCreation", keys);
+      MetaValue mv = super.createMetaValue(on);
+      log.debug(mv);
+      assertTrue("is a CompositeValue", mv instanceof CompositeValue);
+
+      CompositeValue cv = (CompositeValue) mv;
+      MetaValue domainMV = cv.get("domain");
+      assertNotNull(domainMV);
+      assertTrue("domain is a STRING", domainMV.getMetaType() == SimpleMetaType.STRING);
+      MetaValue keyPropertyList = cv.get("keyPropertyList");
+      assertNotNull(keyPropertyList);
+      assertTrue("keyPropertyList is a Properties", keyPropertyList instanceof PropertiesMetaValue);
+
+      ObjectName on2 = (ObjectName) super.unwrapMetaValue(mv);
+      assertEquals(on, on2);
+   }
+   /**
+    * Test ObjectName(String)
+    * @throws Exception
+    */
+   public void testObjectNameMVCreation2()
+      throws Exception
+   {
+      ObjectName on = new ObjectName("testObjectNameMVCreation2:key1=value1,key2=value2");
+      MetaValue mv = super.createMetaValue(on);
+      log.debug(mv);
+      assertTrue("is a CompositeValue", mv instanceof CompositeValue);
+
+      CompositeValue cv = (CompositeValue) mv;
+      MetaValue domainMV = cv.get("domain");
+      assertNotNull(domainMV);
+      assertTrue("domain is a STRING", domainMV.getMetaType() == SimpleMetaType.STRING);
+      MetaValue keyPropertyList = cv.get("keyPropertyList");
+      assertNotNull(keyPropertyList);
+      assertTrue("keyPropertyList is a Properties", keyPropertyList instanceof PropertiesMetaValue);
+
+      ObjectName on2 = (ObjectName) super.unwrapMetaValue(mv);
+      assertEquals(on, on2);
+   }
+
+
+}




More information about the jboss-cvs-commits mailing list