You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Christoph Gaffga <cg...@triplemind.com> on 2003/08/27 23:07:42 UTC

Re: [betwixt] Use interface, if class if proxy

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.

    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 = showClass.getName();
        int idx = name.lastIndexOf( '.' );
        if ( idx >= 0 ) {
            name = name.substring( idx + 1 );
        }
        name += ".betwixt";

        URL url = showClass.getResource( name ); // Use showClass
classloader

This works fine.

I have two questions left:

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

- Is there any chance to integrate my mechanism into betwixt? Is there
anybody else also interested in such a behavior?

Any respone would be appreciated.

regards
Christoph






[PATCH] [betwixt] Use interface dot-betwixt-file, if class is proxy

Posted by Christoph Gaffga <cg...@triplemind.com>.
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();




Re: [betwixt] Use interface, if class if proxy

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
On Wednesday, August 27, 2003, at 10:07 PM, Christoph Gaffga wrote:

> 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.
>
>     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 = showClass.getName();
>         int idx = name.lastIndexOf( '.' );
>         if ( idx >= 0 ) {
>             name = name.substring( idx + 1 );
>         }
>         name += ".betwixt";
>
>         URL url = showClass.getResource( name ); // Use showClass
> classloader
>
> This works fine.
>
> I have two questions left:
>
> - How/Where can I change behavior to use the interface-Description instead
> of the classes one if no dot-betwixt-file ist found?

one way to approach this problem would be by creating a registry which 
would allow an interface class to be substituted for any class 
implementing it. this has the advantage of being generic (it allows any 
implementation of an interface to be serialized in the same form which may 
be an advantage to some users).

this should be pretty easy so i might even take a look at it myself (if no 
one beats me to it).

> - Is there any chance to integrate my mechanism into betwixt? Is there
> anybody else also interested in such a behavior?

i (for one) am quite intrigued by these ideas but i don't have a direct 
use. i believe that there's a certain level of demand amongst the cocoon 
community (it's just a pity that betwixt isn't finished yet. too little 
time :(

if you are interested in contributing to betwixt then there are a few 
things to keep in mind:

1. please read the guidelines (this saves everybody's energy)
2. please make sure you're patching CVS HEAD. betwixt has undergone 
extensive refactoring since the last release.
3. please don't lose enthusiasm if it takes a while for the patch to get 
committed. i've got a ton of code laying around on my machine (a lot of it 
from patches) which i really need to get polished off and committed but i'
m trying to be careful about the design and get it right (this time).

- robert