@SuppressWarnings("unused") private static void validatePropertyRefMap(Bean bean) { Schema schema = bean.getSchema(); for (SchemaPropertyRefMap prop : schema.get(SchemaPropertyRefMap.class)) { } }
public JaxrsSchema(Schema schema) { this.schemaName = schema.getName(); this.className = schema.getType(); this.desc = schema.getDesc(); this.idName = schema.getId().getName(); this.idDesc = schema.getId().getDesc(); this.singleton = schema.getId().isSingleton(); for (Schema.SchemaProperty prop : schema.get(Schema.SchemaProperty.class)) { property.add(new SchemaProperty(prop)); propertyNames.add(prop.getName()); } for (Schema.SchemaPropertyList prop : schema.get(Schema.SchemaPropertyList.class)) { propertyList.add(new SchemaPropertyList(prop)); propertyNames.add(prop.getName()); } for (Schema.SchemaPropertyRef prop : schema.get(Schema.SchemaPropertyRef.class)) { propertyRef.add(new SchemaPropertyRef(prop)); propertyNames.add(prop.getName()); } for (Schema.SchemaPropertyRefList prop : schema.get(Schema.SchemaPropertyRefList.class)) { propertyRefList.add(new SchemaPropertyRefList(prop)); propertyNames.add(prop.getName()); } for (Schema.SchemaPropertyRefMap prop : schema.get(Schema.SchemaPropertyRefMap.class)) { propertyRefMap.add(new SchemaPropertyRefMap(prop)); propertyNames.add(prop.getName()); } }
private void convertPropertyRefList(Bean source, Map<String, Object> values, Map<BeanId, Object> instanceCache) { for (SchemaPropertyRefList prop : source.getSchema().get(SchemaPropertyRefList.class)) { List<BeanId> references = source.getReference(prop.getName()); if (references == null) { continue; } Collection<Object> c = newCollection(loadClass(prop.getCollectionType())); for (BeanId beanId : references) { Bean b = beanId.getBean(); if (b != null) { Object beanInstance = instanceCache.get(beanId); if (beanInstance == null) { String type = b.getSchema().getType(); try { beanInstance = newInstance(loadClass(type)); } catch (Exception e) { throw new UnsupportedOperationException(e); } beanInstance = convert(b, beanInstance, new HashMap<String, Object>(), instanceCache); } c.add(beanInstance); } } values.put(prop.getFieldName(), c); } }
@SuppressWarnings("unused") private static void validatePropertyRefList(Bean bean) { Schema schema = bean.getSchema(); for (SchemaPropertyRefList prop : schema.get(SchemaPropertyRefList.class)) { } }
private void convertPropertyRefMap(Bean source, Map<String, Object> values, Map<BeanId, Object> instanceCache) { for (SchemaPropertyRefMap prop : source.getSchema().get(SchemaPropertyRefMap.class)) { List<BeanId> beans = source.getReference(prop.getName()); if (beans == null) { continue; } Map<Object, Object> c = newMap(loadClass(prop.getMapType())); for (BeanId beanId : beans) { Bean b = beanId.getBean(); if (b != null) { Object beanInstance = instanceCache.get(beanId); if (beanInstance == null) { try { beanInstance = newInstance(loadClass(b.getSchema().getType())); } catch (Exception e) { throw new UnsupportedOperationException(e); } beanInstance = convert(b, beanInstance, new HashMap<String, Object>(), instanceCache); } c.put(beanId.getInstanceId(), beanInstance); } } values.put(prop.getFieldName(), c); } }
public Set<Class<?>> getReferenceSchemaTypes() { Set<Class<?>> names = new HashSet<>(); for (AbstractSchemaProperty prop : get(SchemaPropertyRef.class)) { names.add(prop.getClassType()); } for (AbstractSchemaProperty prop : get(SchemaPropertyRefList.class)) { names.add(prop.getClassType()); } for (AbstractSchemaProperty prop : get(SchemaPropertyRefMap.class)) { names.add(prop.getClassType()); } return names; }
/** * Returns all property names that exist for this schema. */ public Set<String> getPropertyNames() { Set<String> names = new HashSet<>(); for (AbstractSchemaProperty prop : get(SchemaProperty.class)) { names.add(prop.getName()); } for (AbstractSchemaProperty prop : get(SchemaPropertyList.class)) { names.add(prop.getName()); } return names; }
/** * Returns all property names that exist for this schema. */ public Set<String> getPropertyNames() { Set<String> names = new HashSet<>(); for (AbstractSchemaProperty prop : get(SchemaProperty.class)) { names.add(prop.getName()); } for (AbstractSchemaProperty prop : get(SchemaPropertyList.class)) { names.add(prop.getName()); } return names; }
public Set<Class<?>> getReferenceSchemaTypes() { Set<Class<?>> names = new HashSet<>(); for (AbstractSchemaProperty prop : get(SchemaPropertyRef.class)) { names.add(prop.getClassType()); } for (AbstractSchemaProperty prop : get(SchemaPropertyRefList.class)) { names.add(prop.getClassType()); } for (AbstractSchemaProperty prop : get(SchemaPropertyRefMap.class)) { names.add(prop.getClassType()); } return names; }
/** * Returns a specific properties of a particular type identified with a name. * * @param clazz specific type of property to get. * @param name The AbstractSchemaProperty name of the property. * @return Matching property. */ public <T extends AbstractSchemaProperty> T get(final Class<T> clazz, final String name) { Set<T> propertyCollection = get(clazz); for (T property : propertyCollection) { if (property.getName().equals(name)) { return property; } } return null; }
/** * Returns all reference names that exist for this schema. */ public Set<String> getReferenceNames() { Set<String> names = new HashSet<>(); for (AbstractSchemaProperty prop : get(SchemaPropertyRef.class)) { names.add(prop.getName()); } for (AbstractSchemaProperty prop : get(SchemaPropertyRefList.class)) { names.add(prop.getName()); } for (AbstractSchemaProperty prop : get(SchemaPropertyRefMap.class)) { names.add(prop.getName()); } return names; }
/** * Returns a specific properties of a particular type identified with a name. * * @param clazz specific type of property to get. * @param name The AbstractSchemaProperty name of the property. * @return Matching property. */ public <T extends AbstractSchemaProperty> T get(final Class<T> clazz, final String name) { Set<T> propertyCollection = get(clazz); for (T property : propertyCollection) { if (property.getName().equals(name)) { return property; } } return null; }
/** * Returns all reference names that exist for this schema. */ public Set<String> getReferenceNames() { Set<String> names = new HashSet<>(); for (AbstractSchemaProperty prop : get(SchemaPropertyRef.class)) { names.add(prop.getName()); } for (AbstractSchemaProperty prop : get(SchemaPropertyRefList.class)) { names.add(prop.getName()); } for (AbstractSchemaProperty prop : get(SchemaPropertyRefMap.class)) { names.add(prop.getName()); } return names; }
private static void validatePropertyReferences(Bean bean) { Schema schema = bean.getSchema(); for (SchemaPropertyRef prop : schema.get(SchemaPropertyRef.class)) { validateSingle(bean, prop); } }
private void setSingletonReferences(Bean bean) { Schema s = bean.getSchema(); for (SchemaPropertyRef ref : s.get(SchemaPropertyRef.class)) { if (ref.isSingleton()) { Schema singletonSchema = schemaManager.getSchema(ref.getSchemaName()); Optional<Bean> singleton = beanManager.getSingleton(ref.getSchemaName()); if (singleton.isPresent()) { singleton.get().set(singletonSchema); BeanId singletonId = singleton.get().getId(); singletonId.setBean(singleton.get()); // recursive call. setSingletonReferences(singleton.get()); bean.setReference(ref.getName(), singletonId); } } } }
private void convertProperty(Bean source, Map<String, Object> values) { for (SchemaProperty prop : source.getSchema().get(SchemaProperty.class)) { String value = source.getSingleValue(prop.getName()); String field = prop.getFieldName(); Object converted = conversion.convert(value, loadClass(prop.getType())); values.put(field, converted); } }
private void setSingletonReferences(Bean bean) { Schema s = bean.getSchema(); for (SchemaPropertyRef ref : s.get(SchemaPropertyRef.class)) { if (ref.isSingleton()) { Schema singletonSchema = schemaManager.getSchema(ref.getSchemaName()); Optional<Bean> singleton = beanManager.getSingleton(ref.getSchemaName()); if (!singleton.isPresent()) { initFile(null); Bean fileBean = FILE_CONFIG.get(BeanId.createSingleton(ref.getSchemaName())); if (fileBean != null) { singleton = Optional.of(fileBean); } } if (!singleton.isPresent()) { singleton = Optional.of(Bean.create(BeanId.createSingleton(ref.getSchemaName()))); } singleton.get().set(singletonSchema); BeanId singletonId = singleton.get().getId(); singletonId.setBean(singleton.get()); // recursive call. setSingletonReferences(singleton.get()); bean.setReference(ref.getName(), singletonId); } } }
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 static void validateProperties(Bean bean) { Schema schema = bean.getSchema(); for (SchemaProperty prop : schema.get(SchemaProperty.class)) { String value = validateSingle(bean, prop); if (value == null) { continue; } 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(); 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); } } } }