You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by tv...@apache.org on 2009/05/19 20:02:55 UTC
svn commit: r776396 - in /incubator/pivot/trunk: build.xml
wtk/src/pivot/wtkx/BindProcessor.java wtk/src/pivot/wtkx/Bindable.java
Author: tvolkert
Date: Tue May 19 18:02:54 2009
New Revision: 776396
URL: http://svn.apache.org/viewvc?rev=776396&view=rev
Log:
Made slight change to WTKX binding to better leverage the Bindable.ObjectHierarchy interface
Modified:
incubator/pivot/trunk/build.xml
incubator/pivot/trunk/wtk/src/pivot/wtkx/BindProcessor.java
incubator/pivot/trunk/wtk/src/pivot/wtkx/Bindable.java
Modified: incubator/pivot/trunk/build.xml
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/build.xml?rev=776396&r1=776395&r2=776396&view=diff
==============================================================================
--- incubator/pivot/trunk/build.xml (original)
+++ incubator/pivot/trunk/build.xml Tue May 19 18:02:54 2009
@@ -452,7 +452,7 @@
target="${compiler.target}"
encoding="${compiler.encoding}"
failonerror="true">
- <compilerarg value="-Xlint"/>
+ <compilerarg line="-Xlint -processor pivot.wtkx.BindProcessor"/>
<classpath>
<pathelement location="core/${folder.bin}"/>
<pathelement location="wtk/${folder.bin}"/>
Modified: incubator/pivot/trunk/wtk/src/pivot/wtkx/BindProcessor.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtkx/BindProcessor.java?rev=776396&r1=776395&r2=776396&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtkx/BindProcessor.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtkx/BindProcessor.java Tue May 19 18:02:54 2009
@@ -257,8 +257,8 @@
StringBuilder buf = new StringBuilder("class _TMP {");
buf.append("@Override @SuppressWarnings({\"unchecked\",\"cast\"}) ");
buf.append("protected void bind(pivot.collections.Dictionary<String,");
- buf.append("pivot.collections.Dictionary<String, Object>> namedObjectDictionaries) {");
- buf.append("super.bind(namedObjectDictionaries);");
+ buf.append("ObjectHierarchy> objectHierarchies) {");
+ buf.append("super.bind(objectHierarchies);");
// Process @Load fields (and their associated @Bind fields)
if (loadGroups != null) {
@@ -408,8 +408,7 @@
// Public and protected fields get kept for subclasses
if ((loadField.mods.flags & (Flags.PUBLIC | Flags.PROTECTED)) != 0) {
buf.append(String.format
- ("namedObjectDictionaries.put(\"%s\", wtkxSerializer.getNamedObjects());",
- loadFieldName));
+ ("objectHierarchies.put(\"%s\", wtkxSerializer);", loadFieldName));
}
// Process @Bind variables
@@ -450,7 +449,7 @@
* The list of <tt>@Bind</tt> fields
*/
private void processStrandedBinds(StringBuilder buf, List<JCVariableDecl> strandedBindFields) {
- buf.append("pivot.collections.Dictionary<String, Object> namedObjects;");
+ buf.append("ObjectHierarchy objectHierarchy;");
for (JCVariableDecl bindField : strandedBindFields) {
String bindFieldName = bindField.name.toString();
@@ -464,23 +463,19 @@
}
buf.append(String.format
- ("namedObjects = namedObjectDictionaries.get(\"%s\");", loadFieldName));
+ ("objectHierarchy = objectHierarchies.get(\"%s\");", loadFieldName));
buf.append
- ("if (namedObjects == null) {");
+ ("if (objectHierarchy == null) ");
buf.append(String.format
("throw new pivot.wtkx.BindException(\"Property not found: %s.\");", loadFieldName));
- buf.append
- ("}");
buf.append(String.format
- ("object = namedObjects.get(\"%s\");", id));
- buf.append
- ("if (object == null) ");
+ ("%s = objectHierarchy.getObjectByID(\"%s\");", bindFieldName, id));
buf.append(String.format
- ("throw new pivot.wtkx.BindException(\"Element not found: %s.\");", id));
+ ("if (%s == null) ", bindFieldName));
buf.append(String.format
- ("%s = (%s)object;", bindFieldName, bindField.vartype.toString()));
+ ("throw new pivot.wtkx.BindException(\"Element not found: %s.\");", id));
}
}
}
Modified: incubator/pivot/trunk/wtk/src/pivot/wtkx/Bindable.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtkx/Bindable.java?rev=776396&r1=776395&r2=776396&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtkx/Bindable.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtkx/Bindable.java Tue May 19 18:02:54 2009
@@ -183,8 +183,14 @@
* @author tvolkert
*/
public static interface ObjectHierarchy {
+ /**
+ * Gets the root of the object hierarchy.
+ */
<T> T getRootObject();
+ /**
+ * Gets a named object by its ID.
+ */
<T> T getObjectByID(String id);
}
@@ -390,9 +396,8 @@
}
} else {
// Invoke the bind overload
- HashMap<String, Dictionary<String, Object>> namedObjectDictionaries =
- new HashMap<String, Dictionary<String, Object>>();
- bind(namedObjectDictionaries);
+ HashMap<String, ObjectHierarchy> objectHierarchies = new HashMap<String, ObjectHierarchy>();
+ bind(objectHierarchies);
}
}
@@ -401,7 +406,7 @@
* override. It exists to support {@link BindProcessor}. Dealing directly
* with this method in any way may yield unpredictable behavior.
*/
- protected void bind(Dictionary<String, Dictionary<String, Object>> namedObjectDictionaries) {
+ protected void bind(Dictionary<String, ObjectHierarchy> objectHierarchies) {
// No-op
}
}