I have posted a proposed enhancement to the javassist.reflect package, to support 
constructor interception.

The enhancement provides the following additional features:

An event is generated prior to the calling of a reflected class's super constructor.
An event is generated prior to the calling of a reflected class's constructor body.  
This event has access to the object under-construction, and can optionally bypass the 
constructor body if required (the default behaviour is to execute the constructor body.
An event is generated at the completion of the reflected class's constructor body.  
The entire body is wrapped in a try/catch block that will catch unchecked Throwables 
(RuntimeException and Error), as well as any checked Exceptions declared in the 
constructor.  The caught Throwables are available to the event along with the object 
under-construction, and by default they are re-thrown, or they can optionally remain 
caught. 

The three events are available as three new callback methods in ClassMetaobject:

public void trapBeforeSuperConstructor() throws Throwable {}
  | public boolean trapBeforeClassConstructor(Object underConstruction) throws 
Throwable {} // return false to bypass constructor body
  | public boolean trapAfterClassConstructor(Object underConstruction, Throwable 
threw) throws Throwable {} // return false to prevent re-throw

Initially I had though to attempt to wrap the constructors using 
CtNewWrappedConstructor or similar, or replicating the constructors as a static 
factory method.  This was less attractive when I considered the additional difficulty 
of actually replacing the object constructed in memory.

The main TODO is to make the constructor arguments available to the events as 
Object[].  I guess this would be fairly easy with a WrappedConstructor, but another 
construction is not what I was after.

This proposed enhancement is posted on Sourceforge for review.


View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3843615#3843615

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3843615


-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click
_______________________________________________
JBoss-Development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to