You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by km...@apache.org on 2008/01/29 15:37:10 UTC

svn commit: r616346 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/xml: XMLDecoder.java XMLMappingDescriptor.java

Author: kmenard
Date: Tue Jan 29 06:37:08 2008
New Revision: 616346

URL: http://svn.apache.org/viewvc?rev=616346&view=rev
Log:
Replaced DataContext uses with ObjectContext.

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/xml/XMLDecoder.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/xml/XMLMappingDescriptor.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/xml/XMLDecoder.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/xml/XMLDecoder.java?rev=616346&r1=616345&r2=616346&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/xml/XMLDecoder.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/xml/XMLDecoder.java Tue Jan 29 06:37:08 2008
@@ -36,6 +36,7 @@
 
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.Persistent;
+import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.access.DataContext;
 import org.apache.cayenne.reflect.PropertyUtils;
 import org.apache.cayenne.util.Util;
@@ -67,17 +68,17 @@
     /** The root of the XML document being decoded. */
     private Element root;
 
-    /** The data context to register decoded DataObjects with. */
-    private DataContext dataContext;
+    /** The context to register decoded DataObjects with. */
+    private ObjectContext objectContext;
 
     // TODO: H to the A to the C to the K
     private List<Element> decodedCollections = new ArrayList<Element>();
 
     /**
      * Default constructor. This will create an XMLDecoder instance that will decode
-     * objects from XML, but will not register them with any DataContext.
+     * objects from XML, but will not register them with any context.
      * 
-     * @see XMLDecoder#XMLDecoder(DataContext)
+     * @see XMLDecoder#XMLDecoder(ObjectContext)
      */
     public XMLDecoder() {
         this(null);
@@ -85,12 +86,12 @@
 
     /**
      * Creates an XMLDecoder that will register decoded DataObjects with the specified
-     * DataContext.
+     * context.
      * 
-     * @param dc The DataContext to register decoded DataObjects with.
+     * @param objectContext The context to register decoded DataObjects with.
      */
-    public XMLDecoder(DataContext dc) {
-        this.dataContext = dc;
+    public XMLDecoder(ObjectContext objectContext) {
+        this.objectContext = objectContext;
     }
 
     /**
@@ -320,13 +321,13 @@
         // MappingUtils will really do all the work.
         XMLMappingDescriptor mu = new XMLMappingDescriptor(mappingUrl);
 
-        Object ret = mu.decode(data.getDocumentElement(), dataContext);
+        Object ret = mu.decode(data.getDocumentElement(), objectContext);
 
         return ret;
     }
 
     /**
-     * Decodes the XML element to an object. If the supplied DataContext is not null, the
+     * Decodes the XML element to an object. If the supplied context is not null, the
      * object will be registered with it and committed to the database.
      * 
      * @param element The XML element.
@@ -351,8 +352,8 @@
             throw new CayenneRuntimeException("Error instantiating object", th);
         }
 
-        if ((null != dataContext) && (object instanceof Persistent)) {
-            dataContext.registerNewObject(object);
+        if ((null != objectContext) && (object instanceof Persistent)) {
+            objectContext.registerNewObject(object);
         }
 
         root = oldRoot;
@@ -363,7 +364,7 @@
 
     /**
      * Decodes a Collection represented by XML wrapped by a Reader into a List of objects.
-     * Each object will be registered with the supplied DataContext.
+     * Each object will be registered with the supplied context.
      * 
      * @param xml The XML element representing the elements in the collection to decode.
      * @return A List of all the decoded objects.
@@ -417,16 +418,16 @@
     }
 
     /**
-     * Decodes a list of DataObjects, registering them the supplied DataContext.
+     * Decodes a list of DataObjects, registering them the supplied context.
      * 
      * @param xml The wrapped XML encoding of the list of DataObjects.
-     * @param dc The DataContext to register the decode DataObjects with.
+     * @param objectContext The context to register the decode DataObjects with.
      * @return The list of decoded DataObjects.
      * @throws CayenneRuntimeException
      */
-    public static List decodeList(Reader xml, DataContext dc)
+    public static List decodeList(Reader xml, ObjectContext objectContext)
             throws CayenneRuntimeException {
-        return decodeList(xml, null, dc);
+        return decodeList(xml, null, objectContext);
     }
 
     /**
@@ -446,19 +447,19 @@
 
     /**
      * Decodes a list of DataObjects using the supplied mapping file to guide the decoding
-     * process, registering them the supplied DataContext.
+     * process, registering them the supplied context.
      * 
      * @param xml The wrapped XML encoding of the list of objects.
      * @param mappingUrl Mapping file describing how the XML elements and object
      *            properties correlate.
-     * @param dataContext The DataContext to register the decode DataObjects with.
+     * @param objectContext The context to register the decode DataObjects with.
      * @return The list of decoded DataObjects.
      * @throws CayenneRuntimeException
      */
-    public static List decodeList(Reader xml, String mappingUrl, DataContext dataContext)
+    public static List decodeList(Reader xml, String mappingUrl, ObjectContext objectContext)
             throws CayenneRuntimeException {
 
-        XMLDecoder decoder = new XMLDecoder(dataContext);
+        XMLDecoder decoder = new XMLDecoder(objectContext);
         Element listRoot = parse(xml).getDocumentElement();
 
         List ret;
@@ -490,10 +491,10 @@
             Object o;
 
             if (mu != null) {
-                o = mu.decode(e, dataContext);
+                o = mu.decode(e, objectContext);
             }
             else {
-                // decoder will do DataContext registration if needed.
+                // The decoder will do context registration if needed.
                 o = decoder.decodeElement(e);
             }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/xml/XMLMappingDescriptor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/xml/XMLMappingDescriptor.java?rev=616346&r1=616345&r2=616346&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/xml/XMLMappingDescriptor.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/xml/XMLMappingDescriptor.java Tue Jan 29 06:37:08 2008
@@ -28,6 +28,7 @@
 
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.Persistent;
+import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.access.DataContext;
 import org.apache.cayenne.reflect.PropertyUtils;
 import org.w3c.dom.Attr;
@@ -46,7 +47,7 @@
 
     private SerializableEntity rootEntity;
     private Map<String, SerializableEntity> entities;
-    private DataContext dataContext;
+    private ObjectContext objectContext;
 
     /**
      * Creates new XMLMappingDescriptor using a URL that points to the mapping file.
@@ -102,13 +103,13 @@
      * @return The decoded object.
      * @throws CayenneRuntimeException
      */
-    Object decode(Element xml, DataContext dataContext) throws CayenneRuntimeException {
+    Object decode(Element xml, ObjectContext objectContext) throws CayenneRuntimeException {
 
         // TODO: Add an error check to make sure the mapping file actually is for this
         // data file.
 
         // Store a local copy of the data context.
-        this.dataContext = dataContext;
+        this.objectContext = objectContext;
         
         // Create the object to be returned.
         Object ret = createObject(rootEntity.getDescriptor(), xml);
@@ -244,8 +245,8 @@
         }
         
         // If a data context has been supplied by the user, then register the data object with the context.
-        if ((null != dataContext) && (object instanceof Persistent)) {
-            dataContext.registerNewObject(object);
+        if ((null != objectContext) && (object instanceof Persistent)) {
+            objectContext.registerNewObject(object);
         }
 
         NamedNodeMap attributes = objectData.getAttributes();