[jboss-cvs] JBossAS SVN: r59855 - in trunk/profileservice/src: main/org/jboss/profileservice/management and 6 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Jan 19 13:42:22 EST 2007
Author: scott.stark at jboss.org
Date: 2007-01-19 13:42:22 -0500 (Fri, 19 Jan 2007)
New Revision: 59855
Added:
trunk/profileservice/src/main/org/jboss/profileservice/management/builders/FakeConnectionFactoryDeployerManagedObjectBuilder.java
trunk/profileservice/src/main/org/jboss/profileservice/management/builders/ServiceAttributeFields.java
trunk/profileservice/src/main/org/jboss/profileservice/management/builders/ServiceManagedObject.java
trunk/profileservice/src/main/org/jboss/profileservice/management/templates/FakeDsXmlDataSourceTemplate.java
trunk/profileservice/src/main/org/jboss/profileservice/mock/
trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/
trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/DataSourceDeployment.java
trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/FakeDataSourceConn.java
trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/FakeDataSourceConnMBean.java
trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/FakeDataSourceDeployer.java
trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/MockDataSource.java
trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/TestParse.java
Modified:
trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java
trunk/profileservice/src/main/org/jboss/profileservice/management/messages.properties
trunk/profileservice/src/main/org/jboss/profileservice/management/plugins/BasicDeploymentTemplateInfo.java
trunk/profileservice/src/main/org/jboss/profileservice/management/templates/DsXmlDataSourceTemplateInfo.java
trunk/profileservice/src/resources/profileservice-beans.xml
Log:
Get the add via template working for fake datasource
Modified: trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java 2007-01-19 18:41:02 UTC (rev 59854)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java 2007-01-19 18:42:22 UTC (rev 59855)
@@ -32,6 +32,8 @@
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.jboss.deployers.plugins.structure.AbstractDeploymentContext;
import org.jboss.deployers.spi.DeploymentException;
@@ -146,6 +148,28 @@
return names;
}
+ public Set<String> getMatchingDeploymentName(ProfileKey key, String regex)
+ throws NoSuchProfileException, NoSuchDeploymentException
+ {
+ Set<String> names = getDeploymentNames(key);
+ HashSet<String> matches = new HashSet<String>();
+ Pattern p = Pattern.compile(regex);
+ for(String name : names)
+ {
+ Matcher m = p.matcher(name);
+ if( m.matches() )
+ matches.add(name);
+ }
+ if( matches.size() == 0 )
+ {
+ formatter.applyPattern(i18n.getString("ManagementView.NoSuchDeploymentException")); //$NON-NLS-1$
+ Object[] args = {regex};
+ String msg = formatter.format(args);
+ throw new NoSuchDeploymentException(msg);
+ }
+ return matches;
+ }
+
public Set<String> getTemplateNames()
{
HashSet<String> tmp = new HashSet<String>(templates.keySet());
@@ -198,6 +222,7 @@
}
DeploymentTemplateInfo info = template.getInfo();
+ log.debug("getTemplate, "+info);
return info;
}
@@ -242,23 +267,71 @@
// Apply the managed properties
Map<String, ManagedObject> mos = mainDeployer.getManagedObjects(ctx);
- if( log.isTraceEnabled() )
- log.trace("applyTemplate, key="+key+", deploymentBaseName="+deploymentBaseName+", phase="+phase+", :"+mos);
+ log.debug("applyTemplate, key="+key+", deploymentBaseName="+deploymentBaseName+", phase="+phase+", :"+mos);
for(ManagedProperty prop : info.getProperties().values())
{
+ // Skip null values
+ if( prop.getValue() == null )
+ continue;
+
ManagedObject mo = prop.getManagedObject();
ManagedObject ctxMO = mos.get(mo.getName());
+ if( ctxMO == null )
+ {
+ formatter.applyPattern(i18n.getString("ManagementView.InvalidTemplateKey")); //$NON-NLS-1$
+ Object[] args = {mo.getName()};
+ String msg = formatter.format(args);
+ throw new IllegalArgumentException(msg);
+ }
ManagedProperty ctxProp = ctxMO.getProperty(prop.getName());
+ // Check for a mapped name
+ if( ctxProp == null )
+ {
+ String mappedName = prop.getMappedName();
+ if( mappedName != null )
+ ctxProp = ctxMO.getProperty(mappedName);
+ }
+ if( ctxProp == null )
+ {
+ formatter.applyPattern(i18n.getString("ManagementView.InvalidTemplateProperty")); //$NON-NLS-1$
+ Object[] args = {prop.getName()};
+ String msg = formatter.format(args);
+ throw new IllegalArgumentException(msg);
+ }
ctxProp.setValue((Serializable)prop.getValue());
}
log.info("Updated mo: "+mos);
// Process the updated deployment
// TODO this is a complete reparse because of deployments like datasource that update a parser input
- mainDeployer.process();
+ mainDeployer.process(Deployer.CLASSLOADER_DEPLOYER, Integer.MAX_VALUE);
checkIncomplete();
}
+ public void removeDeployment(ProfileKey key, String deploymentName, DeploymentPhase phase)
+ throws NoSuchProfileException, NoSuchDeploymentException, Exception
+ {
+ Profile profile = ps.getProfile(key);
+ if( profile == null )
+ {
+ formatter.applyPattern(i18n.getString("ManagementView.NoSuchProfileException")); //$NON-NLS-1$
+ Object[] args = {key};
+ String msg = formatter.format(args);
+ throw new NoSuchProfileException(msg);
+ }
+ DeploymentContext ctx = profile.removeDeployment(deploymentName, phase);
+ if( ctx == null )
+ {
+ formatter.applyPattern(i18n.getString("ManagementView.NoSuchDeploymentException")); //$NON-NLS-1$
+ Object[] args = {deploymentName};
+ String msg = formatter.format(args);
+ throw new NoSuchDeploymentException(msg);
+ }
+ mainDeployer.removeDeploymentContext(deploymentName);
+ mainDeployer.process();
+ checkIncomplete();
+ }
+
/**
* Check whether we are incomplete
*
Added: trunk/profileservice/src/main/org/jboss/profileservice/management/builders/FakeConnectionFactoryDeployerManagedObjectBuilder.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/builders/FakeConnectionFactoryDeployerManagedObjectBuilder.java (rev 0)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/builders/FakeConnectionFactoryDeployerManagedObjectBuilder.java 2007-01-19 18:42:22 UTC (rev 59855)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.builders;
+
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentUnit;
+import org.jboss.deployers.spi.managed.ManagedObjectBuilder;
+import org.jboss.logging.Logger;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.plugins.DefaultFieldsImpl;
+import org.jboss.managed.plugins.ManagedObjectImpl;
+import org.jboss.managed.plugins.ManagedPropertyImpl;
+import org.jboss.managed.plugins.advice.WrapperAdvice;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.system.metadata.ServiceDeployment;
+import org.jboss.system.metadata.ServiceMetaData;
+
+/**
+ * A ManagedObjectBuilder for use as an override to the FakeDataSourceDeployer
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class FakeConnectionFactoryDeployerManagedObjectBuilder
+ implements ManagedObjectBuilder
+{
+ private static Logger log = Logger.getLogger(ConnectionFactoryDeployerManagedObjectBuilder.class);
+
+ private Map<String, String> propertyNameMappings;
+
+ public Map<String, String> getPropertyNameMappings()
+ {
+ return propertyNameMappings;
+ }
+
+ public void setPropertyNameMappings(Map<String, String> propertyNameMappings)
+ {
+ this.propertyNameMappings = propertyNameMappings;
+ }
+
+ public void build(DeploymentUnit unit, Map<String, ManagedObject> map)
+ throws DeploymentException
+ {
+ String name = unit.getSimpleName();
+ if(name.endsWith("-dsf.xml"))
+ {
+ Map<String, Object> attachments = unit.getAttachments();
+ log.info(name+" attachments: "+attachments);
+ ServiceDeployment service = unit.getAttachment(ServiceDeployment.class);
+ if( service == null )
+ throw new DeploymentException("Failed to find ServiceDeployment in "+unit.getName());
+ List<ServiceMetaData> services = service.getServices();
+ // TODO, can have multiple datasources in a deployment
+ if( services.size() != 1 )
+ throw new DeploymentException("Expected only 1 ServiceMetaData but saw "+services.size()+" in "+unit.getName());
+ ServiceMetaData dsMetaData = services.get(0);
+ String attachName = ServiceMetaData.class.getName();
+ ManagedObject mo = new ServiceManagedObject(attachName, dsMetaData);
+ ManagedObject wrapMO = WrapperAdvice.wrapManagedObject(mo);
+ map.put(attachName, wrapMO);
+ }
+ }
+}
Property changes on: trunk/profileservice/src/main/org/jboss/profileservice/management/builders/FakeConnectionFactoryDeployerManagedObjectBuilder.java
___________________________________________________________________
Name: svn:keywords
+ Id,Revision
Name: svn:eol-style
+ native
Added: trunk/profileservice/src/main/org/jboss/profileservice/management/builders/ServiceAttributeFields.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/builders/ServiceAttributeFields.java (rev 0)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/builders/ServiceAttributeFields.java 2007-01-19 18:42:22 UTC (rev 59855)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.builders;
+
+import java.io.Serializable;
+
+import org.jboss.managed.api.Fields;
+import org.jboss.managed.plugins.DefaultFieldsImpl;
+import org.jboss.system.metadata.ServiceAttributeMetaData;
+import org.jboss.system.metadata.ServiceTextValueMetaData;
+
+/**
+ * A Fields implementation that maps to a service attribute.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class ServiceAttributeFields extends DefaultFieldsImpl
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
+ /** The datasource element */
+ private ServiceAttributeMetaData metaData;
+
+ /**
+ * Create a new ServiceAttributeFields.
+ *
+ * @param metaData the service attribute metadata the field maps to.
+ */
+ public ServiceAttributeFields(ServiceAttributeMetaData metaData)
+ {
+ this(metaData, metaData.getName(), null);
+ }
+ /**
+ * Create a new ServiceAttributeFields with the given field name;
+ *
+ * @param metaData the service attribute metadata the field maps to.
+ * @param fieldName the field name to use. If its null the attribute
+ * name will be used.
+ */
+ public ServiceAttributeFields(ServiceAttributeMetaData metaData, String fieldName,
+ String mappedName)
+ {
+ this.metaData = metaData;
+ if( fieldName == null )
+ fieldName = metaData.getName();
+ this.setField(Fields.NAME, fieldName);
+ if( mappedName != null )
+ this.setField(Fields.MAPPED_NAME, mappedName);
+ }
+
+ public Serializable getField(String name)
+ {
+ if (VALUE.equals(name))
+ {
+ ServiceTextValueMetaData text = (ServiceTextValueMetaData) metaData.getValue();
+ return text.getText();
+ }
+ return super.getField(name);
+ }
+
+ public void setField(String name, Serializable value)
+ {
+ if (VALUE.equals(name))
+ {
+ String string = (String) value;
+ ServiceTextValueMetaData text = new ServiceTextValueMetaData(string);
+ this.metaData.setValue(text);
+ return;
+ }
+ super.setField(name, value);
+ }
+}
Property changes on: trunk/profileservice/src/main/org/jboss/profileservice/management/builders/ServiceAttributeFields.java
___________________________________________________________________
Name: svn:keywords
+ Id,Revision
Name: svn:eol-style
+ native
Added: trunk/profileservice/src/main/org/jboss/profileservice/management/builders/ServiceManagedObject.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/builders/ServiceManagedObject.java (rev 0)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/builders/ServiceManagedObject.java 2007-01-19 18:42:22 UTC (rev 59855)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.builders;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.plugins.ManagedObjectImpl;
+import org.jboss.managed.plugins.ManagedPropertyImpl;
+import org.jboss.system.metadata.ServiceAttributeMetaData;
+import org.jboss.system.metadata.ServiceMetaData;
+
+/**
+ * A ManagedObject implementation for ServiceMetaData attachments.
+ *
+ * TODO: move to common location.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class ServiceManagedObject extends ManagedObjectImpl
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * ServiceManagedObject ctor
+ */
+ public ServiceManagedObject(String attachmentName, ServiceMetaData metaData)
+ {
+ this(attachmentName, metaData, null);
+ }
+ public ServiceManagedObject(String attachmentName, ServiceMetaData metaData,
+ Map<String, String> propertyNameMappings)
+ {
+ super(attachmentName);
+ try
+ {
+ Set<ManagedProperty> properties = getProperties();
+ List<ServiceAttributeMetaData> attributes = metaData.getAttributes();
+ for(ServiceAttributeMetaData attr : attributes)
+ {
+ String fieldName = attr.getName();
+ String mappedName = null;
+ if( propertyNameMappings != null )
+ mappedName = propertyNameMappings.get(fieldName);
+ ServiceAttributeFields attrFields = new ServiceAttributeFields(attr, fieldName, mappedName);
+ properties.add(new ManagedPropertyImpl(this, attrFields));
+ }
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Error creating ServiceManagedObject", e);
+ }
+
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder tmp = new StringBuilder("ServiceManagedObject{");
+ tmp.append(super.getProperties());
+ tmp.append('}');
+ return tmp.toString();
+ }
+
+}
Property changes on: trunk/profileservice/src/main/org/jboss/profileservice/management/builders/ServiceManagedObject.java
___________________________________________________________________
Name: svn:keywords
+ Id,Revision
Name: svn:eol-style
+ native
Modified: trunk/profileservice/src/main/org/jboss/profileservice/management/messages.properties
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/messages.properties 2007-01-19 18:41:02 UTC (rev 59854)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/messages.properties 2007-01-19 18:42:22 UTC (rev 59855)
@@ -1,3 +1,6 @@
#
ManagementView.NoSuchProfileException=Failed to find profile for key: {0}
-ManagementViewImp.NoSuchTemplate=Failed to find template for: {0}
+ManagementView.NoSuchDeploymentException=Failed to find deployment for name: {0}
+ManagementView.NoSuchTemplate=Failed to find template for: {0}
+ManagementView.InvalidTemplateKey=Failed to map key: {0} to managed attachments for deployment
+ManagementView.InvalidTemplateProperty=Failed to map property: {0} to managed properties for deployment
\ No newline at end of file
Modified: trunk/profileservice/src/main/org/jboss/profileservice/management/plugins/BasicDeploymentTemplateInfo.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/plugins/BasicDeploymentTemplateInfo.java 2007-01-19 18:41:02 UTC (rev 59854)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/plugins/BasicDeploymentTemplateInfo.java 2007-01-19 18:42:22 UTC (rev 59855)
@@ -75,5 +75,17 @@
{
this.properties.put(property.getName(), property);
}
-
+
+ public String toString()
+ {
+ StringBuilder tmp = new StringBuilder(super.toString());
+ tmp.append('{');
+ tmp.append(name);
+ tmp.append(",description=");
+ tmp.append(description);
+ tmp.append(",properties=");
+ tmp.append(properties);
+ tmp.append('}');
+ return tmp.toString();
+ }
}
Modified: trunk/profileservice/src/main/org/jboss/profileservice/management/templates/DsXmlDataSourceTemplateInfo.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/templates/DsXmlDataSourceTemplateInfo.java 2007-01-19 18:41:02 UTC (rev 59854)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/templates/DsXmlDataSourceTemplateInfo.java 2007-01-19 18:42:22 UTC (rev 59855)
@@ -21,6 +21,9 @@
*/
package org.jboss.profileservice.management.templates;
+import java.util.Map;
+
+import org.jboss.managed.api.Fields;
import org.jboss.managed.plugins.DefaultFieldsImpl;
import org.jboss.managed.plugins.ManagedObjectImpl;
import org.jboss.managed.plugins.ManagedPropertyImpl;
@@ -29,22 +32,44 @@
import org.jboss.system.metadata.ServiceDeployment;
/**
+ * The properties used by the DsXmlDataSourceTemplate.
*
* @author Scott.Stark at jboss.org
- * @version $Revision:$
+ * @version $Revision$
*/
public class DsXmlDataSourceTemplateInfo extends BasicDeploymentTemplateInfo
{
private static final long serialVersionUID = 1;
+ private Map<String, String> propertyNameMappings;
+ private String attachmentName;
public DsXmlDataSourceTemplateInfo(String name, String description)
{
+ this(name, description, ServiceDeployment.class.getName());
+ }
+ public DsXmlDataSourceTemplateInfo(String name, String description,
+ String attachmentName)
+ {
super(name, description);
+ this.attachmentName = attachmentName;
+ }
- ManagedObjectImpl mo = new ManagedObjectImpl(ServiceDeployment.class.getName());
+ public Map<String, String> getPropertyNameMappings()
+ {
+ return propertyNameMappings;
+ }
+
+ public void setPropertyNameMappings(Map<String, String> propertyNameMappings)
+ {
+ this.propertyNameMappings = propertyNameMappings;
+ }
+
+ public void start()
+ {
+ ManagedObjectImpl mo = new ManagedObjectImpl(attachmentName);
// The jndi name field info
DefaultFieldsImpl f0 = new DefaultFieldsImpl();
- f0.setName("jndi-name");
+ setFieldName("jndi-name", f0);
f0.setDescription("The jndi name to bind the DataSource under");
f0.setMandatory(true);
f0.setMetaType(SimpleMetaType.STRING);
@@ -52,7 +77,7 @@
super.addProperty(jndiName);
// The connection-url field info
DefaultFieldsImpl f1 = new DefaultFieldsImpl();
- f1.setName("connection-url");
+ setFieldName("connection-url", f1);
f1.setDescription("The jdbc url of the DataSource");
f1.setMandatory(true);
f1.setMetaType(SimpleMetaType.STRING);
@@ -60,7 +85,7 @@
super.addProperty(conURL);
// The user field info
DefaultFieldsImpl f2 = new DefaultFieldsImpl();
- f2.setName("user-name");
+ setFieldName("user-name", f2);
f2.setDescription("The username for the connection-url");
f2.setMandatory(false);
f2.setMetaType(SimpleMetaType.STRING);
@@ -68,20 +93,38 @@
super.addProperty(user);
// The password field info
DefaultFieldsImpl f3 = new DefaultFieldsImpl();
- f3.setName("password");
+ setFieldName("password", f3);
f3.setDescription("The password for the connection-url");
f3.setMandatory(false);
f3.setMetaType(SimpleMetaType.STRING);
ManagedPropertyImpl password = new ManagedPropertyImpl(mo, f3);
super.addProperty(password);
- // The security-domain field info
+ // The security-domain field info
DefaultFieldsImpl f4 = new DefaultFieldsImpl();
- f4.setName("security-domain");
+ setFieldName("security-domain", f4);
f4.setDescription("The security-domain used to validate connections");
f4.setMandatory(false);
f4.setMetaType(SimpleMetaType.STRING);
ManagedPropertyImpl secDomain = new ManagedPropertyImpl(mo, f4);
super.addProperty(secDomain);
+ // The driver-class field info
+ DefaultFieldsImpl f5 = new DefaultFieldsImpl();
+ setFieldName("driver-class", f5);
+ f5.setDescription("The jdbc driver class name");
+ f5.setMandatory(true);
+ f5.setMetaType(SimpleMetaType.STRING);
+ ManagedPropertyImpl dc = new ManagedPropertyImpl(mo, f5);
+ super.addProperty(dc);
}
+ protected void setFieldName(String name, Fields f)
+ {
+ f.setField(Fields.NAME, name);
+ if( propertyNameMappings != null )
+ {
+ String mappedName = propertyNameMappings.get(name);
+ if( mappedName != null )
+ f.setField(Fields.MAPPED_NAME, mappedName);
+ }
+ }
}
Added: trunk/profileservice/src/main/org/jboss/profileservice/management/templates/FakeDsXmlDataSourceTemplate.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/templates/FakeDsXmlDataSourceTemplate.java (rev 0)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/templates/FakeDsXmlDataSourceTemplate.java 2007-01-19 18:42:22 UTC (rev 59855)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.templates;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.net.URI;
+
+import org.jboss.deployers.spi.management.DeploymentTemplate;
+import org.jboss.deployers.spi.management.DeploymentTemplateInfo;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * A template for creating a datasource(*-ds.xml) deployments.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class FakeDsXmlDataSourceTemplate
+ implements DeploymentTemplate
+{
+ private DeploymentTemplateInfo info;
+
+ /**
+ * Creates a root/{deploymentBaseName}-dsf.xml base descriptor.
+ */
+ public VirtualFile applyTemplate(VirtualFile root, String deploymentBaseName,
+ DeploymentTemplateInfo values)
+ throws Exception
+ {
+ String dsName = deploymentBaseName+"-dsf.xml";
+ URI dsXmlURI = new URI(root.toURI()+dsName);
+ File dsXml = new File(dsXmlURI.getPath());
+ writeTemplate(dsXml, values);
+ VirtualFile dsXmlVF = root.findChild(dsName);
+ return dsXmlVF;
+ }
+
+ public DeploymentTemplateInfo getInfo()
+ {
+ return info;
+ }
+ public void setInfo(DeploymentTemplateInfo info)
+ {
+ this.info = info;
+ }
+
+ protected void writeTemplate(File dsXml, DeploymentTemplateInfo values)
+ throws Exception
+ {
+ FileWriter fw = new FileWriter(dsXml);
+ fw.write("<datasources>\n");
+ fw.write("<local-tx-datasource>\n");
+ fw.write("<jndi-name>default</jndi-name>\n");
+ fw.write("<connection-url>jdbc:...</connection-url>\n");
+ fw.write("<driver-class>default</driver-class>\n");
+ fw.write("<user-name>default</user-name>\n");
+ fw.write("<password>default</password>\n");
+ fw.write("<min-pool-size>1</min-pool-size>\n");
+ fw.write("<max-pool-size>10</max-pool-size>\n");
+ fw.write("<security-domain>default</security-domain>\n");
+ fw.write("</local-tx-datasource>\n");
+ fw.write("</datasources>\n");
+ fw.flush();
+ fw.close();
+ }
+}
Property changes on: trunk/profileservice/src/main/org/jboss/profileservice/management/templates/FakeDsXmlDataSourceTemplate.java
___________________________________________________________________
Name: svn:keywords
+ Id,Revision
Name: svn:eol-style
+ native
Added: trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/DataSourceDeployment.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/DataSourceDeployment.java (rev 0)
+++ trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/DataSourceDeployment.java 2007-01-19 18:42:22 UTC (rev 59855)
@@ -0,0 +1,247 @@
+package org.jboss.profileservice.mock.ds;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.logging.Logger;
+import org.jboss.system.metadata.ServiceAttributeMetaData;
+import org.jboss.system.metadata.ServiceDependencyMetaData;
+import org.jboss.util.StringPropertyReplacer;
+import org.jboss.util.xml.DOMUtils;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class DataSourceDeployment
+{
+ private static Logger log = Logger.getLogger(DataSourceDeployment.class);
+
+ private boolean replace = true;
+ private String jndiName;
+ private String driverClass;
+ private String typeMapping;
+ private String jdbcURL;
+ private String username;
+ private String password;
+ private String securityDomain;
+ private String minPoolSize;
+ private String maxPoolSize;
+ private ArrayList<String> depends = new ArrayList<String>();
+
+ public String getDriverClass()
+ {
+ return driverClass;
+ }
+
+ public void setDriverClass(String driverClass)
+ {
+ this.driverClass = driverClass;
+ }
+
+ public String getJdbcURL()
+ {
+ return jdbcURL;
+ }
+
+ public void setJdbcURL(String jdbcURL)
+ {
+ this.jdbcURL = jdbcURL;
+ }
+
+ public String getJndiName()
+ {
+ return jndiName;
+ }
+
+ public void setJndiName(String jndiName)
+ {
+ this.jndiName = jndiName;
+ }
+
+ public String getMaxPoolSize()
+ {
+ return maxPoolSize;
+ }
+
+ public void setMaxPoolSize(String maxPoolSize)
+ {
+ this.maxPoolSize = maxPoolSize;
+ }
+
+ public String getMinPoolSize()
+ {
+ return minPoolSize;
+ }
+
+ public void setMinPoolSize(String minPoolSize)
+ {
+ this.minPoolSize = minPoolSize;
+ }
+
+ public String getPassword()
+ {
+ return password;
+ }
+
+ public void setPassword(String password)
+ {
+ this.password = password;
+ }
+
+ public boolean isReplace()
+ {
+ return replace;
+ }
+
+ public void setReplace(boolean replace)
+ {
+ this.replace = replace;
+ }
+
+ public String getSecurityDomain()
+ {
+ return securityDomain;
+ }
+
+ public void setSecurityDomain(String securityDomain)
+ {
+ this.securityDomain = securityDomain;
+ }
+
+ public String getTypeMapping()
+ {
+ return typeMapping;
+ }
+
+ public void setTypeMapping(String typeMapping)
+ {
+ this.typeMapping = typeMapping;
+ }
+
+ public String getUsername()
+ {
+ return username;
+ }
+
+ public void setUsername(String username)
+ {
+ this.username = username;
+ }
+
+ public List<String> getDepends()
+ {
+ return depends;
+ }
+
+ public void parse(Document document)
+ {
+ NodeList datasources = document.getElementsByTagName("local-tx-datasource");
+ for (int i = 0; i < datasources.getLength(); ++i)
+ {
+ Node node = datasources.item(i);
+ if (node.getNodeType() == Node.ELEMENT_NODE)
+ {
+ Element e = (Element) node;
+ System.out.println("ELEMENT_NODE: "+e);
+ NodeList tags = node.getChildNodes();
+ for(int j = 0; j < tags.getLength(); j ++)
+ {
+ Node child = tags.item(j);
+ if(child.getNodeType() == Node.ELEMENT_NODE)
+ {
+ Element ej = (Element) child;
+ if (ej.getTagName().equals("jndi-name"))
+ {
+ jndiName = getText(ej);
+ }
+ else if (ej.getTagName().equals("connection-url"))
+ {
+ this.jdbcURL = getText(ej);
+ }
+ else if (ej.getTagName().equals("user-name"))
+ {
+ this.username = getText(ej);
+ }
+ else if (ej.getTagName().equals("driver-class"))
+ {
+ this.driverClass = getText(ej);
+ }
+ else if (ej.getTagName().equals("password"))
+ {
+ this.password = getText(ej);
+ if(this.password == null)
+ this.password = "";
+ }
+ else if (ej.getTagName().equals("min-pool-size"))
+ {
+ this.minPoolSize = getText(ej);
+ }
+ else if (ej.getTagName().equals("max-pool-size"))
+ {
+ this.maxPoolSize = getText(ej);
+ }
+ else if (ej.getTagName().equals("security-domain"))
+ {
+ this.securityDomain = getText(ej);
+ }
+ else if (ej.getTagName().equals("metadata"))
+ {
+ NodeList tms = ej.getElementsByTagName("type-mapping");
+ Element tm = (Element) tms.item(0);
+ this.typeMapping = getText(tm);
+ }
+ else if (ej.getTagName().equals("depends"))
+ {
+ String depends = getText(ej);
+ addDepends(depends);
+ }
+ }
+ }
+
+ }
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder tmp = new StringBuilder(super.toString());
+ tmp.append('(');
+ tmp.append("depends=");
+ tmp.append(depends);
+ tmp.append(",driverClass=");
+ tmp.append(driverClass);
+ tmp.append(",jdbcURL=");
+ tmp.append(jdbcURL);
+ tmp.append(",jndiName=");
+ tmp.append(jndiName);
+ tmp.append(",username=");
+ tmp.append(username);
+ tmp.append(",password=");
+ tmp.append(password);
+ tmp.append(",minPoolSize=");
+ tmp.append(minPoolSize);
+ tmp.append(",maxPoolSize=");
+ tmp.append(maxPoolSize);
+ tmp.append(",securityDomain=");
+ tmp.append(securityDomain);
+ tmp.append(",typeMapping=");
+ tmp.append(typeMapping);
+ tmp.append(')');
+ return tmp.toString();
+ }
+
+ private void addDepends(String depends)
+ {
+ this.depends.add(depends);
+ }
+
+ private String getText(Node node)
+ {
+ String text = DOMUtils.getTextContent(node);
+ if( text != null && replace )
+ text = StringPropertyReplacer.replaceProperties(text);
+ return text;
+ }
+}
Property changes on: trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/DataSourceDeployment.java
___________________________________________________________________
Name: svn:keywords
+ Id,Revision
Name: svn:eol-style
+ native
Added: trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/FakeDataSourceConn.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/FakeDataSourceConn.java (rev 0)
+++ trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/FakeDataSourceConn.java 2007-01-19 18:42:22 UTC (rev 59855)
@@ -0,0 +1,225 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.mock.ds;
+
+import java.util.List;
+
+import javax.naming.InitialContext;
+
+import org.jboss.logging.Logger;
+import org.jboss.util.naming.Util;
+
+/**
+ * A fake DataSource connection object.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class FakeDataSourceConn
+ implements FakeDataSourceConnMBean
+{
+ private static Logger log = Logger.getLogger(FakeDataSourceConn.class);
+ private DataSourceDeployment ds;
+ private MockDataSource dsConn;
+
+ public FakeDataSourceConn(DataSourceDeployment ds)
+ {
+ this.ds = ds;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.profileservice.mock.ds.x#getDepends()
+ */
+ public List<String> getDepends()
+ {
+ return ds.getDepends();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.profileservice.mock.ds.x#getDriverClass()
+ */
+ public String getDriverClass()
+ {
+ return ds.getDriverClass();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.profileservice.mock.ds.x#getJdbcURL()
+ */
+ public String getJdbcURL()
+ {
+ return ds.getJdbcURL();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.profileservice.mock.ds.x#getJndiName()
+ */
+ public String getJndiName()
+ {
+ return ds.getJndiName();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.profileservice.mock.ds.x#getMaxPoolSize()
+ */
+ public int getMaxPoolSize()
+ {
+ return Integer.parseInt(ds.getMaxPoolSize());
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.profileservice.mock.ds.x#getMinPoolSize()
+ */
+ public int getMinPoolSize()
+ {
+ return Integer.parseInt(ds.getMinPoolSize());
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.profileservice.mock.ds.x#getPassword()
+ */
+ public String getPassword()
+ {
+ return ds.getPassword();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.profileservice.mock.ds.x#getSecurityDomain()
+ */
+ public String getSecurityDomain()
+ {
+ return ds.getSecurityDomain();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.profileservice.mock.ds.x#getTypeMapping()
+ */
+ public String getTypeMapping()
+ {
+ return ds.getTypeMapping();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.profileservice.mock.ds.x#getUsername()
+ */
+ public String getUsername()
+ {
+ return ds.getUsername();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.profileservice.mock.ds.x#setDriverClass(java.lang.String)
+ */
+ public void setDriverClass(String driverClass)
+ {
+ log.info("setDriverClass, "+driverClass);
+ ds.setDriverClass(driverClass);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.profileservice.mock.ds.x#setJdbcURL(java.lang.String)
+ */
+ public void setJdbcURL(String jdbcURL)
+ {
+ log.info("setJdbcURL, "+jdbcURL);
+ ds.setJdbcURL(jdbcURL);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.profileservice.mock.ds.x#setJndiName(java.lang.String)
+ */
+ public void setJndiName(String jndiName)
+ {
+ log.info("setJndiName, "+jndiName);
+ ds.setJndiName(jndiName);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.profileservice.mock.ds.x#setMaxPoolSize(int)
+ */
+ public void setMaxPoolSize(int maxPoolSize)
+ {
+ ds.setMaxPoolSize(""+maxPoolSize);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.profileservice.mock.ds.x#setMinPoolSize(int)
+ */
+ public void setMinPoolSize(int minPoolSize)
+ {
+ ds.setMinPoolSize(""+minPoolSize);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.profileservice.mock.ds.x#setPassword(java.lang.String)
+ */
+ public void setPassword(String password)
+ {
+ ds.setPassword(password);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.profileservice.mock.ds.x#setSecurityDomain(java.lang.String)
+ */
+ public void setSecurityDomain(String securityDomain)
+ {
+ ds.setSecurityDomain(securityDomain);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.profileservice.mock.ds.x#setTypeMapping(java.lang.String)
+ */
+ public void setTypeMapping(String typeMapping)
+ {
+ ds.setTypeMapping(typeMapping);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.profileservice.mock.ds.x#setUsername(java.lang.String)
+ */
+ public void setUsername(String username)
+ {
+ ds.setUsername(username);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.profileservice.mock.ds.x#start()
+ */
+ public void start()
+ throws Exception
+ {
+ dsConn = new MockDataSource();
+ InitialContext ctx = new InitialContext();
+ Util.bind(ctx, ds.getJndiName(), dsConn);
+ log.info("Bound MockDataSource under: "+ds.getJndiName());
+ }
+ /* (non-Javadoc)
+ * @see org.jboss.profileservice.mock.ds.x#stop()
+ */
+ public void stop()
+ throws Exception
+ {
+ InitialContext ctx = new InitialContext();
+ Util.unbind(ctx, ds.getJndiName());
+ log.info("Unbound MockDataSource under: "+ds.getJndiName());
+ }
+}
Property changes on: trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/FakeDataSourceConn.java
___________________________________________________________________
Name: svn:keywords
+ Id,Revision
Name: svn:eol-style
+ native
Added: trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/FakeDataSourceConnMBean.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/FakeDataSourceConnMBean.java (rev 0)
+++ trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/FakeDataSourceConnMBean.java 2007-01-19 18:42:22 UTC (rev 59855)
@@ -0,0 +1,49 @@
+package org.jboss.profileservice.mock.ds;
+
+import java.util.List;
+
+public interface FakeDataSourceConnMBean
+{
+ public List<String> getDepends();
+
+ public String getDriverClass();
+
+ public String getJdbcURL();
+
+ public String getJndiName();
+
+ public int getMaxPoolSize();
+
+ public int getMinPoolSize();
+
+ public String getPassword();
+
+ public String getSecurityDomain();
+
+ public String getTypeMapping();
+
+ public String getUsername();
+
+ public void setDriverClass(String driverClass);
+
+ public void setJdbcURL(String jdbcURL);
+
+ public void setJndiName(String jndiName);
+
+ public void setMaxPoolSize(int maxPoolSize);
+
+ public void setMinPoolSize(int minPoolSize);
+
+ public void setPassword(String password);
+
+ public void setSecurityDomain(String securityDomain);
+
+ public void setTypeMapping(String typeMapping);
+
+ public void setUsername(String username);
+
+ public void start() throws Exception;
+
+ public void stop() throws Exception;
+
+}
Property changes on: trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/FakeDataSourceConnMBean.java
___________________________________________________________________
Name: svn:keywords
+ Id,Revision
Name: svn:eol-style
+ native
Added: trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/FakeDataSourceDeployer.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/FakeDataSourceDeployer.java (rev 0)
+++ trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/FakeDataSourceDeployer.java 2007-01-19 18:42:22 UTC (rev 59855)
@@ -0,0 +1,175 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.mock.ds;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.management.ObjectName;
+
+import org.jboss.deployers.plugins.deployers.helpers.JAXPDeployer;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentUnit;
+import org.jboss.system.metadata.ServiceAttributeMetaData;
+import org.jboss.system.metadata.ServiceConstructorMetaData;
+import org.jboss.system.metadata.ServiceDependencyMetaData;
+import org.jboss.system.metadata.ServiceDeployment;
+import org.jboss.system.metadata.ServiceMetaData;
+import org.jboss.system.metadata.ServiceTextValueMetaData;
+import org.jboss.virtual.VirtualFile;
+import org.w3c.dom.Document;
+
+/**
+ * A fake datasource deployer (*-dsf.xml, subset of *-ds.xml) for testing
+ * the profile service spis. This transforms the *-dsf.xml into a single
+ * ServiceMetaData representing the DataSource connection mbean.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class FakeDataSourceDeployer extends JAXPDeployer<ServiceDeployment>
+{
+
+ public FakeDataSourceDeployer()
+ {
+ super(ServiceDeployment.class);
+ }
+
+ @Override
+ public void deploy(DeploymentUnit unit) throws DeploymentException
+ {
+ createMetaData(unit, null, "-dsf.xml");
+ }
+
+ @Override
+ protected ServiceDeployment parse(DeploymentUnit unit, VirtualFile file, Document document) throws Exception
+ {
+ ServiceDeployment deployment = new ServiceDeployment();
+ ServiceMetaData dsMbean = new ServiceMetaData();
+ DataSourceDeployment ds = new DataSourceDeployment();
+ ds.parse(document);
+ log.info("DataSource settings: "+ds);
+
+ ObjectName objectName = new ObjectName("jboss.jca:type=FakeDataSourceConn,jndiName="+ds.getJndiName());
+ dsMbean.setObjectName(objectName);
+ dsMbean.setCode(FakeDataSourceConn.class.getName());
+ // FakeDataSourceConn(DataSourceDeployment)
+ ServiceConstructorMetaData constructor = new ServiceConstructorMetaData();
+ constructor.setSignature(new String[] {DataSourceDeployment.class.getName()});
+ constructor.setParameters(new Object[] {ds});
+ dsMbean.setConstructor(constructor);
+
+ // Attributes
+ List<ServiceAttributeMetaData> attributes = new ArrayList<ServiceAttributeMetaData>();
+ ServiceAttributeMetaData attribute = new ServiceAttributeMetaData();
+ // jndiName
+ if( ds.getJndiName() != null )
+ {
+ attribute.setName("JndiName");
+ attribute.setReplace(true);
+ attribute.setTrim(true);
+ attribute.setValue(new ServiceTextValueMetaData(ds.getJndiName()));
+ attributes.add(attribute);
+ }
+ // jdbcURL
+ if( ds.getJdbcURL() != null )
+ {
+ attribute = new ServiceAttributeMetaData();
+ attribute.setName("JdbcURL");
+ attribute.setValue(new ServiceTextValueMetaData(ds.getJdbcURL()));
+ attributes.add(attribute);
+ }
+ // driverClass
+ if(ds.getDriverClass() != null)
+ {
+ attribute = new ServiceAttributeMetaData();
+ attribute.setName("DriverClass");
+ attribute.setValue(new ServiceTextValueMetaData(ds.getDriverClass()));
+ attributes.add(attribute);
+ }
+ // username
+ if(ds.getUsername() != null)
+ {
+ attribute = new ServiceAttributeMetaData();
+ attribute.setName("Username");
+ attribute.setValue(new ServiceTextValueMetaData(ds.getUsername()));
+ attributes.add(attribute);
+ }
+ // password
+ if(ds.getPassword() != null)
+ {
+ attribute = new ServiceAttributeMetaData();
+ attribute.setName("Password");
+ attribute.setValue(new ServiceTextValueMetaData(ds.getPassword()));
+ attributes.add(attribute);
+ }
+ // securityDomain
+ if(ds.getSecurityDomain() != null)
+ {
+ attribute = new ServiceAttributeMetaData();
+ attribute.setName("SecurityDomain");
+ attribute.setValue(new ServiceTextValueMetaData(ds.getSecurityDomain()));
+ attributes.add(attribute);
+ }
+ // minPoolSize
+ if(ds.getMinPoolSize() != null)
+ {
+ attribute = new ServiceAttributeMetaData();
+ attribute.setName("MinPoolSize");
+ attribute.setValue(new ServiceTextValueMetaData(ds.getMinPoolSize()));
+ attributes.add(attribute);
+ }
+ // maxPoolSize
+ if(ds.getMaxPoolSize() != null)
+ {
+ attribute = new ServiceAttributeMetaData();
+ attribute.setName("MaxPoolSize");
+ attribute.setValue(new ServiceTextValueMetaData(ds.getMaxPoolSize()));
+ attributes.add(attribute);
+ }
+
+ dsMbean.setAttributes(attributes);
+
+ // Dependencies...Still have old jmx names here
+ Collection<String> depends = ds.getDepends();
+ List<ServiceDependencyMetaData> dependencies = new ArrayList<ServiceDependencyMetaData>();
+ for(String iDependOn : depends)
+ {
+ ServiceDependencyMetaData sdmd = new ServiceDependencyMetaData();
+ sdmd.setIDependOn(iDependOn);
+ }
+ dsMbean.setDependencies(dependencies);
+ ArrayList<ServiceMetaData> services = new ArrayList<ServiceMetaData>();
+ services.add(dsMbean);
+ deployment.setServices(services);
+
+ return deployment;
+ }
+
+ @Override
+ protected boolean allowsReparse()
+ {
+ return true;
+ }
+
+}
Property changes on: trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/FakeDataSourceDeployer.java
___________________________________________________________________
Name: svn:keywords
+ Id,Revision
Name: svn:eol-style
+ native
Added: trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/MockDataSource.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/MockDataSource.java (rev 0)
+++ trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/MockDataSource.java 2007-01-19 18:42:22 UTC (rev 59855)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.mock.ds;
+
+import java.io.PrintWriter;
+import java.io.Serializable;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import javax.sql.DataSource;
+
+/**
+ * A noop DataSource implementation
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class MockDataSource implements DataSource, Serializable
+{
+ private static final long serialVersionUID = 1;
+
+ public MockDataSource()
+ {
+ System.err.println("MockDataSource");
+ }
+
+ public Connection getConnection() throws SQLException
+ {
+ return null;
+ }
+
+ public Connection getConnection(String arg0, String arg1) throws SQLException
+ {
+ return null;
+ }
+
+ public int getLoginTimeout() throws SQLException
+ {
+ return 0;
+ }
+
+ public PrintWriter getLogWriter() throws SQLException
+ {
+ return null;
+ }
+
+ public void setLoginTimeout(int arg0) throws SQLException
+ {
+
+ }
+
+ public void setLogWriter(PrintWriter arg0) throws SQLException
+ {
+
+ }
+
+}
Property changes on: trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/MockDataSource.java
___________________________________________________________________
Name: svn:keywords
+ Id,Revision
Name: svn:eol-style
+ native
Added: trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/TestParse.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/TestParse.java (rev 0)
+++ trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/TestParse.java 2007-01-19 18:42:22 UTC (rev 59855)
@@ -0,0 +1,84 @@
+package org.jboss.profileservice.mock.ds;
+
+import java.io.File;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.jboss.util.xml.DOMUtils;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class TestParse
+{
+ public static void main(String[] args)
+ throws Exception
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ File tst = new File("/tmp/hsqldb-dsf.xml");
+ Document document = builder.parse(tst);
+
+ NodeList datasources = document.getElementsByTagName("local-tx-datasource");
+ System.out.println("Found "+datasources.getLength()+" local-tx-datasources");
+ for (int i = 0; i < datasources.getLength(); ++i)
+ {
+ Node node = datasources.item(i);
+ System.out.println(i+": "+node);
+ if (node.getNodeType() == Node.ELEMENT_NODE)
+ {
+ Element e = (Element) node;
+ System.out.println("ELEMENT_NODE: "+e);
+ NodeList tags = node.getChildNodes();
+ for(int j = 0; j < tags.getLength(); j ++)
+ {
+ Node child = tags.item(j);
+ if(child.getNodeType() == Node.ELEMENT_NODE)
+ {
+ Element ej = (Element) child;
+ if (ej.getTagName().equals("jndi-name"))
+ {
+ System.out.println("jndi-name: "+DOMUtils.getTextContent(ej));
+ }
+ else if (ej.getTagName().equals("user-name"))
+ {
+ System.out.println("user-name: "+DOMUtils.getTextContent(ej));
+ }
+ else if (ej.getTagName().equals("driver-class"))
+ {
+ System.out.println("driver-class: "+DOMUtils.getTextContent(ej));
+ }
+ else if (ej.getTagName().equals("password"))
+ {
+ System.out.println("password: "+DOMUtils.getTextContent(ej));
+ }
+ else if (ej.getTagName().equals("min-pool-size"))
+ {
+ System.out.println("min-pool-size: "+DOMUtils.getTextContent(ej));
+ }
+ else if (ej.getTagName().equals("max-pool-size"))
+ {
+ System.out.println("max-pool-size: "+DOMUtils.getTextContent(ej));
+ }
+ else if (ej.getTagName().equals("security-domain"))
+ {
+ System.out.println("security-domain: "+DOMUtils.getTextContent(ej));
+ }
+ else if (ej.getTagName().equals("metadata"))
+ {
+ NodeList tms = ej.getElementsByTagName("type-mapping");
+ Element tm = (Element) tms.item(0);
+ System.out.println("metadata: "+tm.getTextContent());
+ }
+ else if (ej.getTagName().equals("depends"))
+ {
+ System.out.println("depends: "+DOMUtils.getTextContent(ej));
+ }
+ }
+ }
+ }
+ }
+ }
+}
Property changes on: trunk/profileservice/src/main/org/jboss/profileservice/mock/ds/TestParse.java
___________________________________________________________________
Name: svn:keywords
+ Id,Revision
Name: svn:eol-style
+ native
Modified: trunk/profileservice/src/resources/profileservice-beans.xml
===================================================================
--- trunk/profileservice/src/resources/profileservice-beans.xml 2007-01-19 18:41:02 UTC (rev 59854)
+++ trunk/profileservice/src/resources/profileservice-beans.xml 2007-01-19 18:42:22 UTC (rev 59855)
@@ -48,6 +48,18 @@
<property name="profileService"><inject bean="ProfileService"/></property>
</bean>
+ <!-- ConnectionFactory Deployment -->
+ <bean name="FakeDataSourceDeployer"
+ class="org.jboss.profileservice.mock.ds.FakeDataSourceDeployer">
+ <install bean="MainDeployer" method="addDeployer">
+ <parameter><this/></parameter>
+ </install>
+ <uninstall bean="MainDeployer" method="removeDeployer">
+ <parameter><this/></parameter>
+ </uninstall>
+ <property name="type">jca-ds</property>
+ </bean>
+
<!-- DeploymentTemplates -->
<bean name="DsXmlDataSourceTemplate"
class="org.jboss.profileservice.management.templates.FakeDsXmlDataSourceTemplate">
@@ -67,9 +79,30 @@
class="org.jboss.profileservice.management.templates.DsXmlDataSourceTemplateInfo">
<constructor>
<parameter>DsXmlDataSourceTemplate</parameter>
- <parameter>A template for *-ds.xml deployments</parameter>
+ <parameter>A template for *-dsf.xml deployments</parameter>
+ <parameter>org.jboss.system.metadata.ServiceMetaData</parameter>
</constructor>
+ <!-- Specify a mapping from service attribute names used by the datasource
+ deployment ServiceMetaData to ManagedProperty names.
+ -->
+ <property name="propertyNameMappings">
+ <inject bean="DsPropertyMappings" />
+ </property>
</bean>
+ <bean name="DsPropertyMappings" class="java.util.HashMap">
+ <constructor>
+ <map class="java.util.HashMap" keyClass="java.lang.String" valueClass="java.lang.String">
+ <entry><key>jndi-name</key><value>JndiName</value></entry>
+ <entry><key>connection-url</key><value>JdbcURL</value></entry>
+ <entry><key>user-name</key><value>Username</value></entry>
+ <entry><key>password</key><value>Password</value></entry>
+ <entry><key>driver-class</key><value>DriverClass</value></entry>
+ <entry><key>min-pool-size</key><value>MinPoolSize</value></entry>
+ <entry><key>max-pool-size</key><value>MaxPoolSize</value></entry>
+ <entry><key>security-domain</key><value>SecurityDomain</value></entry>
+ </map>
+ </constructor>
+ </bean>
<!-- Override the ConnectionFactoryDeployer ManagedObjectBuilder -->
<bean name="ConnectionFactoryDeployerManagedObjectBuilder"
@@ -83,7 +116,25 @@
</parameter>
</install>
</bean>
-
+ <!-- Override the FakeDataSourceDeployer ManagedObjectBuilder -->
+ <bean name="FakeConnectionFactoryDeployerManagedObjectBuilder"
+ class="org.jboss.profileservice.management.builders.FakeConnectionFactoryDeployerManagedObjectBuilder">
+ <install bean="MainDeployer" method="setDeployerManagedObjectBuilder">
+ <parameter>
+ <inject bean="FakeDataSourceDeployer" />
+ </parameter>
+ <parameter>
+ <this/>
+ </parameter>
+ </install>
+ <!-- Specify a mapping from service attribute names used by the datasource
+ deployment ServiceMetaData to ManagedProperty names.
+ -->
+ <property name="propertyNameMappings">
+ <inject bean="DsPropertyMappings" />
+ </property>
+ </bean>
+
<bean name="ProfileServiceProxyFactory" class="org.jboss.profileservice.remoting.ProxyFactory">
<property name="dispatchName">ProfileService</property>
<property name="jndiName">ProfileService</property>
More information about the jboss-cvs-commits
mailing list