[jboss-cvs] JBossAS SVN: r86711 - in trunk: profileservice/src/main/org/jboss/profileservice/management/templates and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Apr 2 19:47:05 EDT 2009
Author: scott.stark at jboss.org
Date: 2009-04-02 19:47:05 -0400 (Thu, 02 Apr 2009)
New Revision: 86711
Modified:
trunk/profileservice/src/main/org/jboss/profileservice/management/RemovedPropertyMap.java
trunk/profileservice/src/main/org/jboss/profileservice/management/templates/JmsDestinationTemplate.java
trunk/profileservice/src/main/org/jboss/profileservice/management/templates/JmsDestinationTemplateInfo.java
trunk/testsuite/src/main/org/jboss/test/profileservice/test/JmsDestinationUnitTestCase.java
Log:
JBAS-6672, Update jms destination template to work with generic template info
Modified: trunk/profileservice/src/main/org/jboss/profileservice/management/RemovedPropertyMap.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/RemovedPropertyMap.java 2009-04-02 23:41:18 UTC (rev 86710)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/RemovedPropertyMap.java 2009-04-02 23:47:05 UTC (rev 86711)
@@ -50,7 +50,7 @@
for(String key : delegate.keySet())
{
ManagedProperty mp = delegate.get(key);
- if(mp.isRemoved() == false)
+ if(mp != null && mp.isRemoved() == false)
keySet.add(key);
}
}
@@ -85,7 +85,7 @@
public ManagedProperty get(Object key)
{
ManagedProperty mp = delegate.get(key);
- if(mp.isRemoved())
+ if(mp != null && mp.isRemoved())
mp = null;
return mp;
}
Modified: trunk/profileservice/src/main/org/jboss/profileservice/management/templates/JmsDestinationTemplate.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/templates/JmsDestinationTemplate.java 2009-04-02 23:41:18 UTC (rev 86710)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/templates/JmsDestinationTemplate.java 2009-04-02 23:47:05 UTC (rev 86711)
@@ -27,27 +27,40 @@
import java.util.List;
import java.util.Map;
+import javax.management.ObjectName;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Marshaller;
+import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElements;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
import org.jboss.deployers.spi.management.DeploymentTemplate;
import org.jboss.deployers.vfs.spi.client.VFSDeployment;
import org.jboss.managed.api.DeploymentTemplateInfo;
import org.jboss.managed.api.ManagedProperty;
+import org.jboss.metatype.api.types.CompositeMetaType;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.MapCompositeValueSupport;
import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.MetaValueFactory;
import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.metatype.plugins.values.MetaValueFactoryBuilder;
import org.jboss.virtual.VFS;
import org.jboss.virtual.VirtualFile;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
/**
* A template for creating jms destinations
*
* @author <a href="mailto:alex at jboss.org">Alexey Loubyansky</a>
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version <tt>$Revision$</tt>
*/
public class JmsDestinationTemplate
@@ -57,6 +70,11 @@
/** The file suffix. */
private static final String FILE_SUFFIX = "-service.xml";
+ /** The role attributes. */
+ protected static final String[] attributes = new String[] { "read", "write", "create"};
+
+ private static final MetaValueFactory mvf = MetaValueFactoryBuilder.create();
+
private DeploymentTemplateInfo info;
public String getDeploymentName(String deploymentBaseName)
@@ -104,46 +122,119 @@
private void writeTemplate(File dsXml, DeploymentTemplateInfo info)
throws Exception
{
- JmsDestinationTemplateInfo destinationInfo = (JmsDestinationTemplateInfo)info;
- String destinationType = destinationInfo.getDestinationType();
+ if(info == null)
+ throw new IllegalArgumentException("Null template info.");
+ if(info.getProperties() == null)
+ throw new IllegalArgumentException("Null template info.");
+
+ // Look for the destination type using the destinationType ManagedProperty
+ ManagedProperty destTypeMP = info.getProperties().get("destinationType");
+ String destinationType = null;
+ if(destTypeMP == null)
+ {
+ // Try casting this to a DsDataSourceTemplateInfo
+ destinationType = ((JmsDestinationTemplateInfo)info).getDestinationType();
+ }
+ else
+ {
+ SimpleValue dsTypeSV = (SimpleValue) destTypeMP.getValue();
+ destinationType = dsTypeSV.getValue().toString();
+ }
JmsDestinationMetaData destination = new JmsDestinationMetaData();
- String jndiName = "" + getProperty(info, "JNDIName");
- if("queue".equals(destinationType))
+
+ String destinationName = (String) getProperty(info, "name");
+ String jndiName = (String) getProperty(info, "JNDIName");
+
+ if(jndiName == null)
+ throw new IllegalStateException("Null jndi name.");
+ if(destinationName == null)
+ destinationName = jndiName;
+
+ if("QueueTemplate".equals(destinationType))
{
destination.className = "org.jboss.jms.server.destination.QueueService";
- destination.annotation =
- "@org.jboss.system.deployers.managed.ManagementObjectClass(code=org.jboss.jms.server.destination.QueueServiceMO)";
+// destination.annotation =
+// "@org.jboss.system.deployers.managed.ManagementObjectClass(code=org.jboss.jms.server.destination.QueueServiceMO)";
destination.xmbeanDd = "xmdesc/Queue-xmbean.xml";
- destination.jmxName = "jboss.messaging.destination:service=Queue,name=" + jndiName;
+ destination.jmxName = "jboss.messaging.destination:service=Queue,name=" + destinationName;
}
- else if("topic".equals(destinationType))
+ else if("TopicTemplate".equals(destinationType))
{
destination.className = "org.jboss.jms.server.destination.TopicService";
- destination.annotation =
- "@org.jboss.system.deployers.managed.ManagementObjectClass(code=org.jboss.jms.server.destination.TopicServiceMO)";
+// destination.annotation =
+// "@org.jboss.system.deployers.managed.ManagementObjectClass(code=org.jboss.jms.server.destination.TopicServiceMO)";
destination.xmbeanDd = "xmdesc/Topic-xmbean.xml";
- destination.jmxName = "jboss.messaging.destination:service=Topic,name=" + jndiName;
+ destination.jmxName = "jboss.messaging.destination:service=Topic,name=" + destinationName;
}
else
{
throw new IllegalStateException("Unsupported destination type: " + destinationType);
}
- List<JmsAttributeMetaData> attributes = new ArrayList<JmsAttributeMetaData>();
-
- JmsAttributeMetaData jndiNameMD = new JmsAttributeMetaData("JNDIName", jndiName);
+ List<JmsAttribute> attributes = new ArrayList<JmsAttribute>();
destination.attribute = attributes;
- attributes.add(jndiNameMD);
+
+ Map<String, ManagedProperty> properties = info.getProperties();
+ for(ManagedProperty p : properties.values())
+ {
+ MetaValue v = p.getValue();
+ if(v == null)
+ continue;
+ // Skip the destinationType
+ if(p == destTypeMP)
+ continue;
+
+ String name = p.getName();
+ char c = name.charAt(0);
+ if(Character.isLowerCase(c))
+ name = Character.toUpperCase(c) + name.substring(1);
+
+ if(v.getMetaType().isSimple())
+ {
+ JmsAttributeMetaData attributeMD = new JmsAttributeMetaData(name, "" + ((SimpleValue)v).getValue());
+ attributes.add(attributeMD);
+ }
+ else
+ {
+ if(name.equals("DLQ"))
+ {
+ ObjectName n = (ObjectName) mvf.unwrap(v);
+ attributes.add(new JmsAttributeMetaData("DLQ", n.getCanonicalName()));
+ }
+ else if(name.equals("ExpiryQueue"))
+ {
+ ObjectName n = (ObjectName) mvf.unwrap(v);
+ attributes.add(new JmsAttributeMetaData("ExpiryQueue", n.getCanonicalName()));
+ }
+ else if(name.equals("SecurityConfig"))
+ {
+ Element e = unwrapMetaValue((MapCompositeValueSupport) v);
+ attributes.add(new JmsElementMetaData("SecurityConfig", e));
+ }
+ }
+ }
+
+ // Add dependencies
List<JmsDependencyMetaData> depends = new ArrayList<JmsDependencyMetaData>();
destination.depends = depends;
- depends.add(new JmsDependencyMetaData("ServerPeer", "jboss.messaging:service=ServerPeer"));
+ // Set server peer
+ ObjectName serverPeer = (ObjectName) getProperty(info, "serverPeer");
+ if(serverPeer != null)
+ {
+ depends.add(new JmsDependencyMetaData("ServerPeer", serverPeer.getCanonicalName()));
+ }
+ else
+ {
+ depends.add(new JmsDependencyMetaData("ServerPeer", "jboss.messaging:service=ServerPeer"));
+ }
+ // <depends>
depends.add(new JmsDependencyMetaData("jboss.messaging:service=PostOffice"));
JmsDestinationDeployment deployment = new JmsDestinationDeployment();
deployment.destination = destination;
- Class[] classes = {JmsDestinationDeployment.class};
+ Class<?>[] classes = {JmsDestinationDeployment.class};
JAXBContext context = JAXBContext.newInstance(classes);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty("jaxb.formatted.output", Boolean.TRUE);
@@ -187,19 +278,66 @@
Object value = prop.getValue();
if(value instanceof MetaValue)
{
- if (prop.getMetaType().isComposite())
+ return mvf.unwrap((MetaValue) value);
+ }
+ return value;
+ }
+
+ /**
+ * Unwrap the value.
+ * TODO This should actually be done by the SecurityConfigMapper and
+ * the metaValueFacotyr
+ *
+ * @param metaValue the meta value
+ * @return the element
+ */
+ protected Element unwrapMetaValue(MapCompositeValueSupport metaValue)
+ {
+ if(metaValue == null)
+ return null;
+
+ MapCompositeValueSupport value = (MapCompositeValueSupport) metaValue;
+ CompositeMetaType metaType = value.getMetaType();
+ // Create the dom document
+ Document d = createDocument();
+ // Security
+ Element security = d.createElement("security");
+ // Get the roles
+ for(String name : metaType.itemSet())
+ {
+ // Role
+ CompositeValue row = (CompositeValue) value.get(name);
+ Element role = d.createElement("role");
+ role.setAttribute("name", name);
+
+ // For each attribute: read, write, create
+ for(String attribute : attributes)
{
- throw new IllegalArgumentException("Unable to handle composite: "+prop);
+ SimpleValue v = (SimpleValue) row.get(attribute);
+ if(v != null && v.getValue() != null)
+ {
+ role.setAttribute(attribute, ((Boolean)v.getValue()).toString());
+ }
}
- else if(prop.getMetaType().isSimple())
- {
- SimpleValue sv = SimpleValue.class.cast(value);
- value = sv.getValue();
- }
+ security.appendChild(role);
}
- return value;
+ return security;
}
-
+
+ protected static Document createDocument()
+ {
+ try
+ {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ return db.newDocument();
+ }
+ catch(Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
// the classes below should go away and ServiceDeployment and MetaData
// API should be used instead once their bound with JAXB
@@ -224,11 +362,14 @@
@XmlElement
String annotation;
- public List<JmsAttributeMetaData> attribute;
+ @XmlElements(value = {
+ @XmlElement(type = JmsAttributeMetaData.class),
+ @XmlElement(type = JmsElementMetaData.class) })
+ public List<JmsAttribute> attribute;
public List<JmsDependencyMetaData> depends;
}
- public static class JmsAttributeMetaData
+ public static class JmsAttributeMetaData implements JmsAttribute
{
@XmlAttribute
String name;
@@ -243,29 +384,44 @@
this.value = value;
}
}
+ public static class JmsElementMetaData implements JmsAttribute
+ {
+ @XmlAttribute
+ String name;
+ @XmlAnyElement
+ Element value;
+ public JmsElementMetaData()
+ {
+ }
+ public JmsElementMetaData(String name, Element value)
+ {
+ this.name = name;
+ this.value = value;
+ }
+ }
public static class JmsDependencyMetaData
{
@XmlAttribute(name = "optional-attribute-name")
String attribute;
-
@XmlValue
String value;
-
public JmsDependencyMetaData()
{
}
-
public JmsDependencyMetaData(String value)
{
this.value = value;
}
-
public JmsDependencyMetaData(String attribute, String value)
{
this.attribute = attribute;
this.value = value;
}
}
+ public static interface JmsAttribute
+ {
+ // workaround jaxb
+ }
}
Modified: trunk/profileservice/src/main/org/jboss/profileservice/management/templates/JmsDestinationTemplateInfo.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/templates/JmsDestinationTemplateInfo.java 2009-04-02 23:41:18 UTC (rev 86710)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/templates/JmsDestinationTemplateInfo.java 2009-04-02 23:47:05 UTC (rev 86711)
@@ -21,40 +21,44 @@
*/
package org.jboss.profileservice.management.templates;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.UndeclaredThrowableException;
-import java.util.Collections;
-import java.util.HashMap;
import java.util.Map;
-import org.jboss.annotation.factory.AnnotationProxy;
import org.jboss.managed.api.Fields;
-import org.jboss.managed.api.annotation.ManagementObjectID;
+import org.jboss.managed.api.ManagedProperty;
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.metatype.api.types.MetaType;
import org.jboss.metatype.api.types.SimpleMetaType;
-import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
/**
* @author <a href="mailto:alex at jboss.org">Alexey Loubyansky</a>
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version <tt>$Revision$</tt>
*/
public class JmsDestinationTemplateInfo extends BasicDeploymentTemplateInfo
{
private static final long serialVersionUID = 1;
- private String destinationType = "queue";
-
- public JmsDestinationTemplateInfo(String name, String description, String destinationType)
+ private String destinationType = "QueueTemplate";
+
+ protected static String checkNullName(String name)
{
- super(name, description);
- this.destinationType = destinationType;
+ if(name == null)
+ throw new IllegalArgumentException("Null name.");
+ return name;
+ }
+
+ public JmsDestinationTemplateInfo(String name, String description, Map<String, ManagedProperty> arg2)
+ {
+ super(checkNullName(name), description, arg2);
super.setRootManagedPropertyName("services");
}
-
+ public void setDestinationType(String destinationType)
+ {
+ this.destinationType = destinationType;
+ }
+
public String getDestinationType()
{
return destinationType;
@@ -68,7 +72,8 @@
@Override
public JmsDestinationTemplateInfo copy()
{
- JmsDestinationTemplateInfo copy = new JmsDestinationTemplateInfo(getName(), getDescription(), destinationType);
+ JmsDestinationTemplateInfo copy = new JmsDestinationTemplateInfo(getName(), getDescription(), getProperties());
+ copy.setDestinationType(getDestinationType());
super.copy(copy);
copy.populate();
return copy;
@@ -76,74 +81,27 @@
private void populate()
{
- ManagedObjectImpl mo;
- if("queue".equals(destinationType))
- mo = new ManagedObjectImpl("org.jboss.jms.server.destination.QueueServiceMO");
- else if("topic".equals(destinationType))
- mo = new ManagedObjectImpl("org.jboss.jms.server.destination.TopicServiceMO");
- else
- throw new IllegalStateException("Unexpected destination type: " + destinationType);
+ // Add the destination type as a ManagedProperty
+ DefaultFieldsImpl fields = new DefaultFieldsImpl("destinationType");
+ fields.setDescription("The destination type");
+ fields.setMetaType(SimpleMetaType.STRING);
+ fields.setValue(SimpleValueSupport.wrap(destinationType));
+ fields.setField(Fields.READ_ONLY, Boolean.TRUE);
+ ManagedPropertyImpl destTypeMP = new ManagedPropertyImpl(fields);
+ addProperty(destTypeMP);
- addManagedProperty("name", "The destination name", true, false, SimpleMetaType.STRING, mo);
- addManagedProperty("JNDIName", "The destination's JNDI name", false, true, SimpleMetaType.STRING, mo);
- }
-
- private void addManagedProperty(String fieldName,
- String fieldDescr,
- boolean mandatory,
- boolean isID,
- MetaType metaType,
- ManagedObjectImpl mo)
- {
-
- addManagedProperty(fieldName, fieldDescr, mandatory, isID, metaType, null, 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)
+ // FIXME
+ if(getProperties() == null) return;
+ for(ManagedProperty property : getProperties().values())
{
- Map<String, Annotation> annotations = new HashMap<String, Annotation>();
- Map<String, Object> idFields = Collections.emptyMap();
- try
- {
- ManagementObjectID id = (ManagementObjectID) AnnotationProxy.createProxy(idFields, ManagementObjectID.class);
- annotations.put(ManagementObjectID.class.getName(), id);
- mp.setAnnotations(annotations);
- }
- catch(Exception e)
- {
- throw new UndeclaredThrowableException(e);
- }
+ // Create a new (non-writethrough) managed property
+ Fields f = property.getFields();
+
+ ManagedPropertyImpl newProperty = new ManagedPropertyImpl(f);
+
+ // Override
+ addProperty(newProperty);
}
-
- super.addProperty(mp);
- if(value != null)
- mp.setValue(value);
}
- 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);
- }
-*/
- }
}
Modified: trunk/testsuite/src/main/org/jboss/test/profileservice/test/JmsDestinationUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/profileservice/test/JmsDestinationUnitTestCase.java 2009-04-02 23:41:18 UTC (rev 86710)
+++ trunk/testsuite/src/main/org/jboss/test/profileservice/test/JmsDestinationUnitTestCase.java 2009-04-02 23:47:05 UTC (rev 86711)
@@ -59,6 +59,10 @@
suite.addTest(new JmsDestinationUnitTestCase("testRemoveTopic"));
return suite;
+ // Validate the ObjectName property types
+ ManagedProperty serverPeer = info.getProperties().get("serverPeer");
+ assertNotNull(serverPeer);
+ assertEquals(SimpleMetaType.STRING, serverPeer.getMetaType());
}
/**
@@ -84,8 +88,27 @@
ManagedComponent queue = activeView.getComponent("testCreateQueue", type);
assertNotNull(queue);
assertEquals("testCreateQueue", queue.getName());
+ log.info(queue.getProperties().keySet());
}
+ public void testCreateQueueAndUpdate() throws Exception
+ {
+ Map<String, MetaValue> propValues = new HashMap<String, MetaValue>();
+ String jndiName = getName();
+ propValues.put("JNDIName", SimpleValueSupport.wrap(jndiName));
+ ComponentType type = KnownComponentTypes.JMSDestination.Queue.getType();
+ createComponentTest("QueueTemplate", propValues, getName(), type, jndiName);
+ ManagedComponent queue = activeView.getComponent("testCreateQueueAndUpdate", type);
+ assertNotNull(queue);
+ assertEquals("testCreateQueueAndUpdate", queue.getName());
+ log.info(queue.getProperties());
+ // downCacheSize, createdProgrammatically, scheduledMessageCount, maxSize, messageStatistics, securityConfig, JNDIName, consumerCount, messageCounterHistoryDayLimit, messageCount, redeliveryDelay, maxDeliveryAttempts, fullSize, messageCounter, pageSize, deliveringCount, expiryQueue, DLQ, name, clustered, serverPeer
+ ManagedProperty pageSize = queue.getProperty("pageSize");
+ log.info("pageSize: "+pageSize);
+ pageSize.setValue(null);
+ activeView.updateComponent(queue);
+ }
+
public void testMultipleQueues() throws Exception
{
ManagementView managementView = getManagementView();
More information about the jboss-cvs-commits
mailing list