From: David T. <dav...@us...> - 2003-04-28 08:15:18
|
Update of /cvsroot/wonder/Wonder/Common/Frameworks/ERDirectToWeb/Sources/com/webobjects/directtoweb In directory sc8-pr-cvs1:/tmp/cvs-serv5223 Modified Files: ERD2WUtilities.java Log Message: This method faults the provied EOEnterpriseObject into a new EOEditingContext based on the current state. This method should be used whenever one creates and returns a new EditPage or InspectPage to ensure that nested EC's and EOSharedEC's are respected as well as new, not yet saved EO's. see javadoc for more info. Index: ERD2WUtilities.java =================================================================== RCS file: /cvsroot/wonder/Wonder/Common/Frameworks/ERDirectToWeb/Sources/com/webobjects/directtoweb/ERD2WUtilities.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ERD2WUtilities.java 22 Jul 2002 16:42:32 -0000 1.5 --- ERD2WUtilities.java 28 Apr 2003 08:15:03 -0000 1.6 *************** *** 8,11 **** --- 8,14 ---- import com.webobjects.foundation.*; + import com.webobjects.eoaccess.*; + import com.webobjects.eocontrol.*; + import er.extensions.*; // This is needed because pageFinalized is a protected method. *************** *** 59,61 **** --- 62,118 ---- return result; } + + /** This method faults the provied <code>EOEnterpriseObject</code> into a new <code>EOEditingContext</code> + * based on the current state:<br> + * 1. the <code>EOEnterpriseObject</code> is new: simply returns the <code>EOEnterpriseObject</code>, + * a new <code>EOEnterpriseObject</code> cannot be faulted into another <code>EOEditingContext</code><br> + * + * 2. if the d2wContext's task is 'edit' it creates a new -nested- <code>EOEditingContext</code> and + * faults the <code>EOEnterpriseObject</code> into it. Calls <code>setSharedEditingContext(false)</code> on + * the ec to ensure that this also works if one uses EOSharedEditingContexts. + * + * 3. otherwise it creates a new PeerEditingContext and faults the <code>EOEnterpriseObject</code> into it. + * Calls <code>setSharedEditingContext(false)</code> on the ec to ensure that this also works if + * one uses EOSharedEditingContexts. + * + * This method should be called whenever on returns a new Page for a D2W action. It should simply behave like + * one assumes and not like the WO implementation: no nested EC's, no SharedEditingContext support. + * + * @param eo The <code>EOEnterpriseObject</code> that should be faulted. If the current page is + * a List page then it would mostly be current list object. If the current page is a Edit page then + * it would be object() and NOT the relationship object or whatever. object() because its the main object + * that needs to be faulted, then one must not care about relationships and so on. + * + * @param d2wContext the current d2wContext + * + * @return + */ + public static EOEnterpriseObject localInstanceFromObjectWithD2WContext(EOEnterpriseObject eo, D2WContext d2wContext) { + if (eo.editingContext() == null) { + throw new NullPointerException("localInstanceFromObjectWithD2WContext: the argument eo must have a valid EOEditingContext: eo.editingContext() != null"); + } + EOEnterpriseObject localObject = eo; + if (ERXExtensions.isNewObject(eo)) { + //do nothing, a newObject cannot be faulted into another EC! + } else if ("edit".equals(d2wContext.valueForKey("task"))) { + //create a new nested EC and fault the object into it + EOEditingContext ec = ERXEC.newEditingContext(eo.editingContext()); + //FIXME: we cannot use childEc's because if the EO is not saved to the DB + //then the EO is not displayed as EO if one uses for example a ERD2WEditToOneRelationship + //component: the new EO will not be displayed in the list + //EOEditingContext ec = ERXEC.newEditingContext(); + ec.setSharedEditingContext(null); + localObject = EOUtilities.localInstanceOfObject(ec, eo); + } else { + //create a new Peer EC and fault the object into it + //this is done regardeless if the object's editingContext is + //a sharedec or not. + EOEditingContext ec = ERXEC.newEditingContext(); + ec.setSharedEditingContext(null); + localObject = EOUtilities.localInstanceOfObject(ec, eo); + } + return localObject; + } + + } |