@Override public void bind(PropertyTree propertyTree, Object object, ReadContext context) throws Exception { @SuppressWarnings("unchecked") Set<Object> set = (Set<Object>) object; List<Object> elements = new ArrayList<>(); forEachElement(propertyTree, elementPath -> elements.add(context.getObject(elementPath))); context.bindAll(); set.addAll(elements); }
public Object getObject() { if (rootNode == null) { return null; } try { Object value = properties.get(rootNode.path); ValueType valueType = schemaRoot.getValue(); Object result = valueType.instantiate(rootNode, value, this); objects.put(rootNode.path, result); valueType.bind(rootNode, result, this); bindAll(); return result; } catch (Exception e) { throw new RuntimeException(e); } }
@Override public Object instantiate(PropertyTree propertyTree, Object valueObject, ReadContext context) throws Exception { Object[] params = constructor.newParametersArray(); int i=0; for (String param : constructor.getParameters()) { PropertyTree child = propertyTree.get(NodeId.property(param)); Object value = child != null ? context.getObject(child) : null; params[i++] = value; } if (constructor.hasParameters()) { // Ensure that constructor parameters are bound context.bindAll(); } Object object = constructor.newInstance(params); if (identifier != null && !constructor.hasParameter(identifier.name) && identifier.property.isWritable()) { PropertyTree child = propertyTree.get(NodeId.property(identifier.name)); if (child != null) { Object value = context.getObject(child); if (value != null) { identifier.property.set(object, value); } } } return object; }