use of com.webobjects.appserver._private.WOConstantValueAssociation in project wonder-slim by undur.
the class WOHelperFunctionParser method prettyDeclaration.
protected String prettyDeclaration(WODeclaration declaration) {
StringBuilder declarationStr = new StringBuilder();
if (declaration == null) {
declarationStr.append("[none]");
} else {
declarationStr.append("Component Type = " + declaration.type());
declarationStr.append(", Bindings = { ");
Enumeration keyEnum = declaration.associations().keyEnumerator();
while (keyEnum.hasMoreElements()) {
String key = (String) keyEnum.nextElement();
Object assoc = declaration.associations().objectForKey(key);
if (assoc instanceof WOKeyValueAssociation) {
declarationStr.append(key + "=" + ((WOKeyValueAssociation) assoc).keyPath());
} else if (assoc instanceof WOConstantValueAssociation) {
declarationStr.append(key + "='" + ((WOConstantValueAssociation) assoc).valueInComponent(null) + "'");
} else {
declarationStr.append(key + "=" + assoc);
}
if (keyEnum.hasMoreElements()) {
declarationStr.append(", ");
}
}
declarationStr.append(" }");
}
return declarationStr.toString();
}
use of com.webobjects.appserver._private.WOConstantValueAssociation in project wonder-slim by undur.
the class WOOgnl method convertOgnlConstantAssociations.
public void convertOgnlConstantAssociations(NSMutableDictionary associations) {
for (Enumeration e = associations.keyEnumerator(); e.hasMoreElements(); ) {
String name = (String) e.nextElement();
WOAssociation association = (WOAssociation) associations.objectForKey(name);
boolean isConstant = false;
String keyPath = null;
if (association instanceof WOConstantValueAssociation) {
WOConstantValueAssociation constantAssociation = (WOConstantValueAssociation) association;
// AK: this sucks, but there is no API to get at the value
Object value = constantAssociation.valueInComponent(null);
keyPath = value != null ? value.toString() : null;
isConstant = true;
} else if (association instanceof WOKeyValueAssociation) {
keyPath = association.keyPath();
} else if (association instanceof WOBindingNameAssociation) {
WOBindingNameAssociation b = (WOBindingNameAssociation) association;
// AK: strictly speaking, this is not correct, as we only get the first part of
// the path. But take a look at WOBindingNameAssociation for a bit of fun...
keyPath = "^" + b._parentBindingName;
}
if (keyPath != null) {
if (!associationMappings.isEmpty()) {
int index = name.indexOf(':');
if (index > 0) {
String prefix = name.substring(0, index);
if (prefix != null) {
Class c = associationMappings.get(prefix);
if (c != null) {
String postfix = name.substring(index + 1);
WOAssociation newAssociation = createAssociationForClass(c, keyPath, isConstant);
associations.removeObjectForKey(name);
associations.setObjectForKey(newAssociation, postfix);
}
}
}
}
if (isConstant && keyPath.startsWith(ognlBindingFlag())) {
String ognlExpression = keyPath.substring(ognlBindingFlag().length(), keyPath.length());
if (ognlExpression.length() > 0) {
WOAssociation newAssociation = new WOOgnlAssociation(ognlExpression);
NSArray keys = associations.allKeysForObject(association);
// + (keys.count() == 1 ? keys.lastObject() : keys) + " expression: " + ognlExpression);
if (keys.count() == 1) {
associations.setObjectForKey(newAssociation, keys.lastObject());
} else {
for (Enumeration ee = keys.objectEnumerator(); ee.hasMoreElements(); ) {
associations.setObjectForKey(newAssociation, e.nextElement());
}
}
}
}
}
}
}
use of com.webobjects.appserver._private.WOConstantValueAssociation in project wonder-slim by undur.
the class WOHelperFunctionParser method parserHelperAssociation.
protected WOAssociation parserHelperAssociation(WOAssociation originalAssociation) {
WOAssociation association = originalAssociation;
String originalKeyPath = null;
if (association instanceof WOKeyValueAssociation) {
WOKeyValueAssociation kvAssociation = (WOKeyValueAssociation) association;
originalKeyPath = kvAssociation.keyPath();
}
if (originalKeyPath != null) {
int pipeIndex = originalKeyPath.indexOf('|');
if (pipeIndex != -1) {
String targetKeyPath = originalKeyPath.substring(0, pipeIndex).trim();
String frameworkName = WOHelperFunctionRegistry.APP_FRAMEWORK_NAME;
String helperFunctionName = originalKeyPath.substring(pipeIndex + 1).trim();
String otherParams = null;
int openParenIndex = helperFunctionName.indexOf('(');
if (openParenIndex != -1) {
int closeParenIndex = helperFunctionName.indexOf(')', openParenIndex + 1);
otherParams = helperFunctionName.substring(openParenIndex + 1, closeParenIndex);
helperFunctionName = helperFunctionName.substring(0, openParenIndex);
}
int helperFunctionDotIndex = helperFunctionName.indexOf('.');
if (helperFunctionDotIndex != -1) {
frameworkName = helperFunctionName.substring(0, helperFunctionDotIndex);
helperFunctionName = helperFunctionName.substring(helperFunctionDotIndex + 1);
}
StringBuilder ognlKeyPath = new StringBuilder();
ognlKeyPath.append('~');
ognlKeyPath.append("@" + WOHelperFunctionRegistry.class.getName() + "@registry()._helperInstanceForFrameworkNamed(#this, \"");
ognlKeyPath.append(helperFunctionName);
ognlKeyPath.append("\", \"");
ognlKeyPath.append(targetKeyPath);
ognlKeyPath.append("\", \"");
ognlKeyPath.append(frameworkName);
ognlKeyPath.append("\").");
ognlKeyPath.append(helperFunctionName);
ognlKeyPath.append('(');
ognlKeyPath.append(targetKeyPath);
if (otherParams != null) {
ognlKeyPath.append(',');
ognlKeyPath.append(otherParams);
}
ognlKeyPath.append(')');
log.debug("Converted {} into {}", originalKeyPath, ognlKeyPath);
association = new WOConstantValueAssociation(ognlKeyPath.toString());
}
}
return association;
}
use of com.webobjects.appserver._private.WOConstantValueAssociation in project wonder-slim by undur.
the class NotTagProcessor method createDeclaration.
@Override
public WODeclaration createDeclaration(String elementName, String elementType, NSMutableDictionary associations) {
String newElementType = "ERXWOConditional";
if (associations.objectForKey("negate") != null) {
throw new IllegalArgumentException("You already specified a binding for 'negate' of " + associations.objectForKey("negate") + " on a wo:not.");
}
associations.setObjectForKey(new WOConstantValueAssociation(Boolean.TRUE), "negate");
return super.createDeclaration(elementName, newElementType, associations);
}
use of com.webobjects.appserver._private.WOConstantValueAssociation in project wonder-slim by undur.
the class AjaxFunctionButton method processAssociations.
protected static NSDictionary processAssociations(NSDictionary associations) {
NSMutableDictionary mutableAssociations = (NSMutableDictionary) associations;
mutableAssociations.setObjectForKey(new WOConstantValueAssociation("button"), "type");
return mutableAssociations;
}
Aggregations