/** * Internal method that handles prefetching of to-many relationships.<br> * // TBD This is a workaround to what looks like a bug in WO 5.1 & WO 5.2. Remove as soon as it's * no longer needed * * <p>The problem is that even refreshing fetches don't refresh the to-many relationships they * prefetch. */ public void _followToManyRelationshipWithFetchSpecification( EORelationship relationship, EOFetchSpecification fetchspecification, NSArray objects, EOEditingContext editingcontext) { int count = objects.count(); for (int i = 0; i < count; i++) { EOEnterpriseObject object = (EOEnterpriseObject) objects.objectAtIndex(i); EOGlobalID sourceGlobalID = editingcontext.globalIDForObject(object); String relationshipName = relationship.name(); if (!object.isFault()) { EOFaulting toManyArray = (EOFaulting) object.storedValueForKey(relationshipName); if (!toManyArray.isFault()) { EOFaulting tmpToManyArray = (EOFaulting) arrayFaultWithSourceGlobalID(sourceGlobalID, relationshipName, editingcontext); // Turn the existing array back into a fault by assigning it // the fault handler of the newly created fault toManyArray.turnIntoFault(tmpToManyArray.faultHandler()); } } } super._followToManyRelationshipWithFetchSpecification( relationship, fetchspecification, objects, editingcontext); }
public String entityName() { String entityName = (String) valueForBinding("entityName"); if (entityName == null) { EOEnterpriseObject eo = (EOEnterpriseObject) valueForBinding("object"); if (eo != null) entityName = eo.entityName(); } return entityName; }
/** * This method encodes the entity name of the enterprise object by searching in the default model * group whether it can find the key EncodedEntityNameKey in the user info dictionary. * * @param eo the enterprise object * @return the encoded entity name defaulting to the given eo's entityName */ public static String entityNameEncode(EOEnterpriseObject eo) { // Get the EncodedEntityName of the object // Default to eo's entityName String encodedEntityName = eo.entityName(); EOEntity entity = EOModelGroup.defaultGroup().entityNamed(eo.entityName()); NSDictionary userInfo = entity.userInfo(); if (userInfo != null && userInfo.objectForKey(EncodedEntityNameKey) != null) encodedEntityName = (String) userInfo.objectForKey(EncodedEntityNameKey); return encodedEntityName; }
protected PersonLink defaultSelectionValue() { NSArray list = (NSArray) valueForBinding("forcedList"); if (list != null && list.count() > 0) { return (PersonLink) EOUtilities.localInstanceOfObject(ec, (EOEnterpriseObject) list.objectAtIndex(0)); } list = (NSArray) session().valueForKey("personList"); if (list != null && list.count() > 0) { Enumeration enu = list.objectEnumerator(); while (enu.hasMoreElements()) { EOEnterpriseObject pers = (EOEnterpriseObject) enu.nextElement(); if (entity().equals(pers.entityName())) { return (PersonLink) pers; } } } return null; }
public NSArray personList() { NSArray forcedList = (NSArray) valueForBinding("forcedList"); NSMutableArray result = (forcedList == null) ? new NSMutableArray() : EOUtilities.localInstancesOfObjects(ec, forcedList).mutableClone(); NSArray personList = (NSArray) session().valueForKey("personList"); if (personList != null && personList.count() > 0) { Enumeration enu = personList.objectEnumerator(); while (enu.hasMoreElements()) { EOEnterpriseObject pers = (EOEnterpriseObject) enu.nextElement(); if (!result.contains(pers) && (entity().equals(pers.entityName()) || pers.entityName().equals(alterEntity()))) result.addObject(pers); } } return result; }
public void updateSourceObject(Object anEO) { String masterKey = _localRelationshipKey(); Object aSourceObject = _localSourceObject(); boolean isDictionary = (aSourceObject instanceof NSMutableDictionary); NSMutableDictionary _dictionary = (isDictionary) ? (NSMutableDictionary) aSourceObject : null; EOEnterpriseObject _eo = !(isDictionary) ? (EOEnterpriseObject) aSourceObject : null; if (anEO != null) { if (isDictionary) { _dictionary.setObjectForKey(anEO, masterKey); } else if (_eo.valueForKey(masterKey) != anEO) { _eo.addObjectToBothSidesOfRelationshipWithKey((EOEnterpriseObject) anEO, masterKey); } } else { // remove if (isDictionary) { _dictionary.removeObjectForKey(masterKey); } else if (_eo.valueForKey(masterKey) != null) { _eo.removeObjectFromBothSidesOfRelationshipWithKey( (EOEnterpriseObject) _eo.valueForKey(masterKey), masterKey); } } }
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); } }
/** * Processes a validation exception to make it look better. The resulting exception message is set * in the errorMessages dictionary. * * @param e validation exception. * @param value that failed validation. * @param keyPath that failed validation. * @param errorMessages dictionary to place the formatted message into. * @param displayPropertyKeyPath key used in the case of the formatter exception to calculate the * pretty display name. * @param localizer to use to localize the exception. * @param entity that the validation exception is happening too. * @param pushChanges boolean to flag if the bad values should be pushed onto the eo. */ public static void validationFailedWithException( Throwable e, Object value, String keyPath, NSMutableDictionary errorMessages, String displayPropertyKeyPath, ERXLocalizer localizer, EOEntity entity, boolean pushChanges) { if (log.isDebugEnabled()) log.debug( "ValidationFailedWithException: " + e.getClass().getName() + " message: " + e.getMessage()); String key = null; String newErrorMessage = e.getMessage(); if (e instanceof NSValidation.ValidationException && ((NSValidation.ValidationException) e).key() != null && ((NSValidation.ValidationException) e).object() != null) { NSValidation.ValidationException nve = (NSValidation.ValidationException) e; key = nve.key(); Object eo = nve.object(); // this because exceptions raised by formatters have the failing VALUE in this key.. // strip the exception name // newErrorMessage=newErrorMessage.substring(newErrorMessage.indexOf(":")+1); // newErrorMessage=newErrorMessage.substring(newErrorMessage.indexOf(":")+1); if (eo instanceof EOEnterpriseObject) { // the exception is coming from EREnterpriseObject // WE PUSH THE WRONG VALUE INTO THE EO ANYWAY! if (pushChanges) { try { ((EOEnterpriseObject) eo).takeValueForKeyPath(value, key); } catch (NSKeyValueCoding.UnknownKeyException ex) { // AK: as we could have custom components that have non-existant keys // we of course can't push a value, so we discard the resulting exception } catch (NoSuchElementException ex) { // AK: as we could have custom components that have non-existant keys // we of course can't push a value, so we discard the resulting exception } catch (Exception ex) { log.error("Can't push value to key '" + key + "': " + value, ex); } } entity = EOUtilities.entityForObject( ((EOEnterpriseObject) eo).editingContext(), (EOEnterpriseObject) eo); } else { // the exception is coming from a formatter key = (String) NSArray.componentsSeparatedByString(displayPropertyKeyPath, ".").lastObject(); newErrorMessage = "<b>" + key + "</b>:" + newErrorMessage; } } else { key = keyPath; } if (key != null && newErrorMessage != null) { String displayName = localizedDisplayNameForKey( entity != null ? entity.classDescriptionForInstances() : null, key, localizer); errorMessages.setObjectForKey(newErrorMessage, displayName); } else { if (key != null) { // log.warn("NULL message for key:'"+key+"': " + ((EOGeneralAdaptorException)e).userInfo() , // e); log.warn("NULL message for key:'" + key + "': " + e, e); } else { log.warn("NULL key for message:'" + newErrorMessage + "'", e); } } }