InvocationTargetException,
InstantiationException,
NoSuchFieldException {
ClassWriter cw = new ClassWriter( 0 );
FieldVisitor fv;
MethodVisitor mv;
// get the method bitmask
long mask = TraitRegistry.getInstance().getFieldMask( getTrait().getName(),
core.getDefinedClass().getName() );
String name = TraitFactory.getPropertyWrapperName( getTrait(),
core );
String masterName = TraitFactory.getProxyName( getTrait(),
core );
String internalWrapper = BuildUtils.getInternalType( name );
String internalProxy = BuildUtils.getInternalType( masterName );
String descrWrapper = BuildUtils.getTypeDescriptor( name );
String descrProxy = BuildUtils.getTypeDescriptor( masterName );
String internalCore = BuildUtils.getInternalType( core.getClassName() );
String descrCore = BuildUtils.getTypeDescriptor( core.getClassName() );
String internalTrait = BuildUtils.getInternalType( getTrait().getClassName() );
String descrTrait = BuildUtils.getTypeDescriptor( getTrait().getClassName() );
Class mixinClass = null;
String mixin = null;
Set<Method> mixinMethods = new HashSet<Method>();
Map<String, Method> mixinGetSet = new HashMap<String, Method>();
try {
if (getTrait().getDefinedClass() != null) {
Trait annTrait = getAnnotation( getTrait().getDefinedClass(),
Trait.class );
if (annTrait != null && !annTrait.impl().equals( Trait.NullMixin.class )) {
mixinClass = annTrait.impl();
mixin = mixinClass.getSimpleName().substring( 0,
1 ).toLowerCase() + mixinClass.getSimpleName().substring( 1 );
ClassFieldInspector cfi = new ClassFieldInspector( mixinClass );
for (Method m : mixinClass.getMethods()) {
try {
getTrait().getDefinedClass().getMethod( m.getName(),
m.getParameterTypes() );
if (cfi.getGetterMethods().containsValue( m )
|| cfi.getSetterMethods().containsValue( m )) {
mixinGetSet.put( m.getName(),
m );
} else {
mixinMethods.add( m );
}
} catch (NoSuchMethodException e) {
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
cw.visit( V1_5,
ACC_PUBLIC + ACC_SUPER,
internalProxy,
null,
"org/drools/factmodel/traits/TraitProxy",
new String[] { internalTrait, "java/io/Externalizable" } );
{
fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_TRANSIENT, "object", descrCore, null, null);
fv.visitEnd();
}
{
fv = cw.visitField(ACC_PRIVATE + ACC_TRANSIENT, "store", "Lorg/drools/core/util/TripleStore;", null, null);
fv.visitEnd();
}
{
fv = cw.visitField(ACC_PRIVATE, "storeId", "Ljava/lang/String;", null, null);
fv.visitEnd();
}
if (mixinClass != null) {
{
fv = cw.visitField( ACC_PRIVATE,
mixin,
BuildUtils.getTypeDescriptor( mixinClass.getName() ),
null,
null );
fv.visitEnd();
}
}
{
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();