[Jboss-cvs] JBossAS SVN: r56331 - in branches/MC_VDF_WORK/mbeans: . src src/main/org/jboss/mx src/main/org/jboss/mx/mxbean src/tests src/tests/org src/tests/org/jboss src/tests/org/jboss/test src/tests/org/jboss/test/mx src/tests/org/jboss/test/mx/mxbean src/tests/org/jboss/test/mx/mxbean/support src/tests/org/jboss/test/mx/mxbean/test
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Aug 28 07:33:51 EDT 2006
Author: adrian at jboss.org
Date: 2006-08-28 07:33:35 -0400 (Mon, 28 Aug 2006)
New Revision: 56331
Added:
branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/
branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/CompositeDataInvocationHandler.java
branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/CompositeDataView.java
branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/CompositeTypeMetaData.java
branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/CompositeTypeMetaDataFactory.java
branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/GetterNames.java
branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/ItemMetaData.java
branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/MXBean.java
branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/MXBeanDelegate.java
branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/MXBeanFactory.java
branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/MXBeanInvocationHandler.java
branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/MXBeanMetaData.java
branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/MXBeanSupport.java
branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/MXBeanUtils.java
branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/NotificationType.java
branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/SkeletonOpenType.java
branches/MC_VDF_WORK/mbeans/src/tests/
branches/MC_VDF_WORK/mbeans/src/tests/org/
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/CollectionsInterface.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/CollectionsMXBeanSupport.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/CollectionsMXBeanSupportMXBean.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/CompositeInterface.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/CompositeMXBeanSupport.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/CompositeMXBeanSupportMXBean.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/InvalidInterface.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/NullSimpleObject.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/SimpleInterface.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/SimpleMXBeanSupport.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/SimpleMXBeanSupportMXBean.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/SimpleObject.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/TestEnum.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/TestParameterizedType.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/AbstractMXBeanTest.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataArrayUnitTestCase.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataBigDecimalUnitTestCase.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataBigIntegerUnitTestCase.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataBooleanUnitTestCase.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataByteUnitTestCase.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataCharacterUnitTestCase.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataCollectionUnitTestCase.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataCompositeUnitTestCase.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataDateUnitTestCase.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataDoubleUnitTestCase.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataEnumUnitTestCase.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataFloatUnitTestCase.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataIntegerUnitTestCase.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataInvocationHandlerUnitTestCase.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataLongUnitTestCase.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataMapUnitTestCase.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataObjectNameUnitTestCase.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataShortUnitTestCase.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataStringUnitTestCase.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataTest.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeTypeMetaDataFactoryUnitTestCase.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/MXBeanInvocationHandlerUnitTestCase.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/MXBeanSupportUnitTestCase.java
branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/MXBeanTestSuite.java
Modified:
branches/MC_VDF_WORK/mbeans/.classpath
Log:
Basic (but incomplete) MXBean implementation.
Modified: branches/MC_VDF_WORK/mbeans/.classpath
===================================================================
--- branches/MC_VDF_WORK/mbeans/.classpath 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/.classpath 2006-08-28 11:33:35 UTC (rev 56331)
@@ -1,11 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main"/>
+ <classpathentry output="output/eclipse-test-classes" kind="src" path="src/tests"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="/thirdparty/jboss/common/lib/jboss-common.jar"/>
<classpathentry kind="src" path="/j2se"/>
<classpathentry kind="lib" path="/thirdparty/apache-bcel/lib/bcel.jar"/>
<classpathentry kind="lib" path="/thirdparty/dom4j/lib/dom4j.jar"/>
<classpathentry kind="lib" path="/thirdparty/jboss/jbossxb/lib/jboss-xml-binding.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/apache-log4j/lib/log4j.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/junit/lib/junit.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss/test/lib/jboss-test.jar"/>
<classpathentry kind="output" path="output/eclipse-classes"/>
</classpath>
Added: branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/CompositeDataInvocationHandler.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/CompositeDataInvocationHandler.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/CompositeDataInvocationHandler.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,115 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.lang.reflect.Type;
+
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.InvalidKeyException;
+
+import org.jboss.util.UnreachableStatementException;
+
+/**
+ * CompositeDataInvocationHandler.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class CompositeDataInvocationHandler implements InvocationHandler
+{
+ /** The composite data */
+ private CompositeData compositeData;
+
+ /**
+ * Create a new CompositeDataInvocationHandler.
+ *
+ * @param compositeData
+ */
+ public CompositeDataInvocationHandler(CompositeData compositeData)
+ {
+ if (compositeData == null)
+ throw new IllegalArgumentException("Null compositeData");
+ this.compositeData = compositeData;
+ }
+
+ /**
+ * Get the compositeData.
+ *
+ * @return the compositeData.
+ */
+ public CompositeData getCompositeData()
+ {
+ return compositeData;
+ }
+
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+ {
+ if (Object.class.equals(method.getDeclaringClass()))
+ return handleObjectInvocation(method.getName(), args);
+
+ Object value = getValue(method);
+
+ Type returnType = method.getGenericReturnType();
+ return MXBeanUtils.reconstruct(returnType, value, method);
+ }
+
+ private Object getValue(Method method)
+ {
+ String key = MXBeanUtils.getCompositeDataKey(method);
+ if (key == null)
+ throw new IllegalArgumentException("Unsupported method '" + method + "'; it must be a property getter.");
+ try
+ {
+ return compositeData.get(key);
+ }
+ catch (InvalidKeyException e)
+ {
+ throw new IllegalArgumentException("Unsupported method '" + method + "'; it must be a property getter for one of the item names of the composite data: " + compositeData, e);
+ }
+ }
+
+ private Object handleObjectInvocation(String name, Object[] args) throws Throwable
+ {
+ if ("equals".equals(name))
+ {
+ Object object = args[0];
+ if (object == null || object instanceof Proxy == false)
+ return false;
+ InvocationHandler handler = Proxy.getInvocationHandler(object);
+ if (handler == this)
+ return true;
+ if (handler == null || handler instanceof CompositeDataInvocationHandler == false)
+ return false;
+
+ CompositeDataInvocationHandler other = (CompositeDataInvocationHandler) handler;
+ return getCompositeData().equals(other.getCompositeData());
+ }
+ else if ("hashCode".equals(name))
+ return getCompositeData().hashCode();
+ else if ("toString".equals(name))
+ return getCompositeData().toString();
+ throw new UnreachableStatementException();
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/CompositeDataView.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/CompositeDataView.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/CompositeDataView.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean;
+
+import javax.management.openmbean.CompositeData;
+
+/**
+ * CompositeDataView.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public interface CompositeDataView
+{
+ /**
+ * Convert this object to composite data
+ *
+ * @return the composite data
+ */
+ CompositeData toCompositeData();
+}
Added: branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/CompositeTypeMetaData.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/CompositeTypeMetaData.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/CompositeTypeMetaData.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,198 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.management.openmbean.CompositeType;
+import javax.management.openmbean.OpenType;
+import javax.management.openmbean.SimpleType;
+
+import org.jboss.util.UnexpectedThrowable;
+
+/**
+ * CompositeTypeMetaData.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class CompositeTypeMetaData
+{
+ /** The clazz */
+ private Class<?> clazz;
+
+ /** The composite type */
+ private CompositeType compositeType;
+
+ /** The items */
+ private List<ItemMetaData> items = new ArrayList<ItemMetaData>();
+
+ /**
+ * Create a new CompositeTypeMetaData.
+ *
+ * @param clazz the class
+ */
+ public CompositeTypeMetaData(Class<?> clazz)
+ {
+ this.clazz = clazz;
+ }
+
+ /**
+ * Get the composite type
+ *
+ * @return the composite type
+ */
+ public CompositeType getCompositeType()
+ {
+ if (compositeType == null)
+ {
+ String typeName = clazz.getName();
+ if (items.size() == 0)
+ return generateAnObject(typeName);
+
+ String[] itemNames = new String[items.size()];
+ OpenType[] itemTypes = new OpenType[items.size()];
+ for (int i = 0; i < items.size(); ++i)
+ {
+ ItemMetaData item = items.get(i);
+ itemNames[i] = item.getName();
+ itemTypes[i] = item.getOpenType();
+ }
+ try
+ {
+ compositeType = new CompositeType(typeName, typeName, itemNames, itemNames, itemTypes);
+ }
+ catch (Throwable t)
+ {
+ throw new UnexpectedThrowable("Error creating composite type for: " + typeName, t);
+ }
+ }
+ return compositeType;
+ }
+
+ /**
+ * Generate the metadata
+ */
+ public void generate()
+ {
+ if (Object.class.equals(clazz))
+ {
+ compositeType = generateObject();
+ return;
+ }
+ if (Class.class.equals(clazz))
+ {
+ compositeType = generateClass();
+ return;
+ }
+ if (ClassLoader.class.equals(clazz))
+ {
+ compositeType = generateClassLoader();
+ return;
+ }
+
+ Method[] methods = clazz.getMethods();
+ for (Method method : methods)
+ {
+ Type returnType = method.getGenericReturnType();
+ Class<?> declaring = method.getDeclaringClass();
+ if (Object.class.equals(declaring) == false)
+ {
+ String key = MXBeanUtils.getCompositeDataKey(method);
+ if (key != null)
+ items.add(new ItemMetaData(key, returnType));
+ }
+ }
+ }
+
+ /**
+ * Generate the composite data for an object
+ *
+ * @return the composite type
+ */
+ public static CompositeType generateObject()
+ {
+ return generateAnObject(Object.class.getName());
+ }
+
+ /**
+ * Generate the composite data for an object
+ *
+ * @param name the class name
+ * @return the composite type
+ */
+ private static CompositeType generateAnObject(String name)
+ {
+ String[] itemNames = { "class" };
+ OpenType[] openTypes = { generateClass() };
+ return safeCreateCompositeType(name, itemNames, openTypes);
+ }
+
+ /**
+ * Generate the composite data for a class
+ *
+ * @return the composite type
+ */
+ public static CompositeType generateClass()
+ {
+ String name = Object.class.getName();
+ String[] itemNames = { "name" };
+ OpenType[] openTypes = { SimpleType.STRING };
+ return safeCreateCompositeType(name, itemNames, openTypes);
+ }
+
+ /**
+ * Generate the composite data for a classloader
+ *
+ * @return the composite type
+ */
+ public static CompositeType generateClassLoader()
+ {
+ String name = Object.class.getName();
+ String[] itemNames = { "name" };
+ OpenType[] openTypes = { SimpleType.STRING };
+ return safeCreateCompositeType(name, itemNames, openTypes);
+ }
+
+ /**
+ * Safely create a composite type
+ *
+ * @param name the name
+ * @param itemNames the item names
+ * @param openTypes the open types
+ * @return the composite type
+ */
+ private static CompositeType safeCreateCompositeType(String name, String[] itemNames, OpenType[] openTypes)
+ {
+ try
+ {
+ return new CompositeType(name, name, itemNames, itemNames, openTypes);
+ }
+ catch (Exception e)
+ {
+ throw new UnexpectedThrowable(e);
+ }
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/CompositeTypeMetaDataFactory.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/CompositeTypeMetaDataFactory.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/CompositeTypeMetaDataFactory.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,79 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean;
+
+import javax.management.openmbean.CompositeType;
+
+import org.jboss.util.collection.WeakClassCache;
+
+/**
+ * CompositeTypeMetaDataFactory.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class CompositeTypeMetaDataFactory extends WeakClassCache
+{
+ /** The singleton */
+ private static final CompositeTypeMetaDataFactory SINGLETON = new CompositeTypeMetaDataFactory();
+
+ /**
+ * Get the composite type for a class
+ *
+ * @param clazz the class
+ * @return the composite type
+ */
+ public static CompositeType getCompositeType(Class<?> clazz)
+ {
+ CompositeTypeMetaData metaData = getCompositeTypeMetaData(clazz);
+ return metaData.getCompositeType();
+ }
+
+ /**
+ * Get the composite type meta data
+ *
+ * @param clazz the class
+ * @return the meta data
+ */
+ public static CompositeTypeMetaData getCompositeTypeMetaData(Class<?> clazz)
+ {
+ return (CompositeTypeMetaData) SINGLETON.get(clazz);
+ }
+
+ /**
+ * Singleton
+ */
+ private CompositeTypeMetaDataFactory()
+ {
+ }
+
+ protected Object instantiate(Class clazz)
+ {
+ return new CompositeTypeMetaData(clazz);
+ }
+
+ protected void generate(Class clazz, Object object)
+ {
+ CompositeTypeMetaData metaData = (CompositeTypeMetaData) object;
+ metaData.generate();
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/GetterNames.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/GetterNames.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/GetterNames.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,43 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * GetterNames.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+ at Documented
+ at Target(ElementType.CONSTRUCTOR)
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface GetterNames
+{
+ /** The getter names */
+ String[] value();
+}
Added: branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/ItemMetaData.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/ItemMetaData.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/ItemMetaData.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,73 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean;
+
+import java.lang.reflect.Type;
+
+import javax.management.openmbean.OpenType;
+
+/**
+ * ItemMetaData.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ItemMetaData
+{
+ /** The name */
+ private String name;
+
+ /** The open type */
+ private SkeletonOpenType openType;
+
+ /**
+ * Create a new ItemMetaData.
+ *
+ * @param name the name
+ * @param type the type
+ */
+ public ItemMetaData(String name, Type type)
+ {
+ this.name = name;
+ openType = new SkeletonOpenType(type);
+ }
+
+ /**
+ * Get the name.
+ *
+ * @return the name.
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * Get the openType.
+ *
+ * @return the openType.
+ */
+ public OpenType getOpenType()
+ {
+ return openType.getOpenType();
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/MXBean.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/MXBean.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/MXBean.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,43 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * MXBean.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+ at Documented
+ at Target(ElementType.TYPE)
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface MXBean
+{
+ /** Whether this is an MXBean */
+ boolean value() default true;
+}
Added: branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/MXBeanDelegate.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/MXBeanDelegate.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/MXBeanDelegate.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,510 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.Attribute;
+import javax.management.AttributeList;
+import javax.management.AttributeNotFoundException;
+import javax.management.DynamicMBean;
+import javax.management.InvalidAttributeValueException;
+import javax.management.JMException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanRegistration;
+import javax.management.MBeanServer;
+import javax.management.NotCompliantMBeanException;
+import javax.management.NotificationBroadcasterSupport;
+import javax.management.NotificationEmitter;
+import javax.management.ObjectName;
+import javax.management.ReflectionException;
+import javax.management.openmbean.OpenMBeanAttributeInfo;
+import javax.management.openmbean.OpenMBeanInfo;
+
+import org.jboss.logging.Logger;
+import org.jboss.mx.server.ExceptionHandler;
+
+/**
+ * MXBeanDelegate.
+ *
+ * FIXME: Reflection madness
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MXBeanDelegate extends NotificationBroadcasterSupport implements DynamicMBean, MBeanRegistration, NotificationEmitter
+{
+ /** The logger */
+ private static final Logger log = Logger.getLogger(MXBeanDelegate.class);
+
+ /** The implementation object */
+ private Object implementation;
+
+ /** The management interface */
+ private Class mbeanInterface;
+
+ /** The cached mbeaninfo */
+ private OpenMBeanInfo cachedMBeanInfo;
+
+ /** The attribute mapping */
+ private Map<String, OpenMBeanAttributeInfo> attributeMapping;
+
+ /** The getters */
+ private Map<String, Method> getters;
+
+ /** The setters */
+ private Map<String, Method> setters;
+
+ /** The operatinns */
+ private Map<String, Method> operations;
+
+ /**
+ * Construct a DynamicMBean from the given implementation object
+ * and the passed management interface class.
+ *
+ * @param implementation the object implementing the mbean
+ * @param mbeanInterface the management interface of the mbean
+ * @exception IllegalArgumentException for a null implementation
+ * @exception NotCompliantMBeanException if the management interface
+ * does not follow the JMX design patterns or the implementation
+ * does not implement the interface
+ */
+ public MXBeanDelegate(Object implementation, Class mbeanInterface) throws NotCompliantMBeanException
+ {
+ this.implementation = implementation;
+ this.mbeanInterface = mbeanInterface;
+ }
+
+ /**
+ * Construct a DynamicMBean from this object
+ * and the passed management interface class.<p>
+ *
+ * Used in subclassing
+ *
+ * @param mbeanInterface the management interface of the mbean
+ * @exception NotCompliantMBeanException if the management interface
+ * does not follow the JMX design patterns or this
+ * does not implement the interface
+ */
+ protected MXBeanDelegate(Class mbeanInterface) throws NotCompliantMBeanException
+ {
+ this.implementation = this;
+ this.mbeanInterface = mbeanInterface;
+ }
+
+ /**
+ * Retrieve the implementation object
+ *
+ * @return the implementation
+ */
+ public Object getImplementation()
+ {
+ return implementation;
+ }
+
+ /**
+ * Replace the implementation object
+ *
+ * @todo make this work after the mbean is registered
+ * @param implementation the new implementation
+ * @exception IllegalArgumentException for a null parameter
+ * @exception NotCompliantMBeanException if the new implementation
+ * does not implement the interface supplied at
+ * construction
+ */
+ public void setImplementation(Object implementation) throws NotCompliantMBeanException
+ {
+ if (implementation == null)
+ throw new IllegalArgumentException("Null implementation");
+ this.implementation = implementation;
+ }
+
+ /**
+ * Retrieve the implementation class
+ *
+ * @return the class of the implementation
+ */
+ public Class getImplementationClass()
+ {
+ return implementation.getClass();
+ }
+
+ /**
+ * Retrieve the management interface
+ *
+ * @return the management interface
+ */
+ public final Class getMBeanInterface()
+ {
+ return mbeanInterface;
+ }
+
+ public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException
+ {
+ try
+ {
+ OpenMBeanAttributeInfo attributeInfo = attributeMapping.get(attribute);
+ if (attributeInfo == null)
+ throw new AttributeNotFoundException(attribute);
+ MBeanAttributeInfo mbeanAttributeInfo = (MBeanAttributeInfo) attributeInfo;
+ if (mbeanAttributeInfo.isReadable() == false)
+ throw new AttributeNotFoundException("Attribute is not readable: " + attribute);
+
+ Method method = getters.get(attribute);
+ if (method == null)
+ throw new NoSuchMethodException("No method to get attribute: " + attribute);
+
+ Object result = method.invoke(implementation, new Object[0]);
+
+ return MXBeanUtils.construct(attributeInfo.getOpenType(), result, "Get attribute: " + attribute);
+ }
+ catch (Exception e)
+ {
+ JMException result = ExceptionHandler.handleException(e);
+ if (result instanceof AttributeNotFoundException)
+ throw (AttributeNotFoundException)result;
+ if (result instanceof MBeanException)
+ throw (MBeanException)result;
+ if (result instanceof ReflectionException)
+ throw (ReflectionException)result;
+ throw new MBeanException(e, "Cannot get attribute: " + attribute);
+ }
+ }
+
+ public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException
+ {
+ try
+ {
+ String attributeName = attribute.getName();
+ OpenMBeanAttributeInfo attributeInfo = attributeMapping.get(attributeName);
+ if (attributeInfo == null)
+ throw new AttributeNotFoundException(attributeName);
+ MBeanAttributeInfo mbeanAttributeInfo = (MBeanAttributeInfo) attributeInfo;
+ if (mbeanAttributeInfo.isWritable() == false)
+ throw new AttributeNotFoundException("Attribute is not writable: " + attributeName);
+
+ Method method = setters.get(attributeName);
+ if (method == null)
+ throw new NoSuchMethodException("No method to set attribute: " + attribute);
+
+ Object value = MXBeanUtils.reconstruct(method.getGenericParameterTypes()[0], attribute.getValue(), method);
+
+ method.invoke(implementation, new Object[] { value });
+ }
+ catch (Exception e)
+ {
+ JMException result = ExceptionHandler.handleException(e);
+ if (result instanceof AttributeNotFoundException)
+ throw (AttributeNotFoundException)result;
+ if (result instanceof InvalidAttributeValueException)
+ throw (InvalidAttributeValueException)result;
+ if (result instanceof MBeanException)
+ throw (MBeanException)result;
+ if (result instanceof ReflectionException)
+ throw (ReflectionException)result;
+ throw new MBeanException(e, "Cannot set attribute: " + attribute);
+ }
+ }
+
+ public AttributeList getAttributes(String[] attributes)
+ {
+ try
+ {
+ AttributeList attrList = new AttributeList(attributes.length);
+ for (int i = 0; i < attributes.length; i++)
+ {
+ String name = attributes[i];
+ Object value = getAttribute(name);
+ attrList.add(new Attribute(name, value));
+ }
+ return attrList;
+ }
+ catch (Exception e)
+ {
+ JMException result = ExceptionHandler.handleException(e);
+ // Why is this not throwing the same exceptions as getAttribute(String)
+ throw new RuntimeException("Cannot get attributes", result);
+ }
+ }
+
+ public AttributeList setAttributes(AttributeList attributes)
+ {
+ AttributeList result = new AttributeList(attributes.size());
+ for (int i = 0; i < attributes.size(); ++i)
+ {
+ Attribute attr = (Attribute) attributes.get(i);
+ String name = attr.getName();
+ try
+ {
+ setAttribute(attr);
+ result.add(new Attribute(name, attr.getValue()));
+ }
+ catch (Throwable t)
+ {
+ JMException e = ExceptionHandler.handleException(t);
+ result.add(new Attribute(name, e));
+ }
+ }
+ return result;
+ }
+
+ public Object invoke(String actionName, Object[] params, String[] signature) throws MBeanException, ReflectionException
+ {
+ try
+ {
+ String signatureString = getSignatureString(actionName, signature);
+ Method method = operations.get(signatureString);
+ if (method == null)
+ throw new NoSuchMethodException("Cannot find method for operation: " + signatureString);
+
+ Object[] parameters = params;
+ if (params.length > 0)
+ {
+ parameters = new Object[params.length];
+ Type[] parameterTypes = method.getGenericParameterTypes();
+ for (int i = 0; i < parameters.length; ++i)
+ parameters[i] = MXBeanUtils.reconstruct(parameterTypes[i], params[i], method);
+ }
+
+ Object result = method.invoke(implementation, parameters);
+
+ if (result == null)
+ return null;
+ Type returnType = method.getGenericReturnType();
+ return MXBeanUtils.construct(returnType, result, method);
+ }
+ catch (Exception e)
+ {
+ JMException result = ExceptionHandler.handleException(e);
+ if (result instanceof MBeanException)
+ throw (MBeanException)result;
+ if (result instanceof ReflectionException)
+ throw (ReflectionException)result;
+ throw new MBeanException(e, "Cannot invoke: " + actionName);
+ }
+ }
+
+ public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception
+ {
+ return name;
+ }
+
+ public void postRegister(Boolean registrationDone)
+ {
+ }
+
+ public void preDeregister() throws Exception
+ {
+ }
+
+ public void postDeregister()
+ {
+ }
+
+ public MBeanInfo getMBeanInfo()
+ {
+ OpenMBeanInfo info = getCachedMBeanInfo();
+ if (info == null)
+ {
+ try
+ {
+ info = buildMBeanInfo();
+ cacheMBeanInfo(info);
+ }
+ catch (NotCompliantMBeanException e)
+ {
+ log.error("Unexcepted exception", e);
+ throw new IllegalStateException("Unexcepted exception " + e.toString());
+ }
+
+ }
+ return (MBeanInfo) info;
+ }
+
+ /**
+ * Retrieve the cached mbean info
+ *
+ * @return the cached mbean info
+ */
+ public OpenMBeanInfo getCachedMBeanInfo()
+ {
+ return cachedMBeanInfo;
+ }
+
+ /**
+ * Sets the cached mbean info
+ *
+ * @param info the mbeaninfo to cache, can be null to erase the cache
+ */
+ public void cacheMBeanInfo(OpenMBeanInfo info)
+ {
+ cachedMBeanInfo = info;
+ Map<String, OpenMBeanAttributeInfo> attributeMapping = new HashMap<String, OpenMBeanAttributeInfo>();
+ MBeanAttributeInfo[] attributes = info.getAttributes();
+ for (int i = 0; i < attributes.length; ++i)
+ {
+ OpenMBeanAttributeInfo attribute = (OpenMBeanAttributeInfo) attributes[i];
+ attributeMapping.put(attribute.getName(), attribute);
+ }
+ this.attributeMapping = attributeMapping;
+
+ try
+ {
+ HashMap<String, Method> getters = new HashMap<String, Method>();
+ HashMap<String, Method> setters = new HashMap<String, Method>();
+
+ HashMap<String, Method> operations = new HashMap<String, Method>();
+
+ Method[] methods = implementation.getClass().getMethods();
+ for (Method method : methods)
+ {
+ String methodName = method.getName();
+ Type[] signature = method.getGenericParameterTypes();
+ Type returnType = method.getGenericReturnType();
+
+ if (methodName.startsWith("set") &&
+ methodName.length() > 3 &&
+ signature.length == 1 &&
+ returnType == Void.TYPE)
+ {
+ String key = methodName.substring(3, methodName.length());
+ Method setter = setters.get(key);
+ if (setter != null && setter.getGenericParameterTypes()[0].equals(signature[0]) == false)
+ throw new RuntimeException("overloaded type for attribute set: " + key);
+ setters.put(key, method);
+ }
+ else if (methodName.startsWith("get") &&
+ methodName.length() > 3 &&
+ signature.length == 0 &&
+ returnType != Void.TYPE)
+ {
+ String key = methodName.substring(3, methodName.length());
+ Method getter = getters.get(key);
+ if (getter != null && getter.getName().startsWith("is"))
+ throw new RuntimeException("mixed use of get/is for attribute " + key);
+ getters.put(key, method);
+ }
+ else if (methodName.startsWith("is") &&
+ methodName.length() > 2 &&
+ signature.length == 0 &&
+ returnType == Boolean.TYPE)
+ {
+ String key = methodName.substring(2, methodName.length());
+ Method getter = getters.get(key);
+ if (getter != null && getter.getName().startsWith("get"))
+ throw new RuntimeException("mixed use of get/is for attribute " + key);
+ getters.put(key, method);
+ }
+ else
+ {
+ operations.put(getSignatureString(method), method);
+ }
+ }
+ this.getters = getters;
+ this.setters = setters;
+ this.operations = operations;
+ }
+ catch (RuntimeException e)
+ {
+ log.error("Error: ", e);
+ throw e;
+ }
+ catch (Error e)
+ {
+ log.error("Error: ", e);
+ throw e;
+ }
+ }
+
+ /**
+ * Builds a default MBeanInfo for this MBean, using the Management Interface specified for this MBean.
+ *
+ * While building the MBeanInfo, this method calls the customization hooks that make it possible for subclasses to
+ * supply their custom descriptions, parameter names, etc...
+ *
+ * @return the mbean info
+ * @throws NotCompliantMBeanException when not a valid mbean
+ */
+ public OpenMBeanInfo buildMBeanInfo() throws NotCompliantMBeanException
+ {
+ if (implementation == null)
+ throw new IllegalArgumentException("Null implementation");
+
+ MXBeanMetaData metadata = new MXBeanMetaData(implementation, mbeanInterface);
+ return (OpenMBeanInfo) metadata.build();
+ }
+
+ /**
+ * Get a signature string for a method
+ *
+ * @param method the method
+ * @return the signature
+ */
+ private String getSignatureString(Method method)
+ {
+ String name = method.getName();
+ Class[] signature = method.getParameterTypes();
+ StringBuilder buffer = new StringBuilder(512);
+ buffer.append(name);
+ buffer.append("(");
+ if (signature != null)
+ {
+ for (int i = 0; i < signature.length; i++)
+ {
+ buffer.append(signature[i].getName());
+ if (i < signature.length-1)
+ buffer.append(",");
+ }
+ }
+ buffer.append(")");
+ return buffer.toString();
+ }
+
+ /**
+ * Get a signature string for a method
+ *
+ * @param operation the operation
+ * @param signature the signature
+ * @return the signature
+ */
+ private String getSignatureString(String operation, String[] signature)
+ {
+ StringBuilder buffer = new StringBuilder(512);
+ buffer.append(operation);
+ buffer.append("(");
+ if (signature != null)
+ {
+ for (int i = 0; i < signature.length; i++)
+ {
+ buffer.append(signature[i]);
+ if (i < signature.length-1)
+ buffer.append(",");
+ }
+ }
+ buffer.append(")");
+ return buffer.toString();
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/MXBeanFactory.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/MXBeanFactory.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/MXBeanFactory.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,77 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean;
+
+import java.lang.reflect.Proxy;
+
+import javax.management.DynamicMBean;
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+
+/**
+ * MXBeanFactory.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MXBeanFactory
+{
+ /**
+ * Create a proxy
+ *
+ * @param <T> the interface type
+ * @param mbeanServerConnection the connection
+ * @param objectName the object name
+ * @param mxbeanInterface the interface
+ * @return the proxy
+ */
+ public static <T> T makeProxy(MBeanServerConnection mbeanServerConnection, ObjectName objectName, Class<T> mxbeanInterface)
+ {
+ MXBeanInvocationHandler handler = new MXBeanInvocationHandler(mbeanServerConnection, mxbeanInterface, objectName);
+ Object object = Proxy.newProxyInstance(mxbeanInterface.getClassLoader(), new Class[] { mxbeanInterface }, handler);
+ return mxbeanInterface.cast(object);
+ }
+
+ /**
+ * Create a new MXBean
+ *
+ * @param resource the resource
+ * @return the MXBean
+ */
+ public static DynamicMBean newMXBean(Object resource)
+ {
+ return MXBeanUtils.createMXBean(resource, null);
+ }
+
+ /**
+ * Create a new MXBean
+ *
+ * @param <T> the interface type
+ * @param resource the resource
+ * @param mxbeanInterface the interface
+ * @return the MXBean
+ */
+ public static <T> DynamicMBean newMXBean(T resource, Class<T> mxbeanInterface)
+ {
+ return MXBeanUtils.createMXBean(resource, mxbeanInterface);
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/MXBeanInvocationHandler.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/MXBeanInvocationHandler.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/MXBeanInvocationHandler.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,497 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean;
+
+import java.io.Serializable;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.lang.reflect.Type;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.Attribute;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.MBeanParameterInfo;
+import javax.management.MBeanServerConnection;
+import javax.management.NotificationBroadcaster;
+import javax.management.NotificationEmitter;
+import javax.management.NotificationFilter;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+import javax.management.openmbean.OpenMBeanAttributeInfo;
+import javax.management.openmbean.OpenMBeanInfo;
+import javax.management.openmbean.OpenMBeanOperationInfo;
+import javax.management.openmbean.OpenMBeanParameterInfo;
+import javax.management.openmbean.OpenType;
+
+import org.jboss.mx.util.JMXExceptionDecoder;
+
+/**
+ * MXBeanInvocationHandler.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MXBeanInvocationHandler implements InvocationHandler, Serializable
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -2872014223541692039L;
+
+ private static final Class[] LISTENER = new Class[] { NotificationListener.class };
+ private static final Class[] TRIPLET = new Class[] { NotificationListener.class, NotificationFilter.class, Object.class };
+
+ private static final Method EQUALS;
+ private static final Method HASH_CODE;
+ private static final Method TO_STRING;
+
+ private static final Method ADD_NOTIFICATION_LISTENER;
+ private static final Method GET_NOTIFICATION_INFO;
+ private static final Method REMOVE_NOTIFICATION_LISTENER;
+ private static final Method REMOVE_NOTIFICATION_LISTENER_TRIPLET;
+
+ /** The connection */
+ private MBeanServerConnection mbeanServerConnection;
+
+ /** The interface */
+ private Class<?> mxbeanInterface;
+
+ /** The object name */
+ private ObjectName objectName;
+
+ /** The method mappings */
+ private transient Map<Method, Action> mappings;
+
+ /** The MBean Info */
+ private transient OpenMBeanInfo mbeanInfo;
+
+ static
+ {
+ try
+ {
+ ADD_NOTIFICATION_LISTENER = NotificationBroadcaster.class.getDeclaredMethod("addNotificationListener", TRIPLET);
+ GET_NOTIFICATION_INFO = NotificationBroadcaster.class.getDeclaredMethod("getNotificationInfo", new Class[0]);
+ REMOVE_NOTIFICATION_LISTENER = NotificationBroadcaster.class.getDeclaredMethod("removeNotificationListener", LISTENER);
+ REMOVE_NOTIFICATION_LISTENER_TRIPLET = NotificationEmitter.class.getDeclaredMethod("removeNotificationListener", TRIPLET);
+ EQUALS = Object.class.getDeclaredMethod("equals", new Class[] { Object.class });
+ HASH_CODE = Object.class.getDeclaredMethod("hashCode", new Class[0]);
+ TO_STRING = Object.class.getDeclaredMethod("toString", new Class[0]);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Create a new MXBeanInvocationHandler.
+ *
+ * @param mbeanServerConnection the connection
+ * @param mxbeanInterface the interface
+ * @param objectName the object name
+ */
+ public MXBeanInvocationHandler(MBeanServerConnection mbeanServerConnection, Class<?> mxbeanInterface, ObjectName objectName)
+ {
+ if (mbeanServerConnection == null)
+ throw new IllegalArgumentException("Null mbeanServerConnection");
+ if (mxbeanInterface == null)
+ throw new IllegalArgumentException("Null mxmbeanInterface");
+ if (objectName == null)
+ throw new IllegalArgumentException("Null objectName");
+
+ this.mbeanServerConnection = mbeanServerConnection;
+ this.mxbeanInterface = mxbeanInterface;
+ this.objectName = objectName;
+ }
+
+ /**
+ * Get the mbeanServerConnection.
+ *
+ * @return the mbeanServerConnection.
+ */
+ public MBeanServerConnection getMBeanServerConnection()
+ {
+ return mbeanServerConnection;
+ }
+
+ /**
+ * Get the mxbeanInterface.
+ *
+ * @return the mxbeanInterface.
+ */
+ public Class<?> getMXBeanInterface()
+ {
+ return mxbeanInterface;
+ }
+
+ /**
+ * Get the objectName.
+ *
+ * @return the objectName.
+ */
+ public ObjectName getObjectName()
+ {
+ return objectName;
+ }
+
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+ {
+ try
+ {
+ return getAction(proxy, method).perform(args);
+ }
+ catch (Throwable t)
+ {
+ throw JMXExceptionDecoder.decode(t);
+ }
+ }
+
+ /**
+ * Get the actions for this method
+ * @param proxy the proxy
+ * @param method the method
+ * @return the action
+ * @throws Throwable for any error
+ */
+ private Action getAction(Object proxy, Method method) throws Throwable
+ {
+ // Doesn't really matter if the mappings are
+ // setup twice by two different threads, they are the same.
+ if (mappings == null)
+ mappings = getMappings(proxy);
+
+ // Check the action
+ Action result = mappings.get(method);
+ if (result == null)
+ throw new UnsupportedOperationException("Unknown method: " + method);
+
+ // Return the result
+ return result;
+ }
+
+ /**
+ * Set up the mappings
+ *
+ * @param proxy the proxy
+ * @return the mapping
+ * @throws Throwable for any error
+ */
+ private Map<Method, Action> getMappings(Object proxy) throws Throwable
+ {
+ mbeanInfo = (OpenMBeanInfo) mbeanServerConnection.getMBeanInfo(objectName);
+ Map<String, OpenMBeanAttributeInfo> attributesMap = new HashMap<String, OpenMBeanAttributeInfo>();
+ MBeanAttributeInfo[] attributes = mbeanInfo.getAttributes();
+ for (int i = 0; i < attributes.length; ++i)
+ {
+ OpenMBeanAttributeInfo openAttribute = (OpenMBeanAttributeInfo) attributes[i];
+ attributesMap.put(openAttribute.getName(), openAttribute);
+ }
+ MBeanOperationInfo[] operations = mbeanInfo.getOperations();
+
+ Map<Method, Action> result = new HashMap<Method, Action>();
+
+ Class[] interfaces = proxy.getClass().getInterfaces();
+ for (int i = 0; i < interfaces.length; ++i)
+ {
+ if (NotificationBroadcaster.class.isAssignableFrom(interfaces[i]))
+ {
+ result.put(ADD_NOTIFICATION_LISTENER, new AddNotificationListenerAction());
+ result.put(GET_NOTIFICATION_INFO, new GetNotificationInfoAction());
+ result.put(REMOVE_NOTIFICATION_LISTENER, new RemoveNotificationListenerAction());
+ result.put(REMOVE_NOTIFICATION_LISTENER_TRIPLET, new RemoveNotificationListenerTripletAction());
+ }
+ else
+ {
+ Method[] methods = interfaces[i].getMethods();
+ for (Method method : methods)
+ {
+ String methodName = method.getName();
+ Class returnType = method.getReturnType();
+ Class[] parameterTypes = method.getParameterTypes();
+
+ // Getter
+ if (methodName.startsWith("get") &&
+ methodName.length() > 3 &&
+ Void.TYPE.equals(returnType) == false &&
+ parameterTypes.length == 0)
+ {
+ String name = methodName.substring(3);
+ OpenMBeanAttributeInfo attribute = attributesMap.get(name);
+ if (attribute != null)
+ {
+ Type type = method.getGenericReturnType();
+ result.put(method, new GetAction(attribute, type));
+ continue;
+ }
+ }
+ // Getter (is)
+ else if(methodName.startsWith("is") &&
+ methodName.length() > 2 &&
+ Boolean.TYPE.equals(returnType) &&
+ parameterTypes.length == 0)
+ {
+ String name = methodName.substring(2);
+ OpenMBeanAttributeInfo attribute = attributesMap.get(name);
+ if (attribute != null)
+ {
+ Type type = method.getGenericReturnType();
+ result.put(method, new GetAction(attribute, type));
+ continue;
+ }
+ }
+ // Setter
+ else if(methodName.startsWith("set") &&
+ methodName.length() > 3 &&
+ Void.TYPE.equals(returnType) &&
+ parameterTypes.length == 1)
+ {
+ String name = methodName.substring(3);
+ OpenMBeanAttributeInfo attribute = attributesMap.get(name);
+ if (attribute != null)
+ {
+ result.put(method, new SetAction(attribute));
+ continue;
+ }
+ }
+ // Invoker
+ OpenMBeanOperationInfo operation = findOperation(methodName, method.getGenericParameterTypes(), operations);
+ if (operation != null)
+ {
+ String[] signature = getSignature(method);
+ Type type = method.getGenericReturnType();
+ result.put(method, new InvokeAction(operation, signature, type));
+ }
+ else
+ {
+ result.put(method, new InvalidAction(method));
+ }
+ }
+ }
+ }
+
+ // Add the Object mappings
+ result.put(EQUALS, new EqualsAction());
+ result.put(HASH_CODE, new HashCodeAction());
+ result.put(TO_STRING, new ToStringAction());
+
+ return result;
+ }
+
+ private static OpenMBeanOperationInfo findOperation(String name, Type[] parameterTypes, MBeanOperationInfo[] operations)
+ {
+ OpenType[] signature = getSignature(parameterTypes);
+ for (int i = 0; i < operations.length; ++i)
+ {
+ if (operations[i].getName().equals(name) == false)
+ continue;
+ MBeanParameterInfo[] parameters = operations[i].getSignature();
+ boolean match = true;
+ for (int p = 0; p < parameters.length && match; ++p)
+ {
+ OpenMBeanParameterInfo openMBeanParameterInfo = (OpenMBeanParameterInfo) parameters[p];
+ if (signature[p].equals(openMBeanParameterInfo.getOpenType()) == false)
+ match = false;
+ }
+ if (match)
+ return (OpenMBeanOperationInfo) operations[i];
+ }
+ return null;
+ }
+
+ private static String[] getSignature(final Method method)
+ {
+ Class[] parameterTypes = method.getParameterTypes();
+ String[] signature = new String[parameterTypes.length];
+ for (int p = 0; p < parameterTypes.length; ++p)
+ signature[p] = parameterTypes[p].getName();
+ return signature;
+ }
+
+ private static OpenType[] getSignature(final Type[] parameterTypes)
+ {
+ OpenType[] signature = new OpenType[parameterTypes.length];
+ for (int p = 0; p < parameterTypes.length; ++p)
+ signature[p] = MXBeanUtils.getOpenType(parameterTypes[p]);
+ return signature;
+ }
+
+ private interface Action
+ {
+ public Object perform(Object[] args) throws Throwable;
+ }
+
+ private class GetAction implements Action
+ {
+ private OpenMBeanAttributeInfo attribute;
+ private Type type;
+
+ public GetAction(OpenMBeanAttributeInfo attribute, Type type)
+ {
+ this.attribute = attribute;
+ this.type = type;
+ }
+
+ public Object perform(Object[] args) throws Throwable
+ {
+ Object result = mbeanServerConnection.getAttribute(objectName, attribute.getName());
+
+ return MXBeanUtils.reconstruct(attribute.getOpenType(), type, result, "Get attribute: " + attribute.getName());
+ }
+ }
+
+ private class SetAction implements Action
+ {
+ private OpenMBeanAttributeInfo attribute;
+
+ public SetAction(OpenMBeanAttributeInfo attribute)
+ {
+ this.attribute = attribute;
+ }
+
+ public Object perform(Object[] args) throws Throwable
+ {
+ Object value = MXBeanUtils.construct(attribute.getOpenType(), args[0], "Set attribute: " + attribute.getName());
+
+ Attribute attr = new Attribute(attribute.getName(), value);
+ mbeanServerConnection.setAttribute(objectName, attr);
+ return null;
+ }
+ }
+
+ private class InvokeAction implements Action
+ {
+ private OpenMBeanOperationInfo operation;
+ private String[] signature;
+ private Type type;
+
+ public InvokeAction(OpenMBeanOperationInfo operation, String[] signature, Type type)
+ {
+ this.operation = operation;
+ this.signature = signature;
+ this.type = type;
+ }
+
+ public Object perform(Object[] args) throws Throwable
+ {
+ MBeanParameterInfo[] parameters = operation.getSignature();
+ Object[] arguments = new Object[args.length];
+ for (int i = 0; i < parameters.length; ++i)
+ {
+ OpenMBeanParameterInfo parameter = (OpenMBeanParameterInfo) parameters[i];
+ arguments[i] = MXBeanUtils.construct(parameter.getOpenType(), args[i], operation.getName());
+ }
+
+ Object result = mbeanServerConnection.invoke(objectName, operation.getName(), arguments, signature);
+
+ return MXBeanUtils.reconstruct(operation.getReturnOpenType(), type, result, operation.getName());
+ }
+ }
+
+ private class InvalidAction implements Action
+ {
+ private Method method;
+
+ public InvalidAction(Method method)
+ {
+ this.method = method;
+ }
+
+ public Object perform(Object[] args) throws Throwable
+ {
+ throw new UnsupportedOperationException(method + " is not mapped to the MBeanInfo operations for " + objectName);
+ }
+ }
+
+ private class EqualsAction implements Action
+ {
+ public Object perform(Object[] args) throws Throwable
+ {
+ Object object = args[0];
+ if (object == null || object instanceof Proxy == false)
+ return false;
+ InvocationHandler handler = Proxy.getInvocationHandler(object);
+ if (handler instanceof MXBeanInvocationHandler == false)
+ return false;
+ MXBeanInvocationHandler other = (MXBeanInvocationHandler) handler;
+ return mbeanServerConnection.equals(other.mbeanServerConnection) && objectName.equals(other.objectName);
+ }
+ }
+
+ private class HashCodeAction implements Action
+ {
+ public Object perform(Object[] args) throws Throwable
+ {
+ return objectName.hashCode();
+ }
+ }
+
+ private class ToStringAction implements Action
+ {
+ public Object perform(Object[] args) throws Throwable
+ {
+ return "MXBeanInvocationHandler(" + objectName + ")";
+ }
+ }
+
+ private class AddNotificationListenerAction implements Action
+ {
+ public Object perform(Object[] args) throws Throwable
+ {
+ NotificationListener listener = (NotificationListener) args[0];
+ NotificationFilter filter = (NotificationFilter) args[1];
+ Object handback = args[2];
+ mbeanServerConnection.addNotificationListener(objectName, listener, filter, handback);
+ return null;
+ }
+ }
+
+ private class GetNotificationInfoAction implements Action
+ {
+ public Object perform(Object[] args) throws Throwable
+ {
+ return mbeanServerConnection.getMBeanInfo(objectName).getNotifications();
+ }
+ }
+
+ private class RemoveNotificationListenerAction implements Action
+ {
+ public Object perform(Object[] args) throws Throwable
+ {
+ NotificationListener listener = (NotificationListener) args[0];
+ mbeanServerConnection.removeNotificationListener(objectName, listener);
+ return null;
+ }
+ }
+
+ private class RemoveNotificationListenerTripletAction implements Action
+ {
+ public Object perform(Object[] args) throws Throwable
+ {
+ NotificationListener listener = (NotificationListener) args[0];
+ NotificationFilter filter = (NotificationFilter) args[1];
+ Object handback = args[2];
+ mbeanServerConnection.removeNotificationListener(objectName, listener, filter, handback);
+ return null;
+ }
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/MXBeanMetaData.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/MXBeanMetaData.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/MXBeanMetaData.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,417 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+
+import javax.management.IntrospectionException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanNotificationInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.NotCompliantMBeanException;
+import javax.management.NotificationBroadcaster;
+import javax.management.openmbean.OpenMBeanAttributeInfo;
+import javax.management.openmbean.OpenMBeanAttributeInfoSupport;
+import javax.management.openmbean.OpenMBeanConstructorInfo;
+import javax.management.openmbean.OpenMBeanConstructorInfoSupport;
+import javax.management.openmbean.OpenMBeanInfoSupport;
+import javax.management.openmbean.OpenMBeanOperationInfo;
+import javax.management.openmbean.OpenMBeanOperationInfoSupport;
+import javax.management.openmbean.OpenMBeanParameterInfo;
+import javax.management.openmbean.OpenMBeanParameterInfoSupport;
+import javax.management.openmbean.OpenType;
+
+import org.jboss.mx.metadata.AbstractBuilder;
+
+/**
+ * MXBeanMetaData
+ *
+ * @author <a href="mailto:juha at jboss.org">Juha Lindfors</a>.
+ * @author <a href="mailto:trevor at protocool.com">Trevor Squires</a>.
+ * @author <a href="mailto:thomas.diesler at jboss.com">Thomas Diesler</a>.
+ * @author <a href="mailto:dimitris at jboss.org">Dimitris Andreadis</a>.
+ */
+public class MXBeanMetaData extends AbstractBuilder
+{
+ /** The MBean */
+ private Object mbeanInstance;
+
+ /** The class */
+ private Class<?> mbeanClass;
+
+ /** The interface */
+ private Class<?> mbeanInterface;
+
+ /**
+ * Find the MXBean interface for a class
+ *
+ * @param mbeanClass the mbean class
+ * @return the interface
+ */
+ public static Class<?> findMXBeanInterface(Class<?> mbeanClass)
+ {
+ Class<?> concrete = mbeanClass;
+ while (null != concrete)
+ {
+ Class result = findMXBeanInterface(concrete, concrete.getInterfaces());
+ if (null != result)
+ return result;
+ concrete = concrete.getSuperclass();
+ }
+ return null;
+ }
+
+ /**
+ * Find the MXBean interface for a class
+ *
+ * @param concrete the mbean class
+ * @param interfaces the interfaces to consider
+ * @return the interface
+ */
+ private static Class<?> findMXBeanInterface(Class<?> concrete, Class<?>[] interfaces)
+ {
+ String mxName = concrete.getName() + "MXBean";
+ String stdName = concrete.getName() + "MBean";
+
+ for (Class<?> intf : interfaces)
+ {
+ String name = intf.getName();
+ if (mxName.equals(name) || stdName.equals(name))
+ return intf;
+
+ MXBean mxBean = intf.getAnnotation(MXBean.class);
+ if (mxBean != null && mxBean.value())
+ return intf;
+ }
+ return null;
+ }
+
+ /**
+ * Create a new MXBeanMetaData.
+ *
+ * @param mbeanInstance the mbean instance
+ * @throws NotCompliantMBeanException for any error
+ */
+ public MXBeanMetaData(Object mbeanInstance) throws NotCompliantMBeanException
+ {
+ this(mbeanInstance.getClass());
+ this.mbeanInstance = mbeanInstance;
+ }
+
+ /**
+ * Create a new MXBeanMetaData.
+ *
+ * @param mbeanClass the class
+ * @throws NotCompliantMBeanException for any error
+ */
+ public MXBeanMetaData(Class<?> mbeanClass) throws NotCompliantMBeanException
+ {
+ this.mbeanClass = mbeanClass;
+ this.mbeanInterface = findMXBeanInterface(mbeanClass);
+ if (this.mbeanInterface == null)
+ throw new NotCompliantMBeanException("Cannot obtain MXBean interface for: " + mbeanClass);
+ }
+
+ /**
+ * Create a new MXBeanMetaData.
+ *
+ * @param mbeanInstance the mbean instance
+ * @param mbeanInterface the mbean interface
+ * @throws NotCompliantMBeanException for any error
+ */
+ public MXBeanMetaData(Object mbeanInstance, Class<?> mbeanInterface) throws NotCompliantMBeanException
+ {
+ this.mbeanInstance = mbeanInstance;
+ this.mbeanClass = mbeanInstance.getClass();
+ this.mbeanInterface = mbeanInterface;
+ if (this.mbeanInterface == null)
+ this.mbeanInterface = MXBeanMetaData.findMXBeanInterface(mbeanClass);
+ if (this.mbeanInterface == null)
+ throw new NotCompliantMBeanException("Cannot obtain mxbean interface for: " + mbeanClass);
+ if (this.mbeanInterface.isInterface() == false)
+ throw new NotCompliantMBeanException("Management interface is not an interface: " + mbeanInterface);
+ }
+
+ /**
+ * Retrieve the management interface
+ *
+ * @return the interface
+ */
+ public Class<?> getMBeanInterface()
+ {
+ return mbeanInterface;
+ }
+
+ public MBeanInfo build() throws NotCompliantMBeanException
+ {
+ try
+ {
+ // First check the mbean instance implements the interface
+ if (mbeanInterface == null)
+ throw new NotCompliantMBeanException("The mbean does not implement a management interface");
+ if (mbeanInstance != null && mbeanInterface.isInstance(mbeanInstance) == false)
+ throw new NotCompliantMBeanException("The mbean does not implement its management interface " + mbeanInterface.getName());
+
+ OpenMBeanConstructorInfo[] constructorInfo = buildConstructors();
+
+ HashMap<String, Method> getters = new HashMap<String, Method>();
+ HashMap<String, Method> setters = new HashMap<String, Method>();
+
+ HashMap<String, OpenMBeanOperationInfo> operInfo = new HashMap<String, OpenMBeanOperationInfo>();
+ List<OpenMBeanAttributeInfo> attrInfo = new ArrayList<OpenMBeanAttributeInfo>();
+
+ Method[] methods = mbeanInterface.getMethods();
+ for (Method method : methods)
+ {
+ String methodName = method.getName();
+ Type[] signature = method.getGenericParameterTypes();
+ Type returnType = method.getGenericReturnType();
+
+ if (methodName.startsWith("set") &&
+ methodName.length() > 3 &&
+ signature.length == 1 &&
+ returnType == Void.TYPE)
+ {
+ String key = methodName.substring(3, methodName.length());
+ Method setter = setters.get(key);
+ if (setter != null && setter.getGenericParameterTypes()[0].equals(signature[0]) == false)
+ throw new IntrospectionException("overloaded type for attribute set: " + key);
+ setters.put(key, method);
+ }
+ else if (methodName.startsWith("get") &&
+ methodName.length() > 3 &&
+ signature.length == 0 &&
+ returnType != Void.TYPE)
+ {
+ String key = methodName.substring(3, methodName.length());
+ Method getter = getters.get(key);
+ if (getter != null && getter.getName().startsWith("is"))
+ throw new IntrospectionException("mixed use of get/is for attribute " + key);
+ getters.put(key, method);
+ }
+ else if (methodName.startsWith("is") &&
+ methodName.length() > 2 &&
+ signature.length == 0 &&
+ isBooleanReturn(returnType))
+ {
+ String key = methodName.substring(2, methodName.length());
+ Method getter = getters.get(key);
+ if (getter != null && getter.getName().startsWith("get"))
+ throw new IntrospectionException("mixed use of get/is for attribute " + key);
+ getters.put(key, method);
+ }
+ else
+ {
+ OpenMBeanOperationInfo info = buildOperation(method);
+ operInfo.put(getSignatureString(method), info);
+ }
+ }
+
+ String[] keys = getters.keySet().toArray(new String[getters.size()]);
+ for (String key : keys)
+ {
+ Method getter = getters.remove(key);
+ Method setter = setters.remove(key);
+ OpenMBeanAttributeInfo info = buildAttribute(key, getter, setter);
+ attrInfo.add(info);
+ }
+
+ for (String key : setters.keySet())
+ {
+ Method setter = setters.remove(key);
+ OpenMBeanAttributeInfo info = buildAttribute(key, null, setter);
+ attrInfo.add(info);
+ }
+
+ OpenMBeanAttributeInfo[] attributeInfo = attrInfo.toArray(new OpenMBeanAttributeInfo[attrInfo.size()]);
+ Collection<OpenMBeanOperationInfo> operations = operInfo.values();
+ OpenMBeanOperationInfo[] operationInfo = operations.toArray(new OpenMBeanOperationInfo[operations.size()]);
+
+ MBeanNotificationInfo[] notifications = null;
+ if (mbeanInstance instanceof NotificationBroadcaster)
+ notifications = ((NotificationBroadcaster) mbeanInstance).getNotificationInfo();
+ else
+ notifications = new MBeanNotificationInfo[0];
+
+ return buildMBeanInfo(attributeInfo, constructorInfo, operationInfo, notifications);
+
+ }
+ catch (Throwable t)
+ {
+ NotCompliantMBeanException e = new NotCompliantMBeanException("Error generating OpenMBeanInfo.");
+ e.initCause(t);
+ throw e;
+ }
+ }
+
+ /**
+ * Build the constructors
+ *
+ * @return the info
+ * @throws Exception for any error
+ */
+ private OpenMBeanConstructorInfo[] buildConstructors() throws Exception
+ {
+ Constructor<?>[] constructors = mbeanClass.getConstructors();
+ OpenMBeanConstructorInfo[] constructorInfo = new OpenMBeanConstructorInfo[constructors.length];
+ for (int i = 0; i < constructors.length; ++i)
+ constructorInfo[i] = buildConstructor(constructors[i]);
+ return constructorInfo;
+ }
+
+ /**
+ * Build a constructor
+ *
+ * @param constructor the constructor
+ * @return the info
+ * @throws Exception for any error
+ */
+ private OpenMBeanConstructorInfo buildConstructor(Constructor<?> constructor) throws Exception
+ {
+ Type[] parameterTypes = constructor.getGenericParameterTypes();
+ OpenMBeanParameterInfo[] parameterInfo = new OpenMBeanParameterInfo[parameterTypes.length];
+ for (int i = 0; i < parameterTypes.length; ++i)
+ parameterInfo[i] = buildParameter(i, parameterTypes[i]);
+ return new OpenMBeanConstructorInfoSupport("MBean Constructor.", "MBean Constructor.", parameterInfo);
+ }
+
+ /**
+ * Build a parameter
+ *
+ * @param i the index of the parameter
+ * @param parameterType the parameter type
+ * @return the info
+ * @throws Exception for any error
+ */
+ private OpenMBeanParameterInfo buildParameter(int i, Type parameterType) throws Exception
+ {
+ OpenType openType = MXBeanUtils.getOpenType(parameterType);
+ return new OpenMBeanParameterInfoSupport("arg" + i, "MBean Parameter.", openType);
+ }
+
+ /**
+ * Build an attribute
+ *
+ * @param attrName the attribute name
+ * @param getter the getter
+ * @param setter the setter
+ * @return the info
+ * @throws Exception for any error
+ */
+ private OpenMBeanAttributeInfo buildAttribute(String attrName, Method getter, Method setter) throws Exception
+ {
+ boolean isReadable = (getter != null);
+ boolean isWritable = (setter != null);
+ boolean isIs = false;
+
+ OpenType openType = null;
+ if (getter != null)
+ {
+ openType = MXBeanUtils.getOpenType(getter.getGenericReturnType());
+ if (getter.getName().startsWith("is"))
+ isIs = true;
+ }
+ else
+ {
+ openType = MXBeanUtils.getOpenType(setter.getGenericParameterTypes()[0]);
+ }
+
+ return new OpenMBeanAttributeInfoSupport(attrName, attrName, openType, isReadable, isWritable, isIs);
+ }
+
+ /**
+ * Build the operation info
+ *
+ * @param method the method
+ * @return the info
+ * @throws Exception for any error
+ */
+ private OpenMBeanOperationInfo buildOperation(Method method) throws Exception
+ {
+ Type[] parameterTypes = method.getGenericParameterTypes();
+ OpenMBeanParameterInfo[] parameterInfo = new OpenMBeanParameterInfo[parameterTypes.length];
+ for (int i = 0; i < parameterTypes.length; ++i)
+ parameterInfo[i] = buildParameter(i, parameterTypes[i]);
+ OpenType openType = MXBeanUtils.getOpenType(method.getGenericReturnType());
+ return new OpenMBeanOperationInfoSupport(method.getName(), method.getName(), parameterInfo, openType, MBeanOperationInfo.ACTION);
+ }
+
+ /**
+ * Build the mbean info
+ *
+ * @param attributes the attributes
+ * @param constructors the constructors
+ * @param operations the operations
+ * @param notifications the notifications
+ * @return the info
+ * @throws Exception for any error
+ */
+ private OpenMBeanInfoSupport buildMBeanInfo(OpenMBeanAttributeInfo[] attributes, OpenMBeanConstructorInfo[] constructors, OpenMBeanOperationInfo[] operations, MBeanNotificationInfo[] notifications) throws Exception
+ {
+ return new OpenMBeanInfoSupport(mbeanClass.getName(), mbeanClass.getName(), attributes, constructors, operations, notifications);
+ }
+
+ /**
+ * JMX standard specifies that only "boolean isX()" style methods
+ * represent attributes. "Boolean isX()" methods map to operations.
+ *
+ * @param returnType the return type
+ * @return true when boolean
+ */
+ private boolean isBooleanReturn(Type returnType)
+ {
+ return returnType == Boolean.TYPE;
+ }
+
+ /**
+ * Get a signature string for a method
+ *
+ * @param method the method
+ * @return the signature
+ */
+ private String getSignatureString(Method method)
+ {
+ String name = method.getName();
+ Class[] signature = method.getParameterTypes();
+ StringBuffer buffer = new StringBuffer(512);
+ buffer.append(name);
+ buffer.append("(");
+ if (signature != null)
+ {
+ for (int i = 0; i < signature.length; i++)
+ {
+ buffer.append(signature[i].getName());
+ if (i < signature.length-1)
+ buffer.append(",");
+ }
+ }
+ buffer.append(")");
+ return buffer.toString();
+ }
+}
+
Added: branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/MXBeanSupport.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/MXBeanSupport.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/MXBeanSupport.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,161 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean;
+
+import javax.management.Attribute;
+import javax.management.AttributeList;
+import javax.management.AttributeNotFoundException;
+import javax.management.DynamicMBean;
+import javax.management.InvalidAttributeValueException;
+import javax.management.ListenerNotFoundException;
+import javax.management.MBeanException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanNotificationInfo;
+import javax.management.MBeanRegistration;
+import javax.management.MBeanServer;
+import javax.management.NotificationEmitter;
+import javax.management.NotificationFilter;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+import javax.management.ReflectionException;
+
+/**
+ * MXBeanSupport.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MXBeanSupport implements DynamicMBean, MBeanRegistration, NotificationEmitter
+{
+ /** No notifications */
+ private static final MBeanNotificationInfo[] NO_NOTIFICATIONS = new MBeanNotificationInfo[0];
+
+ /** The delegate */
+ private DynamicMBean delegate;
+
+ /** The mbean registration delegate */
+ private MBeanRegistration registration;
+
+ /** The emitter delegate */
+ private NotificationEmitter emitter;
+
+ /**
+ * Create a new MXBeanSupport.
+ */
+ protected MXBeanSupport()
+ {
+ init(MXBeanUtils.createMXBean(this, null));
+ }
+
+ /**
+ * Create a new MXBeanSupport.
+ *
+ * @param mxbeanInterface the interface
+ */
+ protected MXBeanSupport(Class<?> mxbeanInterface)
+ {
+ init(MXBeanUtils.createMXBean(this, mxbeanInterface));
+ }
+
+ public MBeanInfo getMBeanInfo()
+ {
+ return delegate.getMBeanInfo();
+ }
+
+ public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException
+ {
+ return delegate.getAttribute(attribute);
+ }
+
+ public AttributeList getAttributes(String[] attributes)
+ {
+ return delegate.getAttributes(attributes);
+ }
+
+ public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException
+ {
+ delegate.setAttribute(attribute);
+ }
+
+ public AttributeList setAttributes(AttributeList attributes)
+ {
+ return delegate.setAttributes(attributes);
+ }
+
+ public Object invoke(String actionName, Object[] params, String[] signature) throws MBeanException, ReflectionException
+ {
+ return delegate.invoke(actionName, params, signature);
+ }
+
+ public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception
+ {
+ return registration.preRegister(server, name);
+ }
+
+ public void postRegister(Boolean registrationDone)
+ {
+ registration.postDeregister();
+ }
+
+ public void preDeregister() throws Exception
+ {
+ registration.preDeregister();
+ }
+
+ public void postDeregister()
+ {
+ registration.postDeregister();
+ }
+
+ public MBeanNotificationInfo[] getNotificationInfo()
+ {
+ return NO_NOTIFICATIONS;
+ }
+
+ public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) throws IllegalArgumentException
+ {
+ emitter.addNotificationListener(listener, filter, handback);
+
+ }
+
+ public void removeNotificationListener(NotificationListener listener) throws ListenerNotFoundException
+ {
+ emitter.removeNotificationListener(listener);
+ }
+
+ public void removeNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) throws ListenerNotFoundException
+ {
+ emitter.removeNotificationListener(listener, filter, handback);
+ }
+
+ /**
+ * Initialise the delegates
+ *
+ * @param delegate the delegate
+ */
+ private void init(DynamicMBean delegate)
+ {
+ this.delegate = delegate;
+ this.registration = (MBeanRegistration) delegate;
+ this.emitter = (NotificationEmitter) delegate;
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/MXBeanUtils.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/MXBeanUtils.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/MXBeanUtils.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,1041 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.GenericArrayType;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Proxy;
+import java.lang.reflect.Type;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+
+import javax.management.DynamicMBean;
+import javax.management.ObjectName;
+import javax.management.openmbean.ArrayType;
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.CompositeDataSupport;
+import javax.management.openmbean.CompositeType;
+import javax.management.openmbean.OpenType;
+import javax.management.openmbean.SimpleType;
+import javax.management.openmbean.TabularData;
+import javax.management.openmbean.TabularDataSupport;
+import javax.management.openmbean.TabularType;
+
+import org.jboss.util.collection.WeakValueHashMap;
+
+/**
+ * Utils.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MXBeanUtils
+{
+ /** A cache of methods to keys */
+ private static final Map<Method, String> compositeDataKeyCache = Collections.synchronizedMap(new WeakHashMap<Method, String>());
+
+ /** A cache of classes to key to getters */
+ private static final Map<Class, Map<String, Method>> compositeDataMethodCache = Collections.synchronizedMap(new WeakHashMap<Class, Map<String, Method>>());
+
+ /** The map key */
+ public static final String MAP_KEY = "key";
+
+ /** The map value */
+ public static final String MAP_VALUE = "value";
+
+ /** Map index names */
+ public static final String[] MAP_INDEX_NAMES = { MAP_KEY };
+
+ /** Map item names */
+ public static final String[] MAP_ITEM_NAMES = { MAP_KEY, MAP_VALUE };
+
+ /**
+ * Get the OpenType for a class
+ *
+ * @param type the type
+ * @return the open type
+ */
+ public static OpenType getOpenType(Type type)
+ {
+ if (type == null)
+ throw new IllegalArgumentException("Null type");
+
+ OpenType result = checkType(type);
+ if (result != null)
+ return result;
+ Class clazz = (Class) type;
+ return CompositeTypeMetaDataFactory.getCompositeType(clazz);
+ }
+
+ /**
+ * Get the SimpleType for a class
+ *
+ * @param type the type
+ * @return the open type
+ * @throws Exception for any error
+ */
+ public static SimpleType getSimpleType(Class type) throws Exception
+ {
+ SimpleType simpleType = checkSimpleType(type);
+ if (simpleType == null)
+ throw new IllegalArgumentException("Not a SimpleType: " + type.getName());
+ return simpleType;
+ }
+
+ /**
+ * Get the for a class that is not composite
+ *
+ * @param type the type
+ * @return the open type or null if composite
+ */
+ public static OpenType checkType(Type type)
+ {
+ OpenType result = checkSimpleType(type);
+ if (result != null)
+ return result;
+ result = checkEnum(type);
+ if (result != null)
+ return result;
+ result = checkArray(type);
+ if (result != null)
+ return result;
+ result = checkCollection(type);
+ if (result != null)
+ return result;
+ return checkMap(type);
+ }
+
+ /**
+ * Create a composite data proxy
+ *
+ * @param <T> the interface type
+ * @param intf the interface type
+ * @param compositeData the composite data
+ * @return the proxy
+ */
+ public static <T> T createCompositeDataProxy(Class<T> intf, CompositeData compositeData)
+ {
+ if (intf == null)
+ throw new IllegalArgumentException("Null interface");
+ InvocationHandler handler = new CompositeDataInvocationHandler(compositeData);
+ Object object = Proxy.newProxyInstance(intf.getClassLoader(), new Class[] { intf }, handler);
+ return intf.cast(object);
+ }
+
+ /**
+ * Construct some open data
+ *
+ * @param type the type
+ * @param value the value
+ * @param context the context
+ * @return the open data
+ * @throws Exception for any error
+ */
+ public static Object construct(Type type, Object value, Object context) throws Exception
+ {
+ OpenType openType = getOpenType(type);
+ return construct(openType, value, context);
+ }
+
+ /**
+ * Construct some open data
+ *
+ * @param openType the open type
+ * @param value the value
+ * @param context the context
+ * @return the open data
+ * @throws Exception for any error
+ */
+ public static Object construct(OpenType openType, Object value, Object context) throws Exception
+ {
+ if (openType instanceof SimpleType)
+ return constructSimpleData(value);
+ if (openType.isArray())
+ return constructArrayData(openType, value, context);
+ if (openType instanceof TabularType)
+ return constructTabularData(openType, value, context);
+ return constructCompositeData(openType, value, context);
+ }
+
+ /**
+ * Reconstruct a type from an object
+ *
+ * @param type the type
+ * @param value the value
+ * @param context for error reporting
+ * @return the object
+ * @throws Exception for any error
+ */
+ public static Object reconstruct(Type type, Object value, Object context) throws Exception
+ {
+ OpenType openType = MXBeanUtils.getOpenType(type);
+ return reconstruct(openType, type, value, context);
+ }
+
+ /**
+ * Reconstruct a type from an object
+ *
+ * @param openType the open type
+ * @param type the type
+ * @param value the value
+ * @param context for error reporting
+ * @return the object
+ * @throws Exception for any error
+ */
+ public static Object reconstruct(OpenType openType, Type type, Object value, Object context) throws Exception
+ {
+ if (openType instanceof SimpleType)
+ return reconstructSimpleData(type, value, context);
+ if (openType.isArray())
+ return reconstructArrayData(openType, type, value, context);
+ if (openType instanceof TabularType)
+ return reconstructTabularData(openType, type, value, context);
+ return reconstructCompositeData(openType, type, value, context);
+ }
+
+ /**
+ * Get the SimpleType for a class
+ *
+ * @param type the type
+ * @return the simple type or null if not a simple type
+ */
+ public static SimpleType checkSimpleType(Type type)
+ {
+ if (BigDecimal.class.equals(type))
+ return SimpleType.BIGDECIMAL;
+ if (BigInteger.class.equals(type))
+ return SimpleType.BIGINTEGER;
+ if (Boolean.class.equals(type))
+ return SimpleType.BOOLEAN;
+ if (Boolean.TYPE.equals(type))
+ return SimpleType.BOOLEAN;
+ if (Byte.class.equals(type))
+ return SimpleType.BYTE;
+ if (Byte.TYPE.equals(type))
+ return SimpleType.BYTE;
+ if (Character.class.equals(type))
+ return SimpleType.CHARACTER;
+ if (Character.TYPE.equals(type))
+ return SimpleType.CHARACTER;
+ if (Date.class.equals(type))
+ return SimpleType.DATE;
+ if (Double.class.equals(type))
+ return SimpleType.DOUBLE;
+ if (Double.TYPE.equals(type))
+ return SimpleType.DOUBLE;
+ if (Float.class.equals(type))
+ return SimpleType.FLOAT;
+ if (Float.TYPE.equals(type))
+ return SimpleType.FLOAT;
+ if (Integer.class.equals(type))
+ return SimpleType.INTEGER;
+ if (Integer.TYPE.equals(type))
+ return SimpleType.INTEGER;
+ if (Long.class.equals(type))
+ return SimpleType.LONG;
+ if (Long.TYPE.equals(type))
+ return SimpleType.LONG;
+ if (ObjectName.class.equals(type))
+ return SimpleType.OBJECTNAME;
+ if (Short.class.equals(type))
+ return SimpleType.SHORT;
+ if (Short.TYPE.equals(type))
+ return SimpleType.SHORT;
+ if (String.class.equals(type))
+ return SimpleType.STRING;
+ if (Void.class.equals(type))
+ return SimpleType.VOID;
+ return null;
+ }
+
+ /**
+ * Get the simple type for an enum
+ *
+ * @param type the type
+ * @return return the enum type or null if it is not an enum
+ */
+ public static SimpleType checkEnum(Type type)
+ {
+ if (type instanceof Class == false)
+ return null;
+ Class clazz = (Class) type;
+ if (clazz.isEnum() || Enum.class.equals(clazz))
+ return SimpleType.STRING;
+ return null;
+ }
+
+ /**
+ * Construct a simple type open data
+ *
+ * @param value the value
+ * @return the simple type
+ */
+ public static Object constructSimpleData(Object value)
+ {
+ if (value != null && value instanceof Enum)
+ {
+ Enum enumeration = (Enum) value;
+ return enumeration.name();
+ }
+ return value;
+ }
+
+ /**
+ * Reconstruct a simple type open data
+ *
+ * @param type the type
+ * @param value the value
+ * @param context the context
+ * @return the simple type
+ */
+ @SuppressWarnings("unchecked")
+ private static Object reconstructSimpleData(Type type, Object value, Object context)
+ {
+ if (type instanceof Class)
+ {
+ if (value != null)
+ {
+ Class clazz = (Class) type;
+ if (clazz.isEnum() || Enum.class.equals(clazz))
+ {
+ String string = (String) value;
+ return Enum.valueOf(clazz, string);
+ }
+ }
+ else
+ {
+ Class clazz = (Class) type;
+ if (clazz.isPrimitive())
+ throw new IllegalArgumentException("Attempt to use null as a primitive for: " + context);
+ return null;
+ }
+ }
+ return value;
+ }
+
+ /**
+ * Get the array type for a class
+ *
+ * @param type the type
+ * @return return the array type or null if it is not an array
+ */
+ public static ArrayType checkArray(Type type)
+ {
+ if (type instanceof Class)
+ {
+ Class clazz = (Class) type;
+ if (clazz.isArray() == false)
+ return null;
+ int dimension = 1;
+ Class componentType = clazz.getComponentType();
+ while (componentType.isArray())
+ {
+ ++dimension;
+ componentType = componentType.getComponentType();
+ }
+ OpenType componentOpenType = getOpenType(componentType);
+ try
+ {
+ return new ArrayType(dimension, componentOpenType);
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ if (type instanceof GenericArrayType)
+ {
+ GenericArrayType arrayType = (GenericArrayType) type;
+ int dimension = 1;
+ Type componentType = arrayType.getGenericComponentType();
+ while (componentType instanceof GenericArrayType)
+ {
+ ++dimension;
+ arrayType = (GenericArrayType) componentType;
+ componentType = arrayType.getGenericComponentType();
+ }
+ OpenType componentOpenType = getOpenType(componentType);
+ try
+ {
+ return new ArrayType(dimension, componentOpenType);
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Get the collection type for a class
+ *
+ * @param type the type
+ * @return return the array type or null if it is not a collection
+ */
+ public static ArrayType checkCollection(Type type)
+ {
+ if (type instanceof ParameterizedType == false)
+ {
+ if (type instanceof Class)
+ return checkCollectionClass((Class) type);
+ else
+ return null;
+ }
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ Type rawType = parameterizedType.getRawType();
+ if (rawType instanceof Class == false)
+ return null;
+ Class rawClass = (Class) rawType;
+ if (Collection.class.isAssignableFrom(rawClass) == false)
+ return null;
+ Type componentType = parameterizedType.getActualTypeArguments()[0];
+ OpenType componentOpenType = getOpenType(componentType);
+ try
+ {
+ return new ArrayType(1, componentOpenType);
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Get the collection type for a class
+ *
+ * @param clazz the class
+ * @return return the array type or null if it is not a collection
+ */
+ public static ArrayType checkCollectionClass(Class clazz)
+ {
+ if (Collection.class.isAssignableFrom(clazz) == false)
+ return null;
+ OpenType componentOpenType = getOpenType(Object.class);
+ try
+ {
+ return new ArrayType(1, componentOpenType);
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Construct an array type open data
+ *
+ * @param openType the open type
+ * @param value the value
+ * @param context the context
+ * @return the open data
+ * @throws Exception for any error
+ */
+ public static Object constructArrayData(OpenType openType, Object value, Object context) throws Exception
+ {
+ if (value == null)
+ return null;
+
+ ArrayType arrayType = (ArrayType) openType;
+ OpenType elementType = arrayType.getElementOpenType();
+ int dimension = arrayType.getDimension();
+
+ Class clazz = value.getClass();
+ if (clazz.isArray())
+ {
+ Object[] oldArray = (Object[]) value;
+ Class<?> componentType = Class.forName(arrayType.getClassName());
+ return constructArray(elementType, componentType.getComponentType(), dimension, oldArray, context);
+ }
+ if (value instanceof Collection)
+ {
+ Collection c = (Collection) value;
+ Object[] oldArray = c.toArray();
+ Class<?> componentType = Class.forName(arrayType.getClassName());
+ return constructArray(elementType, componentType.getComponentType(), dimension, oldArray, context);
+ }
+ throw new UnsupportedOperationException("Cannot construct array for: " + value);
+ }
+
+ /**
+ * Construct an array of open data
+ *
+ * @param elementType the element type
+ * @param componentType the componentType
+ * @param dimension the dimension
+ * @param oldArray the old array
+ * @param context the context
+ * @return the array
+ * @throws Exception for any error
+ */
+ private static Object[] constructArray(OpenType elementType, Class<?> componentType, int dimension, Object[] oldArray, Object context) throws Exception
+ {
+ if (oldArray == null)
+ return null;
+
+ Object[] newArray = (Object[]) Array.newInstance(componentType, oldArray.length);
+ if (dimension > 1)
+ {
+ for (int i = 0; i < oldArray.length; ++i)
+ {
+ Object[] nestedOld = (Object[]) oldArray[i];
+ newArray[i] = constructArray(elementType, componentType.getComponentType(), dimension-1, nestedOld, context);
+ }
+ }
+ else
+ {
+ if (Object.class.equals(componentType))
+ {
+ for (int i = 0; i < oldArray.length; ++i)
+ newArray[i] = oldArray[i];
+ }
+ else
+ {
+ for (int i = 0; i < oldArray.length; ++i)
+ newArray[i] = construct(elementType, oldArray[i], context);
+ }
+ }
+
+ return newArray;
+ }
+
+ /**
+ * Reconstruct an array type
+ *
+ * @param openType the open type
+ * @param type the type
+ * @param value the value
+ * @param context the context
+ * @return the value
+ * @throws Exception for any error
+ */
+ public static Object reconstructArrayData(OpenType openType, Type type, Object value, Object context) throws Exception
+ {
+ if (value == null)
+ return null;
+
+ ArrayType arrayType = (ArrayType) getOpenType(type);
+ OpenType elementType = arrayType.getElementOpenType();
+ int dimension = arrayType.getDimension();
+ Object[] oldArray = (Object[]) value;
+ if (type instanceof Class)
+ {
+ Class clazz = (Class) type;
+ if (clazz.isArray())
+ return reconstructArray(elementType, clazz.getComponentType(), dimension, oldArray, context);
+ // TODO FIXME
+ // else if (Set.class.isAssignableFrom(clazz))
+ // return createSet(oldArray);
+ // else if (Collection.class.isAssignableFrom(clazz))
+ // return createCollection(oldArray);
+ }
+ else if (type instanceof ParameterizedType)
+ {
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ Type rawType = parameterizedType.getRawType();
+ if (rawType instanceof Class)
+ {
+ Class raw = (Class) rawType;
+ if (Set.class.isAssignableFrom(raw))
+ return createSet(oldArray);
+ else if (Collection.class.isAssignableFrom(raw))
+ return createCollection(oldArray);
+ }
+ }
+ throw new UnsupportedOperationException("Cannot convert array type: " + type);
+ }
+
+ /**
+ * Reconstruct an array
+ *
+ * @param elementType the element type
+ * @param componentType the componentType
+ * @param dimension the dimension
+ * @param oldArray the old array of open data
+ * @param context the context
+ * @return the array
+ * @throws Exception for any error
+ */
+ private static Object[] reconstructArray(OpenType elementType, Class componentType, int dimension, Object[] oldArray, Object context) throws Exception
+ {
+ if (oldArray == null)
+ return null;
+
+ Object[] newArray = (Object[]) Array.newInstance(componentType, oldArray.length);
+ if (dimension > 1)
+ {
+ for (int i = 0; i < oldArray.length; ++i)
+ {
+ Object[] nestedOld = (Object[]) oldArray[i];
+ newArray[i] = reconstructArray(elementType, componentType.getComponentType(), dimension-1, nestedOld, context);
+ }
+ }
+ else
+ {
+ for (int i = 0; i < oldArray.length; ++i)
+ newArray[i] = reconstruct(elementType, componentType, oldArray[i], context);
+ }
+
+ return newArray;
+ }
+
+ /**
+ * Create a collection
+ *
+ * @param array the array
+ * @return the collection
+ */
+ private static Collection createCollection(Object[] array)
+ {
+ return Arrays.asList(array);
+ }
+
+ /**
+ * Create a set
+ *
+ * @param array the array
+ * @return the set
+ */
+ @SuppressWarnings("unchecked")
+ private static Set createSet(Object[] array)
+ {
+ HashSet result = new HashSet(array.length);
+ for (int i = 0; i < array.length; ++i)
+ result.add(array[i]);
+ return result;
+ }
+
+ /**
+ * Get the map type for a class
+ *
+ * @param type the type
+ * @return return the tabular type or null if it is not a collection
+ */
+ public static TabularType checkMap(Type type)
+ {
+ if (type instanceof ParameterizedType == false)
+ {
+ if (type instanceof Class)
+ return checkMapClass((Class) type);
+ else
+ return null;
+ }
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ Type rawType = parameterizedType.getRawType();
+ if (rawType instanceof Class == false)
+ return null;
+ Class rawClass = (Class) rawType;
+ if (Map.class.isAssignableFrom(rawClass) == false)
+ return null;
+ Type[] args = parameterizedType.getActualTypeArguments();
+ Type keyType = args[0];
+ Type valueType = args[1];
+ return createMapType(keyType, valueType);
+ }
+
+ /**
+ * Get the map type for a class
+ *
+ * @param clazz the class
+ * @return return the tabular type or null if it is not a collection
+ */
+ public static TabularType checkMapClass(Class clazz)
+ {
+ if (Map.class.isAssignableFrom(clazz) == false)
+ return null;
+ return createMapType(Object.class, Object.class);
+ }
+
+ /**
+ * Create a map type
+ *
+ * @param keyType the key type
+ * @param valueType the value type
+ * @return the map type
+ */
+ public static TabularType createMapType(Type keyType, Type valueType)
+ {
+ String name = Map.class.getName();
+ OpenType[] itemTypes = { getOpenType(keyType), getOpenType(valueType) };
+ try
+ {
+ CompositeType entryType = createMapEntryType(itemTypes);
+ return new TabularType(name, name, entryType, MAP_INDEX_NAMES);
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Create a map type
+ *
+ * @param itemTypes the item types
+ * @return the map entry type
+ */
+ private static CompositeType createMapEntryType(OpenType[] itemTypes)
+ {
+ String entryName = Map.Entry.class.getName();
+ try
+ {
+ return new CompositeType(entryName, entryName, MAP_ITEM_NAMES, MAP_ITEM_NAMES, itemTypes);
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Construct a tabular type open data
+ *
+ * @param openType the open type
+ * @param value the value
+ * @param context the context
+ * @return the open data
+ * @throws Exception for any error
+ */
+ @SuppressWarnings("unchecked")
+ public static Object constructTabularData(OpenType openType, Object value, Object context) throws Exception
+ {
+ if (value == null)
+ return null;
+
+ TabularType tabularType = (TabularType) openType;
+
+ if (value instanceof Map)
+ {
+ TabularDataSupport table = new TabularDataSupport(tabularType);
+ CompositeType entryType = tabularType.getRowType();
+ OpenType keyType = entryType.getType(MAP_KEY);
+ OpenType valueType = entryType.getType(MAP_VALUE);
+
+ Map<Object, Object> m = (Map<Object, Object>) value;
+ for (Iterator<Map.Entry<Object, Object>> i = m.entrySet().iterator(); i.hasNext();)
+ {
+ Map.Entry<Object, Object> entry = i.next();
+ Object key = construct(keyType, entry.getKey(), context);
+ Object val = construct(valueType, entry.getValue(), context);
+ CompositeDataSupport data = new CompositeDataSupport(entryType, MXBeanUtils.MAP_ITEM_NAMES, new Object[] { key, val });
+ table.put(data);
+ }
+ return table;
+ }
+ throw new UnsupportedOperationException("Cannot construct map for: " + value);
+ }
+
+ /**
+ * Reconstruct a tabular type
+ *
+ * @param openType the open type
+ * @param type the type
+ * @param value the value
+ * @param context the context
+ * @return the value
+ * @throws Exception for any error
+ */
+ public static Object reconstructTabularData(OpenType openType, Type type, Object value, Object context) throws Exception
+ {
+ if (value == null)
+ return null;
+
+ TabularType tabularType = (TabularType) getOpenType(type);
+ if (type instanceof Class)
+ {
+ // TODO FIXME
+ // Class clazz = (Class) type;
+ // if (Map.class.isAssignableFrom(clazz))
+ // return createMap(tabularType, Object.class, Object.class, value, context);
+ }
+ else if (type instanceof ParameterizedType)
+ {
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ Type rawType = parameterizedType.getRawType();
+ if (rawType instanceof Class)
+ {
+ Class raw = (Class) rawType;
+ if (Map.class.isAssignableFrom(raw))
+ {
+ Type keyType = parameterizedType.getActualTypeArguments()[0];
+ Type valueType = parameterizedType.getActualTypeArguments()[1];
+ return createMap(tabularType, keyType, valueType, value, context);
+ }
+ }
+ }
+ throw new UnsupportedOperationException("Cannot convert array type: " + type);
+ }
+
+ /**
+ * Create a map
+ *
+ * @param openType the open type
+ * @param keyType the key type
+ * @param valueType the value type
+ * @param value the value
+ * @param context the context
+ * @return the map
+ * @throws Exception for any problem
+ */
+ @SuppressWarnings("unchecked")
+ private static Map createMap(TabularType openType, Type keyType, Type valueType, Object value, Object context) throws Exception
+ {
+ if (value == null)
+ return null;
+
+ Map<Object, Object> result = new HashMap<Object, Object>();
+
+ TabularData table = (TabularData) value;
+ Collection<CompositeData> values = table.values();
+ for (CompositeData entry : values)
+ {
+ Object key = reconstruct(keyType, entry.get(MAP_KEY), context);
+ Object val = reconstruct(valueType, entry.get(MAP_VALUE), context);
+ result.put(key, val);
+ }
+
+ return result;
+ }
+
+ /**
+ * Construct composite type open data
+ *
+ * @param openType the open type
+ * @param value the value
+ * @param context the context
+ * @return the open data
+ * @throws Exception for any error
+ */
+ @SuppressWarnings("unchecked")
+ public static Object constructCompositeData(OpenType openType, Object value, Object context) throws Exception
+ {
+ if (value == null)
+ return null;
+
+ Class clazz = value.getClass();
+
+ CompositeType compositeType = (CompositeType) openType;
+ Set<String> nameSet = compositeType.keySet();
+ String[] names = nameSet.toArray(new String[nameSet.size()]);
+
+ Object[] values = new Object[names.length];
+
+ for (int i = 0 ; i < names.length; ++i)
+ {
+ String name = names[i];
+ OpenType itemType = compositeType.getType(name);
+ Method method = getCompositeDataMethod(clazz, name, itemType == SimpleType.BOOLEAN);
+ Object itemValue = method.invoke(value, null);
+ values[i] = construct(itemType, itemValue, context);
+ }
+ return new CompositeDataSupport(compositeType, names, values);
+ }
+
+ /**
+ * Reconstruct a composite type
+ *
+ * @param openType the open type
+ * @param type the type
+ * @param value the value
+ * @param context the context
+ * @return the value
+ * @throws Exception for any error
+ */
+ public static Object reconstructCompositeData(OpenType openType, Type type, Object value, Object context) throws Exception
+ {
+ if (value == null)
+ return null;
+
+ CompositeData compositeData = (CompositeData) value;
+ CompositeDataInvocationHandler handler = new CompositeDataInvocationHandler(compositeData);
+ Class clazz = (Class) type;
+ Class[] interfaces = null;
+ if (clazz.isInterface())
+ interfaces = new Class[] { clazz };
+ else
+ interfaces = clazz.getInterfaces();
+ return Proxy.newProxyInstance(clazz.getClassLoader(), interfaces, handler);
+ }
+
+ /**
+ * Get the key for a composite data getter method
+ *
+ * @param method the method
+ * @return the key
+ */
+ public static String getCompositeDataKey(Method method)
+ {
+ String key = compositeDataKeyCache.get(method);
+ if (key != null)
+ return key;
+
+ StringBuilder fieldName = null;
+
+ Class returnType = method.getReturnType();
+ Class[] paramTypes = method.getParameterTypes();
+ if (Void.TYPE.equals(returnType) == false && paramTypes.length == 0)
+ {
+ String name = method.getName();
+ if (name.startsWith("is") && name.length() > 2)
+ {
+ if (Boolean.TYPE.equals(returnType))
+ {
+ fieldName = new StringBuilder();
+ fieldName.append(Character.toLowerCase(name.charAt(2)));
+ if (name.length() > 3)
+ fieldName.append(name.substring(3));
+ }
+ }
+ else if (name.startsWith("get") && name.length() > 3)
+ {
+ fieldName = new StringBuilder();
+ fieldName.append(Character.toLowerCase(name.charAt(3)));
+ if (name.length() > 4)
+ fieldName.append(name.substring(4));
+ }
+ }
+
+ if (fieldName == null)
+ return null;
+
+ String result = fieldName.toString();
+ compositeDataKeyCache.put(method, result);
+ return result;
+ }
+
+ /**
+ * Get the key for a composite data getter method
+ *
+ * @param clazz the class
+ * @param key the key
+ * @param isBoolean whether it is boolean
+ * @return the method
+ * @throws Exception for any error
+ */
+ @SuppressWarnings("unchecked")
+ public static Method getCompositeDataMethod(Class clazz, String key, boolean isBoolean) throws Exception
+ {
+ Map<String, Method> cache = compositeDataMethodCache.get(clazz);
+ if (cache != null)
+ {
+ Method method = cache.get(key);
+ if (method != null)
+ return method;
+ }
+
+ StringBuilder name = new StringBuilder();
+ name.append(Character.toUpperCase(key.charAt(0)));
+ if (key.length() > 1)
+ name.append(key.substring(1));
+ Method method = null;
+ try
+ {
+ method = clazz.getMethod("get" + name, null);
+ }
+ catch (NoSuchMethodException e)
+ {
+ if (isBoolean)
+ {
+ try
+ {
+ method = clazz.getMethod("is" + name, null);
+ }
+ catch (NoSuchMethodException ignored)
+ {
+ throw e;
+ }
+ }
+ else
+ {
+ throw e;
+ }
+ }
+
+ if (cache == null)
+ {
+ cache = new WeakValueHashMap();
+ compositeDataMethodCache.put(clazz, cache);
+ }
+ cache.put(key, method);
+ return method;
+ }
+
+ /**
+ * Create a new MXBean
+ *
+ * @param resource the resource
+ * @param mxbeanInterface the interface
+ * @return the MXBean
+ */
+ public static DynamicMBean createMXBean(Object resource, Class<?> mxbeanInterface)
+ {
+ try
+ {
+ return new MXBeanDelegate(resource, mxbeanInterface);
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Error creating MXBean", e);
+ }
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/NotificationType.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/NotificationType.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/NotificationType.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,48 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * NotificationType.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+ at Documented
+ at Inherited
+ at Target(ElementType.TYPE)
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface NotificationType
+{
+ /** The notification type */
+ String value();
+
+ /** The user data class */
+ Class userDataClass() default void.class;
+}
Added: branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/SkeletonOpenType.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/SkeletonOpenType.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/main/org/jboss/mx/mxbean/SkeletonOpenType.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,85 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean;
+
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+
+import javax.management.openmbean.OpenType;
+
+import org.jboss.util.UnreachableStatementException;
+
+/**
+ * SkeletonOpenType.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class SkeletonOpenType
+{
+ /** The open type */
+ private OpenType openType;
+
+ /** The composite type meta data */
+ private CompositeTypeMetaData composite;
+
+ /**
+ * Create a new SkeletonOpenType.
+ *
+ * @param type the type
+ */
+ public SkeletonOpenType(Type type)
+ {
+ openType = MXBeanUtils.checkType(type);
+ if (openType != null)
+ return;
+ Class clazz = null;
+ if (type instanceof ParameterizedType)
+ {
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ clazz = (Class) parameterizedType.getRawType();
+ }
+ else if (type instanceof Class)
+ {
+ clazz = (Class) type;
+ }
+ else
+ {
+ throw new UnsupportedOperationException("Unable to create open type for " + type);
+ }
+ composite = CompositeTypeMetaDataFactory.getCompositeTypeMetaData(clazz);
+ }
+
+ /**
+ * Get the openType.
+ *
+ * @return the openType.
+ */
+ public OpenType getOpenType()
+ {
+ if (openType != null)
+ return openType;
+ if (composite != null)
+ return composite.getCompositeType();
+ throw new UnreachableStatementException();
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/CollectionsInterface.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/CollectionsInterface.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/CollectionsInterface.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,98 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.support;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.management.openmbean.ArrayType;
+import javax.management.openmbean.OpenType;
+import javax.management.openmbean.SimpleType;
+
+import org.jboss.mx.mxbean.MXBeanUtils;
+
+/**
+ * CollectionsInterface.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public interface CollectionsInterface
+{
+ String ARRAY = "array";
+ String COLLECTION = "collection";
+ String SET = "set";
+ String LIST = "list";
+ String MAP = "map";
+ String ENUM = "enum";
+
+ String[] KEYS =
+ {
+ ARRAY,
+ COLLECTION,
+ SET,
+ LIST,
+ MAP,
+ ENUM
+ };
+
+ OpenType[] TYPES = Initializer._TYPES;
+
+ String[] getArray();
+
+ Collection<String> getCollection();
+
+ Set<String> getSet();
+
+ List<String> getList();
+
+ Map<String, Integer> getMap();
+
+ TestEnum getEnum();
+
+ public static class Initializer
+ {
+ static OpenType[] _TYPES;
+
+ static
+ {
+ try
+ {
+ _TYPES = new OpenType[]
+ {
+ new ArrayType(1, SimpleType.STRING),
+ new ArrayType(1, SimpleType.STRING),
+ new ArrayType(1, SimpleType.STRING),
+ new ArrayType(1, SimpleType.STRING),
+ MXBeanUtils.createMapType(String.class, Integer.class),
+ SimpleType.STRING
+ };
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/CollectionsMXBeanSupport.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/CollectionsMXBeanSupport.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/CollectionsMXBeanSupport.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,129 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.support;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.mx.mxbean.MXBeanSupport;
+
+/**
+ * CollectionsMXBeanSupport.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class CollectionsMXBeanSupport extends MXBeanSupport implements CollectionsMXBeanSupportMXBean
+{
+ String[] array;
+ Collection<String> collection;
+ Set<String> set;
+ List<String> list;
+ Map<String, Integer> map;
+ TestEnum enumeration;
+
+ public CollectionsMXBeanSupport()
+ {
+ }
+
+ public CollectionsMXBeanSupport(String[] array, Collection<String> collection, Set<String> set, List<String> list, Map<String, Integer> map, TestEnum enumeration)
+ {
+ this.array = array;
+ this.collection = collection;
+ this.set = set;
+ this.list = list;
+ this.map = map;
+ this.enumeration = enumeration;
+ }
+
+ public String[] getArray()
+ {
+ return array;
+ }
+
+ public Collection<String> getCollection()
+ {
+ return collection;
+ }
+
+ public List<String> getList()
+ {
+ return list;
+ }
+
+ public Set<String> getSet()
+ {
+ return set;
+ }
+
+ public Map<String, Integer> getMap()
+ {
+ return map;
+ }
+
+ public TestEnum getEnum()
+ {
+ return enumeration;
+ }
+
+ public void setEnum(TestEnum enumeration)
+ {
+ this.enumeration = enumeration;
+ }
+
+ public void setArray(String[] array)
+ {
+ this.array = array;
+ }
+
+ public void setCollection(Collection<String> collection)
+ {
+ this.collection = collection;
+ }
+
+ public void setList(List<String> list)
+ {
+ this.list = list;
+ }
+
+ public void setMap(Map<String, Integer> map)
+ {
+ this.map = map;
+ }
+
+ public void setSet(Set<String> set)
+ {
+ this.set = set;
+ }
+
+ public List<String> echoReverse(List<String> list)
+ {
+ ArrayList<String> result = new ArrayList<String>(list.size());
+ for (ListIterator<String> i = list.listIterator(list.size()); i.hasPrevious();)
+ result.add(i.previous());
+ return result;
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/CollectionsMXBeanSupportMXBean.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/CollectionsMXBeanSupportMXBean.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/CollectionsMXBeanSupportMXBean.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,57 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.support;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.management.ObjectName;
+
+import org.jboss.mx.util.ObjectNameFactory;
+
+/**
+ * CollectionsMXBeanSupportMXBean.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public interface CollectionsMXBeanSupportMXBean extends CollectionsInterface
+{
+ /** The Object name */
+ ObjectName REGISTERED_OBJECT_NAME = ObjectNameFactory.create("test:test=CollectionsMXBeanSupport");
+
+ void setEnum(TestEnum enumeration);
+
+ void setArray(String[] array);
+
+ void setCollection(Collection<String> collection);
+
+ void setList(List<String> list);
+
+ void setMap(Map<String, Integer> map);
+
+ void setSet(Set<String> set);
+
+ List<String> echoReverse(List<String> list);
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/CompositeInterface.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/CompositeInterface.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/CompositeInterface.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,55 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.support;
+
+import javax.management.openmbean.OpenType;
+import javax.management.openmbean.SimpleType;
+
+import org.jboss.mx.mxbean.CompositeTypeMetaDataFactory;
+
+/**
+ * CompositeInterface.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public interface CompositeInterface
+{
+ String SIMPLE = "simple";
+ String COMPOSITE = "composite";
+
+ String[] KEYS =
+ {
+ SIMPLE,
+ COMPOSITE
+ };
+
+ OpenType[] TYPES =
+ {
+ SimpleType.STRING,
+ CompositeTypeMetaDataFactory.getCompositeType(SimpleInterface.class)
+ };
+
+ String getSimple();
+
+ SimpleInterface getComposite();
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/CompositeMXBeanSupport.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/CompositeMXBeanSupport.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/CompositeMXBeanSupport.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,71 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.support;
+
+import org.jboss.mx.mxbean.MXBeanSupport;
+
+/**
+ * SimpleMXBeanSupport.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class CompositeMXBeanSupport extends MXBeanSupport implements CompositeMXBeanSupportMXBean
+{
+ private String simple;
+ private SimpleInterface composite;
+
+ public String getSimple()
+ {
+ return simple;
+ }
+
+ public CompositeMXBeanSupport(String simple, SimpleInterface composite)
+ {
+ this.simple = simple;
+ this.composite = composite;
+ }
+
+ public SimpleInterface getComposite()
+ {
+ return composite;
+ }
+
+ public void setComposite(SimpleInterface composite)
+ {
+ this.composite = composite;
+ }
+
+ public void setSimple(String simple)
+ {
+ this.simple = simple;
+ }
+
+ public SimpleInterface echoReverse(SimpleInterface composite)
+ {
+ SimpleObject result = new SimpleObject();
+ StringBuilder builder = new StringBuilder(composite.getString());
+ builder.reverse();
+ result.setString(builder.toString());
+ return result;
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/CompositeMXBeanSupportMXBean.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/CompositeMXBeanSupportMXBean.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/CompositeMXBeanSupportMXBean.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,44 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.support;
+
+import javax.management.ObjectName;
+
+import org.jboss.mx.util.ObjectNameFactory;
+
+/**
+ * CompositeMXBeanSupportMXBean.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public interface CompositeMXBeanSupportMXBean extends CompositeInterface
+{
+ /** The Object name */
+ ObjectName REGISTERED_OBJECT_NAME = ObjectNameFactory.create("test:test=CompositeMXBeanSupport");
+
+ void setComposite(SimpleInterface composite);
+
+ void setSimple(String simple);
+
+ SimpleInterface echoReverse(SimpleInterface composite);
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/InvalidInterface.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/InvalidInterface.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/InvalidInterface.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,38 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.support;
+
+/**
+ * SimpleInterface.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public interface InvalidInterface
+{
+ Object getInvalid();
+ void notAGetter();
+ void getString();
+ String isString();
+ String getString(Object parameter);
+ Boolean isBoolean();
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/NullSimpleObject.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/NullSimpleObject.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/NullSimpleObject.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,142 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.support;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Date;
+
+import javax.management.ObjectName;
+
+/**
+ * NullSimpleObject.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class NullSimpleObject implements SimpleInterface
+{
+ public BigDecimal getBigDecimal()
+ {
+ return null;
+ }
+
+ public BigInteger getBigInteger()
+ {
+ return null;
+ }
+
+ public Boolean getBoolean()
+ {
+ return null;
+ }
+
+ public Byte getByte()
+ {
+ return null;
+ }
+
+ public Character getCharacter()
+ {
+ return null;
+ }
+
+ public Date getDate()
+ {
+ return null;
+ }
+
+ public Double getDouble()
+ {
+ return null;
+ }
+
+ public Float getFloat()
+ {
+ return null;
+ }
+
+ public Integer getInteger()
+ {
+ return null;
+ }
+
+ public Long getLong()
+ {
+ return null;
+ }
+
+ public ObjectName getObjectName()
+ {
+ return null;
+ }
+
+ public byte getPrimitiveByte()
+ {
+ return primitiveByteValue;
+ }
+
+ public char getPrimitiveChar()
+ {
+ return primitiveCharValue;
+ }
+
+ public double getPrimitiveDouble()
+ {
+ return primitiveDoubleValue;
+ }
+
+ public float getPrimitiveFloat()
+ {
+ return primitiveFloatValue;
+ }
+
+ public int getPrimitiveInt()
+ {
+ return primitiveIntValue;
+ }
+
+ public long getPrimitiveLong()
+ {
+ return primitiveLongValue;
+ }
+
+ public short getPrimitiveShort()
+ {
+ return primitiveShortValue;
+ }
+
+ public Short getShort()
+ {
+ return null;
+ }
+
+ public String getString()
+ {
+ return null;
+ }
+
+ public boolean isPrimitiveBoolean()
+ {
+ return primitiveBooleanValue;
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/SimpleInterface.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/SimpleInterface.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/SimpleInterface.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,337 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * 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.mx.mxbean.support;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Date;
+
+import javax.management.ObjectName;
+
+import org.jboss.mx.util.ObjectNameFactory;
+import org.jboss.test.mx.mxbean.test.AbstractMXBeanTest;
+
+/**
+ * SimpleInterface.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public interface SimpleInterface
+{
+ String BIG_DECIMAL = "bigDecimal";
+
+ BigDecimal bigDecimalValue = new BigDecimal("12e4");
+ BigDecimal bigDecimalChangedValue = new BigDecimal("12e5");
+
+ String BIG_INTEGER = "bigInteger";
+
+ BigInteger bigIntegerValue = new BigInteger("123456");
+ BigInteger bigIntegerChangedValue = new BigInteger("123457");
+
+ String BOOLEAN = "boolean";
+
+ Boolean booleanValue = Boolean.TRUE;
+ Boolean booleanChangedValue = Boolean.FALSE;
+
+ String BOOLEAN_PRIMITIVE = "primitiveBoolean";
+
+ boolean primitiveBooleanValue = booleanValue.booleanValue();
+ boolean primitiveBooleanChangedValue = booleanChangedValue.booleanValue();
+
+ String BYTE = "byte";
+
+ Byte byteValue = new Byte("12");
+ Byte byteChangedValue = new Byte("13");
+
+ String BYTE_PRIMITIVE = "primitiveByte";
+
+ byte primitiveByteValue = byteValue.byteValue();
+ byte primitiveByteChangedValue = byteChangedValue.byteValue();
+
+ String CHARACTER = "character";
+
+ Character characterValue = new Character('a');
+ Character characterChangedValue = new Character('b');
+
+ String CHAR_PRIMITIVE = "primitiveChar";
+
+ char primitiveCharValue = characterValue.charValue();
+ char primitiveCharChangedValue = characterChangedValue.charValue();
+
+ String DATE = "date";
+
+ Date dateValue = AbstractMXBeanTest.createDate(2001, 1, 1);
+ Date dateChangedValue = AbstractMXBeanTest.createDate(2002, 2, 2);
+
+ String DOUBLE = "double";
+
+ Double doubleValue = new Double("3.14e12");
+ Double doubleChangedValue = new Double("3.14e13");
+
+ String DOUBLE_PRIMITIVE = "primitiveDouble";
+
+ double primitiveDoubleValue = doubleValue.doubleValue();
+ double primitiveDoubleChangedValue = doubleChangedValue.doubleValue();
+
+ String FLOAT = "float";
+
+ Float floatValue = new Float("3.14");
+ Float floatChangedValue = new Float("3.15");
+
+ String FLOAT_PRIMITIVE = "primitiveFloat";
+
+ float primitiveFloatValue = floatValue.floatValue();
+ float primitiveFloatChangedValue = floatChangedValue.floatValue();
+
+ String INTEGER = "integer";
+
+ Integer integerValue = new Integer("1234");
+ Integer integerChangedValue = new Integer("1235");
+
+ String INT_PRIMITIVE = "primitiveInt";
+
+ int primitiveIntValue = integerValue.intValue();
+ int primitiveIntChangedValue = integerChangedValue.intValue();
+
+ String LONG = "long";
+
+ Long longValue = new Long("12345");
+ Long longChangedValue = new Long("12346");
+
+ String LONG_PRIMITIVE = "primitiveLong";
+
+ long primitiveLongValue = longValue.longValue();
+ long primitiveLongChangedValue = longChangedValue.longValue();
+
+ String OBJECT_NAME = "objectName";
+
+ ObjectName objectNameValue = ObjectNameFactory.create("domain:key=property");
+ ObjectName objectNameChangedValue = ObjectNameFactory.create("domain:key=property2");
+
+ String SHORT = "short";
+
+ Short shortValue = new Short("123");
+ Short shortChangedValue = new Short("124");
+
+ String SHORT_PRIMITIVE = "primitiveShort";
+
+ short primitiveShortValue = shortValue.shortValue();
+ short primitiveShortChangedValue = shortChangedValue.shortValue();
+
+ String STRING = "string";
+
+ String stringValue = new String("StringValue");
+ String stringChangedValue = new String("ChangedValue");
+
+ String[] KEYS =
+ {
+ BIG_DECIMAL,
+ BIG_INTEGER,
+ BOOLEAN,
+ BOOLEAN_PRIMITIVE,
+ BYTE,
+ BYTE_PRIMITIVE,
+ CHARACTER,
+ CHAR_PRIMITIVE,
+ DATE,
+ DOUBLE,
+ DOUBLE_PRIMITIVE,
+ FLOAT,
+ FLOAT_PRIMITIVE,
+ INTEGER,
+ INT_PRIMITIVE,
+ LONG,
+ LONG_PRIMITIVE,
+ OBJECT_NAME,
+ SHORT,
+ SHORT_PRIMITIVE,
+ STRING
+ };
+
+ Object[] VALUES =
+ {
+ bigDecimalValue,
+ bigIntegerValue,
+ booleanValue,
+ primitiveBooleanValue,
+ byteValue,
+ primitiveByteValue,
+ characterValue,
+ primitiveCharValue,
+ dateValue,
+ doubleValue,
+ primitiveDoubleValue,
+ floatValue,
+ primitiveFloatValue,
+ integerValue,
+ primitiveIntValue,
+ longValue,
+ primitiveLongValue,
+ objectNameValue,
+ shortValue,
+ primitiveShortValue,
+ stringValue
+ };
+
+ Object[] CHANGED_VALUES =
+ {
+ bigDecimalChangedValue,
+ bigIntegerChangedValue,
+ booleanChangedValue,
+ primitiveBooleanChangedValue,
+ byteChangedValue,
+ primitiveByteChangedValue,
+ characterChangedValue,
+ primitiveCharChangedValue,
+ dateChangedValue,
+ doubleChangedValue,
+ primitiveDoubleChangedValue,
+ floatChangedValue,
+ primitiveFloatChangedValue,
+ integerChangedValue,
+ primitiveIntChangedValue,
+ longChangedValue,
+ primitiveLongChangedValue,
+ objectNameChangedValue,
+ shortChangedValue,
+ primitiveShortChangedValue,
+ stringChangedValue
+ };
+
+ Class[] TYPES =
+ {
+ BigDecimal.class,
+ BigInteger.class,
+ Boolean.class,
+ Boolean.TYPE,
+ Byte.class,
+ Byte.TYPE,
+ Character.class,
+ Character.TYPE,
+ Date.class,
+ Double.class,
+ Double.TYPE,
+ Float.class,
+ Float.TYPE,
+ Integer.class,
+ Integer.TYPE,
+ Long.class,
+ Long.TYPE,
+ ObjectName.class,
+ Short.class,
+ Short.TYPE,
+ String.class
+ };
+
+ Object[] NULL_VALUES =
+ {
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null
+ };
+
+ Object[] LEGAL_NULL_VALUES =
+ {
+ null,
+ null,
+ null,
+ primitiveBooleanValue,
+ null,
+ primitiveByteValue,
+ null,
+ primitiveCharValue,
+ null,
+ null,
+ primitiveDoubleValue,
+ null,
+ primitiveFloatValue,
+ null,
+ primitiveIntValue,
+ null,
+ primitiveLongValue,
+ null,
+ null,
+ primitiveShortValue,
+ null,
+ };
+
+ BigDecimal getBigDecimal();
+
+ BigInteger getBigInteger();
+
+ boolean isPrimitiveBoolean();
+
+ Boolean getBoolean();
+
+ byte getPrimitiveByte();
+
+ Byte getByte();
+
+ char getPrimitiveChar();
+
+ Character getCharacter();
+
+ Date getDate();
+
+ double getPrimitiveDouble();
+
+ Double getDouble();
+
+ float getPrimitiveFloat();
+
+ Float getFloat();
+
+ int getPrimitiveInt();
+
+ Integer getInteger();
+
+ long getPrimitiveLong();
+
+ Long getLong();
+
+ ObjectName getObjectName();
+
+ short getPrimitiveShort();
+
+ Short getShort();
+
+ String getString();
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/SimpleMXBeanSupport.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/SimpleMXBeanSupport.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/SimpleMXBeanSupport.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,278 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.support;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Date;
+
+import javax.management.ObjectName;
+
+import org.jboss.mx.mxbean.MXBeanSupport;
+
+/**
+ * SimpleMXBeanSupport.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class SimpleMXBeanSupport extends MXBeanSupport implements SimpleMXBeanSupportMXBean
+{
+ private BigDecimal bigDecimal = bigDecimalValue;
+ private BigInteger bigInteger = bigIntegerValue;
+ private Boolean booleanV = booleanValue;
+ private Byte byteV = byteValue;
+ private Character characterV = characterValue;
+ private Date date = dateValue;
+ private Double doubleV = doubleValue;
+ private Float floatV = floatValue;
+ private Integer integer = integerValue;
+ private Long longV = longValue;
+ private ObjectName objectName = objectNameValue;
+ private boolean primitiveBoolean = primitiveBooleanValue;
+ private byte primitiveByte = primitiveByteValue;
+ private char primitiveChar = primitiveCharValue;
+ private double primitiveDouble = primitiveDoubleValue;
+ private float primitiveFloat = primitiveFloatValue;
+ private int primitiveInt = primitiveIntValue;
+ private long primitiveLong = primitiveLongValue;
+ private Short shortV = shortValue;
+ private short primitiveShort = primitiveShortValue;
+ private String string = stringValue;
+
+ public BigDecimal getBigDecimal()
+ {
+ return bigDecimal;
+ }
+
+ public BigInteger getBigInteger()
+ {
+ return bigInteger;
+ }
+
+ public Boolean getBoolean()
+ {
+ return booleanV;
+ }
+
+ public Byte getByte()
+ {
+ return byteV;
+ }
+
+ public Character getCharacter()
+ {
+ return characterV;
+ }
+
+ public Date getDate()
+ {
+ return date;
+ }
+
+ public Double getDouble()
+ {
+ return doubleV;
+ }
+
+ public Float getFloat()
+ {
+ return floatV;
+ }
+
+ public Integer getInteger()
+ {
+ return integer;
+ }
+
+ public Long getLong()
+ {
+ return longV;
+ }
+
+ public ObjectName getObjectName()
+ {
+ return objectName;
+ }
+
+ public byte getPrimitiveByte()
+ {
+ return primitiveByte;
+ }
+
+ public char getPrimitiveChar()
+ {
+ return primitiveChar;
+ }
+
+ public double getPrimitiveDouble()
+ {
+ return primitiveDouble;
+ }
+
+ public float getPrimitiveFloat()
+ {
+ return primitiveFloat;
+ }
+
+ public int getPrimitiveInt()
+ {
+ return primitiveInt;
+ }
+
+ public long getPrimitiveLong()
+ {
+ return primitiveLong;
+ }
+
+ public short getPrimitiveShort()
+ {
+ return primitiveShort;
+ }
+
+ public Short getShort()
+ {
+ return shortV;
+ }
+
+ public String getString()
+ {
+ return string;
+ }
+
+ public boolean isPrimitiveBoolean()
+ {
+ return primitiveBoolean;
+ }
+
+ public void setBoolean(Boolean booleanV)
+ {
+ this.booleanV = booleanV;
+ }
+
+ public void setByte(Byte byteV)
+ {
+ this.byteV = byteV;
+ }
+
+ public void setCharacter(Character characterV)
+ {
+ this.characterV = characterV;
+ }
+
+ public void setDouble(Double doubleV)
+ {
+ this.doubleV = doubleV;
+ }
+
+ public void setFloat(Float floatV)
+ {
+ this.floatV = floatV;
+ }
+
+ public void setLong(Long longV)
+ {
+ this.longV = longV;
+ }
+
+ public void setShort(Short shortV)
+ {
+ this.shortV = shortV;
+ }
+
+ public void setBigDecimal(BigDecimal bigDecimal)
+ {
+ this.bigDecimal = bigDecimal;
+ }
+
+ public void setBigInteger(BigInteger bigInteger)
+ {
+ this.bigInteger = bigInteger;
+ }
+
+ public void setDate(Date date)
+ {
+ this.date = date;
+ }
+
+ public void setInteger(Integer integer)
+ {
+ this.integer = integer;
+ }
+
+ public void setObjectName(ObjectName objectName)
+ {
+ this.objectName = objectName;
+ }
+
+ public void setPrimitiveBoolean(boolean primitiveBoolean)
+ {
+ this.primitiveBoolean = primitiveBoolean;
+ }
+
+ public void setPrimitiveByte(byte primitiveByte)
+ {
+ this.primitiveByte = primitiveByte;
+ }
+
+ public void setPrimitiveChar(char primitiveChar)
+ {
+ this.primitiveChar = primitiveChar;
+ }
+
+ public void setPrimitiveDouble(double primitiveDouble)
+ {
+ this.primitiveDouble = primitiveDouble;
+ }
+
+ public void setPrimitiveFloat(float primitiveFloat)
+ {
+ this.primitiveFloat = primitiveFloat;
+ }
+
+ public void setPrimitiveInt(int primitiveInt)
+ {
+ this.primitiveInt = primitiveInt;
+ }
+
+ public void setPrimitiveLong(long primitiveLong)
+ {
+ this.primitiveLong = primitiveLong;
+ }
+
+ public void setPrimitiveShort(short primitiveShort)
+ {
+ this.primitiveShort = primitiveShort;
+ }
+
+ public void setString(String string)
+ {
+ this.string = string;
+ }
+
+ public String echoReverse(String string)
+ {
+ StringBuilder builder = new StringBuilder(string);
+ builder.reverse();
+ return builder.toString();
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/SimpleMXBeanSupportMXBean.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/SimpleMXBeanSupportMXBean.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/SimpleMXBeanSupportMXBean.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,86 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.support;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Date;
+
+import javax.management.ObjectName;
+
+import org.jboss.mx.util.ObjectNameFactory;
+
+/**
+ * SimpleMXBeanSupportMXBean.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public interface SimpleMXBeanSupportMXBean extends SimpleInterface
+{
+ /** The Object name */
+ ObjectName REGISTERED_OBJECT_NAME = ObjectNameFactory.create("test:test=SimpleMXBeanSupport");
+
+ void setBoolean(Boolean booleanV);
+
+ void setByte(Byte byteV);
+
+ void setCharacter(Character characterV);
+
+ void setDouble(Double doubleV);
+
+ void setFloat(Float floatV);
+
+ void setLong(Long longV);
+
+ void setShort(Short shortV);
+
+ void setBigDecimal(BigDecimal bigDecimal);
+
+ void setBigInteger(BigInteger bigInteger);
+
+ void setDate(Date date);
+
+ void setInteger(Integer integer);
+
+ void setObjectName(ObjectName objectName);
+
+ void setPrimitiveBoolean(boolean primitiveBoolean);
+
+ void setPrimitiveByte(byte primitiveByte);
+
+ void setPrimitiveChar(char primitiveChar);
+
+ void setPrimitiveDouble(double primitiveDouble);
+
+ void setPrimitiveFloat(float primitiveFloat);
+
+ void setPrimitiveInt(int primitiveInt);
+
+ void setPrimitiveLong(long primitiveLong);
+
+ void setPrimitiveShort(short primitiveShort);
+
+ void setString(String string);
+
+ String echoReverse(String string);
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/SimpleObject.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/SimpleObject.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/SimpleObject.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,269 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.support;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Date;
+
+import javax.management.ObjectName;
+
+/**
+ * SimpleObject.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class SimpleObject implements SimpleInterface
+{
+ private BigDecimal bigDecimal = bigDecimalValue;
+ private BigInteger bigInteger = bigIntegerValue;
+ private Boolean booleanV = booleanValue;
+ private Byte byteV = byteValue;
+ private Character characterV = characterValue;
+ private Date date = dateValue;
+ private Double doubleV = doubleValue;
+ private Float floatV = floatValue;
+ private Integer integer = integerValue;
+ private Long longV = longValue;
+ private ObjectName objectName = objectNameValue;
+ private boolean primitiveBoolean = primitiveBooleanValue;
+ private byte primitiveByte = primitiveByteValue;
+ private char primitiveChar = primitiveCharValue;
+ private double primitiveDouble = primitiveDoubleValue;
+ private float primitiveFloat = primitiveFloatValue;
+ private int primitiveInt = primitiveIntValue;
+ private long primitiveLong = primitiveLongValue;
+ private Short shortV = shortValue;
+ private short primitiveShort = primitiveShortValue;
+ private String string = stringValue;
+
+ public BigDecimal getBigDecimal()
+ {
+ return bigDecimal;
+ }
+
+ public BigInteger getBigInteger()
+ {
+ return bigInteger;
+ }
+
+ public Boolean getBoolean()
+ {
+ return booleanV;
+ }
+
+ public Byte getByte()
+ {
+ return byteV;
+ }
+
+ public Character getCharacter()
+ {
+ return characterV;
+ }
+
+ public Date getDate()
+ {
+ return date;
+ }
+
+ public Double getDouble()
+ {
+ return doubleV;
+ }
+
+ public Float getFloat()
+ {
+ return floatV;
+ }
+
+ public Integer getInteger()
+ {
+ return integer;
+ }
+
+ public Long getLong()
+ {
+ return longV;
+ }
+
+ public ObjectName getObjectName()
+ {
+ return objectName;
+ }
+
+ public byte getPrimitiveByte()
+ {
+ return primitiveByte;
+ }
+
+ public char getPrimitiveChar()
+ {
+ return primitiveChar;
+ }
+
+ public double getPrimitiveDouble()
+ {
+ return primitiveDouble;
+ }
+
+ public float getPrimitiveFloat()
+ {
+ return primitiveFloat;
+ }
+
+ public int getPrimitiveInt()
+ {
+ return primitiveInt;
+ }
+
+ public long getPrimitiveLong()
+ {
+ return primitiveLong;
+ }
+
+ public short getPrimitiveShort()
+ {
+ return primitiveShort;
+ }
+
+ public Short getShort()
+ {
+ return shortV;
+ }
+
+ public String getString()
+ {
+ return string;
+ }
+
+ public boolean isPrimitiveBoolean()
+ {
+ return primitiveBoolean;
+ }
+
+ public void setBoolean(Boolean booleanV)
+ {
+ this.booleanV = booleanV;
+ }
+
+ public void setByte(Byte byteV)
+ {
+ this.byteV = byteV;
+ }
+
+ public void setCharacter(Character characterV)
+ {
+ this.characterV = characterV;
+ }
+
+ public void setDouble(Double doubleV)
+ {
+ this.doubleV = doubleV;
+ }
+
+ public void setFloat(Float floatV)
+ {
+ this.floatV = floatV;
+ }
+
+ public void setLong(Long longV)
+ {
+ this.longV = longV;
+ }
+
+ public void setShort(Short shortV)
+ {
+ this.shortV = shortV;
+ }
+
+ public void setBigDecimal(BigDecimal bigDecimal)
+ {
+ this.bigDecimal = bigDecimal;
+ }
+
+ public void setBigInteger(BigInteger bigInteger)
+ {
+ this.bigInteger = bigInteger;
+ }
+
+ public void setDate(Date date)
+ {
+ this.date = date;
+ }
+
+ public void setInteger(Integer integer)
+ {
+ this.integer = integer;
+ }
+
+ public void setObjectName(ObjectName objectName)
+ {
+ this.objectName = objectName;
+ }
+
+ public void setPrimitiveBoolean(boolean primitiveBoolean)
+ {
+ this.primitiveBoolean = primitiveBoolean;
+ }
+
+ public void setPrimitiveByte(byte primitiveByte)
+ {
+ this.primitiveByte = primitiveByte;
+ }
+
+ public void setPrimitiveChar(char primitiveChar)
+ {
+ this.primitiveChar = primitiveChar;
+ }
+
+ public void setPrimitiveDouble(double primitiveDouble)
+ {
+ this.primitiveDouble = primitiveDouble;
+ }
+
+ public void setPrimitiveFloat(float primitiveFloat)
+ {
+ this.primitiveFloat = primitiveFloat;
+ }
+
+ public void setPrimitiveInt(int primitiveInt)
+ {
+ this.primitiveInt = primitiveInt;
+ }
+
+ public void setPrimitiveLong(long primitiveLong)
+ {
+ this.primitiveLong = primitiveLong;
+ }
+
+ public void setPrimitiveShort(short primitiveShort)
+ {
+ this.primitiveShort = primitiveShort;
+ }
+
+ public void setString(String string)
+ {
+ this.string = string;
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/TestEnum.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/TestEnum.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/TestEnum.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,33 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.support;
+
+/**
+ * TestEnum.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public enum TestEnum
+{
+ FIRST, SECOND
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/TestParameterizedType.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/TestParameterizedType.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/support/TestParameterizedType.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,66 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.support;
+
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+
+import org.jboss.util.NotImplementedException;
+
+/**
+ * TestParameterizedType.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestParameterizedType implements ParameterizedType
+{
+ private Type raw;
+ private Type[] args;
+
+ /**
+ * Create a new TestParameterizedType.
+ *
+ * @param raw the raw type
+ * @param args the args the type args
+ */
+ public TestParameterizedType(Type raw, Type[] args)
+ {
+ this.raw = raw;
+ this.args = args;
+ }
+
+ public Type[] getActualTypeArguments()
+ {
+ return args;
+ }
+
+ public Type getRawType()
+ {
+ return raw;
+ }
+
+ public Type getOwnerType()
+ {
+ throw new NotImplementedException();
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/AbstractMXBeanTest.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/AbstractMXBeanTest.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/AbstractMXBeanTest.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,309 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.test;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Set;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.CompositeDataSupport;
+import javax.management.openmbean.CompositeType;
+import javax.management.openmbean.OpenType;
+import javax.management.openmbean.SimpleType;
+
+import junit.framework.AssertionFailedError;
+
+import org.jboss.logging.Logger;
+import org.jboss.mx.mxbean.CompositeDataInvocationHandler;
+import org.jboss.mx.mxbean.MXBeanUtils;
+import org.jboss.test.BaseTestCase;
+import org.jboss.test.mx.mxbean.support.InvalidInterface;
+import org.jboss.test.mx.mxbean.support.SimpleInterface;
+import org.jboss.util.UnexpectedThrowable;
+
+/**
+ * AbstractMXBeanTest.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractMXBeanTest extends BaseTestCase
+{
+ private static Logger staticLog = Logger.getLogger(AbstractMXBeanTest.class);
+
+ public AbstractMXBeanTest(String name)
+ {
+ super(name);
+ }
+
+ // @fixme move to AbstractTestCase
+ public static void checkThrowableDeep(Class<? extends Throwable> wrapperExpected, Class<? extends Throwable> deepExpected, Throwable throwable) throws Exception
+ {
+ assertNotNull(deepExpected);
+ assertNotNull(throwable);
+
+ Throwable original = throwable;
+
+ if (wrapperExpected != null)
+ {
+ if (wrapperExpected.isInstance(original) == false)
+ {
+ if (original instanceof Exception)
+ throw (Exception) original;
+ else if (original instanceof Error)
+ throw (Error) original;
+ else
+ throw new UnexpectedThrowable("UnexpectedThrowable", original);
+ }
+ staticLog.debug("Got expected " + wrapperExpected.getName() + "(" + original + ")");
+ }
+
+ while (throwable.getCause() != null)
+ throwable = throwable.getCause();
+
+ if (deepExpected.isInstance(throwable) == false)
+ {
+ if (original instanceof Exception)
+ throw (Exception) original;
+ else if (original instanceof Error)
+ throw (Error) original;
+ else
+ throw new UnexpectedThrowable("UnexpectedThrowable", original);
+ }
+ else
+ {
+ staticLog.debug("Got expected " + deepExpected.getName() + "(" + throwable + ")");
+ }
+ }
+
+ // @fixme move to AbstractTestCase
+ public static void checkThrowableDeep(Class<? extends Throwable> expected, Throwable throwable) throws Exception
+ {
+ checkThrowableDeep(null, expected, throwable);
+ }
+
+ // @fixme move to AbstractTestCase
+ public static <T> T assertInstanceOf(Class<T> expected, Object object) throws Exception
+ {
+ if (object == null)
+ return null;
+ assertTrue(object.getClass(). getName() + " is not an instance of " + expected.getName(), expected.isInstance(object));
+ return expected.cast(object);
+ }
+
+ public static void checkArrayEquals(Object expected, Object actual)
+ {
+ Object[] a1 = (Object[]) expected;
+ Object[] a2 = (Object[]) actual;
+ if (Arrays.deepEquals(a1, a2) == false)
+ throw new AssertionFailedError("Expected: " + a1 + "=" + Arrays.deepToString(a1) + " got " + a2 + "=" + Arrays.deepToString(a2));
+ }
+
+ @SuppressWarnings("unchecked")
+ public static void checkCompositeDataHandlerEquals(Object expected, Object actual)
+ {
+ if (expected == null)
+ {
+ assertEquals(expected, actual);
+ return;
+ }
+
+ CompositeDataInvocationHandler handler = (CompositeDataInvocationHandler) Proxy.getInvocationHandler(actual);
+ CompositeData data = handler.getCompositeData();
+ CompositeType type = data.getCompositeType();
+ Set<String> names = type.keySet();
+ Class clazz = expected.getClass();
+ for (String name : names)
+ {
+ OpenType itemType = type.getType(name);
+ try
+ {
+ Method method = MXBeanUtils.getCompositeDataMethod(clazz, name, itemType == SimpleType.BOOLEAN);
+ Object expectedValue = method.invoke(expected, null);
+ Object actualValue = handler.invoke(actual, method, null);
+ assertEquals(expectedValue, actualValue);
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Error e)
+ {
+ throw e;
+ }
+ catch (Throwable t)
+ {
+ throw new RuntimeException(t);
+ }
+ }
+ }
+
+ public static void checkValueEquals(Object expected, Object actual)
+ {
+ if (actual == null)
+ assertEquals(expected, actual);
+ else if (actual instanceof Proxy)
+ checkCompositeDataHandlerEquals(expected, actual);
+ else if (actual.getClass().isArray())
+ checkArrayEquals(expected, actual);
+ else
+ assertEquals(expected, actual);
+ }
+
+ protected CompositeData createCompositeData(String name, String[] keys, Object[] values) throws Exception
+ {
+ assertNotNullArray("values", values);
+
+ Class[] types = new Class[values.length];
+ for (int i = 0; i < values.length; ++i)
+ types[i] = values[i].getClass();
+
+ return createCompositeData(name, keys, types, values);
+ }
+
+ protected CompositeData createCompositeData(String name, String[] keys, Class[] types, Object[] values) throws Exception
+ {
+ CompositeType compositeType = createCompositeType(name, keys, types);
+ return new CompositeDataSupport(compositeType, keys, values);
+ }
+
+ protected CompositeData createCompositeData(String name, String[] keys, OpenType[] openTypes, Object[] values) throws Exception
+ {
+ CompositeType compositeType = createCompositeType(name, keys, openTypes);
+ return new CompositeDataSupport(compositeType, keys, values);
+ }
+
+ protected CompositeType createCompositeType(String name, String[] keys, Class[] types) throws Exception
+ {
+ assertNotNull(name);
+ assertNotNullArray("keys", keys);
+ assertNotNullArray("types", types);
+ assertEquals(keys.length, types.length);
+
+ OpenType[] openTypes = new OpenType[types.length];
+ for (int i = 0; i < types.length; ++i)
+ openTypes[i] = MXBeanUtils.getOpenType(types[i]);
+
+ return new CompositeType(name, name, keys, keys, openTypes);
+ }
+
+ protected CompositeType createCompositeType(String name, String[] keys, OpenType[] openTypes) throws Exception
+ {
+ assertNotNull(name);
+ assertNotNullArray("keys", keys);
+ assertNotNullArray("types", openTypes);
+ assertEquals(keys.length, openTypes.length);
+
+ return new CompositeType(name, name, keys, keys, openTypes);
+ }
+
+ protected <T> T createCompositeDataProxy(Class<T> intf, String[] keys, Object[] values) throws Exception
+ {
+ assertNotNull(intf);
+ return createCompositeDataProxy(intf, intf.getName(), keys, values);
+ }
+
+ protected <T> T createCompositeDataProxy(Class<T> intf, String name, String[] keys, Object[] values) throws Exception
+ {
+ CompositeData compositeData = createCompositeData(name, keys, values);
+ return createCompositeDataProxy(intf, compositeData);
+ }
+
+ protected <T> T createCompositeDataProxy(Class<T> intf, String[] keys, Class[] types, Object[] values) throws Exception
+ {
+ assertNotNull(intf);
+ return createCompositeDataProxy(intf, intf.getName(), keys, types, values);
+ }
+
+ protected <T> T createCompositeDataProxy(Class<T> intf, String name, String[] keys, Class[] types, Object[] values) throws Exception
+ {
+ CompositeData compositeData = createCompositeData(name, keys, types, values);
+ return createCompositeDataProxy(intf, compositeData);
+ }
+
+ protected <T> T createCompositeDataProxy(Class<T> intf, String name, String[] keys, OpenType[] openTypes, Object[] values) throws Exception
+ {
+ CompositeData compositeData = createCompositeData(name, keys, openTypes, values);
+ return createCompositeDataProxy(intf, compositeData);
+ }
+
+ protected <T> T createCompositeDataProxy(Class<T> intf, CompositeData compositeData)
+ {
+ return MXBeanUtils.createCompositeDataProxy(intf, compositeData);
+ }
+
+ protected CompositeData createTestCompositeData() throws Exception
+ {
+ return createCompositeData("Test", SimpleInterface.KEYS, SimpleInterface.VALUES);
+ }
+
+ protected SimpleInterface createTestCompositeDataProxy() throws Exception
+ {
+ return createCompositeDataProxy(SimpleInterface.class, SimpleInterface.KEYS, SimpleInterface.VALUES);
+ }
+
+ protected SimpleInterface createNullCompositeDataProxy() throws Exception
+ {
+ return createCompositeDataProxy(SimpleInterface.class, SimpleInterface.KEYS, SimpleInterface.TYPES, SimpleInterface.NULL_VALUES);
+ }
+
+ protected InvalidInterface createInvalidCompositeDataProxy() throws Exception
+ {
+ return createCompositeDataProxy(InvalidInterface.class, SimpleInterface.KEYS, SimpleInterface.VALUES);
+ }
+
+ protected SimpleInterface createTestCompositeDataProxy(String name) throws Exception
+ {
+ return createCompositeDataProxy(SimpleInterface.class, name, SimpleInterface.KEYS, SimpleInterface.VALUES);
+ }
+
+ protected MBeanServer createMBeanServer()
+ {
+ return MBeanServerFactory.newMBeanServer();
+ }
+
+ protected void assertNotNullArray(String context, Object[] array) throws Exception
+ {
+ assertNotNull(context + " is null ", array);
+ for (int i = 0; i < array.length; ++i)
+ assertNotNull(context + "[" + i + "] is null", array[i]);
+ }
+
+ public static Date createDate(int year, int month, int day)
+ {
+ Calendar calender = Calendar.getInstance();
+ calender.clear();
+ calender.set(year, month-1, day, 0, 0, 0);
+ return calender.getTime();
+ }
+
+ public static String getUpperName(String name)
+ {
+ return Character.toUpperCase(name.charAt(0)) + name.substring(1);
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataArrayUnitTestCase.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataArrayUnitTestCase.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataArrayUnitTestCase.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,103 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.test;
+
+import org.jboss.test.mx.mxbean.support.TestEnum;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * CompositeDataArrayUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class CompositeDataArrayUnitTestCase extends CompositeDataTest
+{
+ public static Test suite()
+ {
+ return new TestSuite(CompositeDataArrayUnitTestCase.class);
+ }
+
+ public CompositeDataArrayUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testArrayString() throws Exception
+ {
+ String[] array = { "one", "two", "three" };
+ constructReconstructTest(array);
+ }
+
+ public void testMultiArrayString() throws Exception
+ {
+ String[][] array = { { "one", "two", "three" }, { "four", "five", "six" } };
+ constructReconstructTest(array);
+ }
+
+ public void testArrayEnum() throws Exception
+ {
+ TestEnum[] array = { TestEnum.FIRST, TestEnum.SECOND };
+ String[] openData = { TestEnum.FIRST.name(), TestEnum.SECOND.name() };
+ constructReconstructTest(array, openData);
+ }
+
+ public void testMultiArrayEnum() throws Exception
+ {
+ TestEnum[][] array = { { TestEnum.FIRST, TestEnum.SECOND }, { TestEnum.SECOND } };
+ String[][] openData = { { TestEnum.FIRST.name(), TestEnum.SECOND.name() }, { TestEnum.SECOND.name() } };
+ constructReconstructTest(array, openData);
+ }
+
+ public void testArrayNull() throws Exception
+ {
+ constructReconstructTest(null, new String[0].getClass());
+ }
+
+ public void testArrayElementNull() throws Exception
+ {
+ TestEnum[] array = { TestEnum.FIRST, null };
+ String[] openData = { TestEnum.FIRST.name(), null };
+ constructReconstructTest(array, openData);
+ }
+
+ public void testMultiArrayElementNull() throws Exception
+ {
+ TestEnum[][] array = { { TestEnum.FIRST, null }, { TestEnum.SECOND } };
+ String[][] openData = { { TestEnum.FIRST.name(), null }, { TestEnum.SECOND.name() } };
+ constructReconstructTest(array, openData);
+ }
+
+ public void testMultiArrayNull() throws Exception
+ {
+ TestEnum[][] array = { { TestEnum.FIRST, TestEnum.SECOND }, null, { TestEnum.SECOND } };
+ String[][] openData = { { TestEnum.FIRST.name(), TestEnum.SECOND.name() }, null, { TestEnum.SECOND.name() } };
+ constructReconstructTest(array, openData);
+ }
+
+ public void checkEquals(Object expected, Object actual)
+ {
+ checkArrayEquals(expected, actual);
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataBigDecimalUnitTestCase.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataBigDecimalUnitTestCase.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataBigDecimalUnitTestCase.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,56 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.test;
+
+import java.math.BigDecimal;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * CompositeDataBigDecimalUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class CompositeDataBigDecimalUnitTestCase extends CompositeDataTest
+{
+ public static Test suite()
+ {
+ return new TestSuite(CompositeDataBigDecimalUnitTestCase.class);
+ }
+
+ public CompositeDataBigDecimalUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testBigDecimal() throws Exception
+ {
+ constructReconstructTest(new BigDecimal("12e4"));
+ }
+
+ public void testBigDecimalNull() throws Exception
+ {
+ constructReconstructTest(null, BigDecimal.class);
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataBigIntegerUnitTestCase.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataBigIntegerUnitTestCase.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataBigIntegerUnitTestCase.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,56 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.test;
+
+import java.math.BigInteger;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * CompositeDataBigIntegerUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class CompositeDataBigIntegerUnitTestCase extends CompositeDataTest
+{
+ public static Test suite()
+ {
+ return new TestSuite(CompositeDataBigIntegerUnitTestCase.class);
+ }
+
+ public CompositeDataBigIntegerUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testBigInteger() throws Exception
+ {
+ constructReconstructTest(new BigInteger("123456"));
+ }
+
+ public void testBigIntegerNull() throws Exception
+ {
+ constructReconstructTest(null, BigInteger.class);
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataBooleanUnitTestCase.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataBooleanUnitTestCase.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataBooleanUnitTestCase.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,74 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * CompositeDataBooleanUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class CompositeDataBooleanUnitTestCase extends CompositeDataTest
+{
+ public static Test suite()
+ {
+ return new TestSuite(CompositeDataBooleanUnitTestCase.class);
+ }
+
+ public CompositeDataBooleanUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testBooleanTrue() throws Exception
+ {
+ constructReconstructTest(new Boolean(true));
+ }
+
+ public void testBooleanFalse() throws Exception
+ {
+ constructReconstructTest(new Boolean(false));
+ }
+
+ public void testBooleanNull() throws Exception
+ {
+ constructReconstructTest(null, Boolean.class);
+ }
+
+ public void testBooleanTruePrimitive() throws Exception
+ {
+ constructReconstructTest(new Boolean(true), Boolean.TYPE);
+ }
+
+ public void testBooleanFalsePrimitive() throws Exception
+ {
+ constructReconstructTest(new Boolean(false), Boolean.TYPE);
+ }
+
+ public void testBooleanNullPrimitive() throws Exception
+ {
+ assertNullFailure(Boolean.TYPE);
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataByteUnitTestCase.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataByteUnitTestCase.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataByteUnitTestCase.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,64 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * CompositeDataByteUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class CompositeDataByteUnitTestCase extends CompositeDataTest
+{
+ public static Test suite()
+ {
+ return new TestSuite(CompositeDataByteUnitTestCase.class);
+ }
+
+ public CompositeDataByteUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testByte() throws Exception
+ {
+ constructReconstructTest(new Byte(Byte.MAX_VALUE));
+ }
+
+ public void testByteNull() throws Exception
+ {
+ constructReconstructTest(null, Byte.class);
+ }
+
+ public void testBytePrimitive() throws Exception
+ {
+ constructReconstructTest(Byte.MAX_VALUE, Byte.TYPE);
+ }
+
+ public void testByteNullPrimitive() throws Exception
+ {
+ assertNullFailure(Byte.TYPE);
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataCharacterUnitTestCase.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataCharacterUnitTestCase.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataCharacterUnitTestCase.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,64 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * CompositeDataCharacterUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class CompositeDataCharacterUnitTestCase extends CompositeDataTest
+{
+ public static Test suite()
+ {
+ return new TestSuite(CompositeDataCharacterUnitTestCase.class);
+ }
+
+ public CompositeDataCharacterUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testCharacter() throws Exception
+ {
+ constructReconstructTest(new Character(Character.MAX_VALUE));
+ }
+
+ public void testCharacterNull() throws Exception
+ {
+ constructReconstructTest(null, Character.class);
+ }
+
+ public void testCharacterPrimitive() throws Exception
+ {
+ constructReconstructTest(Character.MAX_VALUE, Character.TYPE);
+ }
+
+ public void testCharacterNullPrimitive() throws Exception
+ {
+ assertNullFailure(Character.TYPE);
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataCollectionUnitTestCase.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataCollectionUnitTestCase.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataCollectionUnitTestCase.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,137 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.test;
+
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.jboss.test.mx.mxbean.support.TestParameterizedType;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * CompositeDataCollectionUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class CompositeDataCollectionUnitTestCase extends CompositeDataTest
+{
+ private static final TestParameterizedType COLLECTION_OF_STRINGS = new TestParameterizedType(Collection.class, new Type[] { String.class });
+ private static final TestParameterizedType LIST_OF_STRINGS = new TestParameterizedType(List.class, new Type[] { String.class });
+ private static final TestParameterizedType SET_OF_STRINGS = new TestParameterizedType(Set.class, new Type[] { String.class });
+
+ public static Test suite()
+ {
+ return new TestSuite(CompositeDataCollectionUnitTestCase.class);
+ }
+
+ public CompositeDataCollectionUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testCollection() throws Exception
+ {
+ Collection<String> c = new ArrayList<String>();
+ c.add("one");
+ c.add("two");
+ c.add("three");
+ String[] openData = { "one", "two", "three" };
+ constructReconstructTest(c, COLLECTION_OF_STRINGS, openData);
+ }
+
+ public void testCollectionNull() throws Exception
+ {
+ constructReconstructTest(null, COLLECTION_OF_STRINGS);
+ }
+
+ public void testCollectionContainsNull() throws Exception
+ {
+ Collection<String> c = new ArrayList<String>();
+ c.add("one");
+ c.add(null);
+ c.add("three");
+ String[] openData = { "one", null, "three" };
+ constructReconstructTest(c, COLLECTION_OF_STRINGS, openData);
+ }
+
+ public void testList() throws Exception
+ {
+ ArrayList<String> c = new ArrayList<String>();
+ c.add("one");
+ c.add("two");
+ c.add("three");
+ String[] openData = { "one", "two", "three" };
+ constructReconstructTest(c, LIST_OF_STRINGS, openData);
+ }
+
+ public void testListNull() throws Exception
+ {
+ constructReconstructTest(null, LIST_OF_STRINGS);
+ }
+
+ public void testListContainsNull() throws Exception
+ {
+ ArrayList<String> c = new ArrayList<String>();
+ c.add("one");
+ c.add(null);
+ c.add("three");
+ String[] openData = { "one", null, "three" };
+ constructReconstructTest(c, LIST_OF_STRINGS, openData);
+ }
+
+ public void testSet() throws Exception
+ {
+ LinkedHashSet<String> c = new LinkedHashSet<String>();
+ c.add("one");
+ c.add("two");
+ c.add("three");
+ String[] openData = { "one", "two", "three" };
+ constructReconstructTest(c, SET_OF_STRINGS, openData);
+ }
+
+ public void testSetNull() throws Exception
+ {
+ constructReconstructTest(null, SET_OF_STRINGS);
+ }
+
+ public void testSetContainsNull() throws Exception
+ {
+ LinkedHashSet<String> c = new LinkedHashSet<String>();
+ c.add("one");
+ c.add(null);
+ c.add("three");
+ String[] openData = { "one", null, "three" };
+ constructReconstructTest(c, SET_OF_STRINGS, openData);
+ }
+
+ protected void checkOpenDataEquals(Object expected, Object actual)
+ {
+ checkArrayEquals(expected, actual);
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataCompositeUnitTestCase.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataCompositeUnitTestCase.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataCompositeUnitTestCase.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,74 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.test;
+
+import javax.management.openmbean.CompositeData;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.test.mx.mxbean.support.NullSimpleObject;
+import org.jboss.test.mx.mxbean.support.SimpleInterface;
+import org.jboss.test.mx.mxbean.support.SimpleObject;
+
+/**
+ * CompositeDataCompositeUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class CompositeDataCompositeUnitTestCase extends CompositeDataTest
+{
+ public static Test suite()
+ {
+ return new TestSuite(CompositeDataCompositeUnitTestCase.class);
+ }
+
+ public CompositeDataCompositeUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testComposite() throws Exception
+ {
+ SimpleObject simple = new SimpleObject();
+ CompositeData openData = createCompositeData(simple.getClass().getName(), SimpleInterface.KEYS, SimpleInterface.VALUES);
+ constructReconstructTest(simple, openData);
+ }
+
+ public void testCompositeNull() throws Exception
+ {
+ constructReconstructTest(null, SimpleObject.class);
+ }
+
+ public void testCompositeContainsNull() throws Exception
+ {
+ NullSimpleObject simple = new NullSimpleObject();
+ CompositeData openData = createCompositeData(simple.getClass().getName(), SimpleInterface.KEYS, SimpleInterface.TYPES, SimpleInterface.LEGAL_NULL_VALUES);
+ constructReconstructTest(simple, openData);
+ }
+
+ protected void checkFinalEquals(Object expected, Object actual)
+ {
+ checkCompositeDataHandlerEquals(expected, actual);
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataDateUnitTestCase.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataDateUnitTestCase.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataDateUnitTestCase.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,56 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.test;
+
+import java.util.Date;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * CompositeDataDateUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class CompositeDataDateUnitTestCase extends CompositeDataTest
+{
+ public static Test suite()
+ {
+ return new TestSuite(CompositeDataDateUnitTestCase.class);
+ }
+
+ public CompositeDataDateUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testDate() throws Exception
+ {
+ constructReconstructTest(createDate(2001, 1, 1));
+ }
+
+ public void testDateNull() throws Exception
+ {
+ constructReconstructTest(null, Date.class);
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataDoubleUnitTestCase.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataDoubleUnitTestCase.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataDoubleUnitTestCase.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,64 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * CompositeDataDoubleUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class CompositeDataDoubleUnitTestCase extends CompositeDataTest
+{
+ public static Test suite()
+ {
+ return new TestSuite(CompositeDataDoubleUnitTestCase.class);
+ }
+
+ public CompositeDataDoubleUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testDouble() throws Exception
+ {
+ constructReconstructTest(new Double(Double.MAX_VALUE));
+ }
+
+ public void testDoubleNull() throws Exception
+ {
+ constructReconstructTest(null, Double.class);
+ }
+
+ public void testDoublePrimitive() throws Exception
+ {
+ constructReconstructTest(Double.MAX_VALUE, Double.TYPE);
+ }
+
+ public void testDoubleNullPrimitive() throws Exception
+ {
+ assertNullFailure(Double.TYPE);
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataEnumUnitTestCase.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataEnumUnitTestCase.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataEnumUnitTestCase.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,56 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.test;
+
+import org.jboss.test.mx.mxbean.support.TestEnum;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * CompositeTypeEnumUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class CompositeDataEnumUnitTestCase extends CompositeDataTest
+{
+ public static Test suite()
+ {
+ return new TestSuite(CompositeDataEnumUnitTestCase.class);
+ }
+
+ public CompositeDataEnumUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testEnum() throws Exception
+ {
+ constructReconstructTest(TestEnum.FIRST, TestEnum.FIRST.name());
+ }
+
+ public void testEnumNull() throws Exception
+ {
+ constructReconstructTest(null, TestEnum.class);
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataFloatUnitTestCase.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataFloatUnitTestCase.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataFloatUnitTestCase.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,64 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * CompositeDataFloatUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class CompositeDataFloatUnitTestCase extends CompositeDataTest
+{
+ public static Test suite()
+ {
+ return new TestSuite(CompositeDataFloatUnitTestCase.class);
+ }
+
+ public CompositeDataFloatUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testFloat() throws Exception
+ {
+ constructReconstructTest(new Float(Float.MAX_VALUE));
+ }
+
+ public void testFloatNull() throws Exception
+ {
+ constructReconstructTest(null, Float.class);
+ }
+
+ public void testFloatPrimitive() throws Exception
+ {
+ constructReconstructTest(Float.MAX_VALUE, Float.TYPE);
+ }
+
+ public void testFloatNullPrimitive() throws Exception
+ {
+ assertNullFailure(Float.TYPE);
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataIntegerUnitTestCase.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataIntegerUnitTestCase.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataIntegerUnitTestCase.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,64 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * CompositeDataIntegerUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class CompositeDataIntegerUnitTestCase extends CompositeDataTest
+{
+ public static Test suite()
+ {
+ return new TestSuite(CompositeDataIntegerUnitTestCase.class);
+ }
+
+ public CompositeDataIntegerUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testInteger() throws Exception
+ {
+ constructReconstructTest(new Integer(Integer.MAX_VALUE));
+ }
+
+ public void testIntegerNull() throws Exception
+ {
+ constructReconstructTest(null, Integer.class);
+ }
+
+ public void testIntegerPrimitive() throws Exception
+ {
+ constructReconstructTest(Integer.MAX_VALUE, Integer.TYPE);
+ }
+
+ public void testIntegerNullPrimitive() throws Exception
+ {
+ assertNullFailure(Integer.TYPE);
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataInvocationHandlerUnitTestCase.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataInvocationHandlerUnitTestCase.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataInvocationHandlerUnitTestCase.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,361 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.test;
+
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.InvalidKeyException;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.mx.mxbean.CompositeDataInvocationHandler;
+import org.jboss.test.mx.mxbean.support.InvalidInterface;
+import org.jboss.test.mx.mxbean.support.SimpleInterface;
+
+/**
+ * CompositeDataInvocationHandlerUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class CompositeDataInvocationHandlerUnitTestCase extends AbstractMXBeanTest
+{
+ public static Test suite()
+ {
+ return new TestSuite(CompositeDataInvocationHandlerUnitTestCase.class);
+ }
+
+ public CompositeDataInvocationHandlerUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testGetCompositeData() throws Exception
+ {
+ CompositeData compositeData = createTestCompositeData();
+ CompositeDataInvocationHandler test = new CompositeDataInvocationHandler(compositeData);
+ assertTrue(compositeData == test.getCompositeData());
+ }
+
+ public void testNullCompositeData() throws Exception
+ {
+ try
+ {
+ new CompositeDataInvocationHandler(null);
+ fail("Should not be here");
+ }
+ catch (AssertionFailedError e)
+ {
+ throw e;
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+ }
+
+ public void testToEquals() throws Exception
+ {
+ SimpleInterface test1 = createTestCompositeDataProxy("Test1");
+
+ assertFalse(test1.equals(null));
+ assertFalse(test1.equals(new Object()));
+ assertTrue(test1.equals(test1));
+
+ SimpleInterface test2 = createTestCompositeDataProxy("Test2");
+
+ assertFalse(test1.equals(test2));
+ }
+
+ public void testHashCode() throws Exception
+ {
+ CompositeData compositeData = createTestCompositeData();
+ SimpleInterface test = createCompositeDataProxy(SimpleInterface.class, compositeData);
+
+ assertEquals(test.hashCode(), compositeData.hashCode());
+ }
+
+ public void testToString() throws Exception
+ {
+ CompositeData compositeData = createTestCompositeData();
+ SimpleInterface test = createCompositeDataProxy(SimpleInterface.class, compositeData);
+
+ assertEquals(test.toString(), compositeData.toString());
+ }
+
+ public void testGetSimpleTypes() throws Exception
+ {
+ SimpleInterface test = createTestCompositeDataProxy();
+ assertEquals(SimpleInterface.bigDecimalValue, test.getBigDecimal());
+ assertEquals(SimpleInterface.bigIntegerValue, test.getBigInteger());
+ assertEquals(SimpleInterface.booleanValue, test.getBoolean());
+ assertEquals(SimpleInterface.primitiveBooleanValue, test.isPrimitiveBoolean());
+ assertEquals(SimpleInterface.byteValue, test.getByte());
+ assertEquals(SimpleInterface.primitiveByteValue, test.getPrimitiveByte());
+ assertEquals(SimpleInterface.characterValue, test.getCharacter());
+ assertEquals(SimpleInterface.primitiveCharValue, test.getPrimitiveChar());
+ assertEquals(SimpleInterface.dateValue, test.getDate());
+ assertEquals(SimpleInterface.doubleValue, test.getDouble());
+ assertEquals(SimpleInterface.primitiveDoubleValue, test.getPrimitiveDouble());
+ assertEquals(SimpleInterface.floatValue, test.getFloat());
+ assertEquals(SimpleInterface.primitiveFloatValue, test.getPrimitiveFloat());
+ assertEquals(SimpleInterface.integerValue, test.getInteger());
+ assertEquals(SimpleInterface.primitiveIntValue, test.getPrimitiveInt());
+ assertEquals(SimpleInterface.longValue, test.getLong());
+ assertEquals(SimpleInterface.primitiveLongValue, test.getPrimitiveLong());
+ assertEquals(SimpleInterface.objectNameValue, test.getObjectName());
+ assertEquals(SimpleInterface.shortValue, test.getShort());
+ assertEquals(SimpleInterface.primitiveShortValue, test.getPrimitiveShort());
+ assertEquals(SimpleInterface.stringValue, test.getString());
+ }
+
+ public void testNullPrimitives() throws Exception
+ {
+ SimpleInterface test = createNullCompositeDataProxy();
+ assertNull(test.getBigDecimal());
+ assertNull(test.getBigInteger());
+ assertNull(test.getBoolean());
+ try
+ {
+ test.isPrimitiveBoolean();
+ fail("Should not be here");
+ }
+ catch (AssertionFailedError e)
+ {
+ throw e;
+ }
+ catch (Throwable t)
+ {
+ checkThrowableDeep(IllegalArgumentException.class, t);
+ }
+ assertNull(test.getByte());
+ try
+ {
+ test.getPrimitiveByte();
+ fail("Should not be here");
+ }
+ catch (AssertionFailedError e)
+ {
+ throw e;
+ }
+ catch (Throwable t)
+ {
+ checkThrowableDeep(IllegalArgumentException.class, t);
+ }
+ assertNull(test.getCharacter());
+ try
+ {
+ test.getPrimitiveChar();
+ fail("Should not be here");
+ }
+ catch (AssertionFailedError e)
+ {
+ throw e;
+ }
+ catch (Throwable t)
+ {
+ checkThrowableDeep(IllegalArgumentException.class, t);
+ }
+ assertNull(test.getDate());
+ assertNull(test.getDouble());
+ try
+ {
+ test.getPrimitiveDouble();
+ fail("Should not be here");
+ }
+ catch (AssertionFailedError e)
+ {
+ throw e;
+ }
+ catch (Throwable t)
+ {
+ checkThrowableDeep(IllegalArgumentException.class, t);
+ }
+ assertNull(test.getFloat());
+ try
+ {
+ test.getPrimitiveFloat();
+ fail("Should not be here");
+ }
+ catch (AssertionFailedError e)
+ {
+ throw e;
+ }
+ catch (Throwable t)
+ {
+ checkThrowableDeep(IllegalArgumentException.class, t);
+ }
+ assertNull(test.getInteger());
+ try
+ {
+ test.getPrimitiveInt();
+ fail("Should not be here");
+ }
+ catch (AssertionFailedError e)
+ {
+ throw e;
+ }
+ catch (Throwable t)
+ {
+ checkThrowableDeep(IllegalArgumentException.class, t);
+ }
+ assertNull(test.getLong());
+ try
+ {
+ test.getPrimitiveLong();
+ fail("Should not be here");
+ }
+ catch (AssertionFailedError e)
+ {
+ throw e;
+ }
+ catch (Throwable t)
+ {
+ checkThrowableDeep(IllegalArgumentException.class, t);
+ }
+ assertNull(test.getObjectName());
+ assertNull(test.getShort());
+ try
+ {
+ test.getPrimitiveShort();
+ fail("Should not be here");
+ }
+ catch (AssertionFailedError e)
+ {
+ throw e;
+ }
+ catch (Throwable t)
+ {
+ checkThrowableDeep(IllegalArgumentException.class, t);
+ }
+ assertNull(SimpleInterface.stringValue, test.getString());
+ }
+
+ public void testGetInvalid() throws Exception
+ {
+ InvalidInterface test = createInvalidCompositeDataProxy();
+ try
+ {
+ test.getInvalid();
+ fail("Should not be here");
+ }
+ catch (AssertionFailedError e)
+ {
+ throw e;
+ }
+ catch (Throwable t)
+ {
+ checkThrowableDeep(IllegalArgumentException.class, InvalidKeyException.class, t);
+ }
+ }
+
+ public void testNotAGetter() throws Exception
+ {
+ InvalidInterface test = createInvalidCompositeDataProxy();
+ try
+ {
+ test.notAGetter();
+ fail("Should not be here");
+ }
+ catch (AssertionFailedError e)
+ {
+ throw e;
+ }
+ catch (Throwable t)
+ {
+ checkThrowableDeep(IllegalArgumentException.class, t);
+ }
+ }
+
+ public void testGetNoReturnType() throws Exception
+ {
+ InvalidInterface test = createInvalidCompositeDataProxy();
+ try
+ {
+ test.getString();
+ fail("Should not be here");
+ }
+ catch (AssertionFailedError e)
+ {
+ throw e;
+ }
+ catch (Throwable t)
+ {
+ checkThrowableDeep(IllegalArgumentException.class, t);
+ }
+ }
+
+ public void testGetWithParameters() throws Exception
+ {
+ InvalidInterface test = createInvalidCompositeDataProxy();
+ try
+ {
+ test.getString(null);
+ fail("Should not be here");
+ }
+ catch (AssertionFailedError e)
+ {
+ throw e;
+ }
+ catch (Throwable t)
+ {
+ checkThrowableDeep(IllegalArgumentException.class, t);
+ }
+ }
+
+ public void testIsNotBoolean() throws Exception
+ {
+ InvalidInterface test = createInvalidCompositeDataProxy();
+ try
+ {
+ test.isString();
+ fail("Should not be here");
+ }
+ catch (AssertionFailedError e)
+ {
+ throw e;
+ }
+ catch (Throwable t)
+ {
+ checkThrowableDeep(IllegalArgumentException.class, t);
+ }
+ }
+
+ public void testIsBoolean() throws Exception
+ {
+ InvalidInterface test = createInvalidCompositeDataProxy();
+ try
+ {
+ test.isBoolean();
+ fail("Should not be here");
+ }
+ catch (AssertionFailedError e)
+ {
+ throw e;
+ }
+ catch (Throwable t)
+ {
+ checkThrowableDeep(IllegalArgumentException.class, t);
+ }
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataLongUnitTestCase.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataLongUnitTestCase.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataLongUnitTestCase.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,64 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * CompositeDataLongUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class CompositeDataLongUnitTestCase extends CompositeDataTest
+{
+ public static Test suite()
+ {
+ return new TestSuite(CompositeDataLongUnitTestCase.class);
+ }
+
+ public CompositeDataLongUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testLong() throws Exception
+ {
+ constructReconstructTest(new Long(Long.MAX_VALUE));
+ }
+
+ public void testLongNull() throws Exception
+ {
+ constructReconstructTest(null, Long.class);
+ }
+
+ public void testLongPrimitive() throws Exception
+ {
+ constructReconstructTest(Long.MAX_VALUE, Long.TYPE);
+ }
+
+ public void testLongNullPrimitive() throws Exception
+ {
+ assertNullFailure(Long.TYPE);
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataMapUnitTestCase.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataMapUnitTestCase.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataMapUnitTestCase.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,106 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.test;
+
+import java.lang.reflect.Type;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import javax.management.openmbean.CompositeDataSupport;
+import javax.management.openmbean.CompositeType;
+import javax.management.openmbean.TabularDataSupport;
+import javax.management.openmbean.TabularType;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.mx.mxbean.MXBeanUtils;
+import org.jboss.test.mx.mxbean.support.TestParameterizedType;
+
+/**
+ * CompositeDataMapUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class CompositeDataMapUnitTestCase extends CompositeDataTest
+{
+ private static final TestParameterizedType MAP_OF_STRINGS_TO_INTEGERS = new TestParameterizedType(Map.class, new Type[] { String.class, Integer.class });
+ private static final TabularType TABLE_STRING_TO_INTEGER = MXBeanUtils.createMapType(String.class, Integer.class);
+
+ public static Test suite()
+ {
+ return new TestSuite(CompositeDataMapUnitTestCase.class);
+ }
+
+ public CompositeDataMapUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testMap() throws Exception
+ {
+ Map<String, Integer> c = new LinkedHashMap<String, Integer>();
+ c.put("one", 1);
+ c.put("two", 2);
+ c.put("three", 3);
+ TabularDataSupport openData = new TabularDataSupport(TABLE_STRING_TO_INTEGER);
+ CompositeType entryType = TABLE_STRING_TO_INTEGER.getRowType();
+ openData.put(new CompositeDataSupport(entryType, MXBeanUtils.MAP_ITEM_NAMES, new Object[] { "one", 1 }));
+ openData.put(new CompositeDataSupport(entryType, MXBeanUtils.MAP_ITEM_NAMES, new Object[] { "two", 2 }));
+ openData.put(new CompositeDataSupport(entryType, MXBeanUtils.MAP_ITEM_NAMES, new Object[] { "three", 3 }));
+ constructReconstructTest(c, MAP_OF_STRINGS_TO_INTEGERS, openData);
+ }
+
+ public void testMapNull() throws Exception
+ {
+ constructReconstructTest(null, MAP_OF_STRINGS_TO_INTEGERS);
+ }
+
+ public void testMapNullKey() throws Exception
+ {
+ Map<String, Integer> c = new LinkedHashMap<String, Integer>();
+ c.put("one", 1);
+ c.put(null, 2);
+ c.put("three", 3);
+ TabularDataSupport openData = new TabularDataSupport(TABLE_STRING_TO_INTEGER);
+ CompositeType entryType = TABLE_STRING_TO_INTEGER.getRowType();
+ openData.put(new CompositeDataSupport(entryType, MXBeanUtils.MAP_ITEM_NAMES, new Object[] { "one", 1 }));
+ openData.put(new CompositeDataSupport(entryType, MXBeanUtils.MAP_ITEM_NAMES, new Object[] { null, 2 }));
+ openData.put(new CompositeDataSupport(entryType, MXBeanUtils.MAP_ITEM_NAMES, new Object[] { "three", 3 }));
+ constructReconstructTest(c, MAP_OF_STRINGS_TO_INTEGERS, openData);
+ }
+
+ public void testMapNullValue() throws Exception
+ {
+ Map<String, Integer> c = new LinkedHashMap<String, Integer>();
+ c.put("one", 1);
+ c.put("two", null);
+ c.put("three", 3);
+ TabularDataSupport openData = new TabularDataSupport(TABLE_STRING_TO_INTEGER);
+ CompositeType entryType = TABLE_STRING_TO_INTEGER.getRowType();
+ openData.put(new CompositeDataSupport(entryType, MXBeanUtils.MAP_ITEM_NAMES, new Object[] { "one", 1 }));
+ openData.put(new CompositeDataSupport(entryType, MXBeanUtils.MAP_ITEM_NAMES, new Object[] { "two", null }));
+ openData.put(new CompositeDataSupport(entryType, MXBeanUtils.MAP_ITEM_NAMES, new Object[] { "three", 3 }));
+ constructReconstructTest(c, MAP_OF_STRINGS_TO_INTEGERS, openData);
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataObjectNameUnitTestCase.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataObjectNameUnitTestCase.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataObjectNameUnitTestCase.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,58 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.test;
+
+import javax.management.ObjectName;
+
+import org.jboss.mx.util.ObjectNameFactory;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * CompositeDataObjectNameUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class CompositeDataObjectNameUnitTestCase extends CompositeDataTest
+{
+ public static Test suite()
+ {
+ return new TestSuite(CompositeDataObjectNameUnitTestCase.class);
+ }
+
+ public CompositeDataObjectNameUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testObjectName() throws Exception
+ {
+ constructReconstructTest(ObjectNameFactory.create("domain:key=property"));
+ }
+
+ public void testObjectNameNull() throws Exception
+ {
+ constructReconstructTest(null, ObjectName.class);
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataShortUnitTestCase.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataShortUnitTestCase.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataShortUnitTestCase.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,64 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * CompositeDataShortUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class CompositeDataShortUnitTestCase extends CompositeDataTest
+{
+ public static Test suite()
+ {
+ return new TestSuite(CompositeDataShortUnitTestCase.class);
+ }
+
+ public CompositeDataShortUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testShort() throws Exception
+ {
+ constructReconstructTest(new Short(Short.MAX_VALUE));
+ }
+
+ public void testShortNull() throws Exception
+ {
+ constructReconstructTest(null, Short.class);
+ }
+
+ public void testShortPrimitive() throws Exception
+ {
+ constructReconstructTest(Short.MAX_VALUE, Short.TYPE);
+ }
+
+ public void testShortNullPrimitive() throws Exception
+ {
+ assertNullFailure(Short.TYPE);
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataStringUnitTestCase.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataStringUnitTestCase.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataStringUnitTestCase.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,59 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * CompositeTypeStringUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class CompositeDataStringUnitTestCase extends CompositeDataTest
+{
+ public static Test suite()
+ {
+ return new TestSuite(CompositeDataStringUnitTestCase.class);
+ }
+
+ public CompositeDataStringUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testString() throws Exception
+ {
+ constructReconstructTest("Hello");
+ }
+
+ public void testStringEmpty() throws Exception
+ {
+ constructReconstructTest("");
+ }
+
+ public void testStringNull() throws Exception
+ {
+ constructReconstructTest(null, String.class);
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataTest.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataTest.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeDataTest.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,129 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.test;
+
+import java.lang.reflect.Type;
+
+import javax.management.openmbean.OpenType;
+
+import junit.framework.AssertionFailedError;
+
+import org.jboss.mx.mxbean.MXBeanUtils;
+
+/**
+ * CompositeDataTest.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class CompositeDataTest extends AbstractMXBeanTest
+{
+ public CompositeDataTest(String name)
+ {
+ super(name);
+ }
+
+ protected void constructReconstructTest(Object initialValue) throws Exception
+ {
+ constructReconstructTest(initialValue, initialValue);
+ }
+
+ protected void constructReconstructTest(Object initialValue, Type type) throws Exception
+ {
+ constructReconstructTest(initialValue, type, initialValue);
+ }
+
+ protected void constructReconstructTest(Object initialValue, Type type, Object expectedOpenData) throws Exception
+ {
+ constructReconstructTest(initialValue, type, expectedOpenData, initialValue);
+ }
+
+ protected void assertNullFailure(Type type) throws Exception
+ {
+ try
+ {
+ constructReconstructTest(null, type);
+ fail("Should not be here");
+ }
+ catch (AssertionFailedError e)
+ {
+ throw e;
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalArgumentException.class, t);
+ }
+ }
+
+ protected void constructReconstructTest(Object initialValue, Object expectedOpenData) throws Exception
+ {
+ constructReconstructTest(initialValue, expectedOpenData, initialValue);
+ }
+
+ protected void constructReconstructTest(Object initialValue, Object expectedOpenData, Object expected) throws Exception
+ {
+ Type type = initialValue.getClass();
+ constructReconstructTest(initialValue, type, expectedOpenData, expected);
+ }
+
+ protected void constructReconstructTest(Object initialValue, Type type, Object expectedOpenData, Object expected) throws Exception
+ {
+ OpenType openType = MXBeanUtils.getOpenType(type);
+ constructReconstructTest(initialValue, type, openType, expectedOpenData, expected);
+ }
+
+ protected void constructReconstructTest(Object initialValue, Type type, OpenType openType, Object expectedOpenData, Object expected) throws Exception
+ {
+ Object openData = construct(openType, type, initialValue);
+ checkOpenDataEquals(expectedOpenData, openData);
+ if (initialValue != null)
+ assertTrue(openData + " is not " + openType, openType.isValue(openData));
+
+ Object finalValue = reconstruct(openType, type, openData);
+ checkFinalEquals(expected, finalValue);
+ }
+
+ protected void checkOpenDataEquals(Object expected, Object actual)
+ {
+ checkEquals(expected, actual);
+ }
+
+ protected void checkFinalEquals(Object expected, Object actual)
+ {
+ checkEquals(expected, actual);
+ }
+
+ protected void checkEquals(Object expected, Object actual)
+ {
+ assertEquals(expected, actual);
+ }
+
+ protected Object construct(OpenType openType, Type type, Object value) throws Exception
+ {
+ return MXBeanUtils.construct(openType, value, getClass().getName() + "#" + getName());
+ }
+
+ protected Object reconstruct(OpenType openType, Type type, Object openData) throws Exception
+ {
+ return MXBeanUtils.reconstruct(openType, type, openData, getClass().getName() + "#" + getName());
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeTypeMetaDataFactoryUnitTestCase.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeTypeMetaDataFactoryUnitTestCase.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/CompositeTypeMetaDataFactoryUnitTestCase.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,113 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.test;
+
+import javax.management.openmbean.CompositeType;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.mx.mxbean.CompositeTypeMetaData;
+import org.jboss.mx.mxbean.CompositeTypeMetaDataFactory;
+import org.jboss.test.mx.mxbean.support.CollectionsInterface;
+import org.jboss.test.mx.mxbean.support.CompositeInterface;
+import org.jboss.test.mx.mxbean.support.SimpleInterface;
+import org.jboss.test.mx.mxbean.support.SimpleObject;
+
+/**
+ * CompositeTypeMetaDataFactoryUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class CompositeTypeMetaDataFactoryUnitTestCase extends AbstractMXBeanTest
+{
+ private static final CompositeType OBJECT_TYPE = CompositeTypeMetaData.generateObject();
+ private static final CompositeType CLASS_TYPE = CompositeTypeMetaData.generateClass();
+ private static final CompositeType CLASSLOADER_TYPE = CompositeTypeMetaData.generateClassLoader();
+
+ public static Test suite()
+ {
+ return new TestSuite(CompositeTypeMetaDataFactoryUnitTestCase.class);
+ }
+
+ public CompositeTypeMetaDataFactoryUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testGetCompositeDataObject() throws Exception
+ {
+ CompositeType type = CompositeTypeMetaDataFactory.getCompositeType(Object.class);
+ assertNotNull(type);
+ assertEquals(OBJECT_TYPE, type);
+ }
+
+ public void testGetCompositeDataClass() throws Exception
+ {
+ CompositeType type = CompositeTypeMetaDataFactory.getCompositeType(Class.class);
+ assertNotNull(type);
+ assertEquals(CLASS_TYPE, type);
+ }
+
+ public void testGetCompositeDataClassLoader() throws Exception
+ {
+ CompositeType type = CompositeTypeMetaDataFactory.getCompositeType(ClassLoader.class);
+ assertNotNull(type);
+ assertEquals(CLASSLOADER_TYPE, type);
+ }
+
+ public void testSimpleInterfaceCompositeType() throws Exception
+ {
+ CompositeType type = CompositeTypeMetaDataFactory.getCompositeType(SimpleInterface.class);
+ assertNotNull(type);
+ assertEquals(createSimpleCompositeType(SimpleInterface.class), type);
+ }
+
+ public void testSimpleObjectCompositeType() throws Exception
+ {
+ CompositeType type = CompositeTypeMetaDataFactory.getCompositeType(SimpleObject.class);
+ assertNotNull(type);
+ assertEquals(createSimpleCompositeType(SimpleObject.class), type);
+ }
+
+ public void testCompositeInterfaceType() throws Exception
+ {
+ CompositeType type = CompositeTypeMetaDataFactory.getCompositeType(CompositeInterface.class);
+ assertNotNull(type);
+ CompositeType expected = createCompositeType(CompositeInterface.class.getName(), CompositeInterface.KEYS, CompositeInterface.TYPES);
+ assertEquals(expected, type);
+ }
+
+ public void testCollectionsInterfaceType() throws Exception
+ {
+ CompositeType type = CompositeTypeMetaDataFactory.getCompositeType(CollectionsInterface.class);
+ assertNotNull(type);
+ CompositeType expected = createCompositeType(CollectionsInterface.class.getName(), CollectionsInterface.KEYS, CollectionsInterface.TYPES);
+ assertEquals(expected, type);
+ }
+
+ protected CompositeType createSimpleCompositeType(Class clazz) throws Exception
+ {
+ return createCompositeType(clazz.getName(), SimpleInterface.KEYS, SimpleInterface.TYPES);
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/MXBeanInvocationHandlerUnitTestCase.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/MXBeanInvocationHandlerUnitTestCase.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/MXBeanInvocationHandlerUnitTestCase.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,311 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.test;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.openmbean.OpenMBeanAttributeInfo;
+import javax.management.openmbean.OpenMBeanInfo;
+import javax.management.openmbean.OpenType;
+import javax.management.openmbean.SimpleType;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.mx.mxbean.MXBeanFactory;
+import org.jboss.mx.mxbean.MXBeanUtils;
+import org.jboss.test.mx.mxbean.support.CollectionsInterface;
+import org.jboss.test.mx.mxbean.support.CollectionsMXBeanSupport;
+import org.jboss.test.mx.mxbean.support.CollectionsMXBeanSupportMXBean;
+import org.jboss.test.mx.mxbean.support.CompositeInterface;
+import org.jboss.test.mx.mxbean.support.CompositeMXBeanSupport;
+import org.jboss.test.mx.mxbean.support.CompositeMXBeanSupportMXBean;
+import org.jboss.test.mx.mxbean.support.SimpleInterface;
+import org.jboss.test.mx.mxbean.support.SimpleMXBeanSupport;
+import org.jboss.test.mx.mxbean.support.SimpleMXBeanSupportMXBean;
+import org.jboss.test.mx.mxbean.support.SimpleObject;
+import org.jboss.test.mx.mxbean.support.TestEnum;
+
+/**
+ * MXBeanInvocationHandlerUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MXBeanInvocationHandlerUnitTestCase extends AbstractMXBeanTest
+{
+ public static Test suite()
+ {
+ return new TestSuite(MXBeanInvocationHandlerUnitTestCase.class);
+ }
+
+ public MXBeanInvocationHandlerUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testGetSimpleAttributes() throws Exception
+ {
+ MBeanServer server = createMBeanServer();
+ SimpleMXBeanSupport support = new SimpleMXBeanSupport();
+ ObjectName objectName = SimpleMXBeanSupportMXBean.REGISTERED_OBJECT_NAME;
+ server.registerMBean(support, objectName);
+ SimpleMXBeanSupportMXBean proxy = MXBeanFactory.makeProxy(server, objectName, SimpleMXBeanSupportMXBean.class);
+ OpenMBeanInfo info = (OpenMBeanInfo) server.getMBeanInfo(objectName);
+ OpenType[] types = new OpenType[SimpleInterface.TYPES.length];
+ for (int i = 0; i < types.length; ++i)
+ types[i] = MXBeanUtils.getOpenType(SimpleInterface.TYPES[i]);
+ checkAttributes(SimpleMXBeanSupportMXBean.class, proxy, support, SimpleInterface.KEYS, types, SimpleInterface.VALUES, info);
+ }
+
+ public void testSetSimpleAttributes() throws Exception
+ {
+ MBeanServer server = createMBeanServer();
+ SimpleMXBeanSupport support = new SimpleMXBeanSupport();
+ ObjectName objectName = SimpleMXBeanSupportMXBean.REGISTERED_OBJECT_NAME;
+ server.registerMBean(support, objectName);
+ SimpleMXBeanSupportMXBean proxy = MXBeanFactory.makeProxy(server, objectName, SimpleMXBeanSupportMXBean.class);
+ OpenMBeanInfo info = (OpenMBeanInfo) server.getMBeanInfo(objectName);
+ OpenType[] types = new OpenType[SimpleInterface.TYPES.length];
+ for (int i = 0; i < types.length; ++i)
+ types[i] = MXBeanUtils.getOpenType(SimpleInterface.TYPES[i]);
+ proxy.setBigDecimal(SimpleInterface.bigDecimalChangedValue);
+ proxy.setBigInteger(SimpleInterface.bigIntegerChangedValue);
+ proxy.setBoolean(SimpleInterface.booleanChangedValue);
+ proxy.setByte(SimpleInterface.byteChangedValue);
+ proxy.setCharacter(SimpleInterface.characterChangedValue);
+ proxy.setDate(SimpleInterface.dateChangedValue);
+ proxy.setDouble(SimpleInterface.doubleChangedValue);
+ proxy.setFloat(SimpleInterface.floatChangedValue);
+ proxy.setInteger(SimpleInterface.integerChangedValue);
+ proxy.setLong(SimpleInterface.longChangedValue);
+ proxy.setObjectName(SimpleInterface.objectNameChangedValue);
+ proxy.setPrimitiveBoolean(SimpleInterface.primitiveBooleanChangedValue);
+ proxy.setPrimitiveByte(SimpleInterface.primitiveByteChangedValue);
+ proxy.setPrimitiveChar(SimpleInterface.primitiveCharChangedValue);
+ proxy.setPrimitiveDouble(SimpleInterface.primitiveDoubleChangedValue);
+ proxy.setPrimitiveFloat(SimpleInterface.primitiveFloatChangedValue);
+ proxy.setPrimitiveInt(SimpleInterface.primitiveIntChangedValue);
+ proxy.setPrimitiveLong(SimpleInterface.primitiveLongChangedValue);
+ proxy.setPrimitiveShort(SimpleInterface.primitiveShortChangedValue);
+ proxy.setShort(SimpleInterface.shortChangedValue);
+ proxy.setString(SimpleInterface.stringChangedValue);
+ checkAttributes(SimpleInterface.class, proxy, support, SimpleInterface.KEYS, types, SimpleInterface.CHANGED_VALUES, info);
+ }
+
+ public void testSimpleInvoke() throws Exception
+ {
+ MBeanServer server = createMBeanServer();
+ SimpleMXBeanSupport support = new SimpleMXBeanSupport();
+ ObjectName objectName = SimpleMXBeanSupportMXBean.REGISTERED_OBJECT_NAME;
+ server.registerMBean(support, objectName);
+ SimpleMXBeanSupportMXBean proxy = MXBeanFactory.makeProxy(server, objectName, SimpleMXBeanSupportMXBean.class);
+ assertEquals("olleH", proxy.echoReverse("Hello"));
+ }
+
+ public void testGetCompositeAttributes() throws Exception
+ {
+ MBeanServer server = createMBeanServer();
+ SimpleObject composite = new SimpleObject();
+ CompositeMXBeanSupport support = new CompositeMXBeanSupport("Simple", composite);
+ ObjectName objectName = CompositeMXBeanSupportMXBean.REGISTERED_OBJECT_NAME;
+ server.registerMBean(support, objectName);
+ CompositeMXBeanSupportMXBean proxy = MXBeanFactory.makeProxy(server, objectName, CompositeMXBeanSupportMXBean.class);
+ OpenMBeanInfo info = (OpenMBeanInfo) server.getMBeanInfo(objectName);
+ Object[] values = { "Simple", composite };
+ checkAttributes(CompositeMXBeanSupportMXBean.class, proxy, support, CompositeInterface.KEYS, CompositeInterface.TYPES, values, info);
+ }
+
+ public void testSetCompositeAttributes() throws Exception
+ {
+ MBeanServer server = createMBeanServer();
+ SimpleObject composite = new SimpleObject();
+ CompositeMXBeanSupport support = new CompositeMXBeanSupport("Simple", composite);
+ ObjectName objectName = CompositeMXBeanSupportMXBean.REGISTERED_OBJECT_NAME;
+ server.registerMBean(support, objectName);
+ CompositeMXBeanSupportMXBean proxy = MXBeanFactory.makeProxy(server, objectName, CompositeMXBeanSupportMXBean.class);
+ OpenMBeanInfo info = (OpenMBeanInfo) server.getMBeanInfo(objectName);
+ SimpleObject changed = new SimpleObject();
+ changed.setBigDecimal(SimpleInterface.bigDecimalChangedValue);
+ changed.setBigInteger(SimpleInterface.bigIntegerChangedValue);
+ changed.setBoolean(SimpleInterface.booleanChangedValue);
+ changed.setByte(SimpleInterface.byteChangedValue);
+ changed.setCharacter(SimpleInterface.characterChangedValue);
+ changed.setDate(SimpleInterface.dateChangedValue);
+ changed.setDouble(SimpleInterface.doubleChangedValue);
+ changed.setFloat(SimpleInterface.floatChangedValue);
+ changed.setInteger(SimpleInterface.integerChangedValue);
+ changed.setLong(SimpleInterface.longChangedValue);
+ changed.setObjectName(SimpleInterface.objectNameChangedValue);
+ changed.setPrimitiveBoolean(SimpleInterface.primitiveBooleanChangedValue);
+ changed.setPrimitiveByte(SimpleInterface.primitiveByteChangedValue);
+ changed.setPrimitiveChar(SimpleInterface.primitiveCharChangedValue);
+ changed.setPrimitiveDouble(SimpleInterface.primitiveDoubleChangedValue);
+ changed.setPrimitiveFloat(SimpleInterface.primitiveFloatChangedValue);
+ changed.setPrimitiveInt(SimpleInterface.primitiveIntChangedValue);
+ changed.setPrimitiveLong(SimpleInterface.primitiveLongChangedValue);
+ changed.setPrimitiveShort(SimpleInterface.primitiveShortChangedValue);
+ changed.setShort(SimpleInterface.shortChangedValue);
+ changed.setString(SimpleInterface.stringChangedValue);
+ proxy.setSimple("Changed");
+ proxy.setComposite(changed);
+ Object[] values = new Object[] { "Changed", changed };
+ checkAttributes(CompositeMXBeanSupportMXBean.class, proxy, support, CompositeInterface.KEYS, CompositeInterface.TYPES, values, info);
+ }
+
+ public void testCompositeInvoke() throws Exception
+ {
+ MBeanServer server = createMBeanServer();
+ SimpleObject composite = new SimpleObject();
+ CompositeMXBeanSupport support = new CompositeMXBeanSupport("Simple", composite);
+ ObjectName objectName = CompositeMXBeanSupportMXBean.REGISTERED_OBJECT_NAME;
+ server.registerMBean(support, objectName);
+ CompositeMXBeanSupportMXBean proxy = MXBeanFactory.makeProxy(server, objectName, CompositeMXBeanSupportMXBean.class);
+ composite = new SimpleObject();
+ composite.setString("hello");
+ SimpleInterface result = proxy.echoReverse(composite);
+ assertEquals("olleh", result.getString());
+ }
+
+ public void testGetCollectionAttributes() throws Exception
+ {
+ MBeanServer server = createMBeanServer();
+ String[] array = { "array" };
+ Collection<String> collection = new ArrayList<String>();
+ collection.add("collection");
+ Set<String> set = new HashSet<String>();
+ set.add("set");
+ List<String> list = new ArrayList<String>();
+ list.add("list");
+ Map<String, Integer> map = new HashMap<String, Integer>();
+ map.put("map", 1);
+ TestEnum enumeration = TestEnum.FIRST;
+ CollectionsMXBeanSupport support = new CollectionsMXBeanSupport(array, collection, set, list, map, enumeration);
+ ObjectName objectName = CollectionsMXBeanSupportMXBean.REGISTERED_OBJECT_NAME;
+ server.registerMBean(support, objectName);
+ CollectionsMXBeanSupportMXBean proxy = MXBeanFactory.makeProxy(server, objectName, CollectionsMXBeanSupportMXBean.class);
+ OpenMBeanInfo info = (OpenMBeanInfo) server.getMBeanInfo(objectName);
+ Object[] values = { array, collection, set, list, map, enumeration };
+ checkAttributes(CollectionsMXBeanSupportMXBean.class, proxy, support, CollectionsInterface.KEYS, CollectionsInterface.TYPES, values, info);
+ }
+
+ public void testSetCollectionAttributes() throws Exception
+ {
+ MBeanServer server = createMBeanServer();
+ String[] array = { "array" };
+ Collection<String> collection = new ArrayList<String>();
+ collection.add("collection");
+ Set<String> set = new LinkedHashSet<String>();
+ set.add("set");
+ List<String> list = new ArrayList<String>();
+ list.add("list");
+ Map<String, Integer> map = new LinkedHashMap<String, Integer>();
+ map.put("map", 1);
+ TestEnum enumeration = TestEnum.FIRST;
+ CollectionsMXBeanSupport support = new CollectionsMXBeanSupport(array, collection, set, list, map, enumeration);
+ ObjectName objectName = CollectionsMXBeanSupportMXBean.REGISTERED_OBJECT_NAME;
+ server.registerMBean(support, objectName);
+ CollectionsMXBeanSupportMXBean proxy = MXBeanFactory.makeProxy(server, objectName, CollectionsMXBeanSupportMXBean.class);
+ OpenMBeanInfo info = (OpenMBeanInfo) server.getMBeanInfo(objectName);
+
+ String[] changedArray = { "arrayChanged" };
+ Collection<String> changedCollection = new ArrayList<String>();
+ changedCollection.add("collectionChanged");
+ Set<String> changedSet = new LinkedHashSet<String>();
+ changedSet.add("setChanged");
+ List<String> changedList = new ArrayList<String>();
+ changedList.add("listChanged");
+ Map<String, Integer> changedMap = new LinkedHashMap<String, Integer>();
+ changedMap.put("mapChanged", 2);
+ TestEnum changedEnumeration = TestEnum.SECOND;
+
+ proxy.setArray(changedArray);
+ proxy.setCollection(changedCollection);
+ proxy.setEnum(changedEnumeration);
+ proxy.setList(changedList);
+ proxy.setMap(changedMap);
+ proxy.setSet(changedSet);
+ Object[] changedValues = { changedArray, changedCollection, changedSet, changedList, changedMap, changedEnumeration };
+ checkAttributes(CollectionsMXBeanSupportMXBean.class, proxy, support, CollectionsInterface.KEYS, CollectionsInterface.TYPES, changedValues, info);
+ }
+
+ public void testCollectionInvoke() throws Exception
+ {
+ MBeanServer server = createMBeanServer();
+ CollectionsMXBeanSupport support = new CollectionsMXBeanSupport();
+ ObjectName objectName = CompositeMXBeanSupportMXBean.REGISTERED_OBJECT_NAME;
+ server.registerMBean(support, objectName);
+ CollectionsMXBeanSupportMXBean proxy = MXBeanFactory.makeProxy(server, objectName, CollectionsMXBeanSupportMXBean.class);
+ List<String> list = new ArrayList<String>();
+ list.add("one");
+ list.add("two");
+ list.add("three");
+ List<String> expected = new ArrayList<String>();
+ expected.add("three");
+ expected.add("two");
+ expected.add("one");
+ List<String> result = proxy.echoReverse(list);
+ assertEquals(expected, result);
+ }
+
+ protected void checkAttributes(Class intf, Object proxy, Object mxbean, String[] keys, OpenType[] types, Object[] values, OpenMBeanInfo info) throws Exception
+ {
+ MBeanAttributeInfo[] attributes = info.getAttributes();
+
+ assertEquals(keys.length, values.length);
+ assertEquals(keys.length, types.length);
+ assertEquals(keys.length, attributes.length);
+
+ Map<String, OpenMBeanAttributeInfo> mapping = new HashMap<String, OpenMBeanAttributeInfo>(attributes.length);
+ for (int i = 0; i < attributes.length; ++i)
+ {
+ OpenMBeanAttributeInfo attribute = (OpenMBeanAttributeInfo) attributes[i];
+ String name = attribute.getName();
+ mapping.put(name, attribute);
+ }
+
+ for (int i = 0; i < keys.length; ++i)
+ {
+ String name = getUpperName(keys[i]);
+ OpenMBeanAttributeInfo attribute = mapping.get(name);
+ assertNotNull("Could not find key " + name + " in " + mapping.keySet(), attribute);
+ Method method = MXBeanUtils.getCompositeDataMethod(intf, keys[i], types[i] == SimpleType.BOOLEAN);
+ Object value = method.invoke(proxy, null);
+ checkValueEquals(values[i], value);
+ value = method.invoke(mxbean, null);
+ checkValueEquals(values[i], value);
+ assertEquals(types[i], attribute.getOpenType());
+ }
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/MXBeanSupportUnitTestCase.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/MXBeanSupportUnitTestCase.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/MXBeanSupportUnitTestCase.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,371 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.test;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.management.Attribute;
+import javax.management.AttributeList;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.CompositeDataSupport;
+import javax.management.openmbean.CompositeType;
+import javax.management.openmbean.OpenMBeanAttributeInfo;
+import javax.management.openmbean.OpenMBeanInfo;
+import javax.management.openmbean.OpenType;
+import javax.management.openmbean.SimpleType;
+import javax.management.openmbean.TabularDataSupport;
+import javax.management.openmbean.TabularType;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.mx.mxbean.MXBeanUtils;
+import org.jboss.test.mx.mxbean.support.CollectionsInterface;
+import org.jboss.test.mx.mxbean.support.CollectionsMXBeanSupport;
+import org.jboss.test.mx.mxbean.support.CollectionsMXBeanSupportMXBean;
+import org.jboss.test.mx.mxbean.support.CompositeInterface;
+import org.jboss.test.mx.mxbean.support.CompositeMXBeanSupport;
+import org.jboss.test.mx.mxbean.support.CompositeMXBeanSupportMXBean;
+import org.jboss.test.mx.mxbean.support.SimpleInterface;
+import org.jboss.test.mx.mxbean.support.SimpleMXBeanSupport;
+import org.jboss.test.mx.mxbean.support.SimpleMXBeanSupportMXBean;
+import org.jboss.test.mx.mxbean.support.SimpleObject;
+import org.jboss.test.mx.mxbean.support.TestEnum;
+
+/**
+ * MXBeanSupportUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MXBeanSupportUnitTestCase extends AbstractMXBeanTest
+{
+ private static final TabularType TABLE_STRING_TO_INTEGER = MXBeanUtils.createMapType(String.class, Integer.class);
+
+ public static Test suite()
+ {
+ return new TestSuite(MXBeanSupportUnitTestCase.class);
+ }
+
+ public MXBeanSupportUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testGetSimpleAttributes() throws Exception
+ {
+ MBeanServer server = createMBeanServer();
+ SimpleMXBeanSupport support = new SimpleMXBeanSupport();
+ ObjectName objectName = SimpleMXBeanSupportMXBean.REGISTERED_OBJECT_NAME;
+ server.registerMBean(support, objectName);
+ OpenMBeanInfo info = (OpenMBeanInfo) server.getMBeanInfo(objectName);
+ OpenType[] types = new OpenType[SimpleInterface.TYPES.length];
+ for (int i = 0; i < types.length; ++i)
+ types[i] = MXBeanUtils.getOpenType(SimpleInterface.TYPES[i]);
+ checkAttributes(server, objectName, SimpleMXBeanSupportMXBean.class, support, SimpleInterface.KEYS, types, SimpleInterface.VALUES, SimpleInterface.VALUES, info);
+ }
+
+ public void testSetSimpleAttributes() throws Exception
+ {
+ MBeanServer server = createMBeanServer();
+ SimpleMXBeanSupport support = new SimpleMXBeanSupport();
+ ObjectName objectName = SimpleMXBeanSupportMXBean.REGISTERED_OBJECT_NAME;
+ server.registerMBean(support, objectName);
+ OpenMBeanInfo info = (OpenMBeanInfo) server.getMBeanInfo(objectName);
+ String[] keys = SimpleInterface.KEYS;
+ Object[] values = SimpleInterface.VALUES;
+ Object[] changedValues = SimpleInterface.CHANGED_VALUES;
+ AttributeList list = new AttributeList(keys.length);
+ OpenType[] types = new OpenType[SimpleInterface.TYPES.length];
+ for (int i = 0; i < types.length; ++i)
+ {
+ types[i] = MXBeanUtils.getOpenType(SimpleInterface.TYPES[i]);
+ String name = getUpperName(keys[i]);
+ server.setAttribute(objectName, new Attribute(name, changedValues[i]));
+ Attribute attribute = new Attribute(name, values[i]);
+ list.add(attribute);
+ }
+ checkAttributes(server, objectName, SimpleMXBeanSupportMXBean.class, support, keys, types, SimpleInterface.CHANGED_VALUES, SimpleInterface.CHANGED_VALUES, info);
+
+ setAttributes(server, objectName, list);
+ checkAttributes(server, objectName, SimpleMXBeanSupportMXBean.class, support, keys, types, SimpleInterface.VALUES, SimpleInterface.VALUES, info);
+ }
+
+ public void testSimpleInvoke() throws Exception
+ {
+ MBeanServer server = createMBeanServer();
+ SimpleMXBeanSupport support = new SimpleMXBeanSupport();
+ ObjectName objectName = SimpleMXBeanSupportMXBean.REGISTERED_OBJECT_NAME;
+ server.registerMBean(support, objectName);
+ assertEquals("olleH", server.invoke(objectName, "echoReverse", new Object[] { "Hello" }, new String[] { String.class.getName() }));
+ }
+
+ public void testGetCompositeAttributes() throws Exception
+ {
+ MBeanServer server = createMBeanServer();
+ SimpleObject composite = new SimpleObject();
+ CompositeMXBeanSupport support = new CompositeMXBeanSupport("Simple", composite);
+ ObjectName objectName = CompositeMXBeanSupportMXBean.REGISTERED_OBJECT_NAME;
+ server.registerMBean(support, objectName);
+ OpenMBeanInfo info = (OpenMBeanInfo) server.getMBeanInfo(objectName);
+ CompositeData data = createCompositeData(SimpleInterface.class.getName(), SimpleInterface.KEYS, SimpleInterface.VALUES);
+ Object[] values = { "Simple", data };
+ Object[] realValues = { "Simple", composite };
+ checkAttributes(server, objectName, CompositeMXBeanSupportMXBean.class, support, CompositeInterface.KEYS, CompositeInterface.TYPES, values, realValues, info);
+ }
+
+ public void testSetCompositeAttributes() throws Exception
+ {
+ MBeanServer server = createMBeanServer();
+ SimpleObject composite = new SimpleObject();
+ CompositeMXBeanSupport support = new CompositeMXBeanSupport("Simple", composite);
+ ObjectName objectName = CompositeMXBeanSupportMXBean.REGISTERED_OBJECT_NAME;
+ server.registerMBean(support, objectName);
+ OpenMBeanInfo info = (OpenMBeanInfo) server.getMBeanInfo(objectName);
+ String[] keys = CompositeInterface.KEYS;
+ CompositeData data = createCompositeData(SimpleInterface.class.getName(), SimpleInterface.KEYS, SimpleInterface.VALUES);
+ Object[] values = { "Simple", data };
+ data = createCompositeData(SimpleInterface.class.getName(), SimpleInterface.KEYS, SimpleInterface.CHANGED_VALUES);
+ Object[] changedValues = { "Changed", data };
+ AttributeList list = new AttributeList(keys.length);
+ for (int i = 0; i < keys.length; ++i)
+ {
+ String name = getUpperName(keys[i]);
+ server.setAttribute(objectName, new Attribute(name, changedValues[i]));
+ Attribute attribute = new Attribute(name, values[i]);
+ list.add(attribute);
+ }
+ SimpleObject changed = new SimpleObject();
+ changed.setBigDecimal(SimpleInterface.bigDecimalChangedValue);
+ changed.setBigInteger(SimpleInterface.bigIntegerChangedValue);
+ changed.setBoolean(SimpleInterface.booleanChangedValue);
+ changed.setByte(SimpleInterface.byteChangedValue);
+ changed.setCharacter(SimpleInterface.characterChangedValue);
+ changed.setDate(SimpleInterface.dateChangedValue);
+ changed.setDouble(SimpleInterface.doubleChangedValue);
+ changed.setFloat(SimpleInterface.floatChangedValue);
+ changed.setInteger(SimpleInterface.integerChangedValue);
+ changed.setLong(SimpleInterface.longChangedValue);
+ changed.setObjectName(SimpleInterface.objectNameChangedValue);
+ changed.setPrimitiveBoolean(SimpleInterface.primitiveBooleanChangedValue);
+ changed.setPrimitiveByte(SimpleInterface.primitiveByteChangedValue);
+ changed.setPrimitiveChar(SimpleInterface.primitiveCharChangedValue);
+ changed.setPrimitiveDouble(SimpleInterface.primitiveDoubleChangedValue);
+ changed.setPrimitiveFloat(SimpleInterface.primitiveFloatChangedValue);
+ changed.setPrimitiveInt(SimpleInterface.primitiveIntChangedValue);
+ changed.setPrimitiveLong(SimpleInterface.primitiveLongChangedValue);
+ changed.setPrimitiveShort(SimpleInterface.primitiveShortChangedValue);
+ changed.setShort(SimpleInterface.shortChangedValue);
+ changed.setString(SimpleInterface.stringChangedValue);
+ Object[] realChangedValues = { "Changed", changed };
+ checkAttributes(server, objectName, CompositeMXBeanSupportMXBean.class, support, CompositeInterface.KEYS, CompositeInterface.TYPES, changedValues, realChangedValues, info);
+
+ setAttributes(server, objectName, list);
+ Object[] realValues = { "Simple", composite };
+ checkAttributes(server, objectName, CompositeMXBeanSupportMXBean.class, support, keys, CompositeInterface.TYPES, values, realValues, info);
+ }
+
+ public void testCompositeInvoke() throws Exception
+ {
+ MBeanServer server = createMBeanServer();
+ SimpleObject composite = new SimpleObject();
+ CompositeMXBeanSupport support = new CompositeMXBeanSupport("Simple", composite);
+ ObjectName objectName = CompositeMXBeanSupportMXBean.REGISTERED_OBJECT_NAME;
+ server.registerMBean(support, objectName);
+ composite = new SimpleObject();
+ composite.setString("hello");
+ CompositeData data = (CompositeData) MXBeanUtils.construct(MXBeanUtils.getOpenType(SimpleInterface.class), composite, getName());
+ Object actual = server.invoke(objectName, "echoReverse", new Object[] { data }, new String[] { SimpleInterface.class.getName() });
+ composite = new SimpleObject();
+ composite.setString("olleh");
+ CompositeData expected = (CompositeData) MXBeanUtils.construct(MXBeanUtils.getOpenType(SimpleInterface.class), composite, getName());
+ checkValueEquals(expected, actual);
+ }
+
+ public void testGetCollectionAttributes() throws Exception
+ {
+ MBeanServer server = createMBeanServer();
+ String[] array = { "array" };
+ Collection<String> collection = new ArrayList<String>();
+ collection.add("collection");
+ Set<String> set = new LinkedHashSet<String>();
+ set.add("set");
+ List<String> list = new ArrayList<String>();
+ list.add("list");
+ Map<String, Integer> map = new LinkedHashMap<String, Integer>();
+ map.put("map", 1);
+ TestEnum enumeration = TestEnum.FIRST;
+ CollectionsMXBeanSupport support = new CollectionsMXBeanSupport(array, collection, set, list, map, enumeration);
+ ObjectName objectName = CollectionsMXBeanSupportMXBean.REGISTERED_OBJECT_NAME;
+ server.registerMBean(support, objectName);
+ OpenMBeanInfo info = (OpenMBeanInfo) server.getMBeanInfo(objectName);
+ String[] collectionArray = collection.toArray(new String[collection.size()]);
+ String[] setArray = set.toArray(new String[set.size()]);
+ String[] listArray = list.toArray(new String[list.size()]);
+ TabularDataSupport mapData = new TabularDataSupport(TABLE_STRING_TO_INTEGER);
+ CompositeType entryType = TABLE_STRING_TO_INTEGER.getRowType();
+ mapData.put(new CompositeDataSupport(entryType, MXBeanUtils.MAP_ITEM_NAMES, new Object[] { "map", 1 }));
+
+ Object[] values = { array, collectionArray, setArray, listArray, mapData, TestEnum.FIRST.name() };
+ Object[] realValues = { array, collection, set, list, map, enumeration };
+ checkAttributes(server, objectName, CollectionsMXBeanSupportMXBean.class, support, CollectionsInterface.KEYS, CollectionsInterface.TYPES, values, realValues, info);
+ }
+
+ public void testSetCollectionAttributes() throws Exception
+ {
+ MBeanServer server = createMBeanServer();
+ String[] array = { "array" };
+ Collection<String> collection = new ArrayList<String>();
+ collection.add("collection");
+ Set<String> set = new LinkedHashSet<String>();
+ set.add("set");
+ List<String> list = new ArrayList<String>();
+ list.add("list");
+ Map<String, Integer> map = new LinkedHashMap<String, Integer>();
+ map.put("map", 1);
+ TestEnum enumeration = TestEnum.FIRST;
+ CollectionsMXBeanSupport support = new CollectionsMXBeanSupport(array, collection, set, list, map, enumeration);
+ ObjectName objectName = CollectionsMXBeanSupportMXBean.REGISTERED_OBJECT_NAME;
+ server.registerMBean(support, objectName);
+ OpenMBeanInfo info = (OpenMBeanInfo) server.getMBeanInfo(objectName);
+
+ String[] keys = CollectionsInterface.KEYS;
+ String[] collectionArray = collection.toArray(new String[collection.size()]);
+ String[] setArray = set.toArray(new String[set.size()]);
+ String[] listArray = list.toArray(new String[list.size()]);
+ TabularDataSupport mapData = new TabularDataSupport(TABLE_STRING_TO_INTEGER);
+ CompositeType entryType = TABLE_STRING_TO_INTEGER.getRowType();
+ mapData.put(new CompositeDataSupport(entryType, MXBeanUtils.MAP_ITEM_NAMES, new Object[] { "map", 1 }));
+ Object[] values = { array, collectionArray, setArray, listArray, mapData, TestEnum.FIRST.name() };
+
+ String[] changedArray = { "arrayChanged" };
+ Collection<String> changedCollection = new ArrayList<String>();
+ changedCollection.add("collectionChanged");
+ Set<String> changedSet = new LinkedHashSet<String>();
+ changedSet.add("setChanged");
+ List<String> changedList = new ArrayList<String>();
+ changedList.add("listChanged");
+
+ String[] changedCollectionArray = changedCollection.toArray(new String[changedCollection.size()]);
+ String[] changedSetArray = changedSet.toArray(new String[changedSet.size()]);
+ String[] changedListArray = changedList.toArray(new String[changedList.size()]);
+ TabularDataSupport changedMapData = new TabularDataSupport(TABLE_STRING_TO_INTEGER);
+ changedMapData.put(new CompositeDataSupport(entryType, MXBeanUtils.MAP_ITEM_NAMES, new Object[] { "mapChanged", 2 }));
+ Object[] changedValues = { changedArray, changedCollectionArray, changedSetArray, changedListArray, changedMapData, TestEnum.SECOND.name() };
+
+ AttributeList attributeList = new AttributeList(keys.length);
+ for (int i = 0; i < keys.length; ++i)
+ {
+ String name = getUpperName(keys[i]);
+ server.setAttribute(objectName, new Attribute(name, changedValues[i]));
+ Attribute attribute = new Attribute(name, values[i]);
+ attributeList.add(attribute);
+ }
+ Map<String, Integer> changedMap = new LinkedHashMap<String, Integer>();
+ changedMap.put("mapChanged", 2);
+ Object[] realChangedValues = { changedArray, changedCollection, changedSet, changedList, changedMap, TestEnum.SECOND };
+ checkAttributes(server, objectName, CollectionsMXBeanSupportMXBean.class, support, keys, CollectionsInterface.TYPES, changedValues, realChangedValues, info);
+
+ setAttributes(server, objectName, attributeList);
+ Object[] realValues = { array, collection, set, list, map, enumeration };
+ checkAttributes(server, objectName, CollectionsMXBeanSupportMXBean.class, support, keys, CollectionsInterface.TYPES, values, realValues, info);
+ }
+
+ public void testCollectionInvoke() throws Exception
+ {
+ MBeanServer server = createMBeanServer();
+ CollectionsMXBeanSupport support = new CollectionsMXBeanSupport();
+ ObjectName objectName = CompositeMXBeanSupportMXBean.REGISTERED_OBJECT_NAME;
+ server.registerMBean(support, objectName);
+ String[] list = { "one", "two", "three" };
+ String[] expected = { "three", "two", "one" };
+ Object result = server.invoke(objectName, "echoReverse", new Object[] { list }, new String[] { List.class.getName() });
+ checkArrayEquals(expected, result);
+ }
+
+ private void checkAttributes(MBeanServer server, ObjectName objectName, Class intf, Object mxbean, String[] keys, OpenType[] types, Object[] values, Object[] realValues, OpenMBeanInfo info) throws Exception
+ {
+ MBeanAttributeInfo[] attributes = info.getAttributes();
+
+ assertEquals(keys.length, values.length);
+ assertEquals(keys.length, types.length);
+ assertEquals(keys.length, attributes.length);
+
+ Map<String, OpenMBeanAttributeInfo> mapping = new HashMap<String, OpenMBeanAttributeInfo>(attributes.length);
+ for (int i = 0; i < attributes.length; ++i)
+ {
+ OpenMBeanAttributeInfo attribute = (OpenMBeanAttributeInfo) attributes[i];
+ String name = attribute.getName();
+ mapping.put(name, attribute);
+ }
+
+ String[] attributeNames = new String[keys.length];
+
+ for (int i = 0; i < keys.length; ++i)
+ {
+ String name = getUpperName(keys[i]);
+ OpenMBeanAttributeInfo attribute = mapping.get(name);
+ assertNotNull("Could not find key " + name + " in " + mapping.keySet(), attribute);
+ Object value = server.getAttribute(objectName, name);
+ checkValueEquals(values[i], value);
+ Method method = MXBeanUtils.getCompositeDataMethod(intf, keys[i], types[i] == SimpleType.BOOLEAN);
+ value = method.invoke(mxbean, null);
+ checkValueEquals(realValues[i], value);
+ assertEquals(types[i], attribute.getOpenType());
+ attributeNames[i] = name;
+ }
+
+ AttributeList list = server.getAttributes(objectName, attributeNames);
+ for (int i = 0; i < keys.length; ++i)
+ {
+ String name = attributeNames[i];
+ OpenMBeanAttributeInfo attribute = mapping.get(name);
+ Attribute attr = (Attribute) list.get(i);
+ checkValueEquals(values[i], attr.getValue());
+ assertEquals(types[i], attribute.getOpenType());
+ }
+ }
+
+ private void setAttributes(MBeanServer server, ObjectName objectName, AttributeList list) throws Exception
+ {
+ AttributeList result = server.setAttributes(objectName, list);
+ for (int i = 0; i < list.size(); ++i)
+ {
+ Attribute attribute = (Attribute) list.get(i);
+ Object expected = attribute.getValue();
+ attribute = (Attribute) result.get(i);
+ Object actual = attribute.getValue();
+ checkValueEquals(expected, actual);
+ }
+ }
+}
Added: branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/MXBeanTestSuite.java
===================================================================
--- branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/MXBeanTestSuite.java 2006-08-28 10:36:20 UTC (rev 56330)
+++ branches/MC_VDF_WORK/mbeans/src/tests/org/jboss/test/mx/mxbean/test/MXBeanTestSuite.java 2006-08-28 11:33:35 UTC (rev 56331)
@@ -0,0 +1,70 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.mx.mxbean.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ * MXBean Test Suite.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 37459 $
+ */
+public class MXBeanTestSuite extends TestSuite
+{
+ public static void main(String[] args)
+ {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("MXBean Tests");
+
+ suite.addTest(CompositeDataInvocationHandlerUnitTestCase.suite());
+ suite.addTest(CompositeTypeMetaDataFactoryUnitTestCase.suite());
+ suite.addTest(CompositeDataBigDecimalUnitTestCase.suite());
+ suite.addTest(CompositeDataBigIntegerUnitTestCase.suite());
+ suite.addTest(CompositeDataBooleanUnitTestCase.suite());
+ suite.addTest(CompositeDataByteUnitTestCase.suite());
+ suite.addTest(CompositeDataCharacterUnitTestCase.suite());
+ suite.addTest(CompositeDataDateUnitTestCase.suite());
+ suite.addTest(CompositeDataDoubleUnitTestCase.suite());
+ suite.addTest(CompositeDataFloatUnitTestCase.suite());
+ suite.addTest(CompositeDataIntegerUnitTestCase.suite());
+ suite.addTest(CompositeDataLongUnitTestCase.suite());
+ suite.addTest(CompositeDataObjectNameUnitTestCase.suite());
+ suite.addTest(CompositeDataShortUnitTestCase.suite());
+ suite.addTest(CompositeDataStringUnitTestCase.suite());
+ suite.addTest(CompositeDataEnumUnitTestCase.suite());
+ suite.addTest(CompositeDataArrayUnitTestCase.suite());
+ suite.addTest(CompositeDataCollectionUnitTestCase.suite());
+ suite.addTest(CompositeDataMapUnitTestCase.suite());
+ suite.addTest(CompositeDataCompositeUnitTestCase.suite());
+ suite.addTest(MXBeanSupportUnitTestCase.suite());
+ suite.addTest(MXBeanInvocationHandlerUnitTestCase.suite());
+
+ return suite;
+ }
+}
More information about the jboss-cvs-commits
mailing list