Class coreKlass = core.getClass();
// get the trait classDef
ClassDefinition tdef = TraitRegistry.getInstance().getTrait( trait.getName() );
ClassDefinition cdef = TraitRegistry.getInstance().getTraitable( coreKlass.getName() );
String proxyName = getProxyName( tdef, cdef );
String wrapperName = getPropertyWrapperName( tdef, cdef );
JavaDialectRuntimeData data = ((JavaDialectRuntimeData) getPackage( tdef.getDefinedClass().getPackage().getName() ).getDialectRuntimeRegistry().
getDialectData( "java" ));
TraitPropertyWrapperClassBuilder propWrapperBuilder = (TraitPropertyWrapperClassBuilder) ClassBuilderFactory.getPropertyWrapperBuilderService();
// switch ( mode ) {
// case TRIPLES : propWrapperBuilder = new TraitTriplePropertyWrapperClassBuilderImpl();
// break;
// case MAP : propWrapperBuilder = new TraitMapPropertyWrapperClassBuilderImpl();
// break;
// default : throw new RuntimeException( " This should not happen : unexpected property wrapping method " + mode );
// }
propWrapperBuilder.init( tdef );
try {
byte[] propWrapper = propWrapperBuilder.buildClass( cdef );
data.write(JavaDialectRuntimeData.convertClassToResourcePath( wrapperName ), propWrapper );
} catch (Exception e) {
e.printStackTrace();
}
TraitProxyClassBuilder proxyBuilder = (TraitProxyClassBuilder) ClassBuilderFactory.getTraitProxyBuilderService();
// switch ( mode ) {
// case TRIPLES : proxyBuilder = new TraitTripleProxyClassBuilderImpl();
// break;
// case MAP : proxyBuilder = new TraitMapProxyClassBuilderImpl();
// break;
// default : throw new RuntimeException( " This should not happen : unexpected property wrapping method " + mode );
// }
proxyBuilder.init( tdef );
try {
byte[] proxy = proxyBuilder.buildClass( cdef );
data.write(JavaDialectRuntimeData.convertClassToResourcePath( proxyName ), proxy);
} catch (Exception e) {
e.printStackTrace();
}
data.onBeforeExecute();
try {
long mask = TraitRegistry.getInstance().getFieldMask( trait.getName(), cdef.getDefinedClass().getName() );
Class<T> proxyClass = (Class<T>) ruleBase.getRootClassLoader().loadClass( proxyName, true );
bindAccessors( proxyClass, tdef, cdef, mask );
Class<T> wrapperClass = (Class<T>) ruleBase.getRootClassLoader().loadClass( wrapperName, true );
bindCoreAccessors( wrapperClass, cdef );
return proxyClass;