From: Adolfo Panizo Date: Fri, 26 Dec 2014 15:49:26 +0000 (+0100) Subject: Adding documentation and renaming some vars X-Git-Tag: gwtquery-project-1.4.3~8^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b571d28f9371a4c95837ddf383699d7211572857;p=gwtquery.git Adding documentation and renaming some vars --- 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 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 valid = getValidMethodsFrom(type.getMethods()); - Hashtable recursiveBuilders = getJsonBuildersFrom(type.getMethods()); + HashSet validAttrs = getAttributeNames(type.getMethods()); + Hashtable 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 getValidMethodsFrom(Method[] methods) { + private HashSet getAttributeNames(Method[] methods) { HashSet valid = new HashSet(); if (methods == null || methods.length == 0) { @@ -311,23 +306,23 @@ public class JsonBuilderHandler implements InvocationHandler { return valid; } - private Hashtable getJsonBuildersFrom(Method[] methods) { - Hashtable recursiveBuilders = new Hashtable(); + private Hashtable getJsonBuilders(Method[] methods) { + Hashtable ispropertyGetters = new Hashtable(); 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