Answering my own questions :( See enclosed diff.txt that allows #2. 

Thanks,
dims

>> Costin,
>> 
>> Right now modeler just allows parameters that are listed in the supportedType 
>> method when we
use
>> introspection.
>> 
>> #1 - How difficult/easy is it to allow other data types? (Why is this list of items 
>> limited?)
>> #2 - How about other beans as parameters? (if you look at
>> test\org\apache\commons\modeler\demo\mbeans-descriptors.xml, StandardServer has 
>> addService,
>> removeService etc that take in a service as parameter)
>> 
>> Thanks,
>> dims

=====
Davanum Srinivas - http://webservices.apache.org/~dims/

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com
cvs -z9 -q diff -u -wb -i MbeansDescriptorsIntrospectionSource.java (in directory 
C:\jakarta\jakarta-commons\modeler\src\java\org\apache\commons\modeler\modules\)
Index: MbeansDescriptorsIntrospectionSource.java
===================================================================
RCS file: 
/home/cvs/jakarta-commons/modeler/src/java/org/apache/commons/modeler/modules/MbeansDescriptorsIntrospectionSource.java,v
retrieving revision 1.9
diff -d -u -b -B -w -u -w -b -i -r1.9 MbeansDescriptorsIntrospectionSource.java
--- MbeansDescriptorsIntrospectionSource.java   20 Jul 2003 07:35:12 -0000      1.9
+++ MbeansDescriptorsIntrospectionSource.java   21 Jul 2003 19:07:55 -0000
@@ -6,6 +6,8 @@
 import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.List;
+import java.util.HashMap;
+import java.util.Map;
 
 import javax.management.ObjectName;
 
@@ -89,7 +91,7 @@
     // createMBean == registerClass + registerMBean
 
     private boolean supportedType( Class ret ) {
-        return ret == String.class ||
+        if(ret == String.class ||
                 ret == Integer.class ||
                 ret == Integer.TYPE ||
                 ret == Long.class ||
@@ -99,8 +101,53 @@
                 ret == Boolean.TYPE ||
                 ret == strArray.getClass() || 
                 ret == ObjectName.class  ||
-                ret == objNameArray.getClass()
-            ;
+                ret == objNameArray.getClass()){
+            return true;
+        }
+        try {
+            if(isBeanCompatible(ret)) {
+                return true;
+            }
+        } catch (Exception e) {
+        }
+        return false;
+    }
+
+    /**
+     * Check if this class conforms to JavaBeans specifications.
+     * @param javaType
+     * @return
+     */
+    protected boolean isBeanCompatible(Class javaType) {
+        // Must be a non-primitive and non array
+        if (javaType.isArray() || javaType.isPrimitive()) {
+            return false;
+        }
+
+        // Anything in the java or javax package that
+        // does not have a defined mapping is excluded.
+        if (javaType.getName().startsWith("java.") || 
+            javaType.getName().startsWith("javax.")) {
+            return false;
+        }
+
+        try {
+            javaType.getConstructor(new Class[]{});
+        } catch (java.lang.NoSuchMethodException e) {
+            return false;
+        }
+
+        // Make sure superclass is compatible
+        Class superClass = javaType.getSuperclass();
+        if (superClass != null && 
+            superClass != java.lang.Object.class && 
+            superClass != java.lang.Exception.class && 
+            superClass != java.lang.Throwable.class) {
+            if (!isBeanCompatible(superClass)) {
+                return false;
+            }
+        }
+        return true;
     }
 
     /** Process the methods and extract 'attributes', methods, etc


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to