You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ba...@apache.org on 2002/04/14 21:43:46 UTC
cvs commit: jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/tools Enhancer.java MethodInterceptor.java
baliuka 02/04/14 12:43:45
Modified: simplestore/src/java/org/apache/commons/simplestore/persistence
MetaObject.java
simplestore/src/java/org/apache/commons/simplestore/tools
Enhancer.java MethodInterceptor.java
Log:
added Documentation
Revision Changes Path
1.5 +51 -1 jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/MetaObject.java
Index: MetaObject.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/MetaObject.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- MetaObject.java 20 Mar 2002 19:28:26 -0000 1.4
+++ MetaObject.java 14 Apr 2002 19:43:45 -0000 1.5
@@ -60,41 +60,91 @@
* used internaly by implementation
* @author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
* baliuka@mwm.lt</a>
- * @version $Id: MetaObject.java,v 1.4 2002/03/20 19:28:26 baliuka Exp $
+ * @version $Id: MetaObject.java,v 1.5 2002/04/14 19:43:45 baliuka Exp $
*/
public interface MetaObject extends Cloneable {
+ /** Returns OID for persistent object
+ * @return OID
+ */
public Object getOID();
+ /** Returns property value by index
+ * @param index property index
+ * @return value
+ */
public Object getProperty(int index);
+ /** modifies property value
+ * @param index property index
+ * @param value peperty value
+ */
public void setProperty(int index, Object value);
+ /** Returs managed properties, returned arry is not cloned and can be used
+ * to manipulate persistent object fields
+ * @return internal Array of values
+ */
public Object[] getProperties();
+ /** Returns managed object class
+ * @return type
+ */
public Class getPersistentClass();
+ /**
+ *
+ * @return true if object is dirty
+ */
public boolean isDirty();
+ /**
+ * @return true if object is new
+ */
public boolean isNew();
+ /**
+ * @return true if object is deleted
+ */
public boolean isDeleted();
+ /**
+ * @return true if object is clean
+ */
public boolean isClean();
+ /** Sets flag to remove object on commit
+ */
public void remove();
+ /**
+ * @return */
public boolean isLoaded();
+ /** used to set dirty flag
+ * @param dirty true if dirty
+ */
public void setDirty(boolean dirty);
+ /** Returns managed opbject
+ * @return */
public Persistent getObject();
+ /** Clones state
+ * @throws CloneNotSupportedException
+ * @return clone
+ */
public Object clone()throws CloneNotSupportedException;
+ /** copies state
+ * @param mo source
+ */
public void assign( MetaObject mo);
+ /** Returns Metaclass for managed object
+ * @return Metaclass
+ */
public MetaClass getMetaClass();
1.20 +33 -2 jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/tools/Enhancer.java
Index: Enhancer.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/tools/Enhancer.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- Enhancer.java 19 Mar 2002 15:03:57 -0000 1.19
+++ Enhancer.java 14 Apr 2002 19:43:45 -0000 1.20
@@ -102,9 +102,40 @@
import org.apache.bcel.generic.Type;
import org.apache.bcel.generic.ArrayType;
/**
- *@author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
+* this code returns Enhanced Vector to intercept all methods for tracing
+* <pre>
+* java.util.Vector vector = (java.util.Vector)Enhancer.enhance(
+* java.util.Vector.class,
+* new Class[]{java.util.List.class},
+*
+* new MethodInterceptor(){
+*
+* public Object beforeInvoke( Object obj,java.lang.reflect.Method method,
+* Object args[] )
+* throws java.lang.Throwable{
+* return null;
+* }
+*
+* public boolean invokeSuper( Object obj,java.lang.reflect.Method method,
+* Object args[], Object retValFromBefore )
+* throws java.lang.Throwable{
+* return true;
+* }
+*
+*
+* public Object afterReturn( Object obj, java.lang.reflect.Method method,
+* Object args[], Object retValFromBefore,
+* boolean invokedSuper, Object retValFromSuper,
+* java.lang.Throwable e )throws java.lang.Throwable{
+* System.out.println(method);
+* return retValFromSuper;//return the same as supper
+* }
+*
+* });
+* </pre>
+*@author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
* baliuka@mwm.lt</a>
- *@version $Id: Enhancer.java,v 1.19 2002/03/19 15:03:57 baliuka Exp $
+ *@version $Id: Enhancer.java,v 1.20 2002/04/14 19:43:45 baliuka Exp $
*/
public class Enhancer implements org.apache.bcel.Constants , Constants{
1.3 +73 -1 jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/tools/MethodInterceptor.java
Index: MethodInterceptor.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/tools/MethodInterceptor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MethodInterceptor.java 6 Mar 2002 14:00:07 -0000 1.2
+++ MethodInterceptor.java 14 Apr 2002 19:43:45 -0000 1.3
@@ -56,22 +56,94 @@
package org.apache.commons.simplestore.tools;
/**
+* Callback interface for code generated by Enhancer
+*
+* Decompiled code for java.util.Vector:
+*<pre>
+*
+*<b> package </b> org.apache.java.util;
+*
+*<b> public class </b> Vector$$EnhancedBySimplestore$$ <b> extends </b>java.util.Vector{
+*
+* <b>org.apache.commons.simplestore.tools.MethodInterceptor</b> h;
+* //...
+* <b>static java.lang.reflect.Method </b> METHOD_23 =
+* Vector.class.getMethod(<span style='color:red'>"removeElement"</span>,
+* new Class[]{Object.class}
+* );
+* //...
+*
+* <b>public boolean</b> removeElement(Object arg1){
+*
+* Object args[] = { arg1 };
+* Object retValFromBefore = h.<b>beforeInvoke</b>(this,METHOD_23,args);
+* boolean invokedSuper = false;
+* Throwable t = null;
+* Object retValFromSuper = null;
+*
+* if( h.<b>invokeSuper</b>(this,METHOD_23,args,retValFromBefore) ){
+* invokedSuper = true;
+* try{
+*
+* retValFromSuper = new Boolean( <b>super</b>.removeElement(arg1) );
+*
+* }catch(Throwable tl){
+* t = tl
+* }
+*
+* }
+*
+* return ((Boolean) h.<b>afterReturn</b>(this, METHOD_23, args,
+* retValFromBefore, invokedSuper, retValFromSuper,t )
+* ).booleanValue();
+*
+*}
+*</pre>
+
+
*@author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
* baliuka@mwm.lt</a>
- *@version $Id: MethodInterceptor.java,v 1.2 2002/03/06 14:00:07 baliuka Exp $
+ *@version $Id: MethodInterceptor.java,v 1.3 2002/04/14 19:43:45 baliuka Exp $
*/
public interface MethodInterceptor {
+ /** Generated code calls this method first
+ * @param obj this
+ * @param method Intercepted method
+ * @param args Arg array
+ * @throws Throwable any exeption to stop execution
+ * @return returned value used as parameter for all
+ * interceptor methods
+ */
public Object beforeInvoke( Object obj,
java.lang.reflect.Method method,
Object args[] )throws java.lang.Throwable;
+ /** Generated code calls this method before invoking super
+ * @param obj this
+ * @param method Method
+ * @param args Arg array
+ * @param retValFromBefore value returned from beforeInvoke
+ * @throws Throwable any exeption to stop execution
+ * @return true if need to invoke super
+ */
public boolean invokeSuper( Object obj,
java.lang.reflect.Method method,
Object args[],
Object retValFromBefore )
throws java.lang.Throwable;
+ /** this method is invoked after execution
+ * @param obj this
+ * @param method Method
+ * @param args Arg array
+ * @param retValFromBefore value returned from beforeInvoke
+ * @param invokedSuper value returned from invoke super
+ * @param retValFromSuper value returner from super
+ * @param e Exception thrown by super
+ * @throws Throwable any exeption
+ * @return value to return from generated method
+ */
public Object afterReturn( Object obj,
java.lang.reflect.Method method,
Object args[],
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>