[jboss-svn-commits] JBL Code SVN: r20243 - in labs/jbossrules/trunk/drools-core/src: main/java/org/drools/base and 11 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sat May 31 11:30:16 EDT 2008
Author: mark.proctor at jboss.com
Date: 2008-05-31 11:30:15 -0400 (Sat, 31 May 2008)
New Revision: 20243
Removed:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ShadowProxyFactory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ShadowProxyHelper.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/objenesis/
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/ObjenesisFactory.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/ShadowProxyFactoryTest.java
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/QueryResult.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ShadowProxy.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultFactHandle.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/EqualityAssertMapComparator.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/IdentityAssertMapComparator.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalFactHandle.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalRuleBase.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/NamedEntryPoint.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/ObjectTypeConfigurationRegistry.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/SingleThreadedObjectStore.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/OutputMarshaller.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ClassObjectTypeConf.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EntryPointNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeConf.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Declaration.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/PatternExtractor.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/JavaIteratorAdapter.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/RuleBaseConfigurationTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/event/AgendaEventSupportTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ObjectTypeNodeTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/OtherwiseTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/FieldConstraintTest.java
Log:
JBRULES-1627 Remove Shadow Proxies
-Shadow proxies are now mostly removed except for the evaluators. The accumulate integration tests are bust for some reason.
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/QueryResult.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/QueryResult.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/QueryResult.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -111,11 +111,6 @@
* @return
*/
private Object getObject(FactHandle factHandle) {
- InternalFactHandle handle = ( InternalFactHandle ) factHandle;
- if ( handle.isShadowFact() ) {
- return ((ShadowProxy) handle.getObject()).getShadowedObject();
- } else {
- return handle.getObject();
- }
+ return (( InternalFactHandle ) factHandle).getObject();
}
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -69,8 +69,6 @@
/**
* drools.maintainTms = <true|false>
- * drools.shadowproxy = <true|false> // sequentail=true always overrides setting this to false
- * drools.shadowproxy.exclude = org.domainy.* org.domainx.ClassZ
* drools.sequential = <true|false>
* drools.sequential.agenda = <sequential|dynamic>
* drools.removeIdentities = <true|false>
@@ -119,10 +117,6 @@
private ConflictResolver conflictResolver;
- private boolean shadowProxy;
- private Map shadowProxyExcludes;
- private boolean useStaticObjenesis;
-
private static final String STAR = "*";
private ContextInstanceFactoryRegistry processContextInstanceFactoryRegistry;
private Map<String, WorkDefinition> workDefinitions;
@@ -151,8 +145,6 @@
out.writeObject( consequenceExceptionHandler );
out.writeObject( ruleBaseUpdateHandler );
out.writeObject( conflictResolver );
- out.writeBoolean( shadowProxy );
- out.writeObject( shadowProxyExcludes );
out.writeObject( processNodeInstanceFactoryRegistry );
}
@@ -176,8 +168,6 @@
consequenceExceptionHandler = (ConsequenceExceptionHandler) in.readObject();
ruleBaseUpdateHandler = (String) in.readObject();
conflictResolver = (ConflictResolver) in.readObject();
- shadowProxy = in.readBoolean();
- shadowProxyExcludes = (Map) in.readObject();
processNodeInstanceFactoryRegistry = (NodeInstanceFactoryRegistry) in.readObject();
}
@@ -298,16 +288,6 @@
setConflictResolver( RuleBaseConfiguration.determineConflictResolver( this.chainedProperties.getProperty( "drools.conflictResolver",
"org.drools.conflict.DepthConflictResolver" ) ) );
-
- // sequential mode always overrides and sets this to false
- setShadowProxy( determineShadowProxy( this.chainedProperties.getProperty( "drools.shadowproxy",
- "true" ) ) );
-
- setShadowProxyExcludes( this.chainedProperties.getProperty( "drools.shadowProxyExcludes",
- "" ) );
-
- setUseStaticObjenesis( Boolean.valueOf( this.chainedProperties.getProperty( "drools.useStaticObjenesis",
- "false" ) ).booleanValue() );
}
/**
@@ -743,24 +723,6 @@
return this.conflictResolver;
}
- public void setShadowProxy(boolean shadowProxy) {
- checkCanChange(); // throws an exception if a change isn't possible;
- this.shadowProxy = shadowProxy;
- }
-
- public boolean isShadowProxy() {
- return this.shadowProxy;
- }
-
- public boolean isUseStaticObjenesis() {
- return useStaticObjenesis;
- }
-
- public void setUseStaticObjenesis(boolean useStaticObjenesis) {
- checkCanChange(); // throws an exception if a change isn't possible;
- this.useStaticObjenesis = useStaticObjenesis;
- }
-
public ClassLoader getClassLoader() {
return classLoader;
}
@@ -769,57 +731,6 @@
this.classLoader = classLoader;
}
- public void setShadowProxyExcludes(String excludes) {
- checkCanChange(); // throws an exception if a change isn't possible;
- if ( excludes == null || "".equals( excludes.trim() ) ) {
- return;
- }
-
- if ( this.shadowProxyExcludes == null ) {
- this.shadowProxyExcludes = new HashMap();
- }
-
- ClassUtils.addImportStylePatterns( this.shadowProxyExcludes, excludes );
-
-// String[] items = excludes.split( " " );
-// for ( int i = 0; i < items.length; i++ ) {
-// String qualifiedNamespace = items[i].substring( 0,
-// items[i].lastIndexOf( '.' ) ).trim();
-// String name = items[i].substring( items[i].lastIndexOf( '.' ) + 1 ).trim();
-// Object object = this.shadowProxyExcludes.get( qualifiedNamespace );
-// if ( object == null ) {
-// if ( STAR.equals( name ) ) {
-// this.shadowProxyExcludes.put( qualifiedNamespace,
-// STAR );
-// } else {
-// // create a new list and add it
-// List list = new ArrayList();
-// list.add( name );
-// this.shadowProxyExcludes.put( qualifiedNamespace,
-// list );
-// }
-// } else if ( name.equals( STAR ) ) {
-// // if its a STAR now add it anyway, we don't care if it was a STAR or a List before
-// this.shadowProxyExcludes.put( qualifiedNamespace,
-// STAR );
-// } else {
-// // its a list so add it if it doesn't already exist
-// List list = (List) object;
-// if ( !list.contains( object ) ) {
-// list.add( name );
-// }
-// }
-// }
- }
-
- public boolean isShadowed(String className) {
- if ( this.shadowProxyExcludes == null ) {
- return true;
- }
-
- return ClassUtils.isMatched( this.shadowProxyExcludes, className );
- }
-
private static ConsequenceExceptionHandler determineConsequenceExceptionHandler(String className) {
return (ConsequenceExceptionHandler) instantiateClass( "ConsequenceExceptionHandler",
className );
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ShadowProxy.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ShadowProxy.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ShadowProxy.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -23,8 +23,4 @@
public void updateProxy();
- public Object getShadowedObject();
-
- public void setShadowedObject(Object object);
-
}
Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ShadowProxyFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ShadowProxyFactory.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ShadowProxyFactory.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -1,1374 +0,0 @@
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.drools.base;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.security.ProtectionDomain;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.drools.RuntimeDroolsException;
-import org.drools.asm.ClassWriter;
-import org.drools.asm.FieldVisitor;
-import org.drools.asm.Label;
-import org.drools.asm.MethodVisitor;
-import org.drools.asm.Opcodes;
-import org.drools.asm.Type;
-import org.drools.util.ShadowProxyUtils;
-
-/**
- * A factory for ShadowProxy classes
- */
-public class ShadowProxyFactory {
- private static final String UPDATE_PROXY = "updateProxy";
- private static final String SET_SHADOWED_OBJECT = "setShadowedObject";
- private static final String GET_SHADOWED_OBJECT = "getShadowedObject";
-
- private static final String BASE_INTERFACE = Type.getInternalName( ShadowProxy.class );
-
- //private static final String FIELD_NAME_PREFIX = "__";
-
- public static final String FIELD_SET_FLAG = "IsSet";
-
- public static final String DELEGATE_FIELD_NAME = "delegate";
-
- public static final String HASHCACHE_FIELD_NAME = "__hashCache";
-
- private static final ProtectionDomain PROTECTION_DOMAIN;
-
- static {
- PROTECTION_DOMAIN = (ProtectionDomain) AccessController.doPrivileged( new PrivilegedAction() {
- public Object run() {
- return ShadowProxyFactory.class.getProtectionDomain();
- }
- } );
- }
-
- public static Class getProxy(final Class clazz) {
- try {
- if ( !isPossibleToGenerateTheProxyFor( clazz ) ) {
- return null;
- }
-
- final String className = getInternalProxyClassNameForClass( clazz );
- // generating byte array to create target class
- final byte[] bytes = dump( clazz,
- className );
- // use bytes to get a class
- final ByteArrayClassLoader classLoader = new ByteArrayClassLoader( Thread.currentThread().getContextClassLoader() );
- final Class newClass = classLoader.defineClass( className.replace( '/',
- '.' ),
- bytes,
- PROTECTION_DOMAIN );
- return newClass;
- } catch ( final Exception e ) {
- throw new RuntimeDroolsException( e );
- }
- }
-
- public static byte[] getProxyBytes(final Class clazz) {
- try {
- if ( !isPossibleToGenerateTheProxyFor( clazz ) ) {
- return null;
- }
-
- final String className = getInternalProxyClassNameForClass( clazz );
- // generating byte array to create target class
- final byte[] bytes = dump( clazz,
- className );
- return bytes;
- } catch ( final Exception e ) {
- throw new RuntimeDroolsException( e );
- }
- }
-
- protected static boolean isPossibleToGenerateTheProxyFor(final Class clazz) throws Exception {
- if ( (clazz.getModifiers() & Modifier.FINAL) != 0 ) {
- return false;
- }
- try {
- Method equals = clazz.getMethod( "equals",
- new Class[]{Object.class} );
- if ( Modifier.isFinal( equals.getModifiers() ) ) {
- return false;
- }
- } catch ( NoSuchMethodException e ) {
- // that's fine
- }
- try {
- Method hashcode = clazz.getMethod( "hashCode",
- new Class[0] );
- if ( Modifier.isFinal( hashcode.getModifiers() ) ) {
- return false;
- }
- } catch ( NoSuchMethodException e ) {
- // that's fine
- }
- return true;
- }
-
- /**
- * @param clazz
- * @return
- */
- public static String getInternalProxyClassNameForClass(final Class clazz) {
- String className = null;
- if ( clazz.getPackage() != null && (clazz.getPackage().getName().startsWith( "java." ) || clazz.getPackage().getName().startsWith( "javax." )) ) {
- className = "org/drools/shadow/" + Type.getInternalName( clazz ) + "ShadowProxy";
- } else {
- className = Type.getInternalName( clazz ) + "ShadowProxy";
- }
- return className;
- }
-
- public static String getProxyClassNameForClass(final Class clazz) {
- String className = null;
- Package pkg = clazz.getPackage();
- if ( pkg != null && (pkg.getName().startsWith( "java." ) || pkg.getName().startsWith( "javax." )) ) {
- className = "org.drools.shadow." + clazz.getName() + "ShadowProxy";
- } else {
- className = clazz.getName() + "ShadowProxy";
- }
- return className;
- }
-
- protected static byte[] dump(final Class clazz,
- final String className) throws Exception {
-
- final ClassWriter cw = new ClassWriter( true );
-
- buildClassHeader( clazz,
- className,
- cw );
-
- buildConstructor( clazz,
- className,
- cw );
-
- buildField( ShadowProxyFactory.DELEGATE_FIELD_NAME,
- Type.getDescriptor( clazz ),
- cw );
-
- final Method getShadowed = ShadowProxy.class.getDeclaredMethod( GET_SHADOWED_OBJECT,
- new Class[]{} );
- final Method setShadowed = ShadowProxy.class.getDeclaredMethod( SET_SHADOWED_OBJECT,
- new Class[]{Object.class} );
- buildSimpleGetMethod( ShadowProxyFactory.DELEGATE_FIELD_NAME,
- clazz,
- getShadowed,
- className,
- clazz,
- cw );
-
- buildSetShadowedObject( clazz,
- className,
- setShadowed,
- cw );
-
- if ( Collection.class.isAssignableFrom( clazz ) ) {
- buildCollectionClass( clazz,
- className,
- cw );
- } else if ( Map.class.isAssignableFrom( clazz ) ) {
- buildMapClass( clazz,
- className,
- cw );
- } else {
- buildRegularClass( clazz,
- className,
- cw );
- }
-
- return cw.toByteArray();
- }
-
- private static void buildCollectionClass(final Class clazz,
- final String className,
- final ClassWriter cw) {
-
- buildCollectionUpdateProxyMethod( clazz,
- className,
- cw );
-
- }
-
- private static void buildMapClass(final Class clazz,
- final String className,
- final ClassWriter cw) {
-
- buildMapUpdateProxyMethod( clazz,
- className,
- cw );
-
- }
-
- private static void buildRegularClass(final Class clazz,
- final String className,
- final ClassWriter cw) {
- final Map fieldTypes = new HashMap();
- final Method[] methods = getMethods( clazz );
- for ( int i = 0; i < methods.length; i++ ) {
- if ( (!Modifier.isFinal( methods[i].getModifiers() )) && Modifier.isPublic( methods[i].getModifiers() ) && (!Modifier.isStatic( methods[i].getModifiers() )) ) {
- if ( (!methods[i].getReturnType().equals( Void.TYPE )) && (methods[i].getParameterTypes().length == 0) && (!methods[i].getName().equals( "hashCode" )) && (!methods[i].getName().equals( "toString" )) ) {
-
- final String fieldName = methods[i].getName();
-
- buildField( fieldName,
- Type.getDescriptor( methods[i].getReturnType() ),
- cw );
- fieldTypes.put( fieldName,
- methods[i] );
-
- buildField( fieldName + ShadowProxyFactory.FIELD_SET_FLAG,
- Type.BOOLEAN_TYPE.getDescriptor(),
- cw );
- buildGetMethod( fieldName,
- methods[i].getReturnType(),
- fieldName + ShadowProxyFactory.FIELD_SET_FLAG,
- methods[i],
- className,
- clazz,
- cw );
- } else if ( (!methods[i].getName().equals( "hashCode" )) && (!methods[i].getName().equals( "equals" )) ) {
- buildDelegateMethod( methods[i],
- clazz,
- className,
- cw );
- }
- }
- }
-
- buildUpdateProxyMethod( fieldTypes,
- className,
- cw );
-
- buildEquals( cw,
- className,
- clazz,
- fieldTypes );
-
- buildField( ShadowProxyFactory.HASHCACHE_FIELD_NAME,
- Type.getDescriptor( int.class ),
- cw );
-
- buildHashCode( cw,
- className,
- clazz,
- fieldTypes );
- }
-
- /**
- * Filter out any method we are not interested in
- * @param clazz
- * @return
- */
- private static Method[] getMethods(final Class clazz) {
- // to help filtering process, we will create a map of maps:
- // Map< String methodName, Map< Class[] parameterTypes, Method method > >
- final Map map = new HashMap();
- final List helperList = new ArrayList();
- final Method[] methods = clazz.getMethods();
- for ( int i = 0; i < methods.length; i++ ) {
- Method previous = null;
- Map signatures = (Map) map.get( methods[i].getName() );
- final ParametersWrapper key = new ParametersWrapper( methods[i].getParameterTypes() );
- if ( signatures != null ) {
- previous = (Method) signatures.get( key );
- }
- // if no previous method with the same name and parameter types is found
- // or if the previous method's return type is a super class of the
- // current method's return type, add current to the map
- // overriding previous if it exists
- if ( (previous == null) || (previous.getReturnType().isAssignableFrom( methods[i].getReturnType() )) ) {
- if ( signatures == null ) {
- signatures = new HashMap();
- map.put( methods[i].getName(),
- signatures );
- }
- if ( signatures.put( key,
- methods[i] ) != null ) {
- helperList.remove( previous );
- }
- helperList.add( methods[i] );
- }
- }
- return (Method[]) helperList.toArray( new Method[helperList.size()] );
- }
-
- private static class ParametersWrapper {
- private Class[] parameters;
-
- public ParametersWrapper(final Class[] parameters) {
- this.parameters = parameters;
- }
-
- public int hashCode() {
- return this.parameters.length;
- }
-
- public boolean equals(final Object o) {
- if ( !(o instanceof ParametersWrapper) ) {
- return false;
- }
- final ParametersWrapper other = (ParametersWrapper) o;
-
- if ( this.parameters.length != other.parameters.length ) {
- return false;
- }
-
- for ( int i = 0; i < this.parameters.length; i++ ) {
- if ( !this.parameters[i].equals( other.parameters[i] ) ) {
- return false;
- }
- }
- return true;
- }
- }
-
- /**
- * Builds the shadow proxy class header
- *
- * @param clazz The class to build shadow proxy for
- * @param className The shadow proxy class name
- * @param cw
- */
- protected static void buildClassHeader(final Class clazz,
- final String className,
- final ClassWriter cw) {
- if ( clazz.isInterface() ) {
- cw.visit( Opcodes.V1_5,
- Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER,
- className,
- null,
- Type.getInternalName( Object.class ),
- new String[]{ShadowProxyFactory.BASE_INTERFACE, Type.getInternalName( clazz )} );
- } else {
- cw.visit( Opcodes.V1_5,
- Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER,
- className,
- null,
- Type.getInternalName( clazz ),
- new String[]{ShadowProxyFactory.BASE_INTERFACE} );
- }
-
- cw.visitSource( null,
- null );
- }
-
- /**
- * Creates the field defined by the given FieldDefinition
- *
- * @param cw
- * @param fieldDef
- */
- protected static void buildField(final String name,
- final String type,
- final ClassWriter cw) {
- FieldVisitor fv;
- fv = cw.visitField( Opcodes.ACC_PRIVATE,
- name,
- type,
- null,
- null );
- fv.visitEnd();
- }
-
- /**
- * Creates a constructor for the shadow proxy receiving
- * the actual delegate class as parameter
- *
- * @param originalClassName
- * @param className
- * @param cw
- */
- private static void buildConstructor(final Class clazz,
- final String className,
- final ClassWriter cw) {
- MethodVisitor mv;
- {
- mv = cw.visitMethod( Opcodes.ACC_PUBLIC,
- "<init>",
- Type.getMethodDescriptor( Type.VOID_TYPE,
- new Type[]{Type.getType( clazz )} ),
- null,
- null );
- mv.visitCode();
-
- // super();
- final Label l0 = new Label();
- mv.visitLabel( l0 );
- mv.visitLineNumber( 41,
- l0 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- if ( clazz.isInterface() ) {
- mv.visitMethodInsn( Opcodes.INVOKESPECIAL,
- Type.getInternalName( Object.class ),
- "<init>",
- Type.getMethodDescriptor( Type.VOID_TYPE,
- new Type[]{} ) );
- } else {
- mv.visitMethodInsn( Opcodes.INVOKESPECIAL,
- Type.getInternalName( clazz ),
- "<init>",
- Type.getMethodDescriptor( Type.VOID_TYPE,
- new Type[]{} ) );
- }
-
- // this.delegate = delegate
- final Label l1 = new Label();
- mv.visitLabel( l1 );
- mv.visitLineNumber( 42,
- l1 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 1 );
- mv.visitFieldInsn( Opcodes.PUTFIELD,
- className,
- ShadowProxyFactory.DELEGATE_FIELD_NAME,
- Type.getDescriptor( clazz ) );
-
- // return
- final Label l2 = new Label();
- mv.visitLabel( l2 );
- mv.visitLineNumber( 43,
- l2 );
- mv.visitInsn( Opcodes.RETURN );
-
- final Label l3 = new Label();
- mv.visitLabel( l3 );
- mv.visitLocalVariable( "this",
- "L" + className + ";",
- null,
- l0,
- l3,
- 0 );
- mv.visitLocalVariable( ShadowProxyFactory.DELEGATE_FIELD_NAME,
- Type.getDescriptor( clazz ),
- null,
- l0,
- l3,
- 1 );
- mv.visitMaxs( 0,
- 0 );
- mv.visitEnd();
- }
- }
-
- /**
- * Creates the proxy reader method for the given method
- *
- * @param fieldName
- * @param fieldFlag
- * @param method
- * @param cw
- */
- protected static void buildGetMethod(final String fieldName,
- final Class fieldType,
- final String fieldFlag,
- final Method method,
- final String className,
- final Class clazz,
- final ClassWriter cw) {
- // method signature
- final Class[] exceptionTypes = method.getExceptionTypes();
- final String[] exceptions = getExceptionArrayAsString( exceptionTypes );
- final MethodVisitor mv = cw.visitMethod( Opcodes.ACC_PUBLIC,
- method.getName(),
- Type.getMethodDescriptor( method ),
- null,
- exceptions );
- mv.visitCode();
-
- // if ( ! _fieldIsSet ) {
- final Label l0 = new Label();
- mv.visitLabel( l0 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitFieldInsn( Opcodes.GETFIELD,
- className,
- fieldFlag,
- Type.BOOLEAN_TYPE.getDescriptor() );
- final Label l1 = new Label();
- mv.visitJumpInsn( Opcodes.IFNE,
- l1 );
-
- // __fieldIsSet = true;
- final Label l3 = new Label();
- mv.visitLabel( l3 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitInsn( Opcodes.ICONST_1 );
- mv.visitFieldInsn( Opcodes.PUTFIELD,
- className,
- fieldFlag,
- Type.BOOLEAN_TYPE.getDescriptor() );
-
- if ( Map.class.isAssignableFrom( fieldType ) || Collection.class.isAssignableFrom( fieldType ) || fieldType.isArray() ) {
-
- // FieldType aux = this.delegate.getField();
- Label l01 = new Label();
- mv.visitLabel( l01 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitFieldInsn( Opcodes.GETFIELD,
- className,
- DELEGATE_FIELD_NAME,
- Type.getDescriptor( clazz ) );
- if ( clazz.isInterface() ) {
- mv.visitMethodInsn( Opcodes.INVOKEINTERFACE,
- Type.getInternalName( clazz ),
- method.getName(),
- Type.getMethodDescriptor( method ) );
- } else {
- mv.visitMethodInsn( Opcodes.INVOKEVIRTUAL,
- Type.getInternalName( clazz ),
- method.getName(),
- Type.getMethodDescriptor( method ) );
- }
- mv.visitVarInsn( Opcodes.ASTORE,
- 1 );
-
- // this.field = (FieldType) ShadoProxyUtils.clone( aux );
- Label l11 = new Label();
- mv.visitLabel( l11 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 1 );
- mv.visitMethodInsn( Opcodes.INVOKESTATIC,
- Type.getInternalName( ShadowProxyUtils.class ),
- "cloneObject",
- "(Ljava/lang/Object;)Ljava/lang/Object;" );
- mv.visitTypeInsn( Opcodes.CHECKCAST,
- Type.getInternalName( fieldType ) );
- mv.visitFieldInsn( Opcodes.PUTFIELD,
- className,
- fieldName,
- Type.getDescriptor( fieldType ) );
-
- } else {
- // __field = this.delegate.method();
- final Label l2 = new Label();
- mv.visitLabel( l2 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitFieldInsn( Opcodes.GETFIELD,
- className,
- ShadowProxyFactory.DELEGATE_FIELD_NAME,
- Type.getDescriptor( clazz ) );
- if ( clazz.isInterface() ) {
- mv.visitMethodInsn( Opcodes.INVOKEINTERFACE,
- Type.getInternalName( clazz ),
- method.getName(),
- Type.getMethodDescriptor( method ) );
- } else {
- mv.visitMethodInsn( Opcodes.INVOKEVIRTUAL,
- Type.getInternalName( clazz ),
- method.getName(),
- Type.getMethodDescriptor( method ) );
- }
- mv.visitFieldInsn( Opcodes.PUTFIELD,
- className,
- fieldName,
- Type.getDescriptor( fieldType ) );
-
- }
-
- // }
- // return __field;
- mv.visitLabel( l1 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitFieldInsn( Opcodes.GETFIELD,
- className,
- fieldName,
- Type.getDescriptor( fieldType ) );
- mv.visitInsn( Type.getType( fieldType ).getOpcode( Opcodes.IRETURN ) );
-
- // local variables table
- final Label l4 = new Label();
- mv.visitLabel( l4 );
- mv.visitLocalVariable( "this",
- "L" + className + ";",
- null,
- l0,
- l4,
- 0 );
- mv.visitMaxs( 0,
- 0 );
- mv.visitEnd();
- }
-
- /**
- * Creates the proxy reader method for the given method
- *
- * @param fieldName
- * @param fieldFlag
- * @param method
- * @param cw
- */
- protected static void buildSimpleGetMethod(final String fieldName,
- final Class fieldType,
- final Method method,
- final String className,
- final Class clazz,
- final ClassWriter cw) {
-
- final Class[] exceptionTypes = method.getExceptionTypes();
- final String[] exceptions = getExceptionArrayAsString( exceptionTypes );
- // method signature
- final MethodVisitor mv = cw.visitMethod( Opcodes.ACC_PUBLIC,
- method.getName(),
- Type.getMethodDescriptor( method ),
- null,
- exceptions );
- mv.visitCode();
-
- // return __field;
- final Label l0 = new Label();
- mv.visitLabel( l0 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitFieldInsn( Opcodes.GETFIELD,
- className,
- fieldName,
- Type.getDescriptor( fieldType ) );
- mv.visitInsn( Type.getType( fieldType ).getOpcode( Opcodes.IRETURN ) );
-
- // local variables table
- final Label l4 = new Label();
- mv.visitLabel( l4 );
- mv.visitLocalVariable( "this",
- "L" + className + ";",
- null,
- l0,
- l4,
- 0 );
- mv.visitMaxs( 0,
- 0 );
- mv.visitEnd();
- }
-
- protected static void buildUpdateProxyMethod(final Map fieldTypes,
- final String className,
- final ClassWriter cw) {
- final MethodVisitor mv = cw.visitMethod( Opcodes.ACC_PUBLIC,
- ShadowProxyFactory.UPDATE_PROXY,
- Type.getMethodDescriptor( Type.VOID_TYPE,
- new Type[]{} ),
- null,
- null );
- mv.visitCode();
- final Label l0 = new Label();
- mv.visitLabel( l0 );
- for ( final Iterator it = fieldTypes.entrySet().iterator(); it.hasNext(); ) {
- final Map.Entry entry = (Map.Entry) it.next();
- final String fieldName = (String) entry.getKey();
- final String fieldFlag = fieldName + ShadowProxyFactory.FIELD_SET_FLAG;
- final Class fieldType = ((Method) entry.getValue()).getReturnType();
- final Label l1 = new Label();
- mv.visitLabel( l1 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- if ( fieldType.isPrimitive() ) {
- if ( fieldType.equals( Long.TYPE ) ) {
- mv.visitInsn( Opcodes.LCONST_0 );
- } else if ( fieldType.equals( Double.TYPE ) ) {
- mv.visitInsn( Opcodes.DCONST_0 );
- } else if ( fieldType.equals( Float.TYPE ) ) {
- mv.visitInsn( Opcodes.FCONST_0 );
- } else {
- mv.visitInsn( Opcodes.ICONST_0 );
- }
- } else {
- mv.visitInsn( Opcodes.ACONST_NULL );
- }
- mv.visitFieldInsn( Opcodes.PUTFIELD,
- className,
- fieldName,
- Type.getDescriptor( fieldType ) );
- final Label l2 = new Label();
- mv.visitLabel( l2 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitInsn( Opcodes.ICONST_0 );
- mv.visitFieldInsn( Opcodes.PUTFIELD,
- className,
- fieldFlag,
- Type.BOOLEAN_TYPE.getDescriptor() );
- }
-
- // this.__hashCache = 0;
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitInsn( Opcodes.ICONST_0 );
- mv.visitFieldInsn( Opcodes.PUTFIELD,
- className,
- ShadowProxyFactory.HASHCACHE_FIELD_NAME,
- Type.getDescriptor( int.class ) );
-
- final Label l4 = new Label();
- mv.visitLabel( l4 );
- mv.visitInsn( Opcodes.RETURN );
- final Label l5 = new Label();
- mv.visitLabel( l5 );
- mv.visitLocalVariable( "this",
- "L" + className + ";",
- null,
- l0,
- l5,
- 0 );
- mv.visitMaxs( 0,
- 0 );
- mv.visitEnd();
- }
-
- protected static void buildSetShadowedObject(final Class clazz,
- final String className,
- final Method setShadowed,
- final ClassWriter cw) {
- final MethodVisitor mv = cw.visitMethod( Opcodes.ACC_PUBLIC,
- setShadowed.getName(),
- Type.getMethodDescriptor( setShadowed ),
- null,
- null );
- mv.visitCode();
- Label l0 = new Label();
- mv.visitLabel( l0 );
- // this.delegate = (<clazz>) object;
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 1 );
- mv.visitTypeInsn( Opcodes.CHECKCAST,
- Type.getInternalName( clazz ) );
- mv.visitFieldInsn( Opcodes.PUTFIELD,
- className,
- DELEGATE_FIELD_NAME,
- Type.getDescriptor( clazz ) );
- if ( Collection.class.isAssignableFrom( clazz ) || Map.class.isAssignableFrom( clazz ) ) {
- Label l1 = new Label();
- mv.visitLabel( l1 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitMethodInsn( Opcodes.INVOKEVIRTUAL,
- className,
- UPDATE_PROXY,
- Type.getMethodDescriptor( Type.VOID_TYPE,
- new Type[0] ) );
- }
- Label l2 = new Label();
- mv.visitLabel( l2 );
- mv.visitInsn( Opcodes.RETURN );
- Label l3 = new Label();
- mv.visitLabel( l3 );
- mv.visitLocalVariable( "this",
- "L" + className + ";",
- null,
- l0,
- l3,
- 0 );
- mv.visitLocalVariable( "object",
- Type.getDescriptor( Object.class ),
- null,
- l0,
- l3,
- 1 );
- mv.visitMaxs( 0,
- 0 );
- mv.visitEnd();
- }
-
- /**
- * Creates an update proxy method for Map classes
- *
- * public void updateProxy() {
- * this.clear();
- * this.addAll( this.delegate );
- * }
- *
- * @param clazz
- * @param className
- * @param cw
- */
- protected static void buildCollectionUpdateProxyMethod(final Class clazz,
- final String className,
- final ClassWriter cw) {
- final MethodVisitor mv = cw.visitMethod( Opcodes.ACC_PUBLIC,
- ShadowProxyFactory.UPDATE_PROXY,
- Type.getMethodDescriptor( Type.VOID_TYPE,
- new Type[]{} ),
- null,
- null );
- mv.visitCode();
- final Label l0 = new Label();
- mv.visitLabel( l0 );
- // this.clear();
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitMethodInsn( Opcodes.INVOKEVIRTUAL,
- className,
- "clear",
- Type.getMethodDescriptor( Type.VOID_TYPE,
- new Type[0] ) );
- Label l1 = new Label();
- mv.visitLabel( l1 );
- // this.addAll( this.delegate );
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitFieldInsn( Opcodes.GETFIELD,
- className,
- DELEGATE_FIELD_NAME,
- Type.getDescriptor( clazz ) );
- mv.visitMethodInsn( Opcodes.INVOKEVIRTUAL,
- className,
- "addAll",
- Type.getMethodDescriptor( Type.BOOLEAN_TYPE,
- new Type[]{Type.getType( Collection.class )} ) );
- mv.visitInsn( Opcodes.POP );
- Label l2 = new Label();
- mv.visitLabel( l2 );
- mv.visitInsn( Opcodes.RETURN );
- Label l3 = new Label();
- mv.visitLabel( l3 );
- mv.visitLocalVariable( "this",
- "L" + className + ";",
- null,
- l0,
- l3,
- 0 );
- mv.visitMaxs( 0,
- 0 );
- mv.visitEnd();
- }
-
- /**
- * Creates an update proxy method for Map classes
- *
- * public void updateProxy() {
- * this.clear();
- * this.putAll( this.delegate );
- * }
- *
- * @param clazz
- * @param className
- * @param cw
- */
- protected static void buildMapUpdateProxyMethod(final Class clazz,
- final String className,
- final ClassWriter cw) {
- final MethodVisitor mv = cw.visitMethod( Opcodes.ACC_PUBLIC,
- ShadowProxyFactory.UPDATE_PROXY,
- Type.getMethodDescriptor( Type.VOID_TYPE,
- new Type[]{} ),
- null,
- null );
- mv.visitCode();
- final Label l0 = new Label();
- mv.visitLabel( l0 );
- // this.clear();
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitMethodInsn( Opcodes.INVOKEVIRTUAL,
- className,
- "clear",
- Type.getMethodDescriptor( Type.VOID_TYPE,
- new Type[0] ) );
- Label l1 = new Label();
- mv.visitLabel( l1 );
- // this.putAll( this.delegate );
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitFieldInsn( Opcodes.GETFIELD,
- className,
- DELEGATE_FIELD_NAME,
- Type.getDescriptor( clazz ) );
- mv.visitMethodInsn( Opcodes.INVOKEVIRTUAL,
- className,
- "putAll",
- Type.getMethodDescriptor( Type.VOID_TYPE,
- new Type[]{Type.getType( Map.class )} ) );
- Label l2 = new Label();
- mv.visitLabel( l2 );
- mv.visitInsn( Opcodes.RETURN );
- Label l3 = new Label();
- mv.visitLabel( l3 );
- mv.visitLocalVariable( "this",
- "L" + className + ";",
- null,
- l0,
- l3,
- 0 );
- mv.visitMaxs( 0,
- 0 );
- mv.visitEnd();
- }
-
- protected static void buildDelegateMethod(final Method method,
- final Class clazz,
- final String className,
- final ClassWriter cw) {
-
- // creating method visitor
- final String[] exceptions = getExceptionArrayAsString( method.getExceptionTypes() );
- final MethodVisitor mv = cw.visitMethod( Opcodes.ACC_PUBLIC,
- method.getName(),
- Type.getMethodDescriptor( method ),
- null,
- exceptions );
- mv.visitCode();
-
- // return this.delegate.method(...);
- final Label l0 = new Label();
- mv.visitLabel( l0 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitFieldInsn( Opcodes.GETFIELD,
- className,
- ShadowProxyFactory.DELEGATE_FIELD_NAME,
- Type.getDescriptor( clazz ) );
-
- final Class[] parameters = method.getParameterTypes();
- for ( int i = 0, offset = 1; i < parameters.length; i++ ) {
- Type type = Type.getType( parameters[i] );
- mv.visitVarInsn( type.getOpcode( Opcodes.ILOAD ),
- offset );
- offset += type.getSize();
- }
- if ( clazz.isInterface() ) {
- mv.visitMethodInsn( Opcodes.INVOKEINTERFACE,
- Type.getInternalName( clazz ),
- method.getName(),
- Type.getMethodDescriptor( method ) );
- } else {
- mv.visitMethodInsn( Opcodes.INVOKEVIRTUAL,
- Type.getInternalName( clazz ),
- method.getName(),
- Type.getMethodDescriptor( method ) );
- }
- mv.visitInsn( Type.getType( method.getReturnType() ).getOpcode( Opcodes.IRETURN ) );
- final Label l1 = new Label();
- mv.visitLabel( l1 );
- mv.visitLocalVariable( "this",
- "L" + className + ";",
- null,
- l0,
- l1,
- 0 );
- for ( int i = 0, offset = 0; i < parameters.length; i++ ) {
- mv.visitLocalVariable( "arg" + i,
- Type.getDescriptor( parameters[i] ),
- null,
- l0,
- l1,
- offset );
- offset += Type.getType( parameters[i] ).getSize();
- }
- mv.visitMaxs( 0,
- 0 );
- mv.visitEnd();
- }
-
- protected static void buildEquals(final ClassWriter cw,
- final String className,
- final Class clazz,
- final Map fieldTypes) {
- MethodVisitor mv;
- // Building equals method
- {
- mv = cw.visitMethod( Opcodes.ACC_PUBLIC,
- "equals",
- Type.getMethodDescriptor( Type.BOOLEAN_TYPE,
- new Type[]{Type.getType( Object.class )} ),
- null,
- null );
- mv.visitCode();
- final Label l0 = new Label();
- mv.visitLabel( l0 );
-
- // if ( this == object || this.delegate == object || this.delegate.equals( object ) ) {
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 1 );
- final Label l1 = new Label();
- mv.visitJumpInsn( Opcodes.IF_ACMPEQ,
- l1 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitFieldInsn( Opcodes.GETFIELD,
- className,
- DELEGATE_FIELD_NAME,
- Type.getDescriptor( clazz ) );
- mv.visitVarInsn( Opcodes.ALOAD,
- 1 );
- mv.visitJumpInsn( Opcodes.IF_ACMPEQ,
- l1 );
-
- mv.visitVarInsn(Opcodes.ALOAD, 0);
- mv.visitFieldInsn( Opcodes.GETFIELD,
- className,
- DELEGATE_FIELD_NAME,
- Type.getDescriptor( clazz ) );
- mv.visitVarInsn(Opcodes.ALOAD, 1);
- if ( clazz.isInterface() ) {
- mv.visitMethodInsn( Opcodes.INVOKEINTERFACE,
- Type.getInternalName( clazz ),
- "equals",
- Type.getMethodDescriptor( Type.BOOLEAN_TYPE,
- new Type[]{Type.getType( Object.class )} ) );
- } else {
- mv.visitMethodInsn( Opcodes.INVOKEVIRTUAL,
- Type.getInternalName( clazz ),
- "equals",
- Type.getMethodDescriptor( Type.BOOLEAN_TYPE,
- new Type[]{Type.getType( Object.class )} ) );
- }
- Label l2 = new Label();
- mv.visitJumpInsn(Opcodes.IFEQ, l2);
-
- // return true;
- mv.visitLabel( l1 );
- mv.visitInsn( Opcodes.ICONST_1 );
- mv.visitInsn( Opcodes.IRETURN );
- mv.visitLabel( l2 );
-
- // if (( object == null ) || ( ! ( object instanceof <class> ) ) )
- mv.visitVarInsn( Opcodes.ALOAD,
- 1 );
- final Label l3 = new Label();
- mv.visitJumpInsn( Opcodes.IFNULL,
- l3 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 1 );
- mv.visitTypeInsn( Opcodes.INSTANCEOF,
- Type.getInternalName( clazz ) );
- final Label l4 = new Label();
- mv.visitJumpInsn( Opcodes.IFNE,
- l4 );
-
- // return false;
- mv.visitLabel( l3 );
- mv.visitInsn( Opcodes.ICONST_0 );
- mv.visitInsn( Opcodes.IRETURN );
- mv.visitLabel( l4 );
-
- // if( object instanceof ShadowProxy &&
- // ( this.delegate == ((ShadowProxy)object).delegate ||
- // this.delegate.equals( ((ShadowProxy)object).delegate ) ) ) {
- Label c0 = new Label();
- mv.visitLabel( c0 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 1 );
- mv.visitTypeInsn( Opcodes.INSTANCEOF,
- className );
- Label c1 = new Label();
- mv.visitJumpInsn( Opcodes.IFEQ,
- c1 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitFieldInsn( Opcodes.GETFIELD,
- className,
- DELEGATE_FIELD_NAME,
- Type.getDescriptor( clazz ) );
- mv.visitVarInsn( Opcodes.ALOAD,
- 1 );
- mv.visitTypeInsn( Opcodes.CHECKCAST,
- className );
- mv.visitFieldInsn( Opcodes.GETFIELD,
- className,
- DELEGATE_FIELD_NAME,
- Type.getDescriptor( clazz ) );
- Label c2 = new Label();
- mv.visitJumpInsn( Opcodes.IF_ACMPEQ,
- c2 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitFieldInsn( Opcodes.GETFIELD,
- className,
- DELEGATE_FIELD_NAME,
- Type.getDescriptor( clazz ) );
- mv.visitVarInsn( Opcodes.ALOAD,
- 1 );
- mv.visitTypeInsn( Opcodes.CHECKCAST,
- className );
- mv.visitFieldInsn( Opcodes.GETFIELD,
- className,
- DELEGATE_FIELD_NAME,
- Type.getDescriptor( clazz ) );
- if ( clazz.isInterface() ) {
- mv.visitMethodInsn( Opcodes.INVOKEINTERFACE,
- Type.getInternalName( clazz ),
- "equals",
- Type.getMethodDescriptor( Type.BOOLEAN_TYPE,
- new Type[]{Type.getType( Object.class )} ) );
- } else {
- mv.visitMethodInsn( Opcodes.INVOKEVIRTUAL,
- Type.getInternalName( clazz ),
- "equals",
- Type.getMethodDescriptor( Type.BOOLEAN_TYPE,
- new Type[]{Type.getType( Object.class )} ) );
- }
- mv.visitJumpInsn( Opcodes.IFEQ,
- c1 );
- mv.visitLabel( c2 );
- // return true;
- mv.visitInsn( Opcodes.ICONST_1 );
- mv.visitInsn( Opcodes.IRETURN );
- // }
- mv.visitLabel( c1 );
-
-
- // return false;
- mv.visitInsn( Opcodes.ICONST_0 );
- mv.visitInsn( Opcodes.IRETURN );
- final Label lastLabel = new Label();
- mv.visitLabel( lastLabel );
-
- mv.visitLocalVariable( "this",
- "L" + className + ";",
- null,
- l0,
- lastLabel,
- 0 );
- mv.visitLocalVariable( "object",
- Type.getDescriptor( Object.class ),
- null,
- l0,
- lastLabel,
- 1 );
-
- mv.visitMaxs( 0,
- 0 );
- mv.visitEnd();
- }
- }
-
- protected static void buildCollectionEquals(final ClassWriter cw,
- final String className,
- final Class clazz) {
-
- final MethodVisitor mv = cw.visitMethod( Opcodes.ACC_PUBLIC,
- "equals",
- Type.getMethodDescriptor( Type.BOOLEAN_TYPE,
- new Type[]{Type.getType( Object.class )} ),
- null,
- null );
- // if ( this == object ) {
- Label l0 = new Label();
- mv.visitLabel( l0 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 1 );
- Label l1 = new Label();
- mv.visitJumpInsn( Opcodes.IF_ACMPNE,
- l1 );
- // return true;
- Label l2 = new Label();
- mv.visitLabel( l2 );
- mv.visitInsn( Opcodes.ICONST_1 );
- mv.visitInsn( Opcodes.IRETURN );
- // }
- mv.visitLabel( l1 );
- // return this.delegate.equals( object );
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitFieldInsn( Opcodes.GETFIELD,
- className,
- DELEGATE_FIELD_NAME,
- Type.getDescriptor( clazz ) );
- mv.visitVarInsn( Opcodes.ALOAD,
- 1 );
- if ( clazz.isInterface() ) {
- mv.visitMethodInsn( Opcodes.INVOKEINTERFACE,
- Type.getInternalName( clazz ),
- "equals",
- Type.getMethodDescriptor( Type.BOOLEAN_TYPE,
- new Type[]{Type.getType( Object.class )} ) );
- } else {
- mv.visitMethodInsn( Opcodes.INVOKEVIRTUAL,
- Type.getInternalName( clazz ),
- "equals",
- Type.getMethodDescriptor( Type.BOOLEAN_TYPE,
- new Type[]{Type.getType( Object.class )} ) );
- }
- mv.visitInsn( Opcodes.IRETURN );
- Label l3 = new Label();
- mv.visitLabel( l3 );
- mv.visitLocalVariable( "this",
- "L" + className + ";",
- null,
- l0,
- l3,
- 0 );
- mv.visitLocalVariable( "object",
- Type.getDescriptor( Object.class ),
- null,
- l0,
- l3,
- 1 );
- mv.visitMaxs( 0,
- 0 );
- mv.visitEnd();
- }
-
- /**
- * Sample of generated code for all primitive + object types
- *
- * public int hashCode() {
- * if( ___hashCache == 0 ) {
- * __hashCache = this.delegate.hashCode();
- * }
- * return this.__hashCache;
- * }
- *
- * @param cw
- * @param className
- * @param clazz
- * @param fieldTypes
- */
- protected static void buildHashCode(final ClassWriter cw,
- final String className,
- final Class clazz,
- final Map fieldTypes) {
- MethodVisitor mv;
- // Building hashcode method
- {
- mv = cw.visitMethod( Opcodes.ACC_PUBLIC,
- "hashCode",
- Type.getMethodDescriptor( Type.INT_TYPE,
- new Type[]{} ),
- null,
- null );
- mv.visitCode();
-
- // if( this.__hashCache == 0 ) {
- Label l0 = new Label();
- mv.visitLabel( l0 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitFieldInsn( Opcodes.GETFIELD,
- className,
- HASHCACHE_FIELD_NAME,
- Type.INT_TYPE.getDescriptor() );
- Label l1 = new Label();
- mv.visitJumpInsn( Opcodes.IFNE,
- l1 );
- Label l2 = new Label();
-
- // this.__hashCache = this.delegate.hashCode();
- mv.visitLabel( l2 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitFieldInsn( Opcodes.GETFIELD,
- className,
- DELEGATE_FIELD_NAME,
- Type.getDescriptor( clazz ) );
- if ( clazz.isInterface() ) {
- mv.visitMethodInsn( Opcodes.INVOKEINTERFACE,
- Type.getInternalName( clazz ),
- "hashCode",
- Type.getMethodDescriptor( Type.INT_TYPE,
- new Type[0] ) );
- } else {
- mv.visitMethodInsn( Opcodes.INVOKEVIRTUAL,
- Type.getInternalName( clazz ),
- "hashCode",
- Type.getMethodDescriptor( Type.INT_TYPE,
- new Type[0] ) );
- }
- mv.visitFieldInsn( Opcodes.PUTFIELD,
- className,
- HASHCACHE_FIELD_NAME,
- Type.INT_TYPE.getDescriptor() );
- // }
- mv.visitLabel( l1 );
-
- // return this.__hashCache;
- mv.visitVarInsn( Opcodes.ALOAD,
- 0 );
- mv.visitFieldInsn( Opcodes.GETFIELD,
- className,
- HASHCACHE_FIELD_NAME,
- Type.INT_TYPE.getDescriptor() );
- mv.visitInsn( Opcodes.IRETURN );
- Label l3 = new Label();
- mv.visitLabel( l3 );
- mv.visitLocalVariable( "this",
- "L" + className + ";",
- null,
- l0,
- l3,
- 0 );
-
- mv.visitMaxs( 0,
- 0 );
- mv.visitEnd();
- }
- }
-
- /**
- * @param exceptionTypes
- * @return
- */
- private static String[] getExceptionArrayAsString(final Class[] exceptionTypes) {
- final String[] exceptions = new String[exceptionTypes.length];
- for ( int i = 0; i < exceptions.length; i++ ) {
- exceptions[i] = Type.getInternalName( exceptionTypes[i] );
- }
- return exceptions;
- }
-
- /**
- * Simple classloader
- * @author Michael Neale
- */
- static class ByteArrayClassLoader extends ClassLoader {
- public ByteArrayClassLoader(final ClassLoader parent) {
- super( parent );
- }
-
- public Class defineClass(final String name,
- final byte[] bytes,
- final ProtectionDomain PROTECTION_DOMAIN) {
- return defineClass( name,
- bytes,
- 0,
- bytes.length,
- PROTECTION_DOMAIN );
- }
- }
-
-}
Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ShadowProxyHelper.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ShadowProxyHelper.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ShadowProxyHelper.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -1,62 +0,0 @@
-/*
- * Copyright 2006 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.drools.base;
-
-import java.lang.reflect.Field;
-
-import org.drools.RuntimeDroolsException;
-
-/**
- * A helper class with utility methods
- *
- * @author etirelli
- */
-public class ShadowProxyHelper {
-
- public static void copyState(final ShadowProxy from,
- final ShadowProxy to) {
- final Field[] fields = from.getClass().getDeclaredFields();
- for ( int i = 0; i < fields.length; i++ ) {
- if ( fields[i].getName().endsWith( ShadowProxyFactory.FIELD_SET_FLAG ) ) {
- fields[i].setAccessible( true );
- try {
- if ( fields[i].getBoolean( from ) ) {
- final String fieldName = fields[i].getName().substring( 0,
- fields[i].getName().length() - ShadowProxyFactory.FIELD_SET_FLAG.length() );
- final Field flag = to.getClass().getDeclaredField( fields[i].getName() );
- final Field fieldFrom = from.getClass().getDeclaredField( fieldName );
- final Field fieldTo = to.getClass().getDeclaredField( fieldName );
- flag.setAccessible( true );
- fieldFrom.setAccessible( true );
- fieldTo.setAccessible( true );
-
- // we know it is set
- flag.setBoolean( to,
- true );
- // copy the value from "from" shadow proxy
- fieldTo.set( to,
- fieldFrom.get( from ) );
- }
- } catch ( final Exception e ) {
- throw new RuntimeDroolsException( "Unable to copy state from one shadow proxy to another" );
- }
-
- }
- }
- }
-
-}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -41,7 +41,6 @@
import org.drools.event.RuleBaseEventListener;
import org.drools.event.RuleBaseEventSupport;
import org.drools.marshalling.Marshaller;
-import org.drools.objenesis.Objenesis;
import org.drools.process.core.Process;
import org.drools.rule.CompositePackageClassLoader;
import org.drools.rule.DialectDatas;
@@ -55,7 +54,6 @@
import org.drools.rule.TypeDeclaration;
import org.drools.spi.FactHandleFactory;
import org.drools.util.ObjectHashSet;
-import org.drools.util.ObjenesisFactory;
/**
* Implementation of <code>RuleBase</code>.
@@ -88,8 +86,6 @@
protected transient MapBackedClassLoader classLoader;
- private transient Objenesis objenesis;
-
/** The fact handle factory. */
protected FactHandleFactory factHandleFactory;
@@ -160,7 +156,6 @@
this.processes = new HashMap();
this.globals = new HashMap();
this.statefulSessions = new ObjectHashSet();
- this.objenesis = createObjenesis();
this.classTypeDeclaration = new HashMap<Class< ? >, TypeDeclaration>();
}
@@ -242,7 +237,6 @@
this.classLoader = new MapBackedClassLoader( this.packageClassLoader,
store );
this.packageClassLoader.addClassLoader( this.classLoader );
- this.objenesis = createObjenesis();
for ( final Object object : this.pkgs.values() ) {
this.packageClassLoader.addClassLoader( ((Package) object).getDialectDatas().getClassLoader() );
@@ -286,18 +280,6 @@
this.populateTypeDeclarationMaps();
}
- /**
- * Creates Objenesis instance for the RuleBase.
- * @return a standart Objenesis instanse with caching turned on.
- */
- protected Objenesis createObjenesis() {
- if ( this.config.isUseStaticObjenesis() ) {
- return ObjenesisFactory.getStaticObjenesis();
- } else {
- return ObjenesisFactory.getDefaultObjenesis();
- }
- }
-
private void populateTypeDeclarationMaps() {
this.classTypeDeclaration = new HashMap<Class< ? >, TypeDeclaration>();
for ( Package pkg : this.pkgs.values() ) {
@@ -775,10 +757,6 @@
return process;
}
- public Objenesis getObjenesis() {
- return objenesis;
- }
-
protected synchronized void addStatefulSession(final StatefulSession statefulSession) {
this.statefulSessions.add( statefulSession );
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -821,11 +821,6 @@
object );
} else {
Object oldObject = handle.getObject();
- if ( oldObject instanceof ShadowProxy ) {
- ((ShadowProxy) oldObject).setShadowedObject( object );
- } else {
- handle.setObject( object );
- }
}
return handle;
} else {
@@ -1150,7 +1145,7 @@
this.ruleBase.executeQueuedActions();
final InternalFactHandle handle = (InternalFactHandle) factHandle;
- final Object originalObject = (handle.isShadowFact()) ? ((ShadowProxy) handle.getObject()).getShadowedObject() : handle.getObject();
+ final Object originalObject = handle.getObject();
if ( this.maintainTms ) {
EqualityKey key = handle.getEqualityKey();
@@ -1235,7 +1230,7 @@
status = ((InternalFactHandle) factHandle).getEqualityKey().getStatus();
}
final InternalFactHandle handle = (InternalFactHandle) factHandle;
- final Object originalObject = (handle.isShadowFact()) ? ((ShadowProxy) handle.getObject()).getShadowedObject() : handle.getObject();
+ final Object originalObject = handle.getObject();
if ( handle.getId() == -1 || object == null ) {
// the handle is invalid, most likely already retracted, so
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultFactHandle.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultFactHandle.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DefaultFactHandle.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -46,7 +46,6 @@
private Object object;
private EqualityKey key;
private int objectHashCode;
- private boolean shadowFact;
private RightTuple rightTuple;
private LeftTuple leftTuple;
@@ -140,14 +139,6 @@
this.object = null;
}
- public boolean isShadowFact() {
- return this.shadowFact;
- }
-
- public void setShadowFact(final boolean shadowFact) {
- this.shadowFact = shadowFact;
- }
-
public Object getObject() {
return this.object;
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/EqualityAssertMapComparator.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/EqualityAssertMapComparator.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/EqualityAssertMapComparator.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -68,7 +68,7 @@
final InternalFactHandle handle = ((InternalFactHandle) o2);
- o2 = (handle.isShadowFact()) ? ((ShadowProxy) handle.getObject()).getShadowedObject() : handle.getObject();
+ o2 = handle.getObject();
return o1 == o2 || o1.equals( o2 );
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/IdentityAssertMapComparator.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/IdentityAssertMapComparator.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/IdentityAssertMapComparator.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -46,9 +46,6 @@
if ( realObject instanceof FactHandle ) {
realObject = ((InternalFactHandle) obj).getObject();
}
- if ( realObject instanceof ShadowProxy ) {
- realObject = ((ShadowProxy)realObject).getShadowedObject();
- }
return rehash( System.identityHashCode( realObject ) );
}
@@ -70,12 +67,9 @@
return ((InternalFactHandle) o1).getObject() == ((InternalFactHandle) o2).getObject();
}
Object left = o1;
- if ( left instanceof ShadowProxy ) {
- left = ((ShadowProxy)left).getShadowedObject();
- }
final InternalFactHandle handle = ((InternalFactHandle) o2);
- return left == ((handle.isShadowFact()) ? ((ShadowProxy) handle.getObject()).getShadowedObject() : handle.getObject());
+ return left == handle.getObject();
}
public int compare(final Object o1,
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalFactHandle.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalFactHandle.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalFactHandle.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -40,10 +40,6 @@
public void invalidate();
public int getObjectHashCode();
-
- public boolean isShadowFact();
-
- public void setShadowFact(boolean shadowFact);
/**
* Returns true if this FactHandle represents
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalRuleBase.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalRuleBase.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalRuleBase.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -26,7 +26,6 @@
import org.drools.StatefulSession;
import org.drools.audit.WorkingMemoryInMemoryLogger;
import org.drools.marshalling.MarshallerReaderContext;
-import org.drools.objenesis.Objenesis;
import org.drools.process.core.Process;
import org.drools.reteoo.Rete;
import org.drools.reteoo.ReteooWorkingMemory;
@@ -118,8 +117,6 @@
* @return
*/
public boolean isEvent( Class clazz );
-
- public Objenesis getObjenesis();
public int getNodeCount();
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/NamedEntryPoint.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/NamedEntryPoint.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/NamedEntryPoint.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -178,7 +178,7 @@
this.ruleBase.executeQueuedActions();
final InternalFactHandle handle = (InternalFactHandle) factHandle;
- final Object originalObject = (handle.isShadowFact()) ? ((ShadowProxy) handle.getObject()).getShadowedObject() : handle.getObject();
+ final Object originalObject = handle.getObject();
if ( handle.getId() == -1 || object == null ) {
// the handle is invalid, most likely already retracted, so
@@ -381,7 +381,7 @@
this.ruleBase.executeQueuedActions();
final InternalFactHandle handle = (InternalFactHandle) factHandle;
- final Object originalObject = (handle.isShadowFact()) ? ((ShadowProxy) handle.getObject()).getShadowedObject() : handle.getObject();
+ final Object originalObject = handle.getObject();
this.handleFactory.increaseFactHandleRecency( handle );
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/ObjectTypeConfigurationRegistry.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/ObjectTypeConfigurationRegistry.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/ObjectTypeConfigurationRegistry.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -43,11 +43,7 @@
String key = ((Fact) object).getFactTemplate().getName();
objectTypeConf = (ObjectTypeConf) this.typeConfMap.get( key );
} else {
- if ( object instanceof ShadowProxy ) {
- cls = ((ShadowProxy) object).getShadowedObject().getClass();
- } else {
- cls = object.getClass();
- }
+ cls = object.getClass();
objectTypeConf = this.typeConfMap.get( cls );
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/SingleThreadedObjectStore.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/SingleThreadedObjectStore.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/SingleThreadedObjectStore.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -88,10 +88,6 @@
Object object = internalHandle.getObject();
- if ( object != null && internalHandle.isShadowFact() ) {
- object = ((ShadowProxy) object).getShadowedObject();
- }
-
return object;
} finally {
this.lock.unlock();
@@ -118,11 +114,7 @@
public void updateHandle(InternalFactHandle handle, Object object){
this.assertMap.remove( handle );
Object oldObject = handle.getObject();
- if ( oldObject instanceof ShadowProxy ) {
- ((ShadowProxy) oldObject).setShadowedObject( object );
- } else {
- handle.setObject( object );
- }
+ handle.setObject( object );
this.assertMap.put( handle,
handle,
false );
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/OutputMarshaller.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/OutputMarshaller.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/marshalling/OutputMarshaller.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -229,9 +229,6 @@
context.out.println( handle.getObject() );
Object object = handle.getObject();
- if ( object instanceof ShadowProxy ) {
- object = ((ShadowProxy) object).getShadowedObject();
- }
PlaceholderResolverStrategy strategy = resolverStrategyFactory.getStrategy( handle.getObject() );
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ClassObjectTypeConf.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ClassObjectTypeConf.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ClassObjectTypeConf.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -32,9 +32,7 @@
import org.drools.base.ClassObjectType;
import org.drools.base.DroolsQuery;
import org.drools.base.ShadowProxy;
-import org.drools.base.ShadowProxyFactory;
import org.drools.common.InternalRuleBase;
-import org.drools.objenesis.instantiator.ObjectInstantiator;
import org.drools.reteoo.builder.BuildContext;
import org.drools.reteoo.builder.PatternBuilder;
import org.drools.rule.EntryPoint;
@@ -53,8 +51,6 @@
private ObjectTypeNode[] objectTypeNodes;
protected boolean shadowEnabled;
- protected Class<ShadowProxy> shadowClass;
- protected transient ObjectInstantiator instantiator;
private ObjectTypeNode concreteObjectTypeNode;
private EntryPoint entryPoint;
@@ -109,7 +105,6 @@
cls = (Class) stream.readObject();
objectTypeNodes = (ObjectTypeNode[]) stream.readObject();
shadowEnabled = stream.readBoolean();
- shadowClass = (Class) stream.readObject();
concreteObjectTypeNode = (ObjectTypeNode) stream.readObject();
entryPoint = (EntryPoint) stream.readObject();
defineShadowProxyData( cls );
@@ -120,7 +115,6 @@
stream.writeObject( cls );
stream.writeObject( objectTypeNodes );
stream.writeBoolean( shadowEnabled );
- stream.writeObject( shadowClass );
stream.writeObject( concreteObjectTypeNode );
stream.writeObject( entryPoint );
}
@@ -134,45 +128,8 @@
}
private void defineShadowProxyData(Class clazz) {
- Rete rete = this.ruleBase.getRete();
-
- if ( !ruleBase.getConfiguration().isShadowProxy() || clazz == null || !ruleBase.getConfiguration().isShadowed( clazz.getName() ) ) {
- this.shadowEnabled = false;
- this.shadowClass = null;
- this.instantiator = null;
- return;
- }
-
- //String pkgName = (pkg != null) ? pkg.getName() : "";
- String pkgName = getPackageName( clazz,
- clazz.getPackage() );
- if ( "org.drools.reteoo".equals( pkgName ) || "org.drools.base".equals( pkgName ) ) {
- // We don't shadow internal classes
- this.shadowEnabled = false;
- this.shadowClass = null;
- this.instantiator = null;
- return;
- }
-
- // try to generate proxy for the actual class
- Class shadowClass = loadOrGenerateProxy( clazz,
- rete );
-
- if ( shadowClass == null ) {
- // if it failed, try to find a parent class
- ObjectTypeNode[] nodes = this.getMatchingObjectTypes( clazz );
- Class shadowClassRoot = clazz;
- while ( shadowClass == null && (shadowClassRoot = this.findAFeasibleSuperclassOrInterface( nodes,
- shadowClassRoot )) != null ) {
- shadowClass = loadOrGenerateProxy( shadowClassRoot,
- rete );
- }
- }
-
- if ( shadowClass != null ) {
- this.shadowClass = shadowClass;
+ if ( ShadowProxy.class.isAssignableFrom( cls ) ) {
this.shadowEnabled = true;
- setInstantiator();
}
}
@@ -194,99 +151,6 @@
}
- private Class loadOrGenerateProxy(Class clazz,
- Rete rete) {
- Class shadowClass = null;
- final String shadowProxyName = ShadowProxyFactory.getProxyClassNameForClass( clazz );
- try {
- // if already loaded
- shadowClass = rete.getRuleBase().getMapBackedClassLoader().loadClass( shadowProxyName );
- } catch ( final ClassNotFoundException cnfe ) {
- // otherwise, create and load
- final byte[] proxyBytes = ShadowProxyFactory.getProxyBytes( clazz );
- if ( proxyBytes != null ) {
- rete.getRuleBase().getMapBackedClassLoader().addClass( shadowProxyName,
- proxyBytes );
- try {
- shadowClass = rete.getRuleBase().getMapBackedClassLoader().loadClass( shadowProxyName );
- } catch ( ClassNotFoundException e ) {
- throw new RuntimeException( "Unable to find or generate the ShadowProxy implementation for '" + clazz + "'" );
- }
- }
-
- }
- return shadowClass;
- }
-
- private Class findAFeasibleSuperclassOrInterface(ObjectTypeNode[] nodes,
- Class clazz) {
-
- // check direct superclass
- Class ret = clazz.getSuperclass();
- boolean isOk = ret != null && ret != Object.class; // we don't want to shadow java.lang.Object
- if ( isOk ) {
- for ( int i = 0; isOk && ret != null && i < nodes.length; i++ ) {
- isOk = nodes[i].getSinkPropagator().size() == 0 || nodes[i].isAssignableFrom( ret );
- }
- }
-
- if ( !isOk ) {
- // try the interfaces now...
- Class[] interfaces = clazz.getInterfaces();
- boolean notFound = true;
- isOk = interfaces.length > 0;
- for ( int i = 0; notFound && i < interfaces.length; i++ ) {
- ret = interfaces[i];
- isOk = interfaces[i] != Serializable.class && interfaces[i] != Cloneable.class && interfaces[i] != Comparable.class;
- for ( int j = 0; isOk && j < nodes.length; j++ ) {
- isOk = nodes[j].getSinkPropagator().size() == 0 || nodes[j].isAssignableFrom( ret );
- }
- notFound = !isOk;
- }
- if ( notFound ) {
- ret = null;
- }
- }
-
- // ret now contains a superclass/interface that can be shadowed or null if none
- return ret;
- }
-
- /**
- *
- */
- private void setInstantiator() {
- this.instantiator = this.ruleBase.getObjenesis().getInstantiatorOf( this.shadowClass );
- }
-
- public Object getShadow(final Object fact) throws RuntimeDroolsException {
- ShadowProxy proxy = null;
- if ( isShadowEnabled() ) {
- try {
- if ( Collection.class.isAssignableFrom( this.shadowClass ) || Map.class.isAssignableFrom( this.shadowClass ) ) {
- // if it is a collection, try to instantiate using constructor
- try {
- proxy = (ShadowProxy) this.shadowClass.getConstructor( new Class[]{cls} ).newInstance( new Object[]{fact} );
- } catch ( Exception e ) {
- // not possible to instantiate using constructor
- }
- }
- if ( proxy == null ) {
- if ( this.instantiator == null ) {
- this.setInstantiator();
- }
- proxy = (ShadowProxy) this.instantiator.newInstance();
- }
-
- proxy.setShadowedObject( fact );
- } catch ( final Exception e ) {
- throw new RuntimeDroolsException( "Error creating shadow fact for object: " + fact,
- e );
- }
- }
- return proxy;
- }
-
public boolean isShadowEnabled() {
return this.shadowEnabled;
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EntryPointNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EntryPointNode.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EntryPointNode.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -131,14 +131,9 @@
final InternalWorkingMemory workingMemory) {
// checks if shadow is enabled
if ( objectTypeConf.isShadowEnabled() ) {
- // need to improve this
- if ( !(handle.getObject() instanceof ShadowProxy) ) {
- // replaces the actual object by its shadow before propagating
- handle.setObject( objectTypeConf.getShadow( handle.getObject() ) );
- handle.setShadowFact( true );
- } else {
- ((ShadowProxy) handle.getObject()).updateProxy();
- }
+ // the user has implemented the ShadowProxy interface, let their implementation
+ // know it is safe to update the information the engine can see.
+ ((ShadowProxy) handle.getObject()).updateProxy();
}
ObjectTypeNode[] cachedNodes = objectTypeConf.getObjectTypeNodes();
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -449,9 +449,6 @@
LeftTuple entry = this;
while ( entry != null ) {
Object object = entry.getLastHandle().getObject();
- if ( object instanceof ShadowProxy ) {
- object = ((ShadowProxy) object).getShadowedObject();
- }
objects[entry.index] = object;
entry = entry.parent;
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeConf.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeConf.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeConf.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -25,8 +25,6 @@
public boolean isShadowEnabled();
- public Object getShadow(final Object fact) throws RuntimeDroolsException;
-
public ObjectTypeNode getConcreteObjectTypeNode();
public void resetCache();
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Declaration.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Declaration.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Declaration.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -228,7 +228,7 @@
Collection newCol = (Collection) result.getClass().newInstance();
for ( Iterator it = ((Collection) result).iterator(); it.hasNext(); ) {
Object element = it.next();
- newCol.add( (element instanceof ShadowProxy) ? ((ShadowProxy) element).getShadowedObject() : element );
+ newCol.add( element );
}
return newCol;
} catch ( InstantiationException e ) {
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/PatternExtractor.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/PatternExtractor.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/PatternExtractor.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -60,9 +60,7 @@
public Object getValue(InternalWorkingMemory workingMemory,
final Object object) {
- // need to use instanceof because an object may be created in nodes like accumulate and from
- // where no shadow is applied
- return (object instanceof ShadowProxy) ? ((ShadowProxy) object).getShadowedObject() : object;
+ return object;
}
public ObjectType getObjectType() {
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/JavaIteratorAdapter.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/JavaIteratorAdapter.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/JavaIteratorAdapter.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -51,9 +51,7 @@
}
if ( this.type == OBJECT ) {
- InternalFactHandle handle = (InternalFactHandle) current.getKey();
- Object object = (handle.isShadowFact()) ? ((ShadowProxy) handle.getObject()).getShadowedObject() : handle.getObject();
- return object;
+ return ((InternalFactHandle) current.getKey()).getObject();
} else {
return current.getKey();
}
@@ -68,8 +66,7 @@
break;
}
if ( this.filter != null ) {
- InternalFactHandle handle = (InternalFactHandle) entry.getKey();
- Object object = (handle.isShadowFact()) ? ((ShadowProxy) handle.getObject()).getShadowedObject() : handle.getObject();
+ Object object = ((InternalFactHandle) entry.getKey()).getObject();
if ( this.filter.accept( object ) == false ) {
entry = null;
}
Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/ObjenesisFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/ObjenesisFactory.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/ObjenesisFactory.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -1,54 +0,0 @@
-/*
- * Copyright 2008 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Created on Mar 17, 2008
- */
-package org.drools.util;
-
-import java.io.Serializable;
-
-import org.drools.objenesis.Objenesis;
-import org.drools.objenesis.ObjenesisStd;
-
-/**
- * A factory interface for Objenesis instances
- *
- * @author etirelli
- */
-public class ObjenesisFactory implements Serializable {
-
- private static final long serialVersionUID = 969174504278340793L;
- private static Objenesis OBJENESIS_INSTANCE = null;
-
- private ObjenesisFactory() {}
-
- /**
- * Returns a statically cached objenesis instance
- */
- public static Objenesis getStaticObjenesis() {
- if( OBJENESIS_INSTANCE == null ) {
- OBJENESIS_INSTANCE = new ObjenesisStd(true);
- }
- return OBJENESIS_INSTANCE;
- }
-
- /**
- * Returns a newly instantiated objenesis instance
- */
- public static Objenesis getDefaultObjenesis() {
- return new ObjenesisStd(true);
- }
-
-}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/RuleBaseConfigurationTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/RuleBaseConfigurationTest.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/RuleBaseConfigurationTest.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -42,47 +42,6 @@
System.getProperties().remove( "drools.indexLeftBetaMemory" );
}
- public void testShadowProxy() {
- // check default for rete
- RuleBaseConfiguration cfg = new RuleBaseConfiguration();
- assertTrue( cfg.isShadowProxy() );
-
- // check default for sequentail
- Properties properties = new Properties();
- properties.setProperty( "drools.sequential", "true" );
- cfg = new RuleBaseConfiguration(properties);
- assertFalse( cfg.isShadowProxy() );
-
- properties = new Properties();
- properties.setProperty( "drools.shadowproxy", "false" );
- cfg = new RuleBaseConfiguration(properties);
- assertFalse( cfg.isShadowProxy() );
-
-
- properties = new Properties();
- properties.setProperty( "drools.sequential", "true" );
- properties.setProperty( "drools.shadowproxy", "false" );
- cfg = new RuleBaseConfiguration(properties);
- assertFalse( cfg.isShadowProxy() );
- }
-
- public void testShadowProxyExcludes() {
- RuleBaseConfiguration cfg = new RuleBaseConfiguration();
-
- Properties properties = new Properties();
- properties.setProperty( "drools.shadowProxyExcludes", "java.util.List java.util.Map java.lang.reflect.*" );
-
- cfg = new RuleBaseConfiguration( properties );
-
- assertFalse( cfg.isShadowed( "java.util.List" ) );
- assertFalse( cfg.isShadowed( "java.util.Map" ) );
- assertTrue( cfg.isShadowed( "java.util.HashMap" ) );
-
- assertFalse( cfg.isShadowed( "java.lang.reflect.Method" ) );
-
- assertTrue( cfg.isShadowed( "java.lang.String" ) );
- }
-
public void testAssertBehaviour() {
Properties properties = new Properties();
properties.setProperty( "drools.assertBehaviour", "identity" );
Deleted: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/ShadowProxyFactoryTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/ShadowProxyFactoryTest.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/ShadowProxyFactoryTest.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -1,655 +0,0 @@
-package org.drools.base;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-import org.drools.Address;
-import org.drools.Cheese;
-import org.drools.CheeseEqual;
-import org.drools.CheeseInterface;
-import org.drools.Person;
-
-public class ShadowProxyFactoryTest extends TestCase {
-
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- public void testProxyForClass() {
- try {
- // creating original object
- final String originalType = "stilton";
- final int originalPrice = 15;
- final Cheese cheese = new Cheese( originalType,
- originalPrice );
-
- // creating proxy
- final Class proxy = ShadowProxyFactory.getProxy( Cheese.class );
- final Cheese cheeseProxy = (Cheese) proxy.getConstructor( new Class[]{Cheese.class} ).newInstance( new Object[]{cheese} );
-
- // proxy is proxying the values
- Assert.assertEquals( originalType,
- cheeseProxy.getType() );
- Assert.assertEquals( originalPrice,
- cheeseProxy.getPrice() );
- Assert.assertSame( cheese,
- ((ShadowProxy) cheeseProxy).getShadowedObject() );
-
- // proxy must recongnize the original object on equals()/hashcode() calls
- //Assert.assertEquals( cheeseProxy.hashCode(), cheese.hashCode() );
- Assert.assertEquals( cheeseProxy,
- cheese );
-
- // changing original values
- final String actualType = "rotten stilton";
- final int actualPrice = 1;
- cheese.setType( actualType );
- cheese.setPrice( actualPrice );
-
- // proxy does not see changes
- Assert.assertEquals( actualType,
- cheese.getType() );
- Assert.assertFalse( actualType.equals( cheeseProxy.getType() ) );
- Assert.assertEquals( originalType,
- cheeseProxy.getType() );
- Assert.assertEquals( actualPrice,
- cheese.getPrice() );
- Assert.assertFalse( actualPrice == cheeseProxy.getPrice() );
- Assert.assertEquals( originalPrice,
- cheeseProxy.getPrice() );
-
- // reseting proxy
- ((ShadowProxy) cheeseProxy).updateProxy();
-
- // now proxy see changes
- Assert.assertEquals( actualType,
- cheese.getType() );
- Assert.assertEquals( actualType,
- cheeseProxy.getType() );
- Assert.assertFalse( originalType.equals( cheeseProxy.getType() ) );
- Assert.assertEquals( actualPrice,
- cheese.getPrice() );
- Assert.assertEquals( actualPrice,
- cheeseProxy.getPrice() );
- Assert.assertFalse( originalPrice == cheeseProxy.getPrice() );
-
- } catch ( final Exception e ) {
- fail( "Error: " + e.getMessage() );
- }
- }
-
- public void testProxyForInterface() {
- try {
- // creating original object
- final String originalType = "stilton";
- final int originalPrice = 15;
- final Cheese cheese = new Cheese( originalType,
- originalPrice );
-
- // creating proxy
- final Class proxy = ShadowProxyFactory.getProxy( CheeseInterface.class );
- final CheeseInterface cheeseProxy = (CheeseInterface) proxy.getConstructor( new Class[]{CheeseInterface.class} ).newInstance( new Object[]{cheese} );
-
- // proxy is proxying the values
- Assert.assertEquals( originalType,
- cheeseProxy.getType() );
- Assert.assertEquals( originalPrice,
- cheeseProxy.getPrice() );
- Assert.assertSame( cheese,
- ((ShadowProxy) cheeseProxy).getShadowedObject() );
-
- // changing original values
- final String actualType = "rotten stilton";
- final int actualPrice = 1;
- cheese.setType( actualType );
- cheese.setPrice( actualPrice );
-
- // proxy does not see changes
- Assert.assertEquals( actualType,
- cheese.getType() );
- Assert.assertFalse( actualType.equals( cheeseProxy.getType() ) );
- Assert.assertEquals( originalType,
- cheeseProxy.getType() );
- Assert.assertEquals( actualPrice,
- cheese.getPrice() );
- Assert.assertFalse( actualPrice == cheeseProxy.getPrice() );
- Assert.assertEquals( originalPrice,
- cheeseProxy.getPrice() );
-
- // reseting proxy
- ((ShadowProxy) cheeseProxy).updateProxy();
-
- // now proxy see changes
- Assert.assertEquals( actualType,
- cheese.getType() );
- Assert.assertEquals( actualType,
- cheeseProxy.getType() );
- Assert.assertFalse( originalType.equals( cheeseProxy.getType() ) );
- Assert.assertEquals( actualPrice,
- cheese.getPrice() );
- Assert.assertEquals( actualPrice,
- cheeseProxy.getPrice() );
- Assert.assertFalse( originalPrice == cheeseProxy.getPrice() );
-
- } catch ( final Exception e ) {
- fail( "Error: " + e.getMessage() );
- }
- }
-
- public void testProxyForAPIClass() {
- try {
- // creating original object
- final List list = new ArrayList();
-
- // creating proxy
- final Class proxy = ShadowProxyFactory.getProxy( ArrayList.class );
- final List listProxy = (List) proxy.getConstructor( new Class[]{ArrayList.class} ).newInstance( new Object[]{list} );
-
- // proxy is proxying the values
- Assert.assertEquals( list,
- listProxy );
- Assert.assertSame( list,
- ((ShadowProxy) listProxy).getShadowedObject() );
-
- } catch ( final Exception e ) {
- fail( "Error: " + e.getMessage() );
- }
- }
-
- public void testEqualsHashCodeForClass() {
- try {
- // creating original object
- final String originalType = "stilton";
- final int originalPrice = 15;
- final Cheese cheese = new Cheese( originalType,
- originalPrice );
-
- // creating proxy
- final Class proxy = ShadowProxyFactory.getProxy( Cheese.class );
- final Cheese cheeseProxy1 = (Cheese) proxy.getConstructor( new Class[]{Cheese.class} ).newInstance( new Object[]{cheese} );
- final Cheese cheeseProxy2 = (Cheese) proxy.getConstructor( new Class[]{Cheese.class} ).newInstance( new Object[]{cheese} );
-
- int cheeseHash = cheese.hashCode();
- Assert.assertEquals( cheeseProxy1,
- cheeseProxy2 );
- Assert.assertEquals( cheeseProxy2,
- cheeseProxy1 );
- Assert.assertEquals( cheeseHash,
- cheeseProxy1.hashCode() );
-
- // changing original values
- final String actualType = "rotten stilton";
- final int actualPrice = 1;
- cheese.setType( actualType );
- cheese.setPrice( actualPrice );
-
- Assert.assertEquals( cheeseHash,
- cheeseProxy1.hashCode() );
-
- // updating proxy1
- ((ShadowProxy) cheeseProxy1).updateProxy();
- cheeseHash = cheese.hashCode();
-
- Assert.assertEquals( cheeseHash,
- cheeseProxy1.hashCode() );
-
- // they are still identity equals
- Assert.assertTrue( cheeseProxy1.equals( cheeseProxy2 ) );
- Assert.assertTrue( cheeseProxy2.equals( cheeseProxy1 ) );
-
- // updating proxy2
- ((ShadowProxy) cheeseProxy2).updateProxy();
-
- // now they are equal again
- Assert.assertEquals( cheeseProxy1,
- cheeseProxy2 );
- Assert.assertEquals( cheeseProxy2,
- cheeseProxy1 );
-
- } catch ( final Exception e ) {
- fail( "Error: " + e.getMessage() );
- }
- }
-
- // TODO: find a new way to test hashcode
- // public void testEqualsHashCodeForClass2() {
- // try {
- // // creating original object
- // final TestBean bean = new TestBean();
- //
- // // creating proxy
- // final Class proxy = ShadowProxyFactory.getProxy( TestBean.class );
- // final TestBean beanProxy1 = (TestBean) proxy.getConstructor( new Class[]{TestBean.class} ).newInstance( new Object[]{bean} );
- // final TestBean beanProxy2 = (TestBean) proxy.getConstructor( new Class[]{TestBean.class} ).newInstance( new Object[]{bean} );
- //
- // Assert.assertEquals( beanProxy1, beanProxy2 );
- // Assert.assertEquals( beanProxy2, beanProxy1 );
- // Assert.assertEquals( -130900686 , beanProxy1.hashCode() );
- //
- // } catch ( final Exception e ) {
- // fail( "Error: " + e.getMessage() );
- // }
- // }
-
- // private int cheeseHashCode(final Cheese cheese) {
- // final int PRIME = 31;
- // int result = 1;
- // result = PRIME * result + ((cheese.getType() == null) ? 0 : cheese.getType().hashCode());
- // result = PRIME * result + cheese.getPrice();
- // return result;
- // }
-
- public void testClassWithStaticMethod() {
- try {
- // creating original object
- final String originalType = "stilton";
- final int originalPrice = 15;
- final Cheese cheese = new Cheese( originalType,
- originalPrice );
-
- // creating proxy
- final Class proxy = ShadowProxyFactory.getProxy( Cheese.class );
- final Cheese cheeseProxy1 = (Cheese) proxy.getConstructor( new Class[]{Cheese.class} ).newInstance( new Object[]{cheese} );
- final Cheese cheeseProxy2 = (Cheese) proxy.getConstructor( new Class[]{Cheese.class} ).newInstance( new Object[]{cheese} );
-
- final int cheesehash = cheese.hashCode();
- Assert.assertEquals( cheeseProxy1,
- cheeseProxy2 );
- Assert.assertEquals( cheeseProxy2,
- cheeseProxy1 );
- Assert.assertEquals( cheesehash,
- cheeseProxy1.hashCode() );
-
- } catch ( final Exception e ) {
- e.printStackTrace();
- fail( "Error: " + e.getMessage() );
- }
- }
-
- public void testClassWithDelegateMethodWithLongParam() {
- try {
- // creating original object
- final String originalType = "stilton";
- final int originalPrice = 15;
- final Cheese cheese = new Cheese( originalType,
- originalPrice );
-
- // creating proxy
- final Class proxy = ShadowProxyFactory.getProxy( Cheese.class );
- final Cheese cheeseProxy1 = (Cheese) proxy.getConstructor( new Class[]{Cheese.class} ).newInstance( new Object[]{cheese} );
- final Cheese cheeseProxy2 = (Cheese) proxy.getConstructor( new Class[]{Cheese.class} ).newInstance( new Object[]{cheese} );
-
- final int cheesehash = cheese.hashCode();
- Assert.assertEquals( cheeseProxy1,
- cheeseProxy2 );
- Assert.assertEquals( cheeseProxy2,
- cheeseProxy1 );
- Assert.assertEquals( cheesehash,
- cheeseProxy1.hashCode() );
-
- } catch ( final Exception e ) {
- e.printStackTrace();
- fail( "Error: " + e.getMessage() );
- }
- }
-
- public void testProxyForCollections() {
- try {
- // creating original object
- List originalList = new ArrayList();
- originalList.add( "a" );
- originalList.add( "b" );
- originalList.add( "c" );
- originalList.add( "d" );
-
- // creating proxy
- final Class proxy = ShadowProxyFactory.getProxy( originalList.getClass() );
- final List listProxy = (List) proxy.getConstructor( new Class[]{originalList.getClass()} ).newInstance( new Object[]{originalList} );
- ((ShadowProxy) listProxy).setShadowedObject( originalList );
-
- // proxy is proxying the values
- Assert.assertEquals( "a",
- listProxy.get( 0 ) );
- Assert.assertTrue( listProxy.contains( "c" ) );
- Assert.assertSame( originalList,
- ((ShadowProxy) listProxy).getShadowedObject() );
-
- // proxy must recongnize the original object on equals() calls
- Assert.assertEquals( listProxy,
- originalList );
-
- originalList.remove( "c" );
- originalList.add( "e" );
- Assert.assertTrue( listProxy.contains( "c" ) );
- Assert.assertFalse( listProxy.contains( "e" ) );
-
- ((ShadowProxy) listProxy).updateProxy();
- Assert.assertFalse( listProxy.contains( "c" ) );
- Assert.assertTrue( listProxy.contains( "e" ) );
-
- // proxy must recongnize the original object on equals() calls
- Assert.assertEquals( listProxy,
- originalList );
- } catch ( final Exception e ) {
- e.printStackTrace();
- fail( "Error: " + e.getMessage() );
- }
- }
-
- public void testProxyForMaps() {
- try {
- // creating original object
- Map originalMap = new HashMap();
- originalMap.put( "name",
- "Edson" );
- originalMap.put( "surname",
- "Tirelli" );
- originalMap.put( "age",
- "28" );
-
- // creating proxy
- final Class proxy = ShadowProxyFactory.getProxy( originalMap.getClass() );
- final Map mapProxy = (Map) proxy.getConstructor( new Class[]{originalMap.getClass()} ).newInstance( new Object[]{originalMap} );
- ((ShadowProxy) mapProxy).setShadowedObject( originalMap );
-
- // proxy is proxying the values
- Assert.assertEquals( "Edson",
- mapProxy.get( "name" ) );
- Assert.assertTrue( mapProxy.containsKey( "age" ) );
- Assert.assertSame( originalMap,
- ((ShadowProxy) mapProxy).getShadowedObject() );
-
- // proxy must recongnize the original object on equals() calls
- Assert.assertEquals( mapProxy,
- originalMap );
-
- originalMap.remove( "age" );
- originalMap.put( "hair",
- "brown" );
- Assert.assertTrue( mapProxy.containsKey( "age" ) );
- Assert.assertFalse( mapProxy.containsKey( "hair" ) );
-
- ((ShadowProxy) mapProxy).updateProxy();
- Assert.assertFalse( mapProxy.containsKey( "age" ) );
- Assert.assertTrue( mapProxy.containsKey( "hair" ) );
-
- // proxy must recongnize the original object on equals() calls
- Assert.assertEquals( mapProxy,
- originalMap );
- } catch ( final Exception e ) {
- e.printStackTrace();
- fail( "Error: " + e.getMessage() );
- }
- }
-
- public void testProxyForMapsAttributes() {
- try {
- Person bob = new Person( "bob",
- 30 );
- Address addr1 = new Address( "street 1",
- "111",
- "11-1111-1111" );
- Address addr2 = new Address( "street 2",
- "222",
- "22-2222-2222" );
- Address addr3 = new Address( "street 3",
- "333",
- "33-3333-3333" );
- Address addr4 = new Address( "street 4",
- "444",
- "44-4444-4444" );
- Map addresses = new HashMap();
- addresses.put( "home",
- addr1 );
- addresses.put( "business",
- addr2 );
- bob.setAddresses( addresses );
-
- // creating proxy
- final Class proxy = ShadowProxyFactory.getProxy( bob.getClass() );
- final Person bobProxy = (Person) proxy.getConstructor( new Class[]{bob.getClass()} ).newInstance( new Object[]{bob} );
- ((ShadowProxy) bobProxy).setShadowedObject( bob );
-
- // proxy is proxying the values
- Assert.assertEquals( bob.getAddresses().get( "business" ),
- bobProxy.getAddresses().get( "business" ) );
- Assert.assertSame( bob,
- ((ShadowProxy) bobProxy).getShadowedObject() );
-
- // proxy must recongnize the original object on equals() calls
- Assert.assertEquals( bobProxy,
- bob );
-
- bob.getAddresses().remove( "business" );
- bob.getAddresses().put( "parents",
- addr3 );
- bob.getAddresses().put( "home",
- addr4 );
- Assert.assertTrue( bobProxy.getAddresses().containsKey( "business" ) );
- Assert.assertFalse( bobProxy.getAddresses().containsKey( "parents" ) );
- Assert.assertEquals( addr1,
- bobProxy.getAddresses().get( "home" ) );
-
- ((ShadowProxy) bobProxy).updateProxy();
- Assert.assertFalse( bobProxy.getAddresses().containsKey( "business" ) );
- Assert.assertTrue( bobProxy.getAddresses().containsKey( "parents" ) );
- Assert.assertEquals( addr4,
- bobProxy.getAddresses().get( "home" ) );
-
- // proxy must recongnize the original object on equals() calls
- Assert.assertEquals( bobProxy,
- bob );
- } catch ( final Exception e ) {
- e.printStackTrace();
- fail( "Error: " + e.getMessage() );
- }
- }
-
- public void testProxyForCollectionAttributes() {
- try {
- Person bob = new Person( "bob",
- 30 );
- Address addr1 = new Address( "street 1",
- "111",
- "11-1111-1111" );
- Address addr2 = new Address( "street 2",
- "222",
- "22-2222-2222" );
- Address addr3 = new Address( "street 3",
- "333",
- "33-3333-3333" );
- bob.getAddressList().add( addr1 );
- bob.getAddressList().add( addr2 );
-
- // creating proxy
- final Class proxy = ShadowProxyFactory.getProxy( bob.getClass() );
- final Person bobProxy = (Person) proxy.getConstructor( new Class[]{bob.getClass()} ).newInstance( new Object[]{bob} );
- ((ShadowProxy) bobProxy).setShadowedObject( bob );
-
- // proxy is proxying the values
- Assert.assertEquals( 2,
- bobProxy.getAddressList().size() );
- Assert.assertSame( bob,
- ((ShadowProxy) bobProxy).getShadowedObject() );
-
- // proxy must recongnize the original object on equals() calls
- Assert.assertEquals( bobProxy,
- bob );
-
- bob.getAddressList().remove( addr2 );
- bob.getAddressList().add( addr3 );
-
- Assert.assertTrue( bobProxy.getAddressList().contains( addr2 ) );
- Assert.assertFalse( bobProxy.getAddressList().contains( addr3 ) );
-
- ((ShadowProxy) bobProxy).updateProxy();
- Assert.assertFalse( bobProxy.getAddressList().contains( addr2 ) );
- Assert.assertTrue( bobProxy.getAddressList().contains( addr3 ) );
-
- // proxy must recongnize the original object on equals() calls
- Assert.assertEquals( bobProxy,
- bob );
- } catch ( final Exception e ) {
- e.printStackTrace();
- fail( "Error: " + e.getMessage() );
- }
- }
-
- public void testProxyForArrayAttributes() {
- try {
- Person bob = new Person( "bob",
- 30 );
- Address addr1 = new Address( "street 1",
- "111",
- "11-1111-1111" );
- Address addr2 = new Address( "street 2",
- "222",
- "22-2222-2222" );
- Address addr3 = new Address( "street 3",
- "333",
- "33-3333-3333" );
- bob.getAddressArray()[0] = addr1;
- bob.getAddressArray()[1] = addr2;
-
- // creating proxy
- final Class proxy = ShadowProxyFactory.getProxy( bob.getClass() );
- final Person bobProxy = (Person) proxy.getConstructor( new Class[]{bob.getClass()} ).newInstance( new Object[]{bob} );
- ((ShadowProxy) bobProxy).setShadowedObject( bob );
-
- // proxy is proxying the values
- Assert.assertEquals( addr1,
- bobProxy.getAddressArray()[0] );
- Assert.assertEquals( addr2,
- bobProxy.getAddressArray()[1] );
- Assert.assertSame( bob,
- ((ShadowProxy) bobProxy).getShadowedObject() );
-
- // proxy must recongnize the original object on equals() calls
- Assert.assertEquals( bobProxy,
- bob );
-
- bob.getAddressArray()[1] = addr3;
-
- Assert.assertEquals( addr1,
- bobProxy.getAddressArray()[0] );
- Assert.assertEquals( addr2,
- bobProxy.getAddressArray()[1] );
-
- ((ShadowProxy) bobProxy).updateProxy();
- Assert.assertEquals( addr1,
- bobProxy.getAddressArray()[0] );
- Assert.assertEquals( addr3,
- bobProxy.getAddressArray()[1] );
-
- // proxy must recongnize the original object on equals() calls
- Assert.assertEquals( bobProxy,
- bob );
- } catch ( final Exception e ) {
- e.printStackTrace();
- fail( "Error: " + e.getMessage() );
- }
- }
-
- public void testProxyForInterface2() {
- try {
- // creating original object
- final String original = "stilton";
-
- // creating proxy
- final Class proxy = ShadowProxyFactory.getProxy( Comparable.class );
- final Comparable comparableProxy = (Comparable) proxy.getConstructor( new Class[]{Comparable.class} ).newInstance( new Object[]{original} );
-
- // proxy is proxying the values
- Assert.assertEquals( comparableProxy,
- original );
- Assert.assertSame( original,
- ((ShadowProxy) comparableProxy).getShadowedObject() );
- Assert.assertEquals( original.hashCode(),
- comparableProxy.hashCode() );
-
- } catch ( final Exception e ) {
- fail( "Error: " + e.getMessage() );
- }
- }
-
- public void testProxyForClassWithEquals() {
- try {
- // creating original object
- final String originalType = "stilton";
- final int originalPrice = 15;
- final CheeseEqual cheese = new CheeseEqual( originalType,
- originalPrice );
-
- // creating proxy
- final Class proxy = ShadowProxyFactory.getProxy( CheeseEqual.class );
- final CheeseEqual cheeseProxy = (CheeseEqual) proxy.getConstructor( new Class[]{CheeseEqual.class} ).newInstance( new Object[]{cheese} );
-
- // proxy is proxying the values
- Assert.assertEquals( originalType,
- cheeseProxy.getType() );
- Assert.assertEquals( originalPrice,
- cheeseProxy.getPrice() );
- Assert.assertSame( cheese,
- ((ShadowProxy) cheeseProxy).getShadowedObject() );
-
- // proxy must recongnize the original object on equals()/hashcode() calls
- //Assert.assertEquals( cheeseProxy.hashCode(), cheese.hashCode() );
- Assert.assertEquals( cheeseProxy,
- cheese );
-
- // changing original values
- final String actualType = "rotten stilton";
- final int actualPrice = 1;
- cheese.setType( actualType );
- cheese.setPrice( actualPrice );
-
- // proxy does not see changes
- Assert.assertEquals( actualType,
- cheese.getType() );
- Assert.assertFalse( actualType.equals( cheeseProxy.getType() ) );
- Assert.assertEquals( originalType,
- cheeseProxy.getType() );
- Assert.assertEquals( actualPrice,
- cheese.getPrice() );
- Assert.assertFalse( actualPrice == cheeseProxy.getPrice() );
- Assert.assertEquals( originalPrice,
- cheeseProxy.getPrice() );
-
- // reseting proxy
- ((ShadowProxy) cheeseProxy).updateProxy();
-
- // now proxy see changes
- Assert.assertEquals( actualType,
- cheese.getType() );
- Assert.assertEquals( actualType,
- cheeseProxy.getType() );
- Assert.assertFalse( originalType.equals( cheeseProxy.getType() ) );
- Assert.assertEquals( actualPrice,
- cheese.getPrice() );
- Assert.assertEquals( actualPrice,
- cheeseProxy.getPrice() );
- Assert.assertFalse( originalPrice == cheeseProxy.getPrice() );
-
- // Another cheese
- final CheeseEqual cheese2 = new CheeseEqual( "brie",
- 10 );
-
- final CheeseEqual cheese2Proxy = (CheeseEqual) proxy.getConstructor( new Class[]{CheeseEqual.class} ).newInstance( new Object[]{cheese2} );
- assertFalse( cheeseProxy.equals( cheese2Proxy ) );
- assertFalse( cheese2Proxy.equals( cheeseProxy ) );
-
- } catch ( final Exception e ) {
- fail( "Error: " + e.getMessage() );
- }
- }
-
-}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/event/AgendaEventSupportTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/event/AgendaEventSupportTest.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/event/AgendaEventSupportTest.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -160,7 +160,7 @@
agendaList.size() );
ActivationCreatedEvent createdEvent = (ActivationCreatedEvent) agendaList.get( 0 );
assertSame( cheddar,
- unwrapShadow( createdEvent.getActivation().getTuple().get( 0 ).getObject() ) );
+ createdEvent.getActivation().getTuple().get( 0 ).getObject() );
agendaList.clear();
// update results in a ActivationCancelledEvent and an ActivationCreatedEvent, note the object is always resolvable
@@ -171,10 +171,10 @@
agendaList.size() );
ActivationCancelledEvent cancelledEvent = (ActivationCancelledEvent) agendaList.get( 0 );
assertSame( cheddar,
- unwrapShadow( cancelledEvent.getActivation().getTuple().get( 0 ).getObject() ) );
+ cancelledEvent.getActivation().getTuple().get( 0 ).getObject() );
createdEvent = (ActivationCreatedEvent) agendaList.get( 1 );
assertSame( cheddar,
- unwrapShadow( createdEvent.getActivation().getTuple().get( 0 ).getObject() ) );
+ createdEvent.getActivation().getTuple().get( 0 ).getObject() );
agendaList.clear();
// retract results in a ActivationCancelledEvent, noe the object is not resolveable now as it no longer exists
@@ -204,20 +204,13 @@
agendaList.size() );
final BeforeActivationFiredEvent beforeEvent = (BeforeActivationFiredEvent) agendaList.get( 0 );
assertSame( cheddar,
- unwrapShadow( beforeEvent.getActivation().getTuple().get( 0 ).getObject() ) );
+ beforeEvent.getActivation().getTuple().get( 0 ).getObject() );
final AfterActivationFiredEvent afterEvent = (AfterActivationFiredEvent) agendaList.get( 1 );
assertSame( cheddar,
- unwrapShadow( afterEvent.getActivation().getTuple().get( 0 ).getObject() ) );
+ afterEvent.getActivation().getTuple().get( 0 ).getObject() );
final AgendaGroupPoppedEvent poppedEvent = (AgendaGroupPoppedEvent) agendaList.get( 2 );
assertEquals( "test group",
poppedEvent.getAgendaGroup().getName() );
}
- private Object unwrapShadow(Object object) {
- if ( object instanceof ShadowProxy ) {
- return ((ShadowProxy) object).getShadowedObject();
- } else {
- return object;
- }
- }
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -1005,12 +1005,4 @@
assertEquals( 0,
workingMemory.getTruthMaintenanceSystem().getAssertMap().size() );
}
-
- private Object unwrapShadow(Object object) {
- if ( object instanceof ShadowProxy ) {
- return ((ShadowProxy) object).getShadowedObject();
- } else {
- return object;
- }
- }
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ObjectTypeNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ObjectTypeNodeTest.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ObjectTypeNodeTest.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -29,7 +29,6 @@
import org.drools.RuleBaseFactory;
import org.drools.base.ClassObjectType;
import org.drools.base.ShadowProxy;
-import org.drools.base.ShadowProxyFactory;
import org.drools.common.DefaultFactHandle;
import org.drools.common.InternalFactHandle;
import org.drools.common.InternalRuleBase;
@@ -386,7 +385,6 @@
final List asserted = sink.getAsserted();
assertLength( 1,
asserted );
- assertTrue( ((InternalFactHandle) ((Object[]) asserted.get( 0 ))[0]).getObject() instanceof ShadowProxy );
assertEquals( cheese,
((InternalFactHandle) ((Object[]) asserted.get( 0 ))[0]).getObject() );
@@ -415,7 +413,6 @@
buildContext );
entryPoint.attach();
- final Class shadowClass = ShadowProxyFactory.getProxy( Person.class );
final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
entryPoint,
new ClassObjectType( Person.class ),
@@ -438,7 +435,6 @@
final List asserted = sink.getAsserted();
assertLength( 1,
asserted );
- assertTrue( ((InternalFactHandle) ((Object[]) asserted.get( 0 ))[0]).getObject() instanceof ShadowProxy );
assertEquals( ((InternalFactHandle) ((Object[]) asserted.get( 0 ))[0]).getObject(),
person );
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/OtherwiseTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/OtherwiseTest.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/OtherwiseTest.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -5,7 +5,6 @@
import org.drools.RuleBaseFactory;
import org.drools.WorkingMemory;
import org.drools.base.ClassObjectType;
-import org.drools.base.ShadowProxyFactory;
import org.drools.base.TestBean;
import org.drools.rule.Pattern;
import org.drools.rule.Package;
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteTest.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteTest.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -209,7 +209,7 @@
final Object[] results = (Object[]) asserted.get( 0 );
assertSame( list,
- unwrapShadow( ((DefaultFactHandle) results[0]).getObject() ) );
+ ((DefaultFactHandle) results[0]).getObject() );
}
public void testAssertObjectWithNoMatchingObjectTypeNode() {
@@ -363,7 +363,7 @@
final Object[] results = (Object[]) retracted.get( 0 );
assertSame( list,
- unwrapShadow( ((DefaultFactHandle) results[0]).getObject() ) );
+ ((DefaultFactHandle) results[0]).getObject() );
}
public void testIsShadowed() {
@@ -394,10 +394,7 @@
null ),
workingMemory );
- assertTrue( h1.isShadowFact() );
-
final Object[] results = (Object[]) sink1.getAsserted().get( 0 );
- assertTrue( ((DefaultFactHandle) results[0]).getObject() instanceof ShadowProxy );
}
public void testNotShadowed() {
@@ -442,16 +439,7 @@
null ),
workingMemory );
- assertFalse( h1.isShadowFact() );
final Object[] results = (Object[]) sink1.getAsserted().get( 0 );
assertFalse( ((DefaultFactHandle) results[0]).getObject() instanceof ShadowProxy );
}
-
- private Object unwrapShadow(Object object) {
- if ( object instanceof ShadowProxy ) {
- return ((ShadowProxy) object).getShadowedObject();
- } else {
- return object;
- }
- }
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/FieldConstraintTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/FieldConstraintTest.java 2008-05-31 09:58:03 UTC (rev 20242)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/FieldConstraintTest.java 2008-05-31 15:30:15 UTC (rev 20243)
@@ -446,19 +446,16 @@
context ) );
cheddar.setPrice( 5 );
- ((ShadowProxy) cheddarHandle.getObject()).updateProxy();
assertFalse( constraint.isAllowed( cheddarHandle,
workingMemory,
context ) );
cheddar.setType( "stilton" );
- ((ShadowProxy) cheddarHandle.getObject()).updateProxy();
assertFalse( constraint.isAllowed( cheddarHandle,
workingMemory,
context ) );
cheddar.setPrice( 15 );
- ((ShadowProxy) cheddarHandle.getObject()).updateProxy();
assertFalse( constraint.isAllowed( cheddarHandle,
workingMemory,
context ) );
@@ -523,19 +520,16 @@
context ) );
cheddar.setPrice( 5 );
- ((ShadowProxy) cheddarHandle.getObject()).updateProxy();
assertTrue( constraint.isAllowed( cheddarHandle,
workingMemory,
context ) );
cheddar.setType( "stilton" );
- ((ShadowProxy) cheddarHandle.getObject()).updateProxy();
assertFalse( constraint.isAllowed( cheddarHandle,
workingMemory,
context ) );
cheddar.setPrice( 15 );
- ((ShadowProxy) cheddarHandle.getObject()).updateProxy();
assertTrue( constraint.isAllowed( cheddarHandle,
workingMemory,
context ) );
@@ -627,19 +621,16 @@
context ) );
cheddar.setPrice( 5 );
- ((ShadowProxy) cheddarHandle.getObject()).updateProxy();
assertFalse( constraint.isAllowed( cheddarHandle,
workingMemory,
context ) );
cheddar.setType( "stilton" );
- ((ShadowProxy) cheddarHandle.getObject()).updateProxy();
assertTrue( constraint.isAllowed( cheddarHandle,
workingMemory,
context ) );
cheddar.setPrice( 15 );
- ((ShadowProxy) cheddarHandle.getObject()).updateProxy();
assertFalse( constraint.isAllowed( cheddarHandle,
workingMemory,
context ) );
More information about the jboss-svn-commits
mailing list