Search in sources :

Example 1 with WOBindingNameAssociation

use of com.webobjects.appserver._private.WOBindingNameAssociation 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());
                        }
                    }
                }
            }
        }
    }
}
Also used : WOAssociation(com.webobjects.appserver.WOAssociation) Enumeration(java.util.Enumeration) NSArray(com.webobjects.foundation.NSArray) WOBindingNameAssociation(com.webobjects.appserver._private.WOBindingNameAssociation) WOConstantValueAssociation(com.webobjects.appserver._private.WOConstantValueAssociation) WOKeyValueAssociation(com.webobjects.appserver._private.WOKeyValueAssociation)

Aggregations

WOAssociation (com.webobjects.appserver.WOAssociation)1 WOBindingNameAssociation (com.webobjects.appserver._private.WOBindingNameAssociation)1 WOConstantValueAssociation (com.webobjects.appserver._private.WOConstantValueAssociation)1 WOKeyValueAssociation (com.webobjects.appserver._private.WOKeyValueAssociation)1 NSArray (com.webobjects.foundation.NSArray)1 Enumeration (java.util.Enumeration)1