[jboss-cvs] JBossAS SVN: r87004 - in projects/jboss-man/branches/Branch_2_1: managed/src/main/java/org/jboss/managed/plugins and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Apr 8 17:45:09 EDT 2009
Author: scott.stark at jboss.org
Date: 2009-04-08 17:45:09 -0400 (Wed, 08 Apr 2009)
New Revision: 87004
Added:
projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/TransientAttachments.java
projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/deployment/JBMessage.java
projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/deployment/MessageListMapper.java
Modified:
projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/ManagedOperation.java
projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/ManagedParameter.java
projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java
projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/ManagedOperationImpl.java
projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/ManagedParameterImpl.java
projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/deployment/JmsDestination.java
projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/deployment/QueueDestination.java
projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/test/AbstractManagedObjectFactoryUnitTestCase.java
projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/api/annotations/MetaMapping.java
Log:
JBMAN-73, StringObjectNameMetaMapper does not deal with null values
JBMAN-74, Support for MetaMapping on operations, parameters
JBMAN-75, Support for transient attachments on operations, parameters
Modified: projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/ManagedOperation.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/ManagedOperation.java 2009-04-08 21:43:57 UTC (rev 87003)
+++ projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/ManagedOperation.java 2009-04-08 21:45:09 UTC (rev 87004)
@@ -32,7 +32,7 @@
* @author Scott.Stark at jboss.org
* @version $Revision$
*/
-public interface ManagedOperation extends Serializable
+public interface ManagedOperation extends Serializable, TransientAttachments
{
/**
* The side-effect impact of invoking an operation
@@ -91,4 +91,5 @@
* @return the MetaValue for the result.
*/
public MetaValue invoke(MetaValue... param);
+
}
Modified: projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/ManagedParameter.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/ManagedParameter.java 2009-04-08 21:43:57 UTC (rev 87003)
+++ projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/ManagedParameter.java 2009-04-08 21:45:09 UTC (rev 87004)
@@ -33,7 +33,7 @@
* @author Scott.Stark at jboss.org
* @version $Revision$
*/
-public interface ManagedParameter extends Serializable
+public interface ManagedParameter extends Serializable, TransientAttachments
{
/**
* Get the fields
@@ -123,5 +123,5 @@
* @return null for a valid value, an error message otherwise
*/
String checkValidValue(MetaValue value);
-
+
}
Modified: projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java 2009-04-08 21:43:57 UTC (rev 87003)
+++ projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java 2009-04-08 21:45:09 UTC (rev 87004)
@@ -39,7 +39,7 @@
* @author Scott.Stark at jboss.org
* @version $Revision: 1.1 $
*/
-public interface ManagedProperty extends Serializable
+public interface ManagedProperty extends Serializable, TransientAttachments
{
/**
* Get the managed object the property is associated with.
@@ -230,37 +230,4 @@
*/
void setRemoved(boolean flag);
- /**
- * Get a transient attachment from the property.
- *
- * @see #setTransientAttachment(String, Object)
- *
- * @param name the name
- * @return the attachment
- */
- Object getTransientAttachment(String name);
-
- /**
- * Get an attachment from the property,
- * uses the expected type as both the name
- * and to cast the resulting object.
- *
- * @param <T> the expected type
- * @param expectedType the expected type
- * @return the attachment
- * @throws ClassCastException when the object is not of the expected type
- */
- <T> T getTransientAttachment(Class<T> expectedType);
-
- /**
- * Set an transient attachment against the property. A transient attachment
- * is one that will not be available to clients of the property, typically
- * admin tools. Such attachments are used by the server side where the
- * underlying metadata to which the property is
- *
- * @param name the name
- * @param attachment the attachment, pass null to remove an attachment
- * @throws IllegalArgumentException for a null name
- */
- void setTransientAttachment(String name, Object attachment);
}
Copied: projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/TransientAttachments.java (from rev 87003, projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/TransientAttachments.java)
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/TransientAttachments.java (rev 0)
+++ projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/TransientAttachments.java 2009-04-08 21:45:09 UTC (rev 87004)
@@ -0,0 +1,65 @@
+/*
+ * 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.managed.api;
+
+/**
+ * A common interface for managed elements that support transient attachments
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public interface TransientAttachments
+{
+ /**
+ * Get a transient attachment from the parameter.
+ *
+ * @see #setTransientAttachment(String, Object)
+ *
+ * @param name the name
+ * @return the attachment
+ */
+ Object getTransientAttachment(String name);
+
+ /**
+ * Get an attachment from the parameter,
+ * uses the expected type as both the name
+ * and to cast the resulting object.
+ *
+ * @param <T> the expected type
+ * @param expectedType the expected type
+ * @return the attachment
+ * @throws ClassCastException when the object is not of the expected type
+ */
+ <T> T getTransientAttachment(Class<T> expectedType);
+
+ /**
+ * Set an transient attachment against the parameter. A transient attachment
+ * is one that will not be available to clients of the parameter, typically
+ * admin tools. Such attachments are used by the server side where the
+ * underlying metadata to which the parameter is associated is available.
+ *
+ * @param name the name
+ * @param attachment the attachment, pass null to remove an attachment
+ * @throws IllegalArgumentException for a null name
+ */
+ void setTransientAttachment(String name, Object attachment);
+}
Modified: projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/ManagedOperationImpl.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/ManagedOperationImpl.java 2009-04-08 21:43:57 UTC (rev 87003)
+++ projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/ManagedOperationImpl.java 2009-04-08 21:45:09 UTC (rev 87004)
@@ -21,6 +21,9 @@
*/
package org.jboss.managed.plugins;
+import java.util.HashMap;
+import java.util.Map;
+
import org.jboss.managed.api.ManagedOperation;
import org.jboss.managed.api.ManagedParameter;
import org.jboss.metatype.api.types.MetaType;
@@ -41,8 +44,9 @@
private String name;
private ManagedParameter[] parameters;
private MetaType returnType;
+ /** The transient attachments map */
+ private transient Map<String, Object> transientAttachments;
-
public ManagedOperationImpl(String name, String description)
{
this(description, name, Impact.Unknown, new ManagedParameter[0], SimpleMetaType.VOID);
@@ -145,4 +149,27 @@
return tmp.toString();
}
+ public <T> T getTransientAttachment(Class<T> expectedType)
+ {
+ T tvalue = null;
+ Object value = getTransientAttachment(expectedType.getName());
+ if(value != null)
+ tvalue = expectedType.cast(value);
+ return tvalue;
+ }
+
+ public Object getTransientAttachment(String name)
+ {
+ Object value = null;
+ if(transientAttachments != null)
+ value = transientAttachments.get(name);
+ return value;
+ }
+
+ public synchronized void setTransientAttachment(String name, Object attachment)
+ {
+ if(transientAttachments == null)
+ transientAttachments = new HashMap<String, Object>();
+ transientAttachments.put(name, attachment);
+ }
}
Modified: projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/ManagedParameterImpl.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/ManagedParameterImpl.java 2009-04-08 21:43:57 UTC (rev 87003)
+++ projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/ManagedParameterImpl.java 2009-04-08 21:45:09 UTC (rev 87004)
@@ -27,6 +27,7 @@
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.annotation.Annotation;
+import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@@ -49,8 +50,10 @@
/** The fields */
private Fields fields;
- /** The property name */
+ /** The parameter name */
private transient String name;
+ /** The transient attachments map */
+ private transient Map<String, Object> transientAttachments;
/**
* Create a new ManagedProperty that is not associated to
@@ -264,6 +267,30 @@
return getName().equals(other.getName());
}
+ public <T> T getTransientAttachment(Class<T> expectedType)
+ {
+ T tvalue = null;
+ Object value = getTransientAttachment(expectedType.getName());
+ if(value != null)
+ tvalue = expectedType.cast(value);
+ return tvalue;
+ }
+
+ public Object getTransientAttachment(String name)
+ {
+ Object value = null;
+ if(transientAttachments != null)
+ value = transientAttachments.get(name);
+ return value;
+ }
+
+ public synchronized void setTransientAttachment(String name, Object attachment)
+ {
+ if(transientAttachments == null)
+ transientAttachments = new HashMap<String, Object>();
+ transientAttachments.put(name, attachment);
+ }
+
/**
* Initialise a ManagedPropertyImpl.
*
Modified: projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java 2009-04-08 21:43:57 UTC (rev 87003)
+++ projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java 2009-04-08 21:45:09 UTC (rev 87004)
@@ -672,42 +672,8 @@
fields.setField(Fields.ACTIVATION_POLICY, apolicy);
// The managed property type
- MetaType metaType = null;
- MetaMapper<?> metaMapper = null;
- MetaMapping metaMapping = getAnnotation(MetaMapping.class, propertyInfo, metaData);
- MetaMappingFactory metaMappingFactory = getAnnotation(MetaMappingFactory.class, propertyInfo, metaData);
- if(metaMappingFactory != null)
- {
- Class<? extends MetaMapperFactory<?>> mmfClass = metaMappingFactory.value();
- try
- {
- MetaMapperFactory<?> mmf = mmfClass.newInstance();
- String[] args = metaMappingFactory.args();
- if(args.length > 0)
- metaMapper = mmf.newInstance(args);
- else
- metaMapper = mmf.newInstance();
- }
- catch(Exception e)
- {
- log.debug("Failed to create MetaMapperFactory: "+metaMappingFactory, e);
- }
- }
- if(metaMapping != null)
- {
- // Use the mapping for the type
- Class<? extends MetaMapper<?>> mapperClass = metaMapping.value();
- try
- {
- metaMapper = mapperClass.newInstance();
- }
- catch(Exception e)
- {
- log.debug("Failed to create MetaMapper: "+metaMapping, e);
- }
- }
- if(metaMapper != null)
- metaType = metaMapper.getMetaType();
+ MetaMapper[] mapperReturn = {null};
+ MetaType metaType = this.getMetaType(propertyInfo, propertyInfo.getType(), metaData, false, mapperReturn);
// Determine meta type based on property type
if(metaType == null)
@@ -766,8 +732,8 @@
if (property == null)
property = createDefaultManagedProperty(fields);
// Pass the MetaMapper as an attachment
- if(metaMapper != null)
- property.setTransientAttachment(MetaMapper.class.getName(), metaMapper);
+ if (mapperReturn[0] != null)
+ property.setTransientAttachment(MetaMapper.class.getName(), mapperReturn[0]);
properties.add(property);
}
else if (trace)
@@ -789,7 +755,7 @@
if (managementOp == null)
continue;
- ManagedOperation op = getManagedOperation(methodInfo, managementOp);
+ ManagedOperation op = getManagedOperation(methodInfo, managementOp, metaData);
operations.add(op);
}
}
@@ -844,18 +810,22 @@
* @param opAnnotation
* @return the managed operation
*/
- protected ManagedOperation getManagedOperation(MethodInfo methodInfo, ManagementOperation opAnnotation)
+ protected ManagedOperation getManagedOperation(MethodInfo methodInfo,
+ ManagementOperation opAnnotation, MetaData metaData)
{
String name = methodInfo.getName();
String description = opAnnotation.description();
Impact impact = opAnnotation.impact();
ManagementParameter[] params = opAnnotation.params();
ParameterInfo[] paramInfo = methodInfo.getParameters();
- TypeInfo returnInfo = methodInfo.getReturnType();
- MetaType returnType = metaTypeFactory.resolve(returnInfo);
ArrayList<ManagedParameter> mparams = new ArrayList<ManagedParameter>();
Class<? extends ManagedParameterConstraintsPopulatorFactory> opConstraintsFactor = opAnnotation.constraintsFactory();
+ // The op return type
+ MetaMapper[] returnTypeMapper = {null};
+ MetaType returnType = getMetaType(methodInfo, methodInfo.getReturnType(), metaData, true, returnTypeMapper);
+
+ // Process the op parameters
if( paramInfo != null )
{
for(int i = 0; i < paramInfo.length; i ++)
@@ -879,7 +849,8 @@
Fields fields = new DefaultFieldsImpl(pname);
if (pdescription != null)
fields.setField(Fields.DESCRIPTION, pdescription);
- MetaType metaType = metaTypeFactory.resolve(pinfo.getParameterType());
+ MetaMapper[] paramMapper = {null};
+ MetaType metaType = getMetaType(pinfo, pinfo.getParameterType(), metaData, true, paramMapper);
fields.setField(Fields.META_TYPE, metaType);
// Delegate others (legal values, min/max etc.) to the constraints factory
try
@@ -901,16 +872,83 @@
}
ManagedParameterImpl mp = new ManagedParameterImpl(fields);
+ if(paramMapper[0] != null)
+ mp.setTransientAttachment(MetaMapper.class.getName(), paramMapper[0]);
mparams.add(mp);
}
}
ManagedParameter[] parameters = new ManagedParameter[mparams.size()];
mparams.toArray(parameters);
- return new ManagedOperationImpl(name, description, impact, parameters, returnType);
+ ManagedOperationImpl op = new ManagedOperationImpl(name, description, impact, parameters, returnType);
+ if(returnTypeMapper[0] != null)
+ op.setTransientAttachment(MetaMapper.class.getName(), returnTypeMapper[0]);
+ return op;
}
/**
+ * Get the MetaType for info by looking for MetaMapping/MetaMappingFactory
+ * annotations in addition to the info type.
+ *
+ * @param methodInfo
+ * @param metaData
+ * @return the MetaType for info's type
+ */
+ protected MetaType getMetaType(AnnotatedInfo info, TypeInfo infoType, MetaData metaData,
+ boolean useTypeFactory, MetaMapper[] mapperReturn)
+ {
+ MetaType returnType = null;
+ // First look for meta mappings
+ MetaMapper<?> metaMapper = null;
+ MetaMapping metaMapping = getAnnotation(MetaMapping.class, info, metaData);
+ MetaMappingFactory metaMappingFactory = getAnnotation(MetaMappingFactory.class, info, metaData);
+ if(metaMappingFactory != null)
+ {
+ Class<? extends MetaMapperFactory<?>> mmfClass = metaMappingFactory.value();
+ try
+ {
+ MetaMapperFactory<?> mmf = mmfClass.newInstance();
+ String[] args = metaMappingFactory.args();
+ if(args.length > 0)
+ metaMapper = mmf.newInstance(args);
+ else
+ metaMapper = mmf.newInstance();
+ }
+ catch(Exception e)
+ {
+ log.debug("Failed to create MetaMapperFactory: "+metaMappingFactory, e);
+ }
+ }
+ if(metaMapping != null)
+ {
+ // Use the mapping for the type
+ Class<? extends MetaMapper<?>> mapperClass = metaMapping.value();
+ try
+ {
+ metaMapper = mapperClass.newInstance();
+ }
+ catch(Exception e)
+ {
+ log.debug("Failed to create MetaMapper: "+metaMapping, e);
+ }
+ }
+ if(metaMapper != null)
+ {
+ returnType = metaMapper.getMetaType();
+ // Return the MetaMapper
+ if(mapperReturn != null && mapperReturn.length > 0)
+ mapperReturn[0] = metaMapper;
+ }
+
+ if(returnType == null && useTypeFactory)
+ {
+ // Use the type factory to convert the info type
+ returnType = metaTypeFactory.resolve(infoType);
+ }
+ return returnType;
+ }
+
+ /**
* Get the builder for a class
*
* @param clazz the class
Copied: projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/deployment/JBMessage.java (from rev 87002, projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/deployment/JBMessage.java)
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/deployment/JBMessage.java (rev 0)
+++ projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/deployment/JBMessage.java 2009-04-08 21:45:09 UTC (rev 87004)
@@ -0,0 +1,46 @@
+/*
+ * 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.test.managed.factory.support.deployment;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class JBMessage
+{
+
+ public String getJMSMessageID()
+ {
+ return "JMSMessageID";
+ }
+
+ public long getJMSTimestamp()
+ {
+ return 12345;
+ }
+
+ public String getJMSCorrelationID()
+ {
+ return "JMSCorrelationID";
+ }
+
+}
Modified: projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/deployment/JmsDestination.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/deployment/JmsDestination.java 2009-04-08 21:43:57 UTC (rev 87003)
+++ projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/deployment/JmsDestination.java 2009-04-08 21:45:09 UTC (rev 87004)
@@ -23,11 +23,15 @@
import java.io.Serializable;
+import javax.management.ObjectName;
+
import org.jboss.managed.api.annotation.ManagementObject;
import org.jboss.managed.api.annotation.ManagementProperty;
import org.jboss.managed.api.annotation.RunStateProperty;
import org.jboss.managed.api.annotation.ViewUse;
import org.jboss.managed.plugins.factory.StringRunStateMapper;
+import org.jboss.metatype.api.annotations.MetaMapping;
+import org.jboss.metatype.plugins.values.mappers.StringObjectNameMetaMapper;
/**
* @author Scott.Stark at jboss.org
@@ -41,8 +45,21 @@
private String jndiName;
private SecDomainMD domain;
private String state;
+ private ObjectName expiryQueue;
+ @ManagementProperty(description="The expiry queue",
+ use={ViewUse.RUNTIME}, includeInTemplate=true)
+ @MetaMapping(StringObjectNameMetaMapper.class)
+ protected ObjectName getExpiryQueue()
+ {
+ return expiryQueue;
+ }
+ protected void setExpiryQueue(ObjectName expiryQueue)
+ {
+ this.expiryQueue = expiryQueue;
+ }
+
@ManagementProperty(description="The destination state",
use={ViewUse.STATISTIC}, includeInTemplate=false)
@RunStateProperty(value=StringRunStateMapper.class,
Copied: projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/deployment/MessageListMapper.java (from rev 87002, projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/deployment/MessageListMapper.java)
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/deployment/MessageListMapper.java (rev 0)
+++ projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/deployment/MessageListMapper.java 2009-04-08 21:45:09 UTC (rev 87004)
@@ -0,0 +1,110 @@
+/*
+ * 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.test.managed.factory.support.deployment;
+
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.metatype.api.types.CollectionMetaType;
+import org.jboss.metatype.api.types.CompositeMetaType;
+import org.jboss.metatype.api.types.ImmutableCompositeMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.CollectionValueSupport;
+import org.jboss.metatype.api.values.MapCompositeValueSupport;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.metatype.spi.values.MetaMapper;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class MessageListMapper extends MetaMapper<List<JBMessage>>
+{
+ public static final CollectionMetaType TYPE;
+ public static final CompositeMetaType MSG_TYPE;
+
+ static
+ {
+ String[] itemNames = {
+ "JMSMessageID",
+ "JMSTimestamp",
+ "JMSCorrelationID"
+ };
+ String[] itemDescriptions = {
+ "JMSMessageID",
+ "JMSTimestamp",
+ "JMSCorrelationID"
+ };
+ MetaType[] itemTypes = {
+ SimpleMetaType.STRING,
+ SimpleMetaType.LONG,
+ SimpleMetaType.STRING
+ };
+ MSG_TYPE = new ImmutableCompositeMetaType("javax.jms.Message", "JMS Message",
+ itemNames, itemDescriptions, itemTypes);
+ TYPE = new CollectionMetaType("java.util.List", MSG_TYPE);
+ }
+
+ @Override
+ public MetaValue createMetaValue(MetaType metaType, List<JBMessage> object)
+ {
+ ArrayList<MetaValue> tmp = new ArrayList<MetaValue>();
+ if(object != null)
+ {
+ for(JBMessage m : object)
+ {
+ MapCompositeValueSupport cvs = new MapCompositeValueSupport(MSG_TYPE);
+ cvs.put("JMSCorrelationID", SimpleValueSupport.wrap(m.getJMSCorrelationID()));
+ cvs.put("JMSTimestamp", SimpleValueSupport.wrap(m.getJMSTimestamp()));
+ cvs.put("JMSMessageID", SimpleValueSupport.wrap(m.getJMSMessageID()));
+ tmp.add(cvs);
+ }
+ }
+ MetaValue[] elements = new MetaValue[tmp.size()];
+ tmp.toArray(elements);
+ CollectionValueSupport msgs = new CollectionValueSupport(TYPE, elements);
+ return msgs;
+ }
+
+ @Override
+ public MetaType getMetaType()
+ {
+ return TYPE;
+ }
+
+ @Override
+ public Type mapToType()
+ {
+ return List.class;
+ }
+
+ @Override
+ public List<JBMessage> unwrapMetaValue(MetaValue metaValue)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Modified: projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/deployment/QueueDestination.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/deployment/QueueDestination.java 2009-04-08 21:43:57 UTC (rev 87003)
+++ projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/deployment/QueueDestination.java 2009-04-08 21:45:09 UTC (rev 87004)
@@ -22,9 +22,16 @@
package org.jboss.test.managed.factory.support.deployment;
import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import javax.management.ObjectName;
+
import org.jboss.managed.api.annotation.ManagementComponent;
import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementOperation;
+import org.jboss.metatype.api.annotations.MetaMapping;
+import org.jboss.metatype.plugins.values.mappers.StringObjectNameMetaMapper;
/**
* @author Scott.Stark at jboss.org
@@ -36,4 +43,21 @@
{
private static final long serialVersionUID = 1;
+ @ManagementOperation(description="List all undelivered msgs")
+ @MetaMapping(MessageListMapper.class)
+ public List listAllMessages()
+ {
+ ArrayList<JBMessage> msgs = new ArrayList<JBMessage>();
+ msgs.add(new JBMessage());
+ return msgs;
+ }
+
+ @ManagementOperation(description="List all undelivered msgs")
+ @MetaMapping(MessageListMapper.class)
+ public List listAllMessages(@MetaMapping(StringObjectNameMetaMapper.class) ObjectName x)
+ {
+ ArrayList<JBMessage> msgs = new ArrayList<JBMessage>();
+ msgs.add(new JBMessage());
+ return msgs;
+ }
}
Modified: projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/test/AbstractManagedObjectFactoryUnitTestCase.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/test/AbstractManagedObjectFactoryUnitTestCase.java 2009-04-08 21:43:57 UTC (rev 87003)
+++ projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/test/AbstractManagedObjectFactoryUnitTestCase.java 2009-04-08 21:45:09 UTC (rev 87004)
@@ -29,16 +29,20 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.jboss.annotation.factory.AnnotationCreator;
import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedOperation;
+import org.jboss.managed.api.ManagedParameter;
import org.jboss.managed.api.ManagedProperty;
import org.jboss.managed.api.annotation.ManagementComponent;
import org.jboss.managed.api.annotation.ManagementObject;
import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.managed.plugins.ManagedOperationMatcher;
import org.jboss.managed.plugins.factory.AbstractInstanceClassFactory;
import org.jboss.managed.plugins.factory.AbstractManagedObjectFactory;
import org.jboss.managed.plugins.factory.DefaultInstanceClassFactory;
@@ -49,12 +53,15 @@
import org.jboss.metatype.api.types.CollectionMetaType;
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.CollectionValue;
import org.jboss.metatype.api.values.CompositeValue;
import org.jboss.metatype.api.values.GenericValue;
import org.jboss.metatype.api.values.MetaValue;
import org.jboss.metatype.api.values.SimpleValue;
import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.metatype.plugins.values.mappers.StringObjectNameMetaMapper;
+import org.jboss.metatype.spi.values.MetaMapper;
import org.jboss.test.managed.factory.AbstractManagedObjectFactoryTest;
import org.jboss.test.managed.factory.support.ManagementObjectChangedName;
import org.jboss.test.managed.factory.support.ManagementPropertySimpleManaged;
@@ -75,6 +82,7 @@
import org.jboss.test.managed.factory.support.deployment.JmsDestination;
import org.jboss.test.managed.factory.support.deployment.JmsDestinationICF;
import org.jboss.test.managed.factory.support.deployment.JmsDestinations;
+import org.jboss.test.managed.factory.support.deployment.MessageListMapper;
import org.jboss.test.managed.factory.support.deployment.QueueDestination;
import org.jboss.test.managed.factory.support.deployment.SecurityDomain;
import org.jboss.test.managed.factory.support.mcf.ConnectionFactoryProperty;
@@ -262,7 +270,44 @@
// Validate this has been written through
assertEquals("java:/jaas/JMS2", q1.getDomain().getDomain());
}
+
+ public void testManagedObjectReturnType()
+ {
+ QueueDestination q1 = new QueueDestination();
+ q1.setJndiName("queues/Q1");
+ q1.setDomain(new SecurityDomain("java:/jaas/JMS"));
+ ManagedObject q1MO = initManagedObject(q1);
+ Set<ManagedOperation> ops = q1MO.getOperations();
+ ManagedOperation listAllMessages = ManagedOperationMatcher.findOperation(ops, "listAllMessages");
+ assertNotNull(listAllMessages);
+ MetaType returnType = listAllMessages.getReturnType();
+ assertEquals(MessageListMapper.TYPE, returnType);
+ MetaMapper returnTypeMapper = listAllMessages.getTransientAttachment(MetaMapper.class);
+ assertNotNull(returnTypeMapper);
+ assertTrue(returnTypeMapper instanceof MessageListMapper);
+ }
+
+ public void testManagedObjectParamsType()
+ {
+ QueueDestination q1 = new QueueDestination();
+ q1.setJndiName("queues/Q1");
+ q1.setDomain(new SecurityDomain("java:/jaas/JMS"));
+
+ ManagedObject q1MO = initManagedObject(q1);
+ Set<ManagedOperation> ops = q1MO.getOperations();
+ ManagedOperation listAllMessages = ManagedOperationMatcher.findOperation(ops, "listAllMessages", SimpleMetaType.STRING);
+ assertNotNull(listAllMessages);
+ MetaType returnType = listAllMessages.getReturnType();
+ assertEquals(MessageListMapper.TYPE, returnType);
+ ManagedParameter[] params = listAllMessages.getParameters();
+ assertEquals(1, params.length);
+ assertEquals(SimpleMetaType.STRING, params[0].getMetaType());
+ MetaMapper mapper = params[0].getTransientAttachment(MetaMapper.class);
+ assertNotNull(mapper);
+ assertTrue(mapper instanceof StringObjectNameMetaMapper);
+ }
+
/**
* Test the transformer value of the ManagementRuntimeRef annotation when
* there is a custom ICF
Modified: projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/api/annotations/MetaMapping.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/api/annotations/MetaMapping.java 2009-04-08 21:43:57 UTC (rev 87003)
+++ projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/api/annotations/MetaMapping.java 2009-04-08 21:45:09 UTC (rev 87004)
@@ -35,7 +35,7 @@
* @author Scott.Stark at jboss.org
* @version $Revision$
*/
- at Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
+ at Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
public @interface MetaMapping
{
More information about the jboss-cvs-commits
mailing list