Search in sources :

Example 6 with IObjectRuleIntrospector

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);
    }
}
Also used : IObjectRuleIntrospector(org.jaffa.rules.IObjectRuleIntrospector) DynaClass(org.apache.commons.beanutils.DynaClass) Properties(java.util.Properties) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 7 with IObjectRuleIntrospector

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;
}
Also used : FieldMetaData(org.jaffa.metadata.FieldMetaData) IObjectRuleIntrospector(org.jaffa.rules.IObjectRuleIntrospector) FrameworkException(org.jaffa.exceptions.FrameworkException)

Example 8 with IObjectRuleIntrospector

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;
}
Also used : IObjectRuleIntrospector(org.jaffa.rules.IObjectRuleIntrospector) Properties(java.util.Properties)

Aggregations

IObjectRuleIntrospector (org.jaffa.rules.IObjectRuleIntrospector)8 Properties (java.util.Properties)7 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Enumeration (java.util.Enumeration)1 JSONArray (net.sf.json.JSONArray)1 DynaClass (org.apache.commons.beanutils.DynaClass)1 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)1 FrameworkException (org.jaffa.exceptions.FrameworkException)1 FlexBean (org.jaffa.flexfields.FlexBean)1 IFlexFields (org.jaffa.flexfields.IFlexFields)1 FieldMetaData (org.jaffa.metadata.FieldMetaData)1 RulesEngineException (org.jaffa.rules.RulesEngineException)1 PendingEventException (org.jaffa.soa.rules.PendingEventException)1