[jboss-cvs] JBossAS SVN: r86702 - in trunk: profileservice/src/main/org/jboss/profileservice/management and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Apr 2 17:45:50 EDT 2009
Author: scott.stark at jboss.org
Date: 2009-04-02 17:45:50 -0400 (Thu, 02 Apr 2009)
New Revision: 86702
Added:
trunk/profileservice/src/main/org/jboss/profileservice/management/FilteredDeploymentTemplateInfo.java
trunk/profileservice/src/main/org/jboss/profileservice/management/RemovedPropertyMap.java
trunk/testsuite/src/main/org/jboss/test/profileservice/test/DataSourceUnitTestCase.java
Modified:
trunk/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplate.java
trunk/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplateInfo.java
trunk/profileservice/src/main/org/jboss/profileservice/management/AbstractTemplateCreator.java
trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java
Log:
JBAS-6672, handle removed properties as unspecified properties with no admin level value.
Modified: trunk/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplate.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplate.java 2009-04-02 21:44:50 UTC (rev 86701)
+++ trunk/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplate.java 2009-04-02 21:45:50 UTC (rev 86702)
@@ -37,6 +37,7 @@
import org.jboss.managed.api.ManagedProperty;
import org.jboss.managed.api.factory.ManagedObjectFactory;
import org.jboss.managed.plugins.factory.ManagedObjectFactoryBuilder;
+import org.jboss.metatype.api.values.SimpleValue;
import org.jboss.resource.metadata.mcf.LocalDataSourceDeploymentMetaData;
import org.jboss.resource.metadata.mcf.ManagedConnectionFactoryDeploymentGroup;
import org.jboss.resource.metadata.mcf.ManagedConnectionFactoryDeploymentMetaData;
@@ -113,7 +114,19 @@
protected void writeTemplate(File dsXml, DeploymentTemplateInfo values)
throws Exception
{
- String cfType = ((DsDataSourceTemplateInfo)values).getConnectionFactoryType();
+ // Look for the CF type using the dsType ManagedProperty
+ ManagedProperty dsTypeMP = values.getProperties().get("dsType");
+ String cfType = null;
+ if(dsTypeMP == null)
+ {
+ // Try casting this to a DsDataSourceTemplateInfo
+ cfType = ((DsDataSourceTemplateInfo)values).getConnectionFactoryType();
+ }
+ else
+ {
+ SimpleValue dsTypeSV = (SimpleValue) dsTypeMP.getValue();
+ cfType = dsTypeSV.getValue().toString();
+ }
ManagedConnectionFactoryDeploymentMetaData mcf;
ManagedObjectFactory mof = ManagedObjectFactoryBuilder.create();
Modified: trunk/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplateInfo.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplateInfo.java 2009-04-02 21:44:50 UTC (rev 86701)
+++ trunk/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplateInfo.java 2009-04-02 21:45:50 UTC (rev 86702)
@@ -21,52 +21,62 @@
*/
package org.jboss.resource.deployers.management;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.UndeclaredThrowableException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-import java.util.List;
-import java.io.Serializable;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.UndeclaredThrowableException;
import org.jboss.annotation.factory.AnnotationProxy;
-import org.jboss.managed.api.DeploymentTemplateInfo;
import org.jboss.managed.api.Fields;
import org.jboss.managed.api.ManagedProperty;
import org.jboss.managed.api.annotation.ManagementObjectID;
import org.jboss.managed.plugins.BasicDeploymentTemplateInfo;
import org.jboss.managed.plugins.DefaultFieldsImpl;
-import org.jboss.managed.plugins.ManagedObjectImpl;
import org.jboss.managed.plugins.ManagedPropertyImpl;
-import org.jboss.managed.plugins.factory.AbstractManagedObjectFactory;
-import org.jboss.metatype.api.types.GenericMetaType;
-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.types.MetaTypeFactory;
import org.jboss.metatype.api.values.MetaValue;
-import org.jboss.metatype.api.values.MetaValueFactory;
-import org.jboss.resource.metadata.mcf.LocalDataSourceDeploymentMetaData;
-import org.jboss.resource.metadata.mcf.XADataSourceDeploymentMetaData;
-import org.jboss.resource.metadata.mcf.DBMSMetaData;
-import org.jboss.resource.metadata.mcf.NoTxDataSourceDeploymentMetaData;
-import org.jboss.resource.metadata.mcf.NoTxConnectionFactoryDeploymentMetaData;
-import org.jboss.resource.metadata.mcf.TxConnectionFactoryDeploymentMetaData;
+import org.jboss.metatype.api.values.SimpleValueSupport;
/**
* The template for creating jca datasources, connection factories
*
* @author Scott.Stark at jboss.org
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version $Revision$
*/
public class DsDataSourceTemplateInfo extends BasicDeploymentTemplateInfo
{
private static final long serialVersionUID = 1;
- /** The meta value factory */
- private static MetaValueFactory METAVALUE_FACTORY = MetaValueFactory.getInstance();
- private static final MetaTypeFactory METATYPE_FACTORY = MetaTypeFactory.getInstance();
+
+ /** The default values. */
+ private static final Map<String, MetaValue> defaultValues = new HashMap<String, MetaValue>();
+
+ /** The property name mappings. */
private Map<String, String> propertyNameMappings;
+
+ /** The datasource type. */
private String dsType = "local-tx-datasource";
+
+ static
+ {
+ // populate the default values
+ defaultValues.put("use-java-context", new SimpleValueSupport(SimpleMetaType.BOOLEAN_PRIMITIVE, true));
+ defaultValues.put("min-pool-size", new SimpleValueSupport(SimpleMetaType.INTEGER_PRIMITIVE, 0));
+ defaultValues.put("max-pool-size", new SimpleValueSupport(SimpleMetaType.INTEGER_PRIMITIVE, 10));
+ defaultValues.put("blocking-timeout-millis", new SimpleValueSupport(SimpleMetaType.LONG_PRIMITIVE, 3000));
+ defaultValues.put("idle-timeout-minutes", new SimpleValueSupport(SimpleMetaType.INTEGER_PRIMITIVE, 30));
+ defaultValues.put("background-validation", new SimpleValueSupport(SimpleMetaType.BOOLEAN_PRIMITIVE, false));
+ defaultValues.put("background-validation-millis", new SimpleValueSupport(SimpleMetaType.LONG_PRIMITIVE, 0));
+ defaultValues.put("validate-on-match", new SimpleValueSupport(SimpleMetaType.BOOLEAN_PRIMITIVE, true));
+ defaultValues.put("interleaving", new SimpleValueSupport(SimpleMetaType.BOOLEAN_PRIMITIVE, false));
+ defaultValues.put("allocation-retry", new SimpleValueSupport(SimpleMetaType.INTEGER_PRIMITIVE, 0));
+ defaultValues.put("allocation-retry-wait-millis", new SimpleValueSupport(SimpleMetaType.INTEGER_PRIMITIVE, 5000));
+ defaultValues.put("prepared-statement-cache-size", new SimpleValueSupport(SimpleMetaType.INTEGER_PRIMITIVE, 0));
+ defaultValues.put("share-prepared-statements", new SimpleValueSupport(SimpleMetaType.BOOLEAN_PRIMITIVE, false));
+ defaultValues.put("set-tx-query-timeout", new SimpleValueSupport(SimpleMetaType.BOOLEAN_PRIMITIVE, false));
+ defaultValues.put("query-timeout", new SimpleValueSupport(SimpleMetaType.INTEGER_PRIMITIVE, 0));
+ }
public DsDataSourceTemplateInfo(String arg0, String arg1, Map<String, ManagedProperty> arg2)
{
@@ -107,8 +117,9 @@
@Override
public DsDataSourceTemplateInfo copy()
{
- DsDataSourceTemplateInfo copy = new DsDataSourceTemplateInfo(getName(), getDescription(), dsType);
+ DsDataSourceTemplateInfo copy = new DsDataSourceTemplateInfo(getName(), getDescription(), getProperties());
copy.setPropertyNameMappings(propertyNameMappings);
+ copy.setConnectionFactoryType(getConnectionFactoryType());
super.copy(copy);
copy.populate();
return copy;
@@ -116,207 +127,76 @@
private void populate()
{
+ populateDefaultValues();
+ // Pass the
+ DefaultFieldsImpl fields = new DefaultFieldsImpl("dsType");
+ fields.setDescription("The datasource type");
+ fields.setMetaType(SimpleMetaType.STRING);
+ fields.setValue(SimpleValueSupport.wrap(dsType));
+ fields.setField(Fields.READ_ONLY, Boolean.TRUE);
+ ManagedPropertyImpl dsTypeMP = new ManagedPropertyImpl(fields);
+ addProperty(dsTypeMP);
+
// DataSource
- if("local-tx-datasource".equals(dsType))
- createLocalTxDsTemplate();
- else if("xa-datasource".equals(dsType))
- createXaDsTemplate();
- else if("tx-connection-factory".equals(dsType))
- createTxCfTemplate();
- else if("no-tx-datasource".equals(dsType))
- createNoTxDsTemplate();
- else if("no-tx-connection-factory".equals(dsType))
- createNoTxCfTemplate();
- else
- throw new IllegalStateException("Unsupported dsType: " + dsType);
+// if("local-tx-datasource".equals(dsType))
+// createLocalTxDsTemplate();
+// else if("xa-datasource".equals(dsType))
+// createXaDsTemplate();
+// else if("tx-connection-factory".equals(dsType))
+// createTxCfTemplate();
+// else if("no-tx-datasource".equals(dsType))
+// createNoTxDsTemplate();
+// else if("no-tx-connection-factory".equals(dsType))
+// createNoTxCfTemplate();
+// else
+// throw new IllegalStateException("Unsupported dsType: " + dsType);
}
-
- private void createXaDsTemplate()
+
+ private void populateDefaultValues()
{
- ManagedObjectImpl mo = new ManagedObjectImpl(XADataSourceDeploymentMetaData.class.getName());
- addDsProperties(mo);
- addManagedProperty("xa-datasource-class", "The xa datasource class name", true, SimpleMetaType.STRING, mo);
- MetaType type = new MapCompositeMetaType(SimpleMetaType.STRING);
- addManagedProperty("xa-datasource-properties", "The xa datasource properties", false, type, mo);
- addManagedProperty("url-property", "The URL property", true, SimpleMetaType.STRING, mo);
- addManagedProperty("xa-resource-timeout", "The XA resource timeout", true, SimpleMetaType.INTEGER, new Integer(0), mo);
- }
-
- private void createLocalTxDsTemplate()
- {
- ManagedObjectImpl mo = new ManagedObjectImpl(LocalDataSourceDeploymentMetaData.class.getName());
- addNonXADsProperties(mo);
- }
-
- private void createNoTxDsTemplate()
- {
- ManagedObjectImpl mo = new ManagedObjectImpl(NoTxDataSourceDeploymentMetaData.class.getName());
- addNonXADsProperties(mo);
- }
-
- private void createTxCfTemplate()
- {
- ManagedObjectImpl mo = new ManagedObjectImpl(TxConnectionFactoryDeploymentMetaData.class.getName());
- addCommonProperties(mo);
- addManagedProperty("xa-resource-timeout", "The XA resource timeout", true, SimpleMetaType.INTEGER, new Integer(0), mo);
- addManagedProperty("xa-transaction", "", true, SimpleMetaType.BOOLEAN, mo);
- }
-
- private void createNoTxCfTemplate()
- {
- ManagedObjectImpl mo = new ManagedObjectImpl(NoTxConnectionFactoryDeploymentMetaData.class.getName());
- addCommonProperties(mo);
- }
-
- private void addNonXADsProperties(ManagedObjectImpl mo)
- {
- addDsProperties(mo);
- addManagedProperty("driver-class", "The jdbc driver class name", true, SimpleMetaType.STRING, mo);
- addManagedProperty("connection-url", "The jdbc url of the DataSource", true, SimpleMetaType.STRING, mo);
- MetaType type = new MapCompositeMetaType(SimpleMetaType.STRING);
- addManagedProperty("connection-properties", "The jdbc driver connection properties", false, type, mo);
- }
-
- private void addDsProperties(ManagedObjectImpl mo)
- {
- addCommonProperties(mo);
- addManagedProperty("transaction-isolation", "The transaction isolation level", false, SimpleMetaType.STRING, mo);
- addManagedProperty("user-name", "The username for the connection-url", false, SimpleMetaType.STRING, mo);
- addManagedProperty("password", "The password for the connection-url", false, SimpleMetaType.STRING, mo);
- addManagedProperty("new-connection-sql", "", false, SimpleMetaType.STRING, mo);
- addManagedProperty("check-valid-connection-sql", "", false, SimpleMetaType.STRING, mo);
- addManagedProperty("valid-connection-checker-class-name", "", false, SimpleMetaType.STRING, mo);
- addManagedProperty("exception-sorter-class-name", "", false, SimpleMetaType.STRING, mo);
- addManagedProperty("stale-connection-checker-class-name", "", false, SimpleMetaType.STRING, mo);
- addManagedProperty("track-statements", "", false, SimpleMetaType.STRING, mo);
- addManagedProperty("prepared-statement-cache-size", "", false, SimpleMetaType.INTEGER, new Integer(0), mo);
- addManagedProperty("share-prepared-statements", "", false, SimpleMetaType.BOOLEAN, Boolean.FALSE, mo);
- addManagedProperty("set-tx-query-timeout", "", false, SimpleMetaType.BOOLEAN, Boolean.FALSE, mo);
- addManagedProperty("query-timeout", "", false, SimpleMetaType.INTEGER, new Integer(0), mo);
- addManagedProperty("url-delimiter", "", false, SimpleMetaType.STRING, mo);
- addManagedProperty("url-selector-strategy-class-name", "", false, SimpleMetaType.STRING, mo);
- addManagedProperty("use-try-lock", "", false, SimpleMetaType.LONG, mo);
- }
-
- private void addCommonProperties(ManagedObjectImpl mo)
- {
- // perhaps these descriptions should be externalized in some way
- addManagedProperty("jndi-name", "The jndi name to bind the DataSource under", true, true, SimpleMetaType.STRING, "", mo);
- addManagedProperty("rar-name", "The resource adapter archive name", true, SimpleMetaType.STRING, mo);
- addManagedProperty("use-java-context", "Whether to bind the connection factory under 'java:' context", true, SimpleMetaType.BOOLEAN, Boolean.TRUE, mo);
- addManagedProperty("connection-definition", "The connection factory class name", true, SimpleMetaType.STRING, mo);
- addManagedProperty("jmx-invoker-name", "The name of the JMX invoker", true, SimpleMetaType.STRING, mo);
- addManagedProperty("min-pool-size", "The min size of the pool", true, SimpleMetaType.INTEGER, new Integer(0), mo);
- addManagedProperty("max-pool-size", "The max size of the pool", true, SimpleMetaType.INTEGER, new Integer(10), mo);
- addManagedProperty("blocking-timeout-millis", "The time to wait for a connection to become available before giving up", true, SimpleMetaType.LONG, new Long(30000), mo);
- addManagedProperty("idle-timeout-minutes", "The idle timeout in minutes", true, SimpleMetaType.INTEGER, new Integer(30), mo);
- addManagedProperty("prefill", "Whether to prefill the pool", true, SimpleMetaType.BOOLEAN, mo);
- addManagedProperty("background-validation", "Whether to use backgroup validation", true, SimpleMetaType.BOOLEAN, Boolean.FALSE, mo);
- addManagedProperty("background-validation-millis", "", false, SimpleMetaType.LONG, new Long(0), mo);
- addManagedProperty("validate-on-match", "", true, SimpleMetaType.BOOLEAN, Boolean.TRUE, mo);
- addManagedProperty("use-strict-min", "", true, SimpleMetaType.BOOLEAN, mo);
- addManagedProperty("no-tx-separate-pools", "", true, SimpleMetaType.BOOLEAN, mo);
- addManagedProperty("statistics-formatter", "", true, SimpleMetaType.STRING, mo);
- addManagedProperty("isSameRM-override-value", "", true, SimpleMetaType.BOOLEAN, mo);
- addManagedProperty("track-connection-by-tx", "", false, SimpleMetaType.BOOLEAN, Boolean.TRUE, mo);
- addManagedProperty("interleaving", "", false, SimpleMetaType.BOOLEAN, mo);
- addManagedProperty("allocation-retry", "The number of times allocation retries should be tried", false, SimpleMetaType.INTEGER, new Integer(0), mo);
- addManagedProperty("allocation-retry-wait-millis", "The time to wait between allocation retries", false, SimpleMetaType.LONG, new Long(5000), mo);
- addManagedProperty("config-property", "The connection factory config properties", false, SimpleMetaType.STRING, mo);
- addManagedProperty("security-domain", "The security-domain used to validate connections", false, AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE, mo);
- addManagedProperty("depends", "", false, METATYPE_FACTORY.resolve(List.class), mo);
- addManagedProperty("metadata", "", false, METATYPE_FACTORY.resolve(DBMSMetaData.class), mo);
- addManagedProperty("type-mapping", "", true, SimpleMetaType.STRING, mo);
- addManagedProperty("local-transaction", "", true, SimpleMetaType.BOOLEAN, mo);
- }
-
- private void addManagedProperty(String fieldName,
- String fieldDescr,
- boolean mandatory,
- MetaType metaType,
- ManagedObjectImpl mo)
- {
- addManagedProperty(fieldName, fieldDescr, mandatory, false, metaType, null, mo);
- }
-
- private void addManagedProperty(String fieldName,
- String fieldDescr,
- boolean mandatory,
- MetaType metaType,
- Serializable value,
- ManagedObjectImpl mo)
- {
- MetaValue mv = METAVALUE_FACTORY.create(value);
- addManagedProperty(fieldName, fieldDescr, mandatory, false, metaType, mv, mo);
- }
- private void addManagedProperty(String fieldName,
- String fieldDescr,
- boolean mandatory,
- MetaType metaType,
- MetaValue value,
- ManagedObjectImpl mo)
- {
- addManagedProperty(fieldName, fieldDescr, mandatory, false, metaType, value, mo);
- }
-
- private void addManagedProperty(String fieldName,
- String fieldDescr,
- boolean mandatory,
- boolean isID,
- MetaType metaType,
- Serializable value,
- ManagedObjectImpl mo)
- {
- MetaValue mv = METAVALUE_FACTORY.create(value);
- addManagedProperty(fieldName, fieldDescr, mandatory, isID, metaType, mv, mo);
- }
- private void addManagedProperty(String fieldName,
- String fieldDescr,
- boolean mandatory,
- boolean isID,
- MetaType metaType,
- MetaValue value,
- ManagedObjectImpl mo)
- {
- DefaultFieldsImpl fields = new DefaultFieldsImpl();
- setFieldName(fieldName, fields);
- fields.setDescription(fieldDescr);
- fields.setMandatory(mandatory);
- fields.setMetaType(metaType);
- ManagedPropertyImpl mp = new ManagedPropertyImpl(mo, fields);
- if(isID)
+ if(getProperties() == null) return;
+ for(ManagedProperty property : getProperties().values())
{
- Map<String, Annotation> annotations = new HashMap<String, Annotation>();
- Map<String, Object> idFields = Collections.emptyMap();
- try
+ String name = property.getName();
+
+
+ // Create a new (non-writethrough) managed property
+ Fields f = property.getFields();
+ if( propertyNameMappings != null )
{
- ManagementObjectID id = (ManagementObjectID) AnnotationProxy.createProxy(idFields, ManagementObjectID.class);
- annotations.put(ManagementObjectID.class.getName(), id);
- mp.setAnnotations(annotations);
+ String mappedName = propertyNameMappings.get(name);
+ if( mappedName != null )
+ f.setField(Fields.MAPPED_NAME, mappedName);
}
- catch(Exception e)
+
+ ManagedPropertyImpl newProperty = new ManagedPropertyImpl(f);
+
+ MetaValue v = defaultValues.get(name);
+ if(v != null)
{
- throw new UndeclaredThrowableException(e);
+ newProperty.setValue(v);
}
+
+ // Override
+ addProperty(newProperty);
}
- super.addProperty(mp);
- if(value != null)
- {
- if((value instanceof MetaValue) == false)
- value = METAVALUE_FACTORY.create(value);
- mp.setValue(value);
- }
}
-
- protected void setFieldName(String name, Fields f)
+
+ private void addID(ManagedPropertyImpl mp)
{
- f.setField(Fields.NAME, name);
- if( propertyNameMappings != null )
+ // TODO
+ Map<String, Annotation> annotations = new HashMap<String, Annotation>();
+ Map<String, Object> idFields = Collections.emptyMap();
+ try
{
- String mappedName = propertyNameMappings.get(name);
- if( mappedName != null )
- f.setField(Fields.MAPPED_NAME, mappedName);
+ ManagementObjectID id = (ManagementObjectID) AnnotationProxy.createProxy(idFields, ManagementObjectID.class);
+ annotations.put(ManagementObjectID.class.getName(), id);
+ mp.setAnnotations(annotations);
}
+ catch(Exception e)
+ {
+ throw new UndeclaredThrowableException(e);
+ }
}
}
Modified: trunk/profileservice/src/main/org/jboss/profileservice/management/AbstractTemplateCreator.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/AbstractTemplateCreator.java 2009-04-02 21:44:50 UTC (rev 86701)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/AbstractTemplateCreator.java 2009-04-02 21:45:50 UTC (rev 86702)
@@ -87,7 +87,9 @@
String deploymentName = template.getDeploymentName(deploymentBaseName);
if(deploymentName == null)
throw new IllegalStateException("getDeploymentName returned a null value.");
- base = template.applyTemplate(info);
+ // Wrap info to exclude all removed properties
+ FilteredDeploymentTemplateInfo filterInfo = new FilteredDeploymentTemplateInfo(info);
+ base = template.applyTemplate(filterInfo);
if(base == null)
throw new IllegalStateException("applyTemplate returned null virtual file.");
Copied: trunk/profileservice/src/main/org/jboss/profileservice/management/FilteredDeploymentTemplateInfo.java (from rev 86691, branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/FilteredDeploymentTemplateInfo.java)
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/FilteredDeploymentTemplateInfo.java (rev 0)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/FilteredDeploymentTemplateInfo.java 2009-04-02 21:45:50 UTC (rev 86702)
@@ -0,0 +1,72 @@
+/*
+ * 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.profileservice.management;
+
+import java.util.Map;
+
+import org.jboss.managed.api.DeploymentTemplateInfo;
+import org.jboss.managed.api.ManagedProperty;
+
+/**
+ * A DeploymentTemplateInfo that filters out any ManagedProperties that have
+ * been removed.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class FilteredDeploymentTemplateInfo
+ implements DeploymentTemplateInfo
+{
+ private DeploymentTemplateInfo delegate;
+
+ public FilteredDeploymentTemplateInfo(DeploymentTemplateInfo delegate)
+ {
+ this.delegate = delegate;
+ }
+
+ public DeploymentTemplateInfo copy()
+ {
+ FilteredDeploymentTemplateInfo copy = new FilteredDeploymentTemplateInfo(delegate.copy());
+ return copy;
+ }
+
+ public String getDescription()
+ {
+ return delegate.getDescription();
+ }
+
+ public String getName()
+ {
+ return delegate.getName();
+ }
+
+ public Map<String, ManagedProperty> getProperties()
+ {
+ RemovedPropertyMap props = new RemovedPropertyMap(delegate.getProperties());
+ return props;
+ }
+
+ public String getRootManagedPropertyName()
+ {
+ return delegate.getRootManagedPropertyName();
+ }
+}
Modified: trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java 2009-04-02 21:44:50 UTC (rev 86701)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java 2009-04-02 21:45:50 UTC (rev 86702)
@@ -1180,9 +1180,17 @@
// Dispatch any runtime component property values
for(ManagedProperty prop : comp.getProperties().values())
{
- // Skip null values && non-CONFIGURATION values
- if( prop.getValue() == null || prop.hasViewUse(ViewUse.CONFIGURATION) == false)
+ // Skip null values && non-CONFIGURATION values, unmodified values, and removed values
+ boolean skip = prop.getValue() == null
+ || prop.hasViewUse(ViewUse.CONFIGURATION) == false
+ || prop.isModified() == false
+ || prop.isRemoved() == true;
+ if( skip )
+ {
+ if(log.isTraceEnabled())
+ log.trace("Skipping component property: "+prop);
continue;
+ }
ManagedProperty ctxProp = serverComp.getProperties().get(prop.getName());
// Check for a mapped name
Copied: trunk/profileservice/src/main/org/jboss/profileservice/management/RemovedPropertyMap.java (from rev 86691, branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/RemovedPropertyMap.java)
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/RemovedPropertyMap.java (rev 0)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/RemovedPropertyMap.java 2009-04-02 21:45:50 UTC (rev 86702)
@@ -0,0 +1,142 @@
+/*
+ * 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.profileservice.management;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.managed.api.ManagedProperty;
+
+/**
+ * Map<String, ManagedProperty> that filters out ManagedPropertys that have
+ * isRemoved == true.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class RemovedPropertyMap
+ implements Map<String, ManagedProperty>
+{
+ private Map<String, ManagedProperty> delegate;
+ private Set<String> keySet;
+
+ public RemovedPropertyMap(Map<String, ManagedProperty> delegate)
+ {
+ this.delegate = delegate;
+ // Filter out the removed property keys
+ keySet = new HashSet<String>();
+ for(String key : delegate.keySet())
+ {
+ ManagedProperty mp = delegate.get(key);
+ if(mp.isRemoved() == false)
+ keySet.add(key);
+ }
+ }
+
+ public void clear()
+ {
+ delegate.clear();
+ keySet.clear();
+ }
+
+ public boolean containsKey(Object key)
+ {
+ return keySet.contains(key);
+ }
+
+ public boolean containsValue(Object value)
+ {
+ ManagedProperty mp = (ManagedProperty) value;
+ return keySet.contains(mp.getName());
+ }
+
+ public Set<Entry<String, ManagedProperty>> entrySet()
+ {
+ return delegate.entrySet();
+ }
+
+ public boolean equals(Object o)
+ {
+ return delegate.equals(o);
+ }
+
+ public ManagedProperty get(Object key)
+ {
+ ManagedProperty mp = delegate.get(key);
+ if(mp.isRemoved())
+ mp = null;
+ return mp;
+ }
+
+ public int hashCode()
+ {
+ return delegate.hashCode();
+ }
+
+ public boolean isEmpty()
+ {
+ return keySet.isEmpty();
+ }
+
+ public Set<String> keySet()
+ {
+ return keySet;
+ }
+
+ public ManagedProperty put(String key, ManagedProperty value)
+ {
+ if(value.isRemoved())
+ keySet.add(key);
+ return delegate.put(key, value);
+ }
+
+ public void putAll(Map<? extends String, ? extends ManagedProperty> t)
+ {
+ delegate.putAll(t);
+ }
+
+ public ManagedProperty remove(Object key)
+ {
+ if(keySet.contains(key))
+ keySet.remove(key);
+ return delegate.remove(key);
+ }
+
+ public int size()
+ {
+ return keySet.size();
+ }
+
+ public Collection<ManagedProperty> values()
+ {
+ ArrayList<ManagedProperty> values = new ArrayList<ManagedProperty>();
+ for(ManagedProperty mp : delegate.values())
+ {
+ if(mp.isRemoved() == false)
+ values.add(mp);
+ }
+ return values;
+ }
+}
Copied: trunk/testsuite/src/main/org/jboss/test/profileservice/test/DataSourceUnitTestCase.java (from rev 86691, branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/DataSourceUnitTestCase.java)
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/profileservice/test/DataSourceUnitTestCase.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/profileservice/test/DataSourceUnitTestCase.java 2009-04-02 21:45:50 UTC (rev 86702)
@@ -0,0 +1,123 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.profileservice.test;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.deployers.spi.management.KnownComponentTypes;
+import org.jboss.deployers.spi.management.ManagementView;
+import org.jboss.managed.api.ComponentType;
+import org.jboss.managed.api.DeploymentTemplateInfo;
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.metatype.api.types.MapCompositeMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+
+/**
+ * Additional tests of managing DataSources
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class DataSourceUnitTestCase extends AbstractProfileServiceTest
+{
+ public DataSourceUnitTestCase(String s)
+ {
+ super(s);
+ }
+
+ /**
+ * JBAS-6672 related testing of properties having default values
+ * @throws Exception
+ */
+ public void testRemovedProperties() throws Exception
+ {
+ ManagementView mgtView = getManagementView();
+ String templateName = "LocalTxDataSourceTemplate";
+ String jndiName = "testRemovedPropertiesDS";
+ DeploymentTemplateInfo dsInfo = mgtView.getTemplate(templateName);
+ assertNotNull("template " + templateName + " found", dsInfo);
+ log.info(dsInfo.getProperties().keySet());
+ Map<String, ManagedProperty> props = dsInfo.getProperties();
+
+ // Set key property values
+ ManagedProperty jndiNameMP = props.get("jndi-name");
+ jndiNameMP.setValue(SimpleValueSupport.wrap(jndiName));
+ ManagedProperty driverClass = props.get("driver-class");
+ driverClass.setValue(SimpleValueSupport.wrap("org.hsqldb.jdbcDriver"));
+ ManagedProperty connUrl = props.get("connection-url");
+ connUrl.setValue(SimpleValueSupport.wrap("jdbc:hsqldb:."));
+ ManagedProperty userName = props.get("user-name");
+ userName.setValue(SimpleValueSupport.wrap("sa"));
+ ManagedProperty password = props.get("password");
+ password.setValue(SimpleValueSupport.wrap(""));
+
+ // Remove the
+ ManagedProperty useJavaCtx = props.get("use-java-context");
+ SimpleValue nullBoolean = SimpleValueSupport.wrap(false);
+ ((SimpleValueSupport)nullBoolean).setValue(null);
+ useJavaCtx.setValue(nullBoolean);
+ useJavaCtx.setRemoved(true);
+
+ mgtView.applyTemplate("testRemovedProperties", dsInfo);
+
+ // reload the view and new datasource component
+ ComponentType componentType = new ComponentType("DataSource", "LocalTx");
+ activeView = null;
+ mgtView = getManagementView();
+ ManagedComponent dsMC = getManagedComponent(mgtView, componentType, jndiName);
+ assertNotNull(dsMC);
+
+ // Validate that the use-java-context value is true
+ useJavaCtx = dsMC.getProperty("use-java-context");
+ assertNotNull(useJavaCtx);
+ assertEquals(SimpleValueSupport.wrap(Boolean.TRUE), useJavaCtx.getValue());
+
+ // Update the use-java-context value
+ ManagedProperty minPoolSize = dsMC.getProperty("min-pool-size");
+ MetaValue oldValue = minPoolSize.getValue();
+ minPoolSize.setValue(SimpleValueSupport.wrap(1));
+ minPoolSize.setRemoved(true);
+ ManagedProperty maxPoolSize = dsMC.getProperty("max-pool-size");
+ maxPoolSize.setValue(SimpleValueSupport.wrap(999));
+ activeView.updateComponent(dsMC);
+ dsMC = getManagedComponent(mgtView, componentType, jndiName);
+ assertNotNull(dsMC);
+ minPoolSize = dsMC.getProperty("min-pool-size");
+ assertEquals(oldValue, minPoolSize.getValue());
+ maxPoolSize = dsMC.getProperty("max-pool-size");
+ assertEquals(SimpleValueSupport.wrap(999), maxPoolSize.getValue());
+
+ // Remove the deployment
+ removeDeployment("testRemovedProperties-ds.xml");
+ }
+
+}
More information about the jboss-cvs-commits
mailing list