[jboss-cvs] JBossAS SVN: r69672 - in trunk: connector/src/main/org/jboss/resource/deployers/management and 10 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Feb 6 15:26:42 EST 2008
Author: scott.stark at jboss.org
Date: 2008-02-06 15:26:41 -0500 (Wed, 06 Feb 2008)
New Revision: 69672
Added:
trunk/connector/src/main/org/jboss/resource/deployers/management/LocalDSInstanceClassFactory.java
trunk/profileservice/src/main/org/jboss/managed/
trunk/profileservice/src/main/org/jboss/managed/plugins/
trunk/profileservice/src/main/org/jboss/managed/plugins/factory/
trunk/profileservice/src/main/org/jboss/managed/plugins/factory/AbstractInstanceClassFactory.java
trunk/profileservice/src/main/org/jboss/metatype/
trunk/profileservice/src/main/org/jboss/metatype/api/
trunk/profileservice/src/main/org/jboss/metatype/api/types/
trunk/profileservice/src/main/org/jboss/metatype/api/types/MapCompositeMetaType.java
trunk/profileservice/src/main/org/jboss/metatype/api/values/
trunk/profileservice/src/main/org/jboss/metatype/api/values/MapCompositeValueSupport.java
Modified:
trunk/connector/.project
trunk/connector/src/main/org/jboss/resource/deployers/management/ConnectionFactoryProperty.java
trunk/connector/src/main/org/jboss/resource/deployers/management/XADataSourceDeploymentMetaDataBuilder.java
trunk/connector/src/main/org/jboss/resource/metadata/mcf/LocalDataSourceDeploymentMetaData.java
trunk/connector/src/main/org/jboss/resource/metadata/mcf/ManagedConnectionFactoryDeploymentMetaData.java
trunk/connector/src/main/org/jboss/resource/metadata/mcf/NonXADataSourceDeploymentMetaData.java
trunk/connector/src/main/org/jboss/resource/metadata/mcf/TxConnectionFactoryDeploymentMetaData.java
trunk/connector/src/tests/org/jboss/tests/jca/managed/ManagedObjectTestCase.java
Log:
JBAS-5194, Change the properties type of ManagedProperty to use MapCompositeMetaType/MapCompositeValueSupport
Modified: trunk/connector/.project
===================================================================
--- trunk/connector/.project 2008-02-06 20:24:12 UTC (rev 69671)
+++ trunk/connector/.project 2008-02-06 20:26:41 UTC (rev 69672)
@@ -6,6 +6,7 @@
<project>common</project>
<project>j2ee</project>
<project>jmx</project>
+ <project>profileservice</project>
<project>security</project>
<project>server</project>
<project>system</project>
Modified: trunk/connector/src/main/org/jboss/resource/deployers/management/ConnectionFactoryProperty.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/deployers/management/ConnectionFactoryProperty.java 2008-02-06 20:24:12 UTC (rev 69671)
+++ trunk/connector/src/main/org/jboss/resource/deployers/management/ConnectionFactoryProperty.java 2008-02-06 20:26:41 UTC (rev 69672)
@@ -33,23 +33,27 @@
import org.jboss.managed.plugins.ManagedPropertyImpl;
import org.jboss.managed.plugins.factory.ManagedObjectFactoryBuilder;
import org.jboss.managed.spi.factory.InstanceClassFactory;
-import org.jboss.metatype.api.values.MetaValueFactory;
import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.types.CompositeMetaType;
+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.SimpleMetaType;
+import org.jboss.metatype.plugins.types.DefaultMetaTypeFactory;
import org.jboss.beans.info.spi.PropertyInfo;
import org.jboss.beans.info.spi.BeanInfo;
-import org.jboss.resource.metadata.mcf.ManagedConnectionFactoryPropertyMetaData;
/**
+ * Override ManagedPropertyImpl to properly define the type/items.
+ * TODO: should be part of the ManagementProperty enum?
+ *
* @author Scott.Stark at jboss.org
* @version $Revision$
*/
public class ConnectionFactoryProperty extends ManagedPropertyImpl
{
private static final long serialVersionUID = 1;
- private MetaValueFactory metaValueFactory;
private ManagedObjectFactory moFactory;
+ private MapCompositeMetaType type;
public ConnectionFactoryProperty(String s)
{
@@ -59,23 +63,26 @@
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 getMapMetaType();
+ return type;
}
public void setField(String fieldName, Serializable value)
{
if(Fields.META_TYPE.equals(fieldName))
- value = getMapMetaType();
+ value = type;
super.setField(fieldName, value);
}
@@ -95,30 +102,13 @@
Serializable attachment = getManagedObject().getAttachment();
if (attachment != null)
{
- MetaValue metaValue;
if (value instanceof MetaValue)
{
- Map<String,Map<String,String>> map = (Map<String, Map<String,String>>)getMetaValueFactory().unwrap((MetaValue)value, getMapType());
- List<ManagedConnectionFactoryPropertyMetaData> list = new ArrayList<ManagedConnectionFactoryPropertyMetaData>();
- for(String name : map.keySet())
- {
- Map<String,String> entry = map.get(name);
- ManagedConnectionFactoryPropertyMetaData prop = new ManagedConnectionFactoryPropertyMetaData();
- prop.setName(entry.get("name"));
- prop.setType(entry.get("type"));
- prop.setValue(entry.get("value"));
- list.add(prop);
- }
- metaValue = getMetaValueFactory().create(list, propertyInfo.getType());
+ MetaValue metaValue = (MetaValue) value;
+ InstanceClassFactory icf = getMOFactory().getInstanceClassFactory(attachment.getClass());
+ BeanInfo beanInfo = propertyInfo.getBeanInfo();
+ icf.setValue(beanInfo, this, attachment, metaValue);
}
- else
- {
- metaValue = getMetaValueFactory().create(value);
- }
-
- InstanceClassFactory icf = getMOFactory().getInstanceClassFactory(attachment.getClass());
- BeanInfo beanInfo = propertyInfo.getBeanInfo();
- icf.setValue(beanInfo, this, attachment, metaValue);
}
}
}
@@ -126,17 +116,10 @@
private ManagedObjectFactory getMOFactory()
{
if(moFactory == null)
- moFactory = ManagedObjectFactoryBuilder.create();
+ moFactory = ManagedObjectFactory.getInstance();
return moFactory;
}
- private MetaValueFactory getMetaValueFactory()
- {
- if(metaValueFactory == null)
- metaValueFactory = MetaValueFactory.getInstance();
- return metaValueFactory;
- }
-
public Serializable getValue()
{
Object o = super.getValue();
@@ -156,28 +139,4 @@
return managedProperty;
}
- private MetaType getMapMetaType()
- {
- Type type = getMapType();
- return MetaTypeFactory.getInstance().resolve(type);
- }
-
- private Type getMapType()
- {
- Type type;
- try
- {
- type = getClass().getMethod("compositeValueMap").getGenericReturnType();
- }
- catch(NoSuchMethodException e)
- {
- throw new IllegalStateException("Failed to find compoditeValueMap method.");
- }
- return type;
- }
-
- public Map<String,Map<String, String>> compositeValueMap()
- {
- return null;
- }
}
Added: trunk/connector/src/main/org/jboss/resource/deployers/management/LocalDSInstanceClassFactory.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/deployers/management/LocalDSInstanceClassFactory.java (rev 0)
+++ trunk/connector/src/main/org/jboss/resource/deployers/management/LocalDSInstanceClassFactory.java 2008-02-06 20:26:41 UTC (rev 69672)
@@ -0,0 +1,95 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, 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.resource.deployers.management;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.plugins.factory.AbstractInstanceClassFactory;
+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.SimpleValueSupport;
+import org.jboss.resource.metadata.mcf.DataSourceConnectionPropertyMetaData;
+import org.jboss.resource.metadata.mcf.LocalDataSourceDeploymentMetaData;
+
+/**
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class LocalDSInstanceClassFactory
+ extends AbstractInstanceClassFactory<LocalDataSourceDeploymentMetaData>
+{
+
+ public MetaValue getValue(BeanInfo beanInfo, ManagedProperty property,
+ LocalDataSourceDeploymentMetaData attachment)
+ {
+ MetaValue value = null;
+ if("connection-properties".equals(property.getName()))
+ {
+ MapCompositeValueSupport mapValue = new MapCompositeValueSupport(SimpleMetaType.STRING);
+ List<DataSourceConnectionPropertyMetaData> list = attachment.getDataSourceConnectionProperties();
+ if(list != null)
+ {
+ for(DataSourceConnectionPropertyMetaData prop : list)
+ {
+ MetaValue wrapped = SimpleValueSupport.wrap(prop.getValue());
+ mapValue.put(prop.getName(), wrapped);
+ }
+ }
+ value = mapValue;
+ }
+ else
+ {
+ value = super.getValue(beanInfo, property, attachment);
+ }
+ return value;
+ }
+
+ @Override
+ protected Object unwrapValue(BeanInfo beanInfo, ManagedProperty property,
+ MetaValue value)
+ {
+ if((value instanceof MapCompositeValueSupport) == false)
+ super.unwrapValue(beanInfo, property, value);
+
+ MapCompositeValueSupport mapValue = (MapCompositeValueSupport) value;
+ Object unwrapValue = null;
+ if("connection-properties".equals(property.getName()))
+ {
+ List<DataSourceConnectionPropertyMetaData> list = new ArrayList<DataSourceConnectionPropertyMetaData>();
+ for(String name : mapValue.getMetaType().keySet())
+ {
+ DataSourceConnectionPropertyMetaData prop = new DataSourceConnectionPropertyMetaData();
+ prop.setName(name);
+ String svalue = (String) getMetaValueFactory().unwrap(mapValue.get(name));
+ prop.setValue(svalue);
+ list.add(prop);
+ }
+ unwrapValue = list;
+ }
+ return unwrapValue;
+ }
+}
Property changes on: trunk/connector/src/main/org/jboss/resource/deployers/management/LocalDSInstanceClassFactory.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Modified: trunk/connector/src/main/org/jboss/resource/deployers/management/XADataSourceDeploymentMetaDataBuilder.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/deployers/management/XADataSourceDeploymentMetaDataBuilder.java 2008-02-06 20:24:12 UTC (rev 69671)
+++ trunk/connector/src/main/org/jboss/resource/deployers/management/XADataSourceDeploymentMetaDataBuilder.java 2008-02-06 20:26:41 UTC (rev 69672)
@@ -24,7 +24,6 @@
import java.io.Serializable;
import java.util.Map;
import java.util.List;
-import java.util.HashMap;
import java.util.ArrayList;
import java.lang.reflect.Type;
import java.lang.reflect.UndeclaredThrowableException;
@@ -32,8 +31,14 @@
import org.jboss.beans.info.spi.PropertyInfo;
import org.jboss.managed.api.ManagedProperty;
import org.jboss.managed.plugins.factory.AbstractManagedObjectFactory;
+import org.jboss.managed.spi.factory.InstanceClassFactory;
+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.MetaValueFactory;
+import org.jboss.resource.metadata.mcf.DataSourceConnectionPropertyMetaData;
+import org.jboss.resource.metadata.mcf.LocalDataSourceDeploymentMetaData;
+import org.jboss.resource.metadata.mcf.NonXADataSourceDeploymentMetaData;
import org.jboss.resource.metadata.mcf.XADataSourceDeploymentMetaData;
import org.jboss.resource.metadata.mcf.XAConnectionPropertyMetaData;
import org.jboss.resource.metadata.mcf.ManagedConnectionFactoryDeploymentMetaData;
@@ -41,6 +46,7 @@
/**
* @author <a href="mailto:alex at jboss.org">Alexey Loubyansky</a>
+ * @author Scott.Stark at jboss.org
* @version <tt>$Revision: $</tt>
*/
public class XADataSourceDeploymentMetaDataBuilder
@@ -82,12 +88,13 @@
List<XAConnectionPropertyMetaData> list = ds.getXADataSourceProperties();
if(list != null)
{
- Map<String, String> map = new HashMap<String, String>();
+ MapCompositeValueSupport map = new MapCompositeValueSupport(SimpleMetaType.STRING);
for(XAConnectionPropertyMetaData prop : list)
{
- map.put(prop.getName(), prop.getValue());
+ MetaValue svalue = metaValueFactory.create(prop.getValue());
+ map.put(prop.getName(), svalue);
}
- metaValue = metaValueFactory.create(map, mapType);
+ metaValue = map;
}
return metaValue;
}
@@ -99,42 +106,59 @@
List<ManagedConnectionFactoryPropertyMetaData> list = mcf.getManagedConnectionFactoryProperties();
if(list != null)
{
- Map<String,Map<String,String>> map = new HashMap<String,Map<String,String>>();
+ MapCompositeValueSupport map = new MapCompositeValueSupport(SimpleMetaType.STRING);
for(ManagedConnectionFactoryPropertyMetaData prop : list)
{
- Map<String,String> value = new HashMap<String,String>();
- value.put("name", prop.getName());
- value.put("type", prop.getType());
- value.put("value", prop.getValue());
- map.put(value.get("name"), value);
+ String name = prop.getName();
+ MetaValue svalue = metaValueFactory.create(prop.getValue());
+ map.put(name, svalue);
+ MetaValue stype = metaValueFactory.create(prop.getType());
+ map.put(name+".type", stype);
}
- metaValue = metaValueFactory.create(map, mapOfMapsType);
+ metaValue = map;
}
return metaValue;
}
+ if("connection-properties".equals(property.getName()))
+ {
+ MetaValue metaValue = null;
+ NonXADataSourceDeploymentMetaData dsmd = (NonXADataSourceDeploymentMetaData)object;
+ List<DataSourceConnectionPropertyMetaData> list = dsmd.getDataSourceConnectionProperties();
+ if(list != null)
+ {
+ MapCompositeValueSupport map = new MapCompositeValueSupport(SimpleMetaType.STRING);
+ for(DataSourceConnectionPropertyMetaData prop : list)
+ {
+ MetaValue svalue = metaValueFactory.create(prop.getValue());
+ map.put(prop.getName(), svalue);
+ }
+ metaValue = map;
+ }
+ return metaValue;
+ }
return super.getValue(beanInfo, property, object);
}
public void setValue(BeanInfo beanInfo, ManagedProperty property, Serializable object, MetaValue value)
{
+ if((value instanceof MapCompositeValueSupport) == false)
+ super.setValue(beanInfo, property, object, value);
+
+ MapCompositeValueSupport mapValue = (MapCompositeValueSupport) value;
if("xa-datasource-properties".equals(property.getName()))
{
String propName = getPropertyName(property);
PropertyInfo propertyInfo = beanInfo.getProperty(propName);
- Map<String, String> map = (Map<String, String>)metaValueFactory.unwrap(value, mapType);
-
List<XAConnectionPropertyMetaData> list = null;
- if(map != null)
+ list = new ArrayList<XAConnectionPropertyMetaData>();
+ for(String name : mapValue.getMetaType().keySet())
{
- list = new ArrayList<XAConnectionPropertyMetaData>();
- for(String name : map.keySet())
- {
- XAConnectionPropertyMetaData xaProp = new XAConnectionPropertyMetaData();
- xaProp.setName(name);
- xaProp.setValue(map.get(name));
- list.add(xaProp);
- }
+ XAConnectionPropertyMetaData xaProp = new XAConnectionPropertyMetaData();
+ xaProp.setName(name);
+ String svalue = (String) metaValueFactory.unwrap(mapValue.get(name));
+ xaProp.setValue(svalue);
+ list.add(xaProp);
}
try
@@ -150,20 +174,23 @@
{
String propName = getPropertyName(property);
PropertyInfo propertyInfo = beanInfo.getProperty(propName);
- Map<String,Map<String, String>> map = (Map<String,Map<String, String>>)metaValueFactory.unwrap(value, mapOfMapsType);
List<ManagedConnectionFactoryPropertyMetaData> list = null;
- if(map != null)
+ list = new ArrayList<ManagedConnectionFactoryPropertyMetaData>();
+ for(String name : mapValue.getMetaType().keySet())
{
- list = new ArrayList<ManagedConnectionFactoryPropertyMetaData>();
- for(Map<String,String> entry : map.values())
+ ManagedConnectionFactoryPropertyMetaData prop = new ManagedConnectionFactoryPropertyMetaData();
+ prop.setName(name);
+ String svalue = (String) metaValueFactory.unwrap(mapValue.get(name));
+ prop.setValue(svalue);
+ String nameType = name+".type";
+ MetaValue typeValue = mapValue.get(nameType);
+ if(typeValue != null)
{
- ManagedConnectionFactoryPropertyMetaData prop = new ManagedConnectionFactoryPropertyMetaData();
- prop.setName(entry.get("name"));
- prop.setValue(entry.get("value"));
- prop.setType(entry.get("type"));
- list.add(prop);
+ String type = (String) metaValueFactory.unwrap(typeValue);
+ prop.setType(type);
}
+ list.add(prop);
}
try
@@ -175,8 +202,30 @@
throw new UndeclaredThrowableException(t);
}
}
- else
- super.setValue(beanInfo, property, object, value);
+ else if("connection-properties".equals(property.getName()))
+ {
+ String propName = getPropertyName(property);
+ PropertyInfo propertyInfo = beanInfo.getProperty(propName);
+
+ List<DataSourceConnectionPropertyMetaData> list = new ArrayList<DataSourceConnectionPropertyMetaData>();
+ for(String name : mapValue.getMetaType().keySet())
+ {
+ DataSourceConnectionPropertyMetaData prop = new DataSourceConnectionPropertyMetaData();
+ prop.setName(name);
+ String svalue = (String) metaValueFactory.unwrap(mapValue.get(name));
+ prop.setValue(svalue);
+ list.add(prop);
+ }
+
+ try
+ {
+ propertyInfo.set(object, list);
+ }
+ catch (Throwable t)
+ {
+ throw new UndeclaredThrowableException(t);
+ }
+ }
}
public Map<String, String> compositeValueMap()
Modified: trunk/connector/src/main/org/jboss/resource/metadata/mcf/LocalDataSourceDeploymentMetaData.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/metadata/mcf/LocalDataSourceDeploymentMetaData.java 2008-02-06 20:24:12 UTC (rev 69671)
+++ trunk/connector/src/main/org/jboss/resource/metadata/mcf/LocalDataSourceDeploymentMetaData.java 2008-02-06 20:26:41 UTC (rev 69672)
@@ -27,6 +27,7 @@
import org.jboss.managed.api.annotation.ManagementComponent;
import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementProperty;
/**
@@ -50,6 +51,7 @@
setTransactionSupportMetaData(ManagedConnectionFactoryTransactionSupportMetaData.LOCAL);
}
+ @ManagementProperty(name="local-transaction")
@Override
public Boolean getLocalTransactions()
{
Modified: trunk/connector/src/main/org/jboss/resource/metadata/mcf/ManagedConnectionFactoryDeploymentMetaData.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/metadata/mcf/ManagedConnectionFactoryDeploymentMetaData.java 2008-02-06 20:24:12 UTC (rev 69671)
+++ trunk/connector/src/main/org/jboss/resource/metadata/mcf/ManagedConnectionFactoryDeploymentMetaData.java 2008-02-06 20:26:41 UTC (rev 69672)
@@ -536,6 +536,7 @@
this.statisticsFormatter = statisticsFormatter;
}
+ @ManagementProperty(name="no-tx-separate-pools")
public Boolean getNoTxSeparatePools()
{
return this.noTxSeparatePools;
@@ -546,6 +547,7 @@
this.noTxSeparatePools = notxpool;
}
+ @ManagementProperty(name="metadata")
public DBMSMetaData getDBMSMetaData()
{
return dbmsMetaData;
Modified: trunk/connector/src/main/org/jboss/resource/metadata/mcf/NonXADataSourceDeploymentMetaData.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/metadata/mcf/NonXADataSourceDeploymentMetaData.java 2008-02-06 20:24:12 UTC (rev 69671)
+++ trunk/connector/src/main/org/jboss/resource/metadata/mcf/NonXADataSourceDeploymentMetaData.java 2008-02-06 20:26:41 UTC (rev 69672)
@@ -75,7 +75,8 @@
this.driverClass = driverClass;
}
- @ManagementProperty(name="connection-properties", description="The DataSource connection properties", managed=true)
+ @ManagementProperty(name="connection-properties", description="The DataSource connection properties",
+ managed=true, propertyFactory=ConnectionFactoryProperty.class)
public List<DataSourceConnectionPropertyMetaData> getDataSourceConnectionProperties()
{
return this.connectionProperties;
@@ -87,7 +88,8 @@
}
@Override
- @ManagementProperty(name="config-property", description="The connection factory property info", managed=true, propertyFactory= ConnectionFactoryProperty.class)
+ @ManagementProperty(name="config-property", description="The connection factory property info",
+ managed=true, propertyFactory= ConnectionFactoryProperty.class)
public List<ManagedConnectionFactoryPropertyMetaData> getManagedConnectionFactoryProperties()
{
Modified: trunk/connector/src/main/org/jboss/resource/metadata/mcf/TxConnectionFactoryDeploymentMetaData.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/metadata/mcf/TxConnectionFactoryDeploymentMetaData.java 2008-02-06 20:24:12 UTC (rev 69671)
+++ trunk/connector/src/main/org/jboss/resource/metadata/mcf/TxConnectionFactoryDeploymentMetaData.java 2008-02-06 20:26:41 UTC (rev 69672)
@@ -81,6 +81,7 @@
}
@Override
+ @ManagementProperty(name="local-transaction")
public Boolean getLocalTransactions()
{
return !getXATransaction();
Modified: trunk/connector/src/tests/org/jboss/tests/jca/managed/ManagedObjectTestCase.java
===================================================================
--- trunk/connector/src/tests/org/jboss/tests/jca/managed/ManagedObjectTestCase.java 2008-02-06 20:24:12 UTC (rev 69671)
+++ trunk/connector/src/tests/org/jboss/tests/jca/managed/ManagedObjectTestCase.java 2008-02-06 20:26:41 UTC (rev 69672)
@@ -22,12 +22,22 @@
package org.jboss.tests.jca.managed;
import java.util.Arrays;
+import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.metatype.api.types.CompositeMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.MapCompositeValueSupport;
+import org.jboss.metatype.api.values.SimpleValueSupport;
import org.jboss.resource.connectionmanager.JBossManagedConnectionPool;
+import org.jboss.resource.deployers.management.LocalDSInstanceClassFactory;
+import org.jboss.resource.deployers.management.XADataSourceDeploymentMetaDataBuilder;
+import org.jboss.resource.metadata.mcf.DataSourceConnectionPropertyMetaData;
import org.jboss.resource.metadata.mcf.LocalDataSourceDeploymentMetaData;
import org.jboss.resource.metadata.mcf.NoTxDataSourceDeploymentMetaData;
import org.jboss.resource.metadata.mcf.XADataSourceDeploymentMetaData;
@@ -36,7 +46,7 @@
import org.jboss.test.BaseTestCase;
/**
- * Tests that validate tat the expected ManagedObjects are created from
+ * Tests that validate that the expected ManagedObjects are created from
* the jca metadata.
*
* @author Scott.Stark at jboss.org
@@ -49,7 +59,6 @@
"rar-name",
"use-java-context",
"connection-definition",
- "connection-property",
"jmx-invoker-name",
"min-pool-size",
"max-pool-size",
@@ -67,7 +76,9 @@
"config-property",
"security-domain",
"type-mapping",
- "local-transaction"
+ "local-transaction",
+ "metadata",
+ "no-tx-separate-pools"
};
static final String[] DataSourceDeploymentMetaData_NAMES = {
"transaction-isolation",
@@ -80,13 +91,19 @@
"prepared-statement-cache-size",
"share-prepared-statements",
"set-tx-query-timeout",
- "query-timeout"
+ "query-timeout",
+ "stale-connection-checker-class-name",
+ "url-delimiter",
+ "url-selector-strategy-class-name"
};
static final String[] NonXADataSourceDeploymentMetaData_NAMES = {
"driver-class",
+ "connection-properties",
"connection-url"
};
static final String[] XADataSourceDeploymentMetaData_NAMES = {
+ "url-property",
+ "xa-datasource-properties",
"xa-datasource-class",
"xa-resource-timeout"
};
@@ -98,7 +115,8 @@
"inUseConnectionCount",
"maxConnectionsInUseCount",
"maxSize",
- "minSize"
+ "minSize",
+ "poolJndiName"
};
public ManagedObjectTestCase(String name)
@@ -124,7 +142,12 @@
{
enableTrace("org.jboss.managed.plugins.factory");
ManagedObjectFactory mof = ManagedObjectFactory.getInstance();
- ManagedObject mo = mof.createManagedObject(LocalDataSourceDeploymentMetaData.class);
+ XADataSourceDeploymentMetaDataBuilder builder = new XADataSourceDeploymentMetaDataBuilder();
+ mof.setBuilder(LocalDataSourceDeploymentMetaData.class, builder);
+ LocalDSInstanceClassFactory icf = new LocalDSInstanceClassFactory();
+ mof.setInstanceClassFactory(LocalDataSourceDeploymentMetaData.class, icf);
+ LocalDataSourceDeploymentMetaData lds = new LocalDataSourceDeploymentMetaData();
+ ManagedObject mo = mof.initManagedObject(lds, "LocalDataSourceDeploymentMetaData", null);
// Validate the expected property names
Set<String> expectedPropertyNames = new TreeSet<String>();
expectedPropertyNames.addAll(Arrays.asList(ManagedConnectionFactoryDeploymentMetaData_NAMES));
@@ -132,12 +155,49 @@
expectedPropertyNames.addAll(Arrays.asList(NonXADataSourceDeploymentMetaData_NAMES));
Set<String> propertyNames = mo.getPropertyNames();
TreeSet<String> sortedPropertyNames = new TreeSet<String>(propertyNames);
- assertEquals(expectedPropertyNames, sortedPropertyNames);
+ if(expectedPropertyNames.equals(sortedPropertyNames) == false)
+ {
+ Set<String> missingNames = new TreeSet<String>();
+ Set<String> extraNames = new TreeSet<String>();
+ analyzeDiffs(expectedPropertyNames, sortedPropertyNames,
+ missingNames, extraNames);
+ fail("Extra properties: "+extraNames+", missing properties: "+missingNames);
+ }
+ // Validate the connection-properties type
+ ManagedProperty connectionProperties = mo.getProperty("connection-properties");
+ MetaType cpType = connectionProperties.getMetaType();
+ assertTrue("connection-properties.type="+cpType, cpType instanceof CompositeMetaType);
+ Object cpValue = connectionProperties.getValue();
+ assertTrue("connection-properties.value="+cpValue, cpValue instanceof CompositeValue);
+ CompositeValue cvalue = (CompositeValue) cpValue;
+ // Now update the values
+ MapCompositeValueSupport map = (MapCompositeValueSupport) cvalue;
+ map.put("key1", SimpleValueSupport.wrap("value1"));
+ map.put("key2", SimpleValueSupport.wrap("value2"));
+ connectionProperties.setValue(map);
+ // Check the underlying values
+ List<DataSourceConnectionPropertyMetaData> ldsProps = lds.getDataSourceConnectionProperties();
+ assertEquals(2, ldsProps.size());
+ DataSourceConnectionPropertyMetaData key1 = null;
+ DataSourceConnectionPropertyMetaData key2 = null;
+ for(DataSourceConnectionPropertyMetaData dspmd : ldsProps)
+ {
+ if(dspmd.getName().equals("key1"))
+ key1 = dspmd;
+ else if(dspmd.getName().equals("key2"))
+ key2 = dspmd;
+ }
+ assertNotNull(key1);
+ assertEquals("value1", key1.getValue());
+ assertNotNull(key2);
+ assertEquals("value2", key2.getValue());
}
public void testXADataSourceDeploymentMetaData()
{
enableTrace("org.jboss.managed.plugins.factory");
ManagedObjectFactory mof = ManagedObjectFactory.getInstance();
+ XADataSourceDeploymentMetaDataBuilder builder = new XADataSourceDeploymentMetaDataBuilder();
+ mof.setBuilder(XADataSourceDeploymentMetaData.class, builder);
ManagedObject mo = mof.createManagedObject(XADataSourceDeploymentMetaData.class);
// Validate the expected property names
Set<String> expectedPropertyNames = new TreeSet<String>();
@@ -146,7 +206,15 @@
expectedPropertyNames.addAll(Arrays.asList(XADataSourceDeploymentMetaData_NAMES));
Set<String> propertyNames = mo.getPropertyNames();
TreeSet<String> sortedPropertyNames = new TreeSet<String>(propertyNames);
- assertEquals(expectedPropertyNames, sortedPropertyNames);
+ if(expectedPropertyNames.equals(sortedPropertyNames) == false)
+ {
+ Set<String> missingNames = new TreeSet<String>();
+ Set<String> extraNames = new TreeSet<String>();
+ analyzeDiffs(expectedPropertyNames, sortedPropertyNames,
+ missingNames, extraNames);
+ fail("Extra properties: "+extraNames+", missing properties: "+missingNames);
+ }
+ // Validate the xa-datasource-properties type
}
public void testJBossManagedConnectionPool()
@@ -163,6 +231,40 @@
expectedPropertyNames.addAll(Arrays.asList(JBossManagedConnectionPool_NAMES));
Set<String> propertyNames = mo.getPropertyNames();
TreeSet<String> sortedPropertyNames = new TreeSet<String>(propertyNames);
- assertEquals(expectedPropertyNames, sortedPropertyNames);
+ if(expectedPropertyNames.equals(sortedPropertyNames) == false)
+ {
+ Set<String> missingNames = new TreeSet<String>();
+ Set<String> extraNames = new TreeSet<String>();
+ analyzeDiffs(expectedPropertyNames, sortedPropertyNames,
+ missingNames, extraNames);
+ fail("Extra properties: "+extraNames+", missing properties: "+missingNames);
+ }
}
+
+ /**
+ * Build the missingNames, extraNames from the input expectedPropertyNames
+ * and sortedPropertyNames.
+ *
+ * @param expectedPropertyNames
+ * @param sortedPropertyNames
+ * @param missingNames
+ * @param extraNames
+ */
+ private void analyzeDiffs(Set<String> expectedPropertyNames,
+ TreeSet<String> sortedPropertyNames,
+ Set<String> missingNames, Set<String> extraNames)
+ {
+ // Build the list of extra names
+ for(String name : sortedPropertyNames)
+ {
+ if(expectedPropertyNames.contains(name) == false)
+ extraNames.add(name);
+ }
+ // Build the list of missing names
+ for(String name : expectedPropertyNames)
+ {
+ if(sortedPropertyNames.contains(name) == false)
+ missingNames.add(name);
+ }
+ }
}
Added: trunk/profileservice/src/main/org/jboss/managed/plugins/factory/AbstractInstanceClassFactory.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/managed/plugins/factory/AbstractInstanceClassFactory.java (rev 0)
+++ trunk/profileservice/src/main/org/jboss/managed/plugins/factory/AbstractInstanceClassFactory.java 2008-02-06 20:26:41 UTC (rev 69672)
@@ -0,0 +1,317 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.managed.plugins.factory;
+
+import java.io.Serializable;
+import java.lang.reflect.UndeclaredThrowableException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.config.plugins.property.PropertyConfiguration;
+import org.jboss.config.spi.Configuration;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.annotation.ManagementObjectRef;
+import org.jboss.managed.api.annotation.ManagementRuntimeRef;
+import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.managed.plugins.factory.AbstractManagedObjectFactory;
+import org.jboss.managed.spi.factory.InstanceClassFactory;
+import org.jboss.managed.spi.factory.RuntimeComponentNameTransformer;
+import org.jboss.metatype.api.types.ArrayMetaType;
+import org.jboss.metatype.api.types.CollectionMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.values.ArrayValueSupport;
+import org.jboss.metatype.api.values.CollectionValueSupport;
+import org.jboss.metatype.api.values.GenericValueSupport;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.MetaValueFactory;
+import org.jboss.reflect.spi.TypeInfo;
+
+/**
+ * TODO: this needs to move to the mc managed project.
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class AbstractInstanceClassFactory<T extends Serializable>
+ implements InstanceClassFactory<T>
+{
+ /** The configuration */
+ private Configuration configuration = new PropertyConfiguration();
+ /** The meta value factory */
+ private MetaValueFactory metaValueFactory = MetaValueFactory.getInstance();
+ /** The instance to name transformers */
+ private Map<TypeInfo, RuntimeComponentNameTransformer> transformers = new WeakHashMap<TypeInfo, RuntimeComponentNameTransformer>();
+ private ManagedObjectFactory mof = new AbstractManagedObjectFactory();
+
+ public Map<TypeInfo, RuntimeComponentNameTransformer> getTransformers()
+ {
+ return transformers;
+ }
+ public void setTransformers(Map<TypeInfo, RuntimeComponentNameTransformer> transformers)
+ {
+ this.transformers = transformers;
+ }
+
+ public Configuration getConfiguration()
+ {
+ return configuration;
+ }
+ public void setConfiguration(Configuration configuration)
+ {
+ this.configuration = configuration;
+ }
+
+ public MetaValueFactory getMetaValueFactory()
+ {
+ return metaValueFactory;
+ }
+ public void setMetaValueFactory(MetaValueFactory metaValueFactory)
+ {
+ this.metaValueFactory = metaValueFactory;
+ }
+
+ public ManagedObjectFactory getMof()
+ {
+ return mof;
+ }
+ public void setMof(ManagedObjectFactory mof)
+ {
+ this.mof = mof;
+ }
+
+ public Object getComponentName(BeanInfo beanInfo, ManagedProperty property,
+ T attachment, MetaValue value)
+ {
+ if (beanInfo != null && property != null && value != null)
+ {
+ String name = getPropertyName(property);
+ PropertyInfo propertyInfo = beanInfo.getProperty(name);
+
+ ManagementRuntimeRef componentRef = propertyInfo.getUnderlyingAnnotation(ManagementRuntimeRef.class);
+ if (componentRef != null)
+ {
+ Object original = this.unwrapValue(beanInfo, property, value);
+ try
+ {
+ Class<? extends RuntimeComponentNameTransformer> tClass = componentRef.transformer();
+ RuntimeComponentNameTransformer transformer;
+ if (tClass != ManagementRuntimeRef.DEFAULT_NAME_TRANSFORMER.class)
+ transformer = getComponentNameTransformer(configuration.getTypeInfo(tClass));
+ else
+ transformer = getComponentNameTransformer(propertyInfo.getType());
+
+ return (transformer != null) ? transformer.transform(original) : original;
+ }
+ catch (Throwable t)
+ {
+ throw new UndeclaredThrowableException(t);
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Default InstanceClassFactory implementation simply returns the
+ * instance class.
+ */
+ public Class<? extends Serializable> getManagedObjectClass(Serializable instance)
+ {
+ return instance.getClass();
+ }
+
+ public MetaValue getValue(BeanInfo beanInfo, ManagedProperty property, Serializable object)
+ {
+ String name = getPropertyName(property);
+ PropertyInfo propertyInfo = beanInfo.getProperty(name);
+
+ Object value;
+ try
+ {
+ value = propertyInfo.get(object);
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Error e)
+ {
+ throw e;
+ }
+ catch (Throwable t)
+ {
+ throw new RuntimeException("Error getting property " + name + " for " + object.getClass().getName(), t);
+ }
+
+ if (value == null)
+ return null;
+
+ MetaType propertyType = property.getMetaType();
+ if (AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE == propertyType)
+ {
+ if (value instanceof Serializable == false)
+ throw new IllegalStateException("Object is not serializable: " + value.getClass().getName());
+ // Look for a ManagementObjectRef
+ ManagementObjectRef ref = (ManagementObjectRef) property.getAnnotations().get(ManagementObjectRef.class.getName());
+ String moName = (ref != null ? ref.name() : value.getClass().getName());
+ String moNameType = (ref != null ? ref.type() : "");
+ ManagedObject mo = mof.initManagedObject((Serializable) value, moName, moNameType);
+ return new GenericValueSupport(AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE, mo);
+ }
+ else if (propertyType.isArray())
+ {
+ ArrayMetaType arrayType = ArrayMetaType.class.cast(propertyType);
+ if (AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE == arrayType.getElementType())
+ {
+ Collection cvalue = getAsCollection(value);
+ // todo - AJ: changed some generics by best guess
+ ArrayMetaType<GenericValueSupport> moType = new ArrayMetaType<GenericValueSupport>(1, AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE);
+ ArrayValueSupport<GenericValueSupport> moArrayValue = new ArrayValueSupport<GenericValueSupport>(moType);
+ List<GenericValueSupport> tmp = new ArrayList<GenericValueSupport>();
+ for(Object element : cvalue)
+ {
+ ManagedObject mo = mof.initManagedObject((Serializable) element, null, null);
+ tmp.add(new GenericValueSupport(AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE, mo));
+ }
+ GenericValueSupport[] mos = new GenericValueSupport[tmp.size()];
+ moArrayValue.setValue(tmp.toArray(mos));
+ return moArrayValue;
+ }
+ }
+ else if (propertyType.isCollection())
+ {
+ CollectionMetaType collectionType = CollectionMetaType.class.cast(propertyType);
+ if (AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE == collectionType.getElementType())
+ {
+ Collection cvalue = getAsCollection(value);
+ List<GenericValueSupport> tmp = new ArrayList<GenericValueSupport>();
+ for(Object element : cvalue)
+ {
+ ManagedObject mo = mof.initManagedObject((Serializable) element, null, null);
+ tmp.add(new GenericValueSupport(AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE, mo));
+ }
+ GenericValueSupport[] mos = new GenericValueSupport[tmp.size()];
+ CollectionMetaType moType = new CollectionMetaType(propertyType.getClassName(), AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE);
+ return new CollectionValueSupport(moType, tmp.toArray(mos));
+ }
+ }
+
+ return metaValueFactory.create(value, propertyInfo.getType());
+ }
+
+
+ /**
+ * Set a value
+ *
+ * @param beanInfo the bean info
+ * @param property the property
+ * @param object the object
+ * @param the meta value
+ */
+ public void setValue(BeanInfo beanInfo, ManagedProperty property, T object, MetaValue value)
+ {
+ String name = getPropertyName(property);
+ PropertyInfo propertyInfo = beanInfo.getProperty(name);
+
+ Object unwrapValue = unwrapValue(beanInfo, property, value);
+ try
+ {
+ setValue(beanInfo, propertyInfo, object, unwrapValue);
+ }
+ catch(Throwable t)
+ {
+ throw new UndeclaredThrowableException(t);
+ }
+ }
+
+ /**
+ * Get component name transformer.
+ *
+ * @param type the type info
+ * @return transformer instance
+ * @throws Exception for any error
+ */
+ protected RuntimeComponentNameTransformer getComponentNameTransformer(TypeInfo type) throws Throwable
+ {
+ synchronized(transformers)
+ {
+ RuntimeComponentNameTransformer transformer = transformers.get(type);
+ if (transformer != null)
+ return transformer;
+
+ TypeInfo rcntType = configuration.getTypeInfo(RuntimeComponentNameTransformer.class);
+ if (rcntType.isAssignableFrom(type))
+ {
+ BeanInfo beanInfo = configuration.getBeanInfo(type);
+ RuntimeComponentNameTransformer newTransformer = (RuntimeComponentNameTransformer)beanInfo.newInstance();
+ transformers.put(type, newTransformer);
+ return newTransformer;
+ }
+
+ return null;
+ }
+ }
+
+ protected Object unwrapValue(BeanInfo beanInfo, ManagedProperty property, MetaValue value)
+ {
+ String name = getPropertyName(property);
+ PropertyInfo propertyInfo = beanInfo.getProperty(name);
+
+ Object unwrapValue = metaValueFactory.unwrap(value, propertyInfo.getType());
+ return unwrapValue;
+ }
+ protected void setValue(BeanInfo beanInfo, PropertyInfo propertyInfo, Object object, Object unwrapValue)
+ throws Throwable
+ {
+ propertyInfo.set(object, unwrapValue);
+ }
+
+ protected Collection getAsCollection(Object value)
+ {
+ if( value.getClass().isArray() )
+ return Arrays.asList(value);
+ else if (value instanceof Collection)
+ return Collection.class.cast(value);
+ return null;
+ }
+
+ /**
+ * Get the property name.
+ *
+ * @param property managed property
+ * @return property name
+ */
+ protected String getPropertyName(ManagedProperty property)
+ {
+ // First look to the mapped name
+ String name = property.getMappedName();
+ if (name == null)
+ property.getName();
+ return name;
+ }
+}
Property changes on: trunk/profileservice/src/main/org/jboss/managed/plugins/factory/AbstractInstanceClassFactory.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Added: trunk/profileservice/src/main/org/jboss/metatype/api/types/MapCompositeMetaType.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/metatype/api/types/MapCompositeMetaType.java (rev 0)
+++ trunk/profileservice/src/main/org/jboss/metatype/api/types/MapCompositeMetaType.java 2008-02-06 20:26:41 UTC (rev 69672)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, 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 org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.plugins.types.AbstractCompositeMetaType;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class MapCompositeMetaType extends AbstractCompositeMetaType
+{
+ private static final long serialVersionUID = 1;
+ private MetaType valueType;
+
+ /**
+ *
+ * @param valueType
+ */
+ public MapCompositeMetaType(MetaType valueType)
+ {
+ super("java.lang.Map", "Map<String,MetaValue>");
+ this.valueType = valueType;
+ }
+
+ /**
+ *
+ * @param itemName
+ */
+ public void addItem(String itemName)
+ {
+ super.addItem(itemName, itemName, valueType);
+ }
+}
Property changes on: trunk/profileservice/src/main/org/jboss/metatype/api/types/MapCompositeMetaType.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Added: trunk/profileservice/src/main/org/jboss/metatype/api/values/MapCompositeValueSupport.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/metatype/api/values/MapCompositeValueSupport.java (rev 0)
+++ trunk/profileservice/src/main/org/jboss/metatype/api/values/MapCompositeValueSupport.java 2008-02-06 20:26:41 UTC (rev 69672)
@@ -0,0 +1,112 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, 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.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.metatype.api.types.CompositeMetaType;
+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.AbstractMetaValue;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.plugins.types.AbstractCompositeMetaType;
+
+/**
+ * A CompositeValue for Map<String,MetaValue>
+ *
+ * TODO: move into mc metatype project
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class MapCompositeValueSupport extends AbstractMetaValue
+ implements CompositeValue
+{
+ private static final long serialVersionUID = 1;
+ private Map<String, MetaValue> map;
+ private MapCompositeMetaType mapType = new MapCompositeMetaType(SimpleMetaType.STRING);
+
+ public MapCompositeValueSupport(MetaType valueType)
+ {
+ this(null, valueType);
+ }
+ public MapCompositeValueSupport(Map<String, MetaValue> map, MetaType valueType)
+ {
+ this.map = new HashMap<String, MetaValue>();
+ if(map != null)
+ {
+ for(Map.Entry<String, MetaValue> entry : map.entrySet())
+ this.put(entry.getKey(), entry.getValue());
+ }
+ }
+
+ public boolean containsKey(String key)
+ {
+ return map.containsKey(key);
+ }
+
+ public boolean containsValue(MetaValue value)
+ {
+ return map.containsValue(value);
+ }
+
+ public MetaValue get(String key)
+ {
+ return map.get(key);
+ }
+ public void put(String key, MetaValue value)
+ {
+ if(mapType.containsItem(key) == false)
+ mapType.addItem(key);
+ map.put(key, value);
+ }
+
+ public MetaValue[] getAll(String[] keys)
+ {
+ ArrayList<MetaValue> values = new ArrayList();
+ if(keys != null)
+ {
+ for(String key : keys)
+ {
+ MetaValue value = map.get(key);
+ values.add(value);
+ }
+ }
+ MetaValue[] mvs = {};
+ return values.toArray(mvs);
+ }
+
+ public CompositeMetaType getMetaType()
+ {
+ return mapType;
+ }
+
+ public Collection<MetaValue> values()
+ {
+ return map.values();
+ }
+}
Property changes on: trunk/profileservice/src/main/org/jboss/metatype/api/values/MapCompositeValueSupport.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
More information about the jboss-cvs-commits
mailing list