[jboss-cvs] JBossAS SVN: r86034 - in projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype: api/values and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Mar 18 02:48:48 EDT 2009


Author: scott.stark at jboss.org
Date: 2009-03-18 02:48:48 -0400 (Wed, 18 Mar 2009)
New Revision: 86034

Added:
   projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/plugins/types/ObjectNameTypeBuilder.java
   projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/PropertiesCompositeObjectNameMetaMapper.java
Modified:
   projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/AbstractMetaType.java
   projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/MetaType.java
   projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/PropertiesMetaType.java
   projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/values/PropertiesMetaValue.java
   projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/plugins/types/DefaultMetaTypeFactory.java
   projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/plugins/values/DefaultMetaValueFactory.java
   projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/ObjectNameMetaMapper.java
Log:
JBMAN-63, ObjectName handling

Modified: projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/AbstractMetaType.java
===================================================================
--- projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/AbstractMetaType.java	2009-03-18 06:40:58 UTC (rev 86033)
+++ projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/AbstractMetaType.java	2009-03-18 06:48:48 UTC (rev 86034)
@@ -163,6 +163,11 @@
       return false;
    }
 
+   public boolean isProperties()
+   {
+      return false;
+   }
+
    public abstract boolean isValue(Object obj);
 
    /**

Modified: projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/MetaType.java
===================================================================
--- projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/MetaType.java	2009-03-18 06:40:58 UTC (rev 86033)
+++ projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/MetaType.java	2009-03-18 06:48:48 UTC (rev 86034)
@@ -183,6 +183,13 @@
    boolean isTable();
 
    /**
+    * Return whether the type is a PropertiesMetaType type.
+    * @see PropertiesMetaType
+    * @return true if type is a PropertiesMetaType
+    */
+   boolean isProperties();
+
+   /**
     * Whether the passed value is one of those described by this meta type.
     *
     * @param obj the object to test

Modified: projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/PropertiesMetaType.java
===================================================================
--- projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/PropertiesMetaType.java	2009-03-18 06:40:58 UTC (rev 86033)
+++ projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/PropertiesMetaType.java	2009-03-18 06:48:48 UTC (rev 86034)
@@ -33,7 +33,7 @@
  * A MetaType for java.util.Properties
  * 
  * @author Scott.Stark at jboss.org
- * @version $Revision:$
+ * @version $Revision$
  */
 public class PropertiesMetaType extends AbstractMetaType
 {
@@ -71,7 +71,13 @@
    {
       return propertyNameDescriptions.get(name);
    }
+   
    @Override
+   public boolean isProperties()
+   {
+      return true;
+   }
+   @Override
    public boolean isValue(Object obj)
    {
       return obj instanceof PropertiesMetaValue;


Property changes on: projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/types/PropertiesMetaType.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision

Modified: projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/values/PropertiesMetaValue.java
===================================================================
--- projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/values/PropertiesMetaValue.java	2009-03-18 06:40:58 UTC (rev 86033)
+++ projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/values/PropertiesMetaValue.java	2009-03-18 06:48:48 UTC (rev 86034)
@@ -29,13 +29,13 @@
 /**
  * A mapping from the jdk Properties to a MetaValue
  * @author Scott.Stark at jboss.org
- * @version $Revision:$
+ * @version $Revision$
  */
 public class PropertiesMetaValue extends Properties
    implements MetaValue
 {
    private static final long serialVersionUID = 1;
-   private PropertiesMetaType type; 
+   private PropertiesMetaType type = PropertiesMetaType.INSTANCE; 
 
    /**
     * Build a PropertiesMetaValue from a Properties by copying all key/value


Property changes on: projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/api/values/PropertiesMetaValue.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision

Modified: projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/plugins/types/DefaultMetaTypeFactory.java
===================================================================
--- projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/plugins/types/DefaultMetaTypeFactory.java	2009-03-18 06:40:58 UTC (rev 86033)
+++ projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/plugins/types/DefaultMetaTypeFactory.java	2009-03-18 06:48:48 UTC (rev 86034)
@@ -33,6 +33,8 @@
 import java.util.Set;
 import java.util.WeakHashMap;
 
+import javax.management.ObjectName;
+
 import org.jboss.beans.info.spi.BeanInfo;
 import org.jboss.beans.info.spi.PropertyInfo;
 import org.jboss.config.plugins.property.PropertyConfiguration;
@@ -110,6 +112,7 @@
    {
       // Special types
       setBuilder(Class.class, ClassMetaTypeBuilder.INSTANCE);
+      setBuilder(ObjectName.class, ObjectNameTypeBuilder.INSTANCE);
    }
    
    @Override

Copied: projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/plugins/types/ObjectNameTypeBuilder.java (from rev 85721, projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/plugins/types/ObjectNameTypeBuilder.java)
===================================================================
--- projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/plugins/types/ObjectNameTypeBuilder.java	                        (rev 0)
+++ projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/plugins/types/ObjectNameTypeBuilder.java	2009-03-18 06:48:48 UTC (rev 86034)
@@ -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;
+   }
+
+}

Modified: projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/plugins/values/DefaultMetaValueFactory.java
===================================================================
--- projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/plugins/values/DefaultMetaValueFactory.java	2009-03-18 06:40:58 UTC (rev 86033)
+++ projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/plugins/values/DefaultMetaValueFactory.java	2009-03-18 06:48:48 UTC (rev 86034)
@@ -32,15 +32,19 @@
 import java.security.PrivilegedAction;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 import java.util.SortedSet;
 import java.util.Stack;
 import java.util.WeakHashMap;
 import java.util.Map.Entry;
 
+import javax.management.ObjectName;
+
 import org.jboss.beans.info.spi.BeanInfo;
 import org.jboss.beans.info.spi.PropertyInfo;
 import org.jboss.config.plugins.property.PropertyConfiguration;
@@ -53,6 +57,7 @@
 import org.jboss.metatype.api.types.MapCompositeMetaType;
 import org.jboss.metatype.api.types.MetaType;
 import org.jboss.metatype.api.types.MetaTypeFactory;
+import org.jboss.metatype.api.types.PropertiesMetaType;
 import org.jboss.metatype.api.types.SimpleMetaType;
 import org.jboss.metatype.api.types.TableMetaType;
 import org.jboss.metatype.api.values.ArrayValue;
@@ -69,6 +74,7 @@
 import org.jboss.metatype.api.values.MapCompositeValueSupport;
 import org.jboss.metatype.api.values.MetaValue;
 import org.jboss.metatype.api.values.MetaValueFactory;
+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.api.values.TableValue;
@@ -87,7 +93,7 @@
  * 
  * @author <a href="ales.justin at jboss.com">Ales Justin</a>
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
+ * @version $Revision$
  */
 public class DefaultMetaValueFactory extends MetaValueFactory
 {
@@ -737,13 +743,30 @@
       {
          BeanInfo beanInfo = configuration.getBeanInfo(typeName, cl);
          ClassInfo classInfo = beanInfo.getClassInfo();
+         Class<?> clazz = classInfo.getType();
          if (classInfo.isInterface())
          {
+            // Handle map specially
+            if (clazz.isAssignableFrom(Map.class))
+               return unwrapCompositeMap(compositeValue);
+
             InvocationHandler handler = createCompositeValueInvocationHandler(compositeValue);
-            Class<?> clazz = classInfo.getType();
             Class<?>[] interfaces = new Class[]{clazz};
             return Proxy.newProxyInstance(clazz.getClassLoader(), interfaces, handler);            
          }
+         else if(clazz.isAssignableFrom(ObjectName.class))
+         {
+            // TODO: this should be handled more generically
+            MetaValue domain = compositeValue.get("domain");
+            String domainUnwrap = (String) unwrap(domain, String.class);
+            MetaValue keys = compositeValue.get("keyPropertyList");
+            Hashtable keysUnwrap = null;
+            if(keys instanceof PropertiesMetaValue)
+               keysUnwrap = (PropertiesMetaValue) keys;
+            ObjectName name = new ObjectName(domainUnwrap, keysUnwrap);
+            return name;
+         }
+
          Object bean = createNewInstance(beanInfo);
          for (String name : compositeMetaType.itemSet())
          {
@@ -760,6 +783,19 @@
       }
    }
 
+   protected Map unwrapCompositeMap(CompositeValue compositeValue)
+   {
+      HashMap map = new HashMap();
+      CompositeMetaType metaType = compositeValue.getMetaType();
+      for(String key : metaType.itemSet())
+      {
+         MetaValue mv = compositeValue.get(key);
+         Object value = unwrap(mv);
+         map.put(key, value);
+      }
+      return map;
+   }
+
    /**
     * Create composite invocation handler.
     *
@@ -862,6 +898,37 @@
    }
 
    /**
+    * Create a PropertiesMetaValue
+    * @param metaType
+    * @param value
+    * @param mapping
+    * @return
+    */
+   protected MetaValue createPropertiesValue(PropertiesMetaType metaType,
+         Object value, Map<Object, MetaValue> mapping)
+   {
+      if (value == null)
+         return null;
+      if((value instanceof Hashtable) == false)
+         throw new IllegalArgumentException("PropertiesMetaType requires a java.lang.Properties value, value.class: "+value.getClass());
+
+      Hashtable pvalue = (Hashtable) value;
+      PropertiesMetaValue pmv = new PropertiesMetaValue();
+      for(Object key : pvalue.keySet())
+      {
+         if ((key instanceof String) == false)
+            throw new IllegalArgumentException("key("+key+") is not a String");
+         String skey = (String) key;
+         Object ovalue = pvalue.get(skey);
+         if ((key instanceof String) == false)
+            throw new IllegalArgumentException("value for key("+key+") is not a String, value.class: "+ovalue.getClass());
+         String svalue = (String) ovalue;
+         pmv.setProperty(skey, svalue);
+      }
+      return pmv;
+   }
+
+   /**
     * Create new instance.
     *
     * @param beanInfo the bean info
@@ -1036,6 +1103,8 @@
                result = createGenericValue((GenericMetaType) metaType, value, mapping);
             else if (metaType.isCollection())
                result = createCollectionValue((CollectionMetaType) metaType, value, mapping);
+            else if (metaType.isProperties())
+               result = createPropertiesValue((PropertiesMetaType) metaType, value, mapping);
             else
                throw new IllegalStateException("Unknown metaType: " + metaType);
          }


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

Modified: projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/ObjectNameMetaMapper.java
===================================================================
--- projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/ObjectNameMetaMapper.java	2009-03-18 06:40:58 UTC (rev 86033)
+++ projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/ObjectNameMetaMapper.java	2009-03-18 06:48:48 UTC (rev 86034)
@@ -104,6 +104,8 @@
       for(String key : cv.getMetaType().itemSet())
       {
          SimpleValue svalue = (SimpleValue) cv.get(key);
+         if(svalue == null)
+            continue;
          String value = (String) svalue.getValue();
          if(key.equalsIgnoreCase("domain"))
             domain = value;

Copied: projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/PropertiesCompositeObjectNameMetaMapper.java (from rev 85721, projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/PropertiesCompositeObjectNameMetaMapper.java)
===================================================================
--- projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/PropertiesCompositeObjectNameMetaMapper.java	                        (rev 0)
+++ projects/jboss-man/trunk/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/PropertiesCompositeObjectNameMetaMapper.java	2009-03-18 06:48:48 UTC (rev 86034)
@@ -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);
+      }
+   }
+
+}




More information about the jboss-cvs-commits mailing list