cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmen...@apache.org
Subject svn commit: r533886 - in /cayenne/main/branches/STABLE-2.0/cayenne/cayenne-java/src/cayenne/java/org/apache/cayenne/xml: XMLDecoder.java XMLMappingDescriptor.java
Date Mon, 30 Apr 2007 23:48:03 GMT
Author: kmenard
Date: Mon Apr 30 16:48:02 2007
New Revision: 533886

URL: http://svn.apache.org/viewvc?view=rev&rev=533886
Log:
CAY-763: XML Deserialization fails on relationships when using a mapping file.
Applied Robert Zeigler's patch mostly unchanged.  This allows the XMLDecoder to pass through
a user supplied data context to the mapping decoder.

Modified:
    cayenne/main/branches/STABLE-2.0/cayenne/cayenne-java/src/cayenne/java/org/apache/cayenne/xml/XMLDecoder.java
    cayenne/main/branches/STABLE-2.0/cayenne/cayenne-java/src/cayenne/java/org/apache/cayenne/xml/XMLMappingDescriptor.java

Modified: cayenne/main/branches/STABLE-2.0/cayenne/cayenne-java/src/cayenne/java/org/apache/cayenne/xml/XMLDecoder.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-2.0/cayenne/cayenne-java/src/cayenne/java/org/apache/cayenne/xml/XMLDecoder.java?view=diff&rev=533886&r1=533885&r2=533886
==============================================================================
--- cayenne/main/branches/STABLE-2.0/cayenne/cayenne-java/src/cayenne/java/org/apache/cayenne/xml/XMLDecoder.java
(original)
+++ cayenne/main/branches/STABLE-2.0/cayenne/cayenne-java/src/cayenne/java/org/apache/cayenne/xml/XMLDecoder.java
Mon Apr 30 16:48:02 2007
@@ -202,18 +202,14 @@
 
         try {
             // This crazy conditional checks if we're decoding a collection. There are two
-            // ways
-            // to enter into this body:
+            // ways to enter into this body:
             // 1) If there are two elements at the same level with the same name, then
-            // they should
-            // part of a collection.
+            // they should be part of a collection.
             // 2) If a single occurring element has the "forceList" attribute set to
-            // "YES", then it
-            // too should be treated as a collection.
+            // "YES", then it too should be treated as a collection.
             // 
             // The final part checks that we have not previously attempted to decode this
-            // collection,
-            // which is necessary to prevent infinite loops .
+            // collection, which is necessary to prevent infinite loops.
             if ((((null != child.getParentNode()) && (XMLUtil.getChildren(
                     child.getParentNode(),
                     child.getNodeName()).size() > 1)) || (child
@@ -324,11 +320,7 @@
         // MappingUtils will really do all the work.
         XMLMappingDescriptor mu = new XMLMappingDescriptor(mappingUrl);
 
-        Object ret = mu.decode(data.getDocumentElement());
-
-        if (dataContext != null) {
-            dataContext.registerNewObject((DataObject) ret);
-        }
+        Object ret = mu.decode(data.getDocumentElement(), dataContext);
 
         return ret;
     }
@@ -498,11 +490,7 @@
             Object o;
 
             if (mu != null) {
-                o = mu.decode(e);
-
-                if (dataContext != null && o instanceof DataObject) {
-                    dataContext.registerNewObject((DataObject) o);
-                }
+                o = mu.decode(e, dataContext);
             }
             else {
                 // decoder will do DataContext registration if needed.

Modified: cayenne/main/branches/STABLE-2.0/cayenne/cayenne-java/src/cayenne/java/org/apache/cayenne/xml/XMLMappingDescriptor.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-2.0/cayenne/cayenne-java/src/cayenne/java/org/apache/cayenne/xml/XMLMappingDescriptor.java?view=diff&rev=533886&r1=533885&r2=533886
==============================================================================
--- cayenne/main/branches/STABLE-2.0/cayenne/cayenne-java/src/cayenne/java/org/apache/cayenne/xml/XMLMappingDescriptor.java
(original)
+++ cayenne/main/branches/STABLE-2.0/cayenne/cayenne-java/src/cayenne/java/org/apache/cayenne/xml/XMLMappingDescriptor.java
Mon Apr 30 16:48:02 2007
@@ -27,6 +27,8 @@
 import javax.xml.parsers.DocumentBuilder;
 
 import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.DataObject;
+import org.apache.cayenne.access.DataContext;
 import org.apache.cayenne.property.PropertyUtils;
 import org.w3c.dom.Attr;
 import org.w3c.dom.Document;
@@ -44,6 +46,7 @@
 
     private SerializableEntity rootEntity;
     private Map entities;
+    private DataContext dataContext;
 
     /**
      * Creates new XMLMappingDescriptor using a URL that points to the mapping file.
@@ -99,11 +102,14 @@
      * @return The decoded object.
      * @throws CayenneRuntimeException
      */
-    Object decode(Element xml) throws CayenneRuntimeException {
+    Object decode(Element xml, DataContext dataContext) 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;
+        
         // Create the object to be returned.
         Object ret = createObject(rootEntity.getDescriptor(), xml);
 
@@ -190,7 +196,7 @@
     }
 
     /**
-     * Sets decoded object property. If a property os of Collection type, an object is
+     * Sets decoded object property. If a property is of Collection type, an object is
      * added to the collection.
      */
     private void setProperty(Object object, String propertyName, Object value) {
@@ -235,6 +241,11 @@
         catch (Exception ex) {
             throw new CayenneRuntimeException("Error creating instance of class "
                     + className, ex);
+        }
+        
+        // If a data context has been supplied by the user, then register the data object
with the context.
+        if ((null != dataContext) && (object instanceof DataObject)) {
+            dataContext.registerNewObject((DataObject) object);
         }
 
         NamedNodeMap attributes = objectData.getAttributes();



Mime
View raw message