private void syncAnnotatedPropertyDefaultAttributes( HashSet<OrmPersistentAttribute> contextAttributes) { Collection<JavaResourceMethod> resourceMethods = CollectionTools.collection(this.getJavaResourceMethods()); // iterate through all resource methods searching for persistable getters for (JavaResourceMethod getterMethod : this.getJavaResourcePropertyGetters()) { JavaResourceMethod setterMethod = JavaResourceMethod.SET_METHOD_TRANSFORMER.transform(getterMethod); if (javaResourcePropertyIsDefault(getterMethod, setterMethod)) { if (getterMethod.isAnnotated() || (setterMethod != null && setterMethod.isAnnotated())) { boolean match = false; for (Iterator<OrmPersistentAttribute> stream = contextAttributes.iterator(); stream.hasNext(); ) { OrmPersistentAttribute contextAttribute = stream.next(); if (contextAttribute.isFor(getterMethod, setterMethod)) { match = true; contextAttribute.update(); stream.remove(); break; } } if (!match) { this.addDefaultAttribute( getDefaultAttributesSize(), this.buildVirtualAttribute(getterMethod, setterMethod)); } } } resourceMethods.remove(getterMethod); resourceMethods.remove(setterMethod); } this.syncRemainingResourceDefaultMethods(contextAttributes, resourceMethods); }
private void syncRemainingResourceDefaultMethods( HashSet<OrmPersistentAttribute> contextAttributes, Collection<JavaResourceMethod> resourceMethods) { // iterate through remaining resource methods and search for those that are annotated. // all getter methods will already be used. for (JavaResourceMethod resourceMethod : resourceMethods) { if (resourceMethod.isAnnotated()) { boolean match = false; // annotated setter(or other random method) with no corresponding getter, bring into context // model for validation purposes for (Iterator<OrmPersistentAttribute> stream = contextAttributes.iterator(); stream.hasNext(); ) { OrmPersistentAttribute contextAttribute = stream.next(); if (contextAttribute.isFor(null, resourceMethod)) { match = true; contextAttribute.update(); stream.remove(); break; } } if (!match) { this.addDefaultAttribute( getDefaultAttributesSize(), this.buildVirtualAttribute(null, resourceMethod)); } } } }
/** * Return whether the pair of Java methods form a "property" (sorta). An annotated getter with no * setter is still brought into the context model (for validation purposes).... */ protected boolean methodPairIsProperty( JavaResourceMethod getterMethod, JavaResourceMethod setterMethod) { return (setterMethod != null) || getterMethod.isAnnotated(); }