use of org.jaffa.rules.IObjectRuleIntrospector in project jaffa-framework by jaffa-projects.
the class FlexClass method instance.
/**
* Creates a FlexClass instance based on the input.
*/
private static FlexClass instance(String className, Class clazz, Object object) throws ApplicationExceptions, FrameworkException {
try {
// determine the arguments
if (object != null)
clazz = object.getClass();
if (clazz != null)
className = clazz.getName();
// Obtain flex info
IObjectRuleIntrospector introspector = RulesEngineFactory.getRulesEngine().getObjectRuleIntrospector(className, object);
Properties flexInfo = introspector.getFlexInfo();
// If flex info is not found for the input class, traverse up the class hierarchy until the flexInfo is found
if (flexInfo == null) {
try {
Class c = clazz == null ? Class.forName(className).getSuperclass() : clazz.getSuperclass();
while (c != null && c != Object.class) {
IObjectRuleIntrospector i = RulesEngineFactory.getRulesEngine().getObjectRuleIntrospector(c.getName(), object);
flexInfo = i.getFlexInfo();
if (flexInfo != null) {
clazz = c;
className = c.getName();
introspector = i;
break;
}
c = c.getSuperclass();
}
} catch (ClassNotFoundException ignore) {
}
}
// Determine name and logicalName
String name, logicalName;
if (flexInfo != null) {
name = flexInfo.getProperty("source");
logicalName = flexInfo.getProperty("name");
} else {
name = className;
Properties domainInfo = introspector.getDomainInfo();
logicalName = domainInfo != null ? domainInfo.getProperty("name") : StringHelper.getShortClassName(className);
}
// Load all the properties for the source class
if (!className.equals(name))
introspector = RulesEngineFactory.getRulesEngine().getObjectRuleIntrospector(name, object);
Map<String, Properties> flexInfoForProperties = introspector.getFlexInfoForProperties();
// Create the FlexClass
FlexClass flexClass = new FlexClass();
flexClass.name = name;
flexClass.logicalName = logicalName;
if (flexInfoForProperties != null) {
for (Map.Entry<String, Properties> me : flexInfoForProperties.entrySet()) {
String propertyName = me.getKey();
FlexProperty flexProperty = new FlexProperty(propertyName, me.getValue());
flexClass.flexProperties.put(propertyName, flexProperty);
flexClass.logicalNames.put(flexProperty.getLogicalName(), propertyName);
}
}
return flexClass;
} catch (Throwable e) {
throw ExceptionHelper.throwAFR(e);
}
}
use of org.jaffa.rules.IObjectRuleIntrospector in project jaffa-framework by jaffa-projects.
the class FlexCriteriaBean method findKeys.
/**
* Returns an array of key field names for the input domain class.
*/
private String[] findKeys(String domainClassName) throws FrameworkException {
// Search for the first available class-level primary-key rule
IObjectRuleIntrospector introspector = RulesEngineFactory.getRulesEngine().getObjectRuleIntrospector(domainClassName, null);
String[] keys = introspector.getPrimaryKey();
// Search for corresponding DomainMeta class, if required
if (keys == null || keys.length == 0) {
try {
FieldMetaData[] keyFields = PersistentHelper.getKeyFields(domainClassName);
if (keyFields != null) {
keys = new String[keyFields.length];
for (int i = 0; i < keyFields.length; i++) keys[i] = keyFields[i].getName();
}
} catch (Exception e) {
// do nothing
}
}
return keys != null && keys.length > 0 ? keys : null;
}
use of org.jaffa.rules.IObjectRuleIntrospector in project jaffa-framework by jaffa-projects.
the class AuditTransactionViewService method getAuditableClasses.
public Map<String, Properties> getAuditableClasses() throws FrameworkException {
Map<String, Properties> output = null;
String[] classNames = RulesEngineFactory.getRulesEngine().getClassNamesByRuleName("audit");
if (classNames != null) {
output = new LinkedHashMap<String, Properties>();
for (String className : classNames) {
IObjectRuleIntrospector introspector = RulesEngineFactory.getRulesEngine().getObjectRuleIntrospector(className, null);
Properties p = introspector.getAuditInfo();
if (p == null)
p = new Properties();
output.put(className, p);
// Add the label
String label = introspector.getLabel();
if (label != null)
p.put("label", MessageHelper.replaceTokens(label));
}
}
return output;
}
Aggregations