See attached a diff for both issues. 

Thanks,
dims

PS: Shall i commit it? 

--- Davanum Srinivas <[EMAIL PROTECTED]> wrote:
> Craig,
> 
> If i hear you right...If the Java class is a well behaved JavaBean then we should 
> not need a
> mbeans-descriptor.xml. Right? That was exactly my point :) I want to use modeler in 
> axis and was
> wondering if i really needed the mbeans-descriptor.xml files. 
> 
> Of course if the tool can generate a sample mbeans-descriptor.xml given a set of 
> java classes
> then
> folks can edit it to their hearts content.
> 
> BTW, can someone commit my patch? or shall i go ahead and commit them? (fixes for 
> both JavaBean
> params and extend the list of supported types to include everything mentioned in the 
> "open
> mbeans"
> spec)
> 
> -- dims
> 
> --- "Craig R. McClanahan" <[EMAIL PROTECTED]> wrote:
> > 
> > 
> > On Mon, 21 Jul 2003, Costin Manolache wrote:
> > 
> > > Date: Mon, 21 Jul 2003 22:28:45 -0700 (PDT)
> > > From: Costin Manolache <[EMAIL PROTECTED]>
> > > Reply-To: Jakarta Commons Developers List <[EMAIL PROTECTED]>
> > > To: Davanum Srinivas <[EMAIL PROTECTED]>
> > > Cc: [EMAIL PROTECTED]
> > > Subject: Re: [modeler] Introspection only for primitives?
> > >
> > > On Mon, 21 Jul 2003, Davanum Srinivas wrote:
> > >
> > > > 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?)
> > >
> > > It's not difficult to add more data types. We added mostly commont types -
> > > I think we should cover at least the types in "open mbeans" part of the
> > > spec.
> > >
> > > We could also add a generic mechanism to allow pluggable types ( i.e. to
> > > add more types to the list of supportedTypes ).
> > >
> > >
> > > > #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)
> > >
> > > Sure - if it doesn't complicates things too much.
> > >
> > > BTW, one of the reason we have the "supportedTypes" is to avoid
> > > introspection extracting too much stuff.
> > >
> > 
> > If you're using tools that rely on standard JavaBeans introspection, the
> > classic mechanism to hide things you don't want seen is BeanInfo.
> > 
> > Of course, the ultimate end of this whole line of "I have to parse my own
> > configuration files" is that you are going to basically re-invent what
> > Digester already does, and does well, but do it in a context that is local
> > to commons-modeler.  Tell me again why depending on something that already
> > works is such a bad thing :-).
> > 
> > >
> > > Costin
> > 
> > Craig
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > 
> 
> 
> =====
> Davanum Srinivas - http://webservices.apache.org/~dims/
> 
> __________________________________
> Do you Yahoo!?
> The New Yahoo! Search - Faster. Easier. Bingo.
> http://search.yahoo.com
> 

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

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.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   22 Jul 2003 12:42:31 -0000
@@ -1,14 +1,5 @@
 package org.apache.commons.modeler.modules;
 
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.List;
-
-import javax.management.ObjectName;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.commons.modeler.AttributeInfo;
@@ -17,6 +8,17 @@
 import org.apache.commons.modeler.ParameterInfo;
 import org.apache.commons.modeler.Registry;
 
+import javax.management.ObjectName;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Arrays;
+import java.math.BigInteger;
+import java.math.BigDecimal;
+
 
 public class MbeansDescriptorsIntrospectionSource extends ModelerSource
 {
@@ -88,19 +90,84 @@
     private static ObjectName objNameArray[]=new ObjectName[0];
     // createMBean == registerClass + registerMBean
 
+    private static Class[] supportedTypes  = new Class[] {
+        Boolean.class,
+        Boolean.TYPE,
+        Byte.class,
+        Byte.TYPE,
+        Character.class,
+        Character.TYPE,
+        Short.class,
+        Short.TYPE,
+        Integer.class,
+        Integer.TYPE,
+        Long.class,
+        Long.TYPE,
+        Float.class, 
+        Float.TYPE,
+        Double.class,
+        Double.TYPE,
+        String.class,
+        strArray.getClass(),
+        BigDecimal.class,
+        BigInteger.class,
+        ObjectName.class,
+        objNameArray.getClass(),
+        java.io.File.class,
+    };
+    
+    /**
+     * Check if this class is one of the supported types.
+     * @param ret
+     * @return true if the class is a supported type.
+     */ 
     private boolean supportedType( Class ret ) {
-        return ret == String.class ||
-                ret == Integer.class ||
-                ret == Integer.TYPE ||
-                ret == Long.class ||
-                ret == Long.TYPE ||
-                ret == java.io.File.class ||
-                ret == Boolean.class ||
-                ret == Boolean.TYPE ||
-                ret == strArray.getClass() || 
-                ret == ObjectName.class  ||
-                ret == objNameArray.getClass()
-            ;
+        for (int i = 0; i < supportedTypes.length; i++) {
+            if (ret == supportedTypes[i]) {
+                return true;
+            }
+        }
+        if (isBeanCompatible(ret)) {
+            return true;
+        }
+        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