public Object theCurrentValue() { // handle the case where it's the - none - string if (theCurrentItem == _noneString) { return theCurrentItem; } return NSKeyValueCoding.Utility.valueForKey(theCurrentItem, _localDestinationDisplayKey()); }
public Object selection() { if (_privateSelection() == null) { set_privateSelection( NSKeyValueCoding.Utility.valueForKey(_localSourceObject(), _localRelationshipKey())); } // deal with isMandatory if ((_privateSelection() == null) && !_localIsMandatory()) { setSelection(_noneString); } return _privateSelection(); }
// This prevents the dreaded KeyValueCoding null object exception, for say key paths: // object.entityName // Should just return null instead of throwing. public static Object contextValueForKeyNoInferenceNoException(D2WContext c, String keyPath) { Object result = null; int i = keyPath.indexOf("."); if (i == -1) { result = c.valueForKeyNoInference(keyPath); } else { String first = keyPath.substring(0, i); String second = keyPath.substring(i + 1); result = c.valueForKeyNoInference(first); if (result != null) { // Optimized for two paths deep try { if (second.indexOf(".") == -1) { result = NSKeyValueCoding.Utility.valueForKey(result, second); } else { NSArray parts = NSArray.componentsSeparatedByString(second, "."); for (int j = 0; j < parts.count(); j++) { String part = (String) parts.objectAtIndex(j); result = NSKeyValueCoding.Utility.valueForKey(result, part); if (result == null) break; } } } catch (NSKeyValueCoding.UnknownKeyException e) { if (log.isDebugEnabled()) { log.debug( "keyPath {} is not available for context with entity: {}; task: {}", keyPath, c.entity().name(), c.task()); } return null; } } } return result; }
public static Object decodeWithKeyValueUnarchiver(EOKeyValueUnarchiver eokeyvalueunarchiver) { ERD2WExtendedRule rule = null; try { rule = new ERD2WExtendedRule(eokeyvalueunarchiver); } catch (Throwable t) { NSMutableDictionary dict = (NSMutableDictionary) NSKeyValueCoding.Utility.valueForKey(eokeyvalueunarchiver, "propertyList"); log.info("Problems with this rule: " + dict + "," + t.getMessage()); dict.takeValueForKeyPath(dict.valueForKeyPath("rhs.class"), "assignmentClassName"); dict.takeValueForKeyPath("com.webobjects.directtoweb.Assignment", "rhs.class"); rule = new ERD2WExtendedRule(eokeyvalueunarchiver); } return rule; }
public void updateSourceObject(NSArray newValues) { Object realSourceObject = realSourceObject(); String realRelationshipKey = realRelationshipKey(); newValues = newValues != null ? newValues : NSArray.EmptyArray; if (realSourceObject instanceof EOEnterpriseObject && // only add/remove if we have an EO and handle a relationship ((EOEnterpriseObject) realSourceObject) .classDescriptionForDestinationKey(realRelationshipKey) != null) { EOEnterpriseObject eo = (EOEnterpriseObject) realSourceObject; NSArray currentValues = (NSArray) eo.valueForKey(realRelationshipKey); currentValues = currentValues != null ? currentValues : NSArray.EmptyArray; for (int i = currentValues.count() - 1; i >= 0; i--) { EOEnterpriseObject o = (EOEnterpriseObject) currentValues.objectAtIndex(i); if (newValues.indexOfIdenticalObject(o) == NSArray.NotFound) { // not found eo.removeObjectFromBothSidesOfRelationshipWithKey(o, realRelationshipKey); } } for (int i = newValues.count() - 1; i >= 0; i--) { EOEnterpriseObject o = (EOEnterpriseObject) newValues.objectAtIndex(i); if (currentValues.indexOfIdenticalObject(o) == NSArray.NotFound) { // not found eo.addObjectToBothSidesOfRelationshipWithKey(o, realRelationshipKey); } } } else { // NOTE ak: this implementation is different from what JavaWOExtensions do. // There, the existing array is fetched and added to/removed from. Here, we simply set the // new array. I changed this because it looked like a bad idea to change the array without // the sourceObjects's knowledge. NSKeyValueCoding.Utility.takeValueForKey( realSourceObject, (newValues instanceof NSMutableArray) ? newValues : newValues.mutableClone(), realRelationshipKey); } }