commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christoph Gaffga" <cgaf...@triplemind.com>
Subject [PATCH] [betwixt] Use interface dot-betwixt-file, if class is proxy
Date Fri, 29 Aug 2003 00:17:23 GMT
hi,

> > I've implemented a way to customize the serialization of EJBs through
> > dot-betwixt-files.
> > My solution looks up the dot-betwixt-file if the class to serialize is a
> > Proxy. I only changed some lines in XMLIntrospector.findByXMLDescriptor.

and here is the patch for it. I hope it finds it way into the betrixt
codebase.
I found it very usefull as it doesn't realy make sense to serialize the
proxy class (perheaps it makes sense to serialize the remote handle in some
cases).

> > - How/Where can I change behavior to use the interface-Description
instead
> > of the classes one if no dot-betwixt-file ist found?

this issue I haven't solved yet.

> 3. please don't lose enthusiasm if it takes a while for the patch to get
> committed.

Sure, but please let me know, if you reject it, and why. Or in favor of
witch solution.

> but i'm trying to be careful about the design and get it right (this
time).

Yeah, and you did a great job. I realy like, what betwix does.

regards
Christoph (cgaffga@triplemind.com)

cvs diff -u XMLIntrospector.java
Index: XMLIntrospector.java
===================================================================
RCS file:
/home/cvspublic/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/
XMLIntrospector.java,v
retrieving revision 1.23
diff -u -w -b -B -r1.23 XMLIntrospector.java
--- XMLIntrospector.java 27 Jul 2003 18:47:39 -0000 1.23
+++ XMLIntrospector.java 28 Aug 2003 23:54:45 -0000
@@ -61,6 +61,7 @@
 import java.beans.IntrospectionException;
 import java.beans.Introspector;
 import java.beans.PropertyDescriptor;
+import java.lang.reflect.Proxy;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
@@ -735,21 +736,29 @@
      * Attempt to lookup the XML descriptor for the given class using the
      * classname + ".betwixt" using the same ClassLoader used to load the
class
      * or return null if it could not be loaded
+     * If <code>aClass</code> is a Proxy use the first interface instead.
      *
      * @param aClass digester .betwixt file for this class
      * @return XMLBeanInfo digested from the .betwixt file if one can be
found.
      *         Otherwise null.
      */
     protected synchronized XMLBeanInfo findByXMLDescriptor( Class aClass )
{
+        Class showClass = aClass;
+
+        // If the class is a Proxy, use the interface
+        if ( Proxy.isProxyClass(aClass) && aClass.getInterfaces().length >
0 ) {
+            showClass = aClass.getInterfaces()[0];
+        }
+
         // trim the package name
-        String name = aClass.getName();
+        String name = showClass.getName();
         int idx = name.lastIndexOf( '.' );
         if ( idx >= 0 ) {
             name = name.substring( idx + 1 );
         }
         name += ".betwixt";

-        URL url = aClass.getResource( name );
+        URL url = showClass.getResource( name );
         if ( url != null ) {
             try {
                 String urlText = url.toString();




Mime
View raw message