use of org.drools.core.base.ClassFieldAccessorStore in project drools by kiegroup.
the class AbstractTraitFactory method buildClassDefinition.
public ClassDefinition buildClassDefinition(Class<?> klazz, Class<?> wrapperClass) throws IOException {
ClassFieldInspector inspector = new ClassFieldInspector(klazz);
ClassFieldAccessorStore store = getClassFieldAccessorStore();
ClassDefinition def;
if (!klazz.isInterface()) {
String className = wrapperClass.getName();
String superClass = wrapperClass != klazz ? klazz.getName() : klazz.getSuperclass().getName();
String[] interfaces = new String[klazz.getInterfaces().length + 1];
for (int j = 0; j < klazz.getInterfaces().length; j++) {
interfaces[j] = klazz.getInterfaces()[j].getName();
}
interfaces[interfaces.length - 1] = CoreWrapper.class.getName();
def = new ClassDefinition(className, superClass, interfaces);
def.setDefinedClass(wrapperClass);
Traitable tbl = wrapperClass.getAnnotation(Traitable.class);
def.setTraitable(true, tbl != null && tbl.logical());
Map<String, Field> fields = inspector.getFieldTypesField();
for (Field f : fields.values()) {
if (f != null) {
FieldDefinition fld = new FieldDefinition();
fld.setName(f.getName());
fld.setTypeName(f.getType().getName());
fld.setInherited(true);
ClassFieldAccessor accessor = store.getAccessor(def.getDefinedClass().getName(), fld.getName());
fld.setReadWriteAccessor(accessor);
if (inspector.getGetterMethods().containsKey(f.getName())) {
fld.setGetterName(inspector.getGetterMethods().get(f.getName()).getName());
}
if (inspector.getSetterMethods().containsKey(f.getName())) {
fld.setSetterName(inspector.getSetterMethods().get(f.getName()).getName());
}
def.addField(fld);
}
}
} else {
String className = klazz.getName();
String superClass = Object.class.getName();
String[] interfaces = new String[klazz.getInterfaces().length];
for (int j = 0; j < klazz.getInterfaces().length; j++) {
interfaces[j] = klazz.getInterfaces()[j].getName();
}
def = new ClassDefinition(className, superClass, interfaces);
def.setDefinedClass(klazz);
Map<String, Method> properties = inspector.getGetterMethods();
for (String key : properties.keySet()) {
Method m = properties.get(key);
if (m != null && m.getDeclaringClass() != TraitType.class && m.getDeclaringClass() != Thing.class && inspector.getSetterMethods().containsKey(key)) {
FieldDefinition fld = new FieldDefinition();
fld.setName(getterToFieldName(m.getName()));
fld.setTypeName(m.getReturnType().getName());
fld.setInherited(true);
ClassFieldAccessor accessor = store.getAccessor(def.getDefinedClass().getName(), fld.getName());
fld.setReadWriteAccessor(accessor);
fld.setGetterName(m.getName());
fld.setSetterName(inspector.getSetterMethods().get(key).getName());
def.addField(fld);
}
}
}
return def;
}
use of org.drools.core.base.ClassFieldAccessorStore in project drools by kiegroup.
the class RightTupleIndexHashTableIteratorTest method getConstraint.
protected BetaNodeFieldConstraint getConstraint(String identifier, Operator operator, String fieldName, Class clazz) {
ClassFieldAccessorStore store = new ClassFieldAccessorStore();
store.setClassFieldAccessorCache(new ClassFieldAccessorCache(Thread.currentThread().getContextClassLoader()));
store.setEagerWire(true);
InternalReadAccessor extractor = store.getReader(clazz, fieldName);
Declaration declaration = new Declaration(identifier, extractor, new Pattern(0, new ClassObjectType(clazz)));
String expression = fieldName + " " + operator.getOperatorString() + " " + declaration.getIdentifier();
return new MvelConstraintTestUtil(expression, declaration, extractor);
}
use of org.drools.core.base.ClassFieldAccessorStore in project drools by kiegroup.
the class LeftLeftTupleIndexHashTableIteratorTest method getConstraint.
protected BetaNodeFieldConstraint getConstraint(String identifier, Operator operator, String fieldName, Class clazz) {
ClassFieldAccessorStore store = new ClassFieldAccessorStore();
store.setClassFieldAccessorCache(new ClassFieldAccessorCache(Thread.currentThread().getContextClassLoader()));
store.setEagerWire(true);
InternalReadAccessor extractor = store.getReader(clazz, fieldName);
Declaration declaration = new Declaration(identifier, extractor, new Pattern(0, new ClassObjectType(clazz)));
String expression = fieldName + " " + operator.getOperatorString() + " " + declaration.getIdentifier();
return new MvelConstraintTestUtil(expression, declaration, extractor);
}
use of org.drools.core.base.ClassFieldAccessorStore in project drools by kiegroup.
the class InstancesHashcodedTest method build.
/*
<dimension name="bck_cycle_dm" item-expression="cycleDimension"
mode="ignore" cache="10" export-to="cycle_id">
<id name="objid" type="long" generator-sql="select bck_dimensions_uid.nextval from dual"/>
<field name="cut_date" type="java.util.Date" value="cutDate" key="true"/>
<field name="due_date" type="java.util.Date" value="dueDate" key="true"/>
<field name="cycle_code" type="java.lang.String" value="cycleCode"/>
<field name="issue_date" type="java.util.Date" value="issueDate"/>
</dimension>
*/
private Class build(ClassBuilder builder, ClassDefinition classDef) throws Exception {
ProjectClassLoader prjClassLoader = ProjectClassLoader.createProjectClassLoader();
byte[] d = builder.buildClass(classDef, prjClassLoader);
JavaDialectRuntimeData data = new JavaDialectRuntimeData();
data.write(convertClassToResourcePath(classDef.getClassName()), d);
ClassLoader classLoader = new PackageClassLoader(data, prjClassLoader);
ClassFieldAccessorStore store = new ClassFieldAccessorStore();
store.setClassFieldAccessorCache(new ClassFieldAccessorCache(classLoader));
store.setEagerWire(true);
Class clazz = classLoader.loadClass(classDef.getClassName());
classDef.setDefinedClass(clazz);
return clazz;
}
use of org.drools.core.base.ClassFieldAccessorStore in project drools by kiegroup.
the class ByteClassFieldExtractorTest method setUp.
@Before
public void setUp() throws Exception {
ClassFieldAccessorStore store = new ClassFieldAccessorStore();
store.setClassFieldAccessorCache(new ClassFieldAccessorCache(Thread.currentThread().getContextClassLoader()));
store.setEagerWire(true);
this.reader = store.getReader(TestBean.class, "byteAttr");
}
Aggregations