aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdolfo Panizo <adolfo.panizo@gmail.com>2014-12-26 16:49:26 +0100
committerAdolfo Panizo <adolfo.panizo@gmail.com>2014-12-26 16:49:26 +0100
commitb571d28f9371a4c95837ddf383699d7211572857 (patch)
tree30c2b5dce0342fc37ace40c31e03a6605ab1f412
parent195620f534fa11002f393ced2657fe80c37a9b29 (diff)
downloadgwtquery-b571d28f9371a4c95837ddf383699d7211572857.tar.gz
gwtquery-b571d28f9371a4c95837ddf383699d7211572857.zip
Adding documentation and renaming some vars
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/IsProperties.java2
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/vm/JsonBuilderHandler.java45
2 files changed, 22 insertions, 25 deletions
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/IsProperties.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/IsProperties.java
index 3b88edf5..f630cf21 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/client/IsProperties.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/IsProperties.java
@@ -35,6 +35,8 @@ public interface IsProperties {
/**
* Removes the extra JSON and leaves only the setters/getters described
* in the JsonBuilder interface.
+ * If the object contains another IsProperties attributes the method strip()
+ * is called on them.
*/
<T extends IsProperties> T strip();
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/vm/JsonBuilderHandler.java b/gwtquery-core/src/main/java/com/google/gwt/query/vm/JsonBuilderHandler.java
index 5e7e1e54..8d9b9a4c 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/vm/JsonBuilderHandler.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/vm/JsonBuilderHandler.java
@@ -231,36 +231,31 @@ public class JsonBuilderHandler implements InvocationHandler {
return s != null && s.length() > 0 ? s.substring(0, 1).toLowerCase() + s.substring(1) : s;
}
- /**
- * @param proxy
+ /*
+ * This method removes all the json which is not mapped into a
+ * method inside the JsonBuilder Object.
+ * Also if the proxy contains another JsonBuilder in their methods
+ * the method strip() is called.
*/
- private void stripProxy(JsonBuilder proxy) {
+ private void stripProxy(JsonBuilder proxy) throws Throwable {
Class<?> type = proxy.getClass().getInterfaces()[0];
- HashSet<String> valid = getValidMethodsFrom(type.getMethods());
- Hashtable<String, Method> recursiveBuilders = getJsonBuildersFrom(type.getMethods());
+ HashSet<String> validAttrs = getAttributeNames(type.getMethods());
+ Hashtable<String, Method> ispropertyGetters = getJsonBuilders(type.getMethods());
for (String key : jsonObject.keys()) {
String name = methodName2AttrName(key);
- if (!valid.contains(name)) {
+ if (!validAttrs.contains(name)) {
jsonObject.remove(key);
continue;
}
- Method recursiveBuilder = recursiveBuilders.get(name);
- if (recursiveBuilder != null) {
- callRecursiveStrip(proxy, recursiveBuilder);
+ Method ispropertyGetter = ispropertyGetters.get(name);
+ if (ispropertyGetter != null) {
+ ((IsProperties) invoke(proxy, ispropertyGetter, new Object[] {})).strip();
}
}
}
- private void callRecursiveStrip(JsonBuilder proxy, Method recursiveBuilder) {
- try {
- ((IsProperties) invoke(proxy, recursiveBuilder, new Object[] {})).strip();
- } catch (Throwable e) {
- e.printStackTrace();
- }
- }
-
private String getDataBindingClassName(Class<?> type) {
for (Class<?> c : type.getInterfaces()) {
if (c.equals(JsonBuilder.class)) {
@@ -292,7 +287,7 @@ public class JsonBuilderHandler implements InvocationHandler {
return ret;
}
- private HashSet<String> getValidMethodsFrom(Method[] methods) {
+ private HashSet<String> getAttributeNames(Method[] methods) {
HashSet<String> valid = new HashSet<String>();
if (methods == null || methods.length == 0) {
@@ -311,23 +306,23 @@ public class JsonBuilderHandler implements InvocationHandler {
return valid;
}
- private Hashtable<String, Method> getJsonBuildersFrom(Method[] methods) {
- Hashtable<String, Method> recursiveBuilders = new Hashtable<String, Method>();
+ private Hashtable<String, Method> getJsonBuilders(Method[] methods) {
+ Hashtable<String, Method> ispropertyGetters = new Hashtable<String, Method>();
if (methods == null || methods.length == 0) {
- return recursiveBuilders;
+ return ispropertyGetters;
}
for (Method m : methods) {
Class<?>[] classes = m.getParameterTypes();
- boolean isRecursiveJsonBuilder =
+ boolean isJsonBuilder =
classes.length == 0 && IsProperties.class.isAssignableFrom(m.getReturnType());
- if (isRecursiveJsonBuilder) {
+ if (isJsonBuilder) {
String attr = methodName2AttrName(m.getName());
- recursiveBuilders.put(attr, m);
+ ispropertyGetters.put(attr, m);
}
}
- return recursiveBuilders;
+ return ispropertyGetters;
}
} \ No newline at end of file