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/03/04 19:27:23 UTC
cvs commit: jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore TestEnhancer.java
baliuka 02/03/04 10:27:23
Modified: simplestore/src/java/org/apache/commons/simplestore/tools
Enhancer.java
Added: simplestore/src/test/org/apache/commons/simplestore
TestEnhancer.java
Log:
Added test for enhancer, fails at this time
Revision Changes Path
1.6 +11 -3 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Enhancer.java 4 Mar 2002 15:42:18 -0000 1.5
+++ Enhancer.java 4 Mar 2002 18:27:23 -0000 1.6
@@ -63,7 +63,7 @@
/**
*@author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
* baliuka@mwm.lt</a>
- *@version $Id: Enhancer.java,v 1.5 2002/03/04 15:42:18 baliuka Exp $
+ *@version $Id: Enhancer.java,v 1.6 2002/03/04 18:27:23 baliuka Exp $
*/
public class Enhancer implements org.apache.bcel.Constants{
@@ -85,6 +85,7 @@
static final String FIELD_NAME = "h";
static final String SOURCE_FILE = "<generated>";
static final String ENHAVCED_CLASS_SUFIX = "$$EnhancedBySimplestore$$";
+ static final String ENHAVCED_CLASS_PREFIX = "org.apache.";
private static int addAfterRef( ConstantPoolGen cp ){
return cp.addInterfaceMethodref(INTERCEPTOR_CLASS,"afterReturn",
@@ -200,6 +201,9 @@
private static JavaClass enhance( Class parentClass,Class interfaces [],java.util.HashMap methodTable ) {
String class_name = parentClass.getName() + ENHAVCED_CLASS_SUFIX;
+ if(class_name.startsWith("java")){
+ class_name = ENHAVCED_CLASS_PREFIX + class_name;
+ }
ClassGen cg = getClassGen(class_name,parentClass);
ConstantPoolGen cp = cg.getConstantPool(); // cg creates constant pool
addHandlerField(cg);
@@ -217,7 +221,9 @@
methods = interfaces[j - 1].getMethods();
}
for( int i = 0 ; i < methods.length; i++ ){
- if( ! java.lang.reflect.Modifier.isStatic(methods[i].getModifiers()) ){
+ int mod = methods[i].getModifiers();
+ if( !java.lang.reflect.Modifier.isStatic(mod) &&
+ !java.lang.reflect.Modifier.isFinal(mod) ){
methodSet.add(methods[i]);
}
@@ -494,6 +500,8 @@
return Type.FLOAT;
}else if (double.class.equals(cls)){
return Type.DOUBLE;
+ }else if (boolean.class.equals(cls)){
+ return Type.BOOLEAN;
}
}else if (cls.isArray()){
@@ -501,7 +509,7 @@
return toType(cls.getComponentType());
}else return new ObjectType(cls.getName());
- return null;
+ throw new java.lang.InternalError(cls.getName());
}
1.1 jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestEnhancer.java
Index: TestEnhancer.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache Cocoon" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.simplestore;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.commons.simplestore.tools.Enhancer;
import org.apache.commons.simplestore.tools.MethodInterceptor;
/**
*@author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
* baliuka@mwm.lt</a>
*@version $Id: TestEnhancer.java,v 1.1 2002/03/04 18:27:23 baliuka Exp $
*/
public class TestEnhancer extends TestCase {
public TestEnhancer(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestEnhancer.class);
}
public static void main(String args[]) {
String[] testCaseName = {TestEnhancer.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
public void testEnhance()throws Throwable{
//test enchance vector:
java.util.Vector vector = (java.util.Vector)Enhancer.enhance(
java.util.Vector.class,
new Class[]{TestPersistent.class},
new MethodInterceptor(){
public Object beforeInvoke( Object obj,java.lang.reflect.Method method,
Object args[] )
throws java.lang.Throwable{
System.out.println("beforeInvoke:" + method);
return null;
}
public boolean invokeSuper( Object obj,java.lang.reflect.Method method,
Object args[], Object retValFromBefore )
throws java.lang.Throwable{
System.out.println("invokeSuper:" + method);
return true;//let super to call this
}
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("afterReturn:" + method);
return retValFromSuper;//return the same as supper
}
});
vector.add("");
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>