You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2010/06/10 18:12:52 UTC

svn commit: r953367 - /pivot/branches/1.5.x/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java

Author: gbrown
Date: Thu Jun 10 16:12:51 2010
New Revision: 953367

URL: http://svn.apache.org/viewvc?rev=953367&view=rev
Log:
Resolve PIVOT-513.

Modified:
    pivot/branches/1.5.x/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java

Modified: pivot/branches/1.5.x/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java
URL: http://svn.apache.org/viewvc/pivot/branches/1.5.x/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java?rev=953367&r1=953366&r2=953367&view=diff
==============================================================================
--- pivot/branches/1.5.x/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java (original)
+++ pivot/branches/1.5.x/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java Thu Jun 10 16:12:51 2010
@@ -44,8 +44,8 @@ import javax.script.SimpleBindings;
 import javax.xml.stream.Location;
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
 
 import org.apache.pivot.beans.BeanAdapter;
 import org.apache.pivot.collections.ArrayList;
@@ -323,7 +323,7 @@ public class WTKXSerializer implements S
         this(resources, null);
     }
 
-    private WTKXSerializer(Resources resources, WTKXSerializer owner) {
+    protected WTKXSerializer(Resources resources, WTKXSerializer owner) {
         this.resources = resources;
 
         if (owner == null) {
@@ -620,7 +620,7 @@ public class WTKXSerializer implements S
                 try {
                     Class<?> type = Class.forName(className);
                     elementType = Element.Type.INSTANCE;
-                    value = type.newInstance();
+                    value = createInstance(type, id);
                 } catch (Exception exception) {
                     throw new SerializationException(exception);
                 }
@@ -674,6 +674,28 @@ public class WTKXSerializer implements S
         }
     }
 
+    /**
+     * Serializer factory method. Subclasses can override this method to return custom
+     * serializer instances.
+     *
+     * @param resources
+     * @param owner
+     */
+    protected WTKXSerializer createSerializer(Resources resources, WTKXSerializer owner) {
+        return new WTKXSerializer(resources, owner);
+    }
+
+    /**
+     * Object factory method. Subclasses can override this method to perform custom
+     * object instantiation.
+     *
+     * @param type
+     * @param id
+     */
+    protected Object createInstance(Class<?> type, String id) throws Exception {
+        return type.newInstance();
+    }
+
     @SuppressWarnings("unchecked")
     private void processEndElement(XMLStreamReader xmlStreamReader)
         throws SerializationException, IOException {
@@ -717,12 +739,7 @@ public class WTKXSerializer implements S
                     }
 
                     // Read the object
-                    WTKXSerializer serializer;
-                    if (inline) {
-                        serializer = new WTKXSerializer(resources, this);
-                    } else {
-                        serializer = new WTKXSerializer(resources);
-                    }
+                    WTKXSerializer serializer = createSerializer(resources, inline ? this : null);
 
                     if (element.id != null) {
                         if (namedSerializers.containsKey(element.id)) {