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/09/17 20:25:33 UTC
svn commit: r998235 - in /pivot/trunk:
core/src/org/apache/pivot/beans/BXMLSerializer.java
tests/src/org/apache/pivot/tests/issues/pivot_556.bxml
Author: gbrown
Date: Fri Sep 17 18:25:33 2010
New Revision: 998235
URL: http://svn.apache.org/viewvc?rev=998235&view=rev
Log:
Resolve PIVOT-556.
Added:
pivot/trunk/tests/src/org/apache/pivot/tests/issues/pivot_556.bxml
Modified:
pivot/trunk/core/src/org/apache/pivot/beans/BXMLSerializer.java
Modified: pivot/trunk/core/src/org/apache/pivot/beans/BXMLSerializer.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/beans/BXMLSerializer.java?rev=998235&r1=998234&r2=998235&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/beans/BXMLSerializer.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/beans/BXMLSerializer.java Fri Sep 17 18:25:33 2010
@@ -75,7 +75,8 @@ public class BXMLSerializer implements S
LISTENER_LIST_PROPERTY,
INCLUDE,
SCRIPT,
- DEFINE
+ DEFINE,
+ REFERENCE
}
public final Element parent;
@@ -273,6 +274,9 @@ public class BXMLSerializer implements S
public static final String DEFINE_TAG = "define";
+ public static final String REFERENCE_TAG = "reference";
+ public static final String REFERENCE_ID_ATTRIBUTE = "id";
+
public static final String DEFAULT_LANGUAGE = "javascript";
public static final String MIME_TYPE = "application/bxml";
@@ -711,6 +715,8 @@ public class BXMLSerializer implements S
elementType = Element.Type.SCRIPT;
} else if (localName.equals(DEFINE_TAG)) {
elementType = Element.Type.DEFINE;
+ } else if (localName.equals(REFERENCE_TAG)) {
+ elementType = Element.Type.REFERENCE;
} else {
throw new SerializationException("Invalid element.");
}
@@ -794,8 +800,8 @@ public class BXMLSerializer implements S
element = new Element(element, elementType, name, propertyClass, value);
processAttributes();
- // If the element is an include, load it
if (elementType == Element.Type.INCLUDE) {
+ // Load the include
if (!element.properties.containsKey(INCLUDE_SRC_ATTRIBUTE)) {
throw new SerializationException(INCLUDE_SRC_ATTRIBUTE
+ " attribute is required for " + BXML_PREFIX + ":" + INCLUDE_TAG
@@ -878,6 +884,20 @@ public class BXMLSerializer implements S
} finally {
inputStream.close();
}
+ } else if (element.type == Element.Type.REFERENCE) {
+ // Dereference the value
+ if (!element.properties.containsKey(REFERENCE_ID_ATTRIBUTE)) {
+ throw new SerializationException(REFERENCE_ID_ATTRIBUTE
+ + " attribute is required for " + BXML_PREFIX + ":" + REFERENCE_TAG
+ + " tag.");
+ }
+
+ String id = element.properties.get(REFERENCE_ID_ATTRIBUTE);
+ if (!namespace.containsKey(id)) {
+ throw new SerializationException("A value with ID \"" + id + "\" does not exist.");
+ }
+
+ element.value = namespace.get(id);
}
// If the element has an ID, add the value to the namespace
@@ -940,6 +960,10 @@ public class BXMLSerializer implements S
property = (localName.equals(SCRIPT_SRC_ATTRIBUTE));
break;
}
+
+ case REFERENCE: {
+ property = (localName.equals(REFERENCE_ID_ATTRIBUTE));
+ }
}
if (property) {
@@ -1050,7 +1074,8 @@ public class BXMLSerializer implements S
private void processEndElement() throws SerializationException {
switch (element.type) {
case INSTANCE:
- case INCLUDE: {
+ case INCLUDE:
+ case REFERENCE: {
// Apply attributes
for (Attribute attribute : element.attributes) {
if (attribute.propertyClass == null) {
Added: pivot/trunk/tests/src/org/apache/pivot/tests/issues/pivot_556.bxml
URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/issues/pivot_556.bxml?rev=998235&view=auto
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/issues/pivot_556.bxml (added)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/issues/pivot_556.bxml Fri Sep 17 18:25:33 2010
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License,
+Version 2.0 (the "License"); you may not use this file except in
+compliance with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+
+<Window title="Value Tag Test" maximized="true"
+ xmlns:bxml="http://pivot.apache.org/bxml"
+ xmlns="org.apache.pivot.wtk">
+ <bxml:define>
+ <BoxPane bxml:id="boxPane"/>
+ </bxml:define>
+
+ <content>
+ <bxml:reference id="boxPane" styles="{horizontalAlignment:'center'}">
+ <Label text="Hello World!"/>
+ </bxml:reference>
+ </content>
+</Window>