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 2009/10/05 18:17:16 UTC

svn commit: r821903 - in /incubator/pivot/trunk/wtk: src/org/apache/pivot/wtkx/WTKXSerializer.java test/org/apache/pivot/wtk/test/include_test.content.wtkx test/org/apache/pivot/wtk/test/include_test.wtkx

Author: gbrown
Date: Mon Oct  5 16:17:16 2009
New Revision: 821903

URL: http://svn.apache.org/viewvc?rev=821903&view=rev
Log:
When a <wtkx:include> tag does not define an ID, add its named values to the parent serializer's namespace.

Modified:
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java
    incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/include_test.content.wtkx
    incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/include_test.wtkx

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java?rev=821903&r1=821902&r2=821903&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java Mon Oct  5 16:17:16 2009
@@ -210,19 +210,14 @@
             throws Throwable {
             Object result = null;
 
-            try {
-                String methodName = method.getName();
-                if (methodName.equals(event)) {
-                    try {
-                        scriptEngine.eval(script);
-                    } catch (ScriptException exception) {
-                        System.err.println(exception);
-                        System.err.println(script);
-                    }
+            String methodName = method.getName();
+            if (methodName.equals(event)) {
+                try {
+                    scriptEngine.eval(script);
+                } catch (ScriptException exception) {
+                    System.err.println(exception);
+                    System.err.println(script);
                 }
-            } catch (Throwable throwable) {
-                throwable.printStackTrace();
-                throw throwable;
             }
 
             // If the function didn't return a value, return the default
@@ -251,22 +246,17 @@
             throws Throwable {
             Object result = null;
 
-            try {
-                String methodName = method.getName();
-                Bindings bindings = scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE);
-                if (bindings.containsKey(methodName)) {
-                    Invocable invocable;
-                    try {
-                        invocable = (Invocable)scriptEngine;
-                    } catch (ClassCastException exception) {
-                        throw new SerializationException(exception);
-                    }
-
-                    result = invocable.invokeFunction(methodName, args);
+            String methodName = method.getName();
+            Bindings bindings = scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE);
+            if (bindings.containsKey(methodName)) {
+                Invocable invocable;
+                try {
+                    invocable = (Invocable)scriptEngine;
+                } catch (ClassCastException exception) {
+                    throw new SerializationException(exception);
                 }
-            } catch (Throwable throwable) {
-                throwable.printStackTrace();
-                throw throwable;
+
+                result = invocable.invokeFunction(methodName, args);
             }
 
             // If the function didn't return a value, return the default
@@ -283,19 +273,19 @@
         }
     };
 
-    private URL location = null;
-    private Resources resources = null;
+    private Resources resources;
+    private HashMap<String, Object> namedObjects;
+    private HashMap<String, WTKXSerializer> namedSerializers;
+
+    private XMLInputFactory xmlInputFactory;
+    private ScriptEngineManager scriptEngineManager;
 
+    private URL location = null;
+    private Element element = null;
     private Object root = null;
-    private HashMap<String, Object> namedObjects = new HashMap<String, Object>();
-    private HashMap<String, WTKXSerializer> includeSerializers = new HashMap<String, WTKXSerializer>();
 
-    private ScriptEngineManager scriptEngineManager = null;
     private String language = DEFAULT_LANGUAGE;
 
-    private XMLInputFactory xmlInputFactory;
-    private Element element = null;
-
     public static final char URL_PREFIX = '@';
     public static final char RESOURCE_KEY_PREFIX = '%';
     public static final char OBJECT_REFERENCE_PREFIX = '$';
@@ -324,7 +314,14 @@
     }
 
     public WTKXSerializer(Resources resources) {
+        this(resources, new HashMap<String, Object>(), new HashMap<String, WTKXSerializer>());
+    }
+
+    private WTKXSerializer(Resources resources, HashMap<String, Object> namedObjects,
+        HashMap<String, WTKXSerializer> namedSerializers) {
         this.resources = resources;
+        this.namedObjects = namedObjects;
+        this.namedSerializers = namedSerializers;
 
         xmlInputFactory = XMLInputFactory.newInstance();
         xmlInputFactory.setProperty("javax.xml.stream.isCoalescing", true);
@@ -655,8 +652,8 @@
                 ArrayList<Attribute> staticPropertyAttributes = new ArrayList<Attribute>();
 
                 if (element.type == Element.Type.INCLUDE) {
-                    // Process attributes looking for wtkx:id, src, resources, asynchronous,
-                    // and static property setters only
+                    // Process attributes looking for src, resources, and static property
+                    // setters only
                     String src = null;
                     Resources resources = this.resources;
 
@@ -683,9 +680,12 @@
                     }
 
                     // Read the object
-                    WTKXSerializer serializer = new WTKXSerializer(resources);
-                    if (element.id != null) {
-                        includeSerializers.put(element.id, serializer);
+                    WTKXSerializer serializer;
+                    if (element.id == null) {
+                        serializer = new WTKXSerializer(resources, namedObjects, namedSerializers);
+                    } else {
+                        serializer = new WTKXSerializer(resources);
+                        namedSerializers.put(element.id, serializer);
                     }
 
                     if (src.charAt(0) == '/') {
@@ -700,7 +700,7 @@
                         System.err.println("Include \"" + src + "\" defines unreachable objects.");
                     }
                 } else {
-                    // Process attributes looking for wtkx:id and all property setters
+                    // Process attributes looking for all property setters
                     for (Attribute attribute : element.attributes) {
                         if (Character.isUpperCase(attribute.localName.charAt(0))) {
                             staticPropertyAttributes.add(attribute);
@@ -1160,14 +1160,14 @@
     @Override
     public boolean isEmpty() {
         return namedObjects.isEmpty()
-            && includeSerializers.isEmpty();
+            && namedSerializers.isEmpty();
     }
 
     public void reset() {
         location = null;
 
         namedObjects.clear();
-        includeSerializers.clear();
+        namedSerializers.clear();
 
         root = null;
         language = DEFAULT_LANGUAGE;
@@ -1208,7 +1208,7 @@
         int n = path.length;
         while (i < n && serializer != null) {
             String id = path[i++];
-            serializer = serializer.includeSerializers.get(id);
+            serializer = serializer.namedSerializers.get(id);
         }
 
         return serializer;

Modified: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/include_test.content.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/include_test.content.wtkx?rev=821903&r1=821902&r2=821903&view=diff
==============================================================================
Binary files - no diff available.

Modified: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/include_test.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/include_test.wtkx?rev=821903&r1=821902&r2=821903&view=diff
==============================================================================
Binary files - no diff available.