[donation] dynamicProxy implementation, based on BCEL

Neeme Praks <[email protected]>
Newsgroups gmane.comp.jakarta.bcel.devel
Message-ID <[email protected]>
After some digging and wrestling, I finally managed to complete first 
shot at implementing dynamic proxies with BCEL.

Attached are the sources and some patches to the existing files that I 
found useful:
* classfile/ConstantUtf8.java should not allow null reference to bytes
* classfile/Field.java sent already earlier
* classfile/Method.java sent already earlier
* generic/PUTSTATIC.java mistake in javadocs
* util/Repository.java sent already earlier

Issues:
* invocation handler is set via a public 
setInvocationHandler(InvocationHandler ih) method on a proxy. If someone 
figures out, how to pass InvocationHandler to a constructor then that 
would be even better... but AFAIK, this is not possible?
* in order to use the generator, there is currently some classloader 
magic involved... should look for ways to make this easier (if possible?)

TODO:
* implement the other three standard static methods for Proxy class:
     * getInvocationHandler(Object proxy)
     * getProxyClass(ClassLoader loader, Class[] interfaces)
     * isProxyClass(Class cl)
* javadocs everywhere
* unit tests
* probably should move some stuff from ProxyClassLoader to util/ClassLoader
* package name... right now I put it in proxy subpackage, but this is 
just a matter of preference

If someone feels like helping me out with any of the issues, feel free 
to contribute.

In order to see the generator in action, extract the archive and apply 
the patches.
Then run:
java -cp bin/classes org.apache.bcel.proxy.sample.SampleLoader

And you should see the result on your console.

While generating the proxy in debug mode, generator prints out a bunch 
of debugging information that should give some idea, what is happening 
behind the scenes.

Ok, will get some sleep now, probably will try to check up on the TODO 
list next week (short of time this week...)

Rgds,
Neeme

--
To unsubscribe, e-mail:   <mailto:[email protected]>
For additional commands, e-mail: <mailto:[email protected]>
proxy.tar.gz (application/gzip, 8 KB) - not displayed
patch.txt (text/plain, 2.3 KB)
Index: src/java/org/apache/bcel/classfile/ConstantUtf8.java
===================================================================
RCS file: /home/cvspublic/jakarta-bcel/src/java/org/apache/bcel/classfile/ConstantUtf8.java,v
retrieving revision 1.2
diff -r1.2 ConstantUtf8.java
97a98
>     if (bytes == null) throw new IllegalArgumentException("bytes cannot be null!");
Index: src/java/org/apache/bcel/classfile/Field.java
===================================================================
RCS file: /home/cvspublic/jakarta-bcel/src/java/org/apache/bcel/classfile/Field.java,v
retrieving revision 1.2
diff -r1.2 Field.java
56a57,58
> import org.apache.bcel.generic.Type;
> 
117a120,126
>   }
> 
>   /**
>    * @return return type of a method
>    */
>   public Type getType() {
>     return Type.getType(getSignature());
Index: src/java/org/apache/bcel/classfile/Method.java
===================================================================
RCS file: /home/cvspublic/jakarta-bcel/src/java/org/apache/bcel/classfile/Method.java,v
retrieving revision 1.4
diff -r1.4 Method.java
56a57,58
> import org.apache.bcel.generic.Type;
> 
164a167,180
>   /**
>    * @return return type of a method
>    */
>   public Type getReturnType() {
>     return Type.getReturnType(getSignature());
>   }
> 
>   /**
>    * @return array of method argument types
>    */
>   public Type[] getArgumentTypes() {
>     return Type.getArgumentTypes(getSignature());
>   }
>   
Index: src/java/org/apache/bcel/generic/PUTSTATIC.java
===================================================================
RCS file: /home/cvspublic/jakarta-bcel/src/java/org/apache/bcel/generic/PUTSTATIC.java,v
retrieving revision 1.1.1.1
diff -r1.1.1.1 PUTSTATIC.java
62c62
<  * <PRE>Stack: ..., objectref, value -&gt; ...</PRE>
---
>  * <PRE>Stack: ..., value -&gt; ...</PRE>
64c64
<  * <PRE>Stack: ..., objectref, value.word1, value.word2 -&gt; ...</PRE>
---
>  * <PRE>Stack: ..., value.word1, value.word2 -&gt; ...</PRE>
Index: src/java/org/apache/bcel/util/Repository.java
===================================================================
RCS file: /home/cvspublic/jakarta-bcel/src/java/org/apache/bcel/util/Repository.java,v
retrieving revision 1.4
diff -r1.4 Repository.java
62c62
<  * Repository.setRpeository method.
---
>  * Repository.setRepository method.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.