continue; source.setProperty(name, values);
private void merge(List<Bean> sources, Bean mergeBean) { HashMap<BeanId, Bean> cache = new HashMap<BeanId, Bean>(); for (Bean source : sources) { for (String name : mergeBean.getPropertyNames()) { List<String> values = mergeBean.getValues(name); if (values == null || values.size() == 0) { continue; } source.setProperty(name, values); } for (String name : mergeBean.getReferenceNames()) { List<BeanId> refs = mergeBean.getReference(name); if (refs == null || refs.size() == 0) { source.setReferences(name, refs); continue; } for (BeanId beanId : refs) { Bean bean = cache.get(beanId); if (bean == null) { bean = beanManager.getLazy(beanId); setSchema(bean, schemaManager.getSchemas()); cache.put(beanId, bean); } beanId.setBean(bean); } source.setReferences(name, refs); } } }
private void replace(Bean target, Bean replace) { if (target == null) { // bean did not exist in storage, create it. target = replace; } checkReferencesExist(replace, new ArrayList<Bean>()); for (String name : replace.getPropertyNames()) { List<String> values = replace.getValues(name); if (values == null || values.size() == 0) { // null/empty indicates a remove/reset-to-default op target.remove(name); } else { target.setProperty(name, replace.getValues(name)); } } for (String name : replace.getReferenceNames()) { List<BeanId> values = replace.getReference(name); if (values == null || values.size() == 0) { // null/empty indicates a remove/reset-to-default op target.remove(name); } else { target.setReferences(name, values); } } }
private void replace(Bean target, Bean replace, Map<BeanId, Bean> all) { if (target == null) { // bean did not exist in storage, create it. target = replace; } checkReferencesExist(replace, all); for (String name : replace.getPropertyNames()) { List<String> values = replace.getValues(name); if (values == null || values.size() == 0) { // null/empty indicates a remove/reset-to-default op target.remove(name); } else { target.setProperty(name, replace.getValues(name)); } } for (String name : replace.getReferenceNames()) { List<BeanId> values = replace.getReference(name); if (values == null || values.size() == 0) { // null/empty indicates a remove/reset-to-default op target.remove(name); } else { target.setReferences(name, values); } } }
} else { String converted = conversion.convert(value, String.class); bean.setProperty(name, converted);
public Bean traverse(Set<Bean> beans, Bean parent) { Bean current = Bean.create(BeanId.create(value + "", "binarytree")); current.setProperty("value", value + ""); if (parent != null) { current.setReference("parent", parent.getId()); } if (left != null) { Bean leftBean = left.traverse(beans, current); current.setReference("left", leftBean.getId()); } if (right != null) { Bean rightBean = right.traverse(beans, current); current.setReference("right", rightBean.getId()); } beans.add(current); return current; }
Bean ten = BinaryTreeUtils.getBean(10, beans); eight.setProperty("value", "9"); four.setProperty("value", "7"); admin.merge(four); fail("setting 4 to 7 should not be possible.");
Bean ten = BinaryTreeUtils.getBean(10, beans); eight.setProperty("value", "9"); four.setProperty("value", "7"); admin.merge(four); fail("setting 4 to 7 should not be possible.");
child.setProperty("prop8", "100000"); admin.set(child); fail("10000 does not fit java.lang.Byte"); parent.setProperty("prop14", "not_a_enum"); admin.set(parent); fail("not_a_enum is not a value of TimeUnit");
private Bean copy(Bean bean) { if (bean == null) { return null; } Bean copy = Bean.create(bean.getId()); for (String property : bean.getPropertyNames()) { copy.setProperty(property, bean.getValues(property)); } for (String property : bean.getReferenceNames()) { List<BeanId> ids = bean.getReference(property); for (BeanId id : ids) { copy.addReference(property, BeanId.create(id.getInstanceId(), id.getSchemaName())); } } return copy; } }
child.setProperty("prop8", "100000"); admin.set(child); fail("10000 does not fit java.lang.Byte"); parent.setProperty("prop14", "not_a_enum"); admin.set(parent); fail("not_a_enum is not a value of TimeUnit");