/** * A helper method for getting the value of single valued properties. Returns * null if the property does not exist. * * @param propertyName name of the property as defined by the bean's schema. * @return final String representations of the property that conforms to * its type as defined by the bean's schema. */ public String getSingleValue(final String propertyName) { Preconditions.checkNotNull(propertyName); List<String> values = getValues(propertyName); if (values == null || values.size() < 1) { return null; } return values.get(0); }
private void createJpaProperties(Bean bean) { for (String name : bean.getPropertyNames()) { List<String> values = bean.getValues(name); if (values == null) { continue; } for (String value : values) { getEmOrFail().persist(new JpaProperty(bean.getId(), name, value)); } } }
if (property instanceof SchemaProperty) { Class<?> cls = ((SchemaProperty) property).getClassType(); List<String> values = bean.getValues(propertyName); if (values != null && values.size() > 0) { value = conv.convert(values.get(0), cls); SchemaPropertyList list = (SchemaPropertyList) property; Class<?> cls = list.getClassType(); List<String> values = bean.getValues(propertyName); if (values != null && values.size() > 0) { value = conv.convert(values, cls);
@Test public void test_context_injection() { CdiSingletonConfig config = new CdiSingletonConfig("newvalue"); Bean bean = toBean(config); admin.create(bean); admin.set(bean); BeanId id = BeanId.createSingleton(CdiSingletonConfig.class.getSimpleName()); bean = admin.get(id).get(); assertThat(bean.getValues("value").get(0), is("newvalue")); config = this.config.get(CdiSingletonConfig.class); assertThat(config.getValue(), is("newvalue")); } }
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 static String validateSingle(Bean bean, AbstractSchemaProperty prop) { List<String> values = bean.getValues(prop.getName()); if (values == null) { return null; } if (prop.isImmutable()) { throw Events.CFG306_PROPERTY_IMMUTABLE(bean.getId(), prop.getName()); } if (values.size() > 1) { throw Events.CFG106_WRONG_MULTIPLICITY_TYPE(bean.getId(), prop.getName()); } if (values.size() == 0) { return null; } return values.get(0); }
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); } } }
private void mergeProperties(Map<BeanId, Bean> mergeBeans, List<Bean> stored) { for (Bean store : stored) { Bean mergeBean = mergeBeans.get(store.getId()); for (String name : mergeBean.getPropertyNames()) { deleteProperty(store.getId(), name); List<String> values = mergeBean.getValues(name); if (values == null) { continue; } for (String value : values) { getEmOrFail().persist(new JpaProperty(mergeBean.getId(), name, value)); } } } }
private static String validateSingle(Bean bean, AbstractSchemaProperty prop) { List<String> values = bean.getValues(prop.getName()); if (values == null) { return null; } if (prop.isImmutable()) { throw Events.CFG306_PROPERTY_IMMUTABLE(bean.getId(), prop.getName()); } if (values.size() > 1) { throw Events.CFG106_WRONG_MULTIPLICITY_TYPE(bean.getId(), prop.getName()); } return values.get(0); } }
for (Bean source : sources) { for (String name : mergeBean.getPropertyNames()) { List<String> values = mergeBean.getValues(name); if (values == null || values.size() == 0) { continue;
public XmlBean(Bean bean) { this.id = bean.getId().getInstanceId(); this.name = bean.getId().getSchemaName(); this.singleton = bean.getId().isSingleton(); for (String name : bean.getPropertyNames()) { List<String> values = bean.getValues(name); if (values == null || values.size() == 0) { continue; } properties.add(new XmlBeanPropertyList(name, values)); } for (String name : bean.getReferenceNames()) { List<BeanId> ids = bean.getReference(name); if (ids == null || ids.size() == 0) { continue; } String schemaName = ids.get(0).getSchemaName(); references.add(new XmlBeanPropertyRefList(name, schemaName, ids)); } } }
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 convertPropertyList(Bean source, Map<String, Object> values) { for (SchemaPropertyList prop : source.getSchema().get(SchemaPropertyList.class)) { List<String> vals = source.getValues(prop.getName()); String field = prop.getFieldName(); if (vals == null) { continue; } Collection<Object> c = newCollection(loadClass(prop.getCollectionType())); for (String val : vals) { Object converted = conversion.convert(val, loadClass(prop.getType())); c.add(converted); } values.put(field, c); } }
private void convertPropertyList(Bean source, Map<String, Object> values) { for (SchemaPropertyList prop : source.getSchema().get(SchemaPropertyList.class)) { List<String> vals = source.getValues(prop.getName()); String field = prop.getFieldName(); if (vals == null) { continue; } Collection<Object> c = newCollection(forName(prop.getCollectionType())); for (String val : vals) { Object converted = conversion.convert(val, forName(prop.getType())); c.add(converted); } values.put(field, c); } }
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; } }
private static void validatePropertyList(Bean bean) { Schema schema = bean.getSchema(); for (SchemaPropertyList prop : schema.get(SchemaPropertyList.class)) { List<String> values = bean.getValues(prop.getName()); if (values == null) { continue; } for (String value : values) { try { conversion.convert(value, forName(prop.getType())); } catch (Exception e) { throw Events.CFG105_WRONG_PROPERTY_TYPE(bean.getId(), prop.getName(), prop.getType(), value); } } } }
private static void validatePropertyList(Bean bean) { Schema schema = bean.getSchema(); ClassRepository repos = new ClassRepository(); for (SchemaPropertyList prop : schema.get(SchemaPropertyList.class)) { List<String> values = bean.getValues(prop.getName()); if (values == null) { continue; } for (String value : values) { try { conversion.convert(value, repos.loadClass(prop.getType())); } catch (Exception e) { throw Events.CFG105_WRONG_PROPERTY_TYPE(bean.getId(), prop.getName(), prop.getType(), value); } } } }