use of org.jaffa.rules.IPropertyRuleIntrospector in project jaffa-framework by jaffa-projects.
the class FinderMetaDataHelper method determinePropertyMetaData.
/**
* Returns meta data for the input field.
*/
private static Map<String, String> determinePropertyMetaData(Class outputClass, Class domainClass, GraphMapping graphMapping, String fieldName) throws Exception {
IPropertyRuleIntrospector i = RulesEngineFactory.getRulesEngine().getPropertyRuleIntrospector(outputClass, fieldName);
// Apply an optional wrapper that also takes the FieldMetaData into account
try {
FieldMetaData fieldMetaData = PersistentHelper.getFieldMetaData(domainClass.getName(), graphMapping != null ? graphMapping.getDomainFieldName(fieldName) : fieldName);
i = new PropertyRuleIntrospectorUsingFieldMetaData(i, fieldMetaData);
} catch (Exception ignore) {
}
// A Map to hold the various attributes of the field
Map<String, String> m = new LinkedHashMap<String, String>();
// determine type
String type = toJsType(i.getPropertyType());
if (type == null) {
// A foreign-key on a Graph will typically be modelled as another Graph, in which case obtain the datatype for that field from the domainClass
type = toJsType(RulesEngineFactory.getRulesEngine().getPropertyRuleIntrospector(domainClass, fieldName).getPropertyType());
}
// Ignore field having unsupported propertyType
if (type == null)
return null;
m.put("type", '\'' + type + '\'');
// determine label
String label = i.getLabel();
if (label == null) {
label = StringHelper.getSpace(StringHelper.getUpper1(fieldName));
} else {
String tmp = label.substring(1);
tmp = tmp.substring(0, tmp.length() - 1);
m.put("labelToken", '\'' + tmp + '\'');
label = StringHelper.escapeJavascript(MessageHelper.replaceTokens(label));
}
m.put("label", '\'' + label + '\'');
// determine maxLength
Integer maxLength = i.getMaxLength();
if (maxLength != null)
m.put("maxLength", maxLength.toString());
// sortable
m.put("sortable", "true");
// determine hidden
Boolean hidden = i.isHidden();
if (hidden) {
m.put("hidden", "true");
m.put("alwaysHidden", "true");
}
// determine caseType
String caseType = i.getCaseType();
if (caseType != null && caseType.toLowerCase().startsWith("upper"))
caseType = "UpperCase";
else if (caseType != null && caseType.toLowerCase().startsWith("lower"))
caseType = "LowerCase";
else
caseType = null;
if (caseType != null)
m.put("caseType", '\'' + caseType + '\'');
return m;
}
use of org.jaffa.rules.IPropertyRuleIntrospector in project jaffa-framework by jaffa-projects.
the class FoldingSectionTag method lookupPropertyTag.
/**
* Checks for the nearest outer PropertyTag.
* Will set the 'key' on this tag, if not specified, with the value from the rules engine.
* If not specifed, it will use the values from the outer PropertyTag to determine the FieldMetaData object to obtain the key
*/
private void lookupPropertyTag() {
PropertyTag propertyTag = (PropertyTag) findCustomTagAncestorWithClass(this, PropertyTag.class);
if (propertyTag != null) {
IPropertyRuleIntrospector propertyRuleIntrospector = propertyTag.getPropertyRuleIntrospector();
if (getKey() == null && getLabel() == null) {
try {
String domainClassName = propertyTag.getPropertyClass();
String fieldName = propertyTag.getPropertyName();
setKey(TagHelper.getFieldMetaData(domainClassName, fieldName).getLabelToken());
} catch (Exception e) {
// do nothing
}
}
}
}
use of org.jaffa.rules.IPropertyRuleIntrospector in project jaffa-framework by jaffa-projects.
the class LabelTag method lookupPropertyTag.
/**
* Checks for the nearest outer PropertyTag.
* Will set the 'key' on this tag, if not specified, with the value from the rules engine.
* Will set the 'domain' and field' on this tag, if not specifed, with the values from the outer PropertyTag.
* @return the IPropertyRuleIntrospector from the outer PropertyTag.
*/
private IPropertyRuleIntrospector lookupPropertyTag() {
// Cannnot use findCustomTagAncestorWithClass, since LabelTag doesn't implement IFormTag, and hence does not have a ParentTag stamped on it
PropertyTag propertyTag = (PropertyTag) findAncestorWithClass(this, PropertyTag.class);
if (propertyTag != null) {
if (log.isDebugEnabled())
log.debug("Found Property Tag for Label. Field=" + propertyTag.getField());
IPropertyRuleIntrospector propertyRuleIntrospector = propertyTag.getPropertyRuleIntrospector();
if (getKey() == null && getDomain() == null && getField() == null) {
if (propertyRuleIntrospector != null) {
setKey(propertyRuleIntrospector.getLabel());
if (log.isDebugEnabled())
log.debug("Found Label via Rules (Field=" + propertyTag.getField() + ") = " + getKey());
}
setDomain(propertyTag.getPropertyClass());
setField(propertyTag.getPropertyName());
}
return propertyRuleIntrospector;
} else
return null;
}
Aggregations