_colDefault.add("simple1"); _colDefault.add("simple2"); SchemaPropertyList col = SchemaPropertyList.create(_name, _fieldName, _classType, _desc, true, new ArrayList<String>(), _colDefault, _colDefault.getClass() .getName(), false);
public String toString() { return Objects.toStringHelper(SchemaPropertyList.class) .add("type", getCollectionType()).add("collectionType", getCollectionType()) .add("defaultValue", getDefaultValues()).toString(); }
@Override public boolean equals(Object obj) { if (!(obj instanceof SchemaPropertyList)) { return false; } SchemaPropertyList o = (SchemaPropertyList) obj; return equals(o) && equal(getCollectionType(), o.getCollectionType()) && equal(getType(), o.getType()); } }
public Map<String, Schema> getSchemas() { Map<String, Schema> result = new HashMap<String, Schema>(); for (XmlSchema b : schemas) { Schema schema = Schema.create( SchemaId.create(b.id.name, b.id.desc, b.id.singleton), b.type, b.name, b.desc); for (XmlSchemaProperty p : b.properties) { schema.add(SchemaProperty.create(p.name, p.fieldName, p.type, p.desc, p.isImmutable, p.isEnum, p.defaultValue)); } for (XmlSchemaCollection p : b.collection) { schema.add(SchemaPropertyList.create(p.name, p.fieldName, p.parameterizedType, p.desc, p.isImmutable, p.isEnum, p.defaultValues, p.collectionType)); } for (XmlSchemaRef p : b.ref) { schema.add(SchemaPropertyRef.create(p.name, p.fieldName, p.schemaName, p.desc, p.isImmutable, p.isSingleton)); } for (XmlSchemaRefCollection p : b.refCollection) { schema.add(SchemaPropertyRefList.create(p.name, p.fieldName, p.schemaName, p.desc, p.isImmutable, p.collectionType)); } for (XmlSchemaRefMap p : b.refMap) { schema.add(SchemaPropertyRefMap.create(p.name, p.fieldName, p.schemaName, p.desc, p.isImmutable, p.mapType)); } result.put(schema.getName(), schema); } return result; }
List<String> defaultValues = new ArrayList<>(converted); return SchemaPropertyList.create(name, fieldName, type.getName(), desc, source .isFinal(), source.getEnums(), defaultValues, source.getCollRawType() .getName(), indexed);
private AbstractSchemaProperty convertSimple(FieldWrap<Config> source) { String name = source.getAnnotation().name(); String desc = source.getAnnotation().desc(); String fieldName = source.getFieldName(); if (name == null || "".equals(name)) { name = fieldName; } Class<?> type = source.getType(); validateField(source); try { if (source.isCollection()) { Collection<String> converted = conversion.convert(source.getDefaultValues(), String.class); List<String> defaultValues = new ArrayList<String>(converted); return SchemaPropertyList.create(name, fieldName, type.getName(), desc, source .isFinal(), source.isEnum(), defaultValues, source.getCollRawType() .getName()); } else { return SchemaProperty.create(name, fieldName, type.getName(), desc, source.isFinal(), source.isEnum(), conversion.convert(source.getDefaultValue(), String.class)); } } catch (ConversionException e) { throw CFG104_UNSUPPORTED_PROPERTY(String.class, name, type); } }
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); } } } }
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 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 Class<?> getType(final AbstractSchemaProperty property) { if (property instanceof SchemaProperty) { return ((SchemaProperty) property).getClassType(); } else if (property instanceof SchemaPropertyList) { return ((SchemaPropertyList) property).getClassCollectionType(); } else if (property instanceof SchemaPropertyRef) { return String.class; } else if (property instanceof SchemaPropertyRefList || property instanceof SchemaPropertyRefMap) { return ArrayList.class; } else { throw new IllegalArgumentException("Unrecognized property"); } }
public XmlSchemaCollection(SchemaPropertyList p) { this.name = p.getName(); this.fieldName = p.getFieldName(); this.parameterizedType = p.getType(); this.collectionType = p.getCollectionType(); this.desc = p.getDesc(); this.isImmutable = p.isImmutable(); this.isImmutable = p.isEnum(); this.defaultValues = p.getDefaultValues(); } }
@Override public int hashCode() { return Objects.hashCode(super.getHashCode(), getType(), getCollectionType()); }
/** * Not to be used by users. */ public static SchemaPropertyList create(final String name, final String fieldName, final String type, final String desc, boolean isImmutable, final List<String> enums, List<String> defaultValues, final String collectionType, final boolean indexed) { return new SchemaPropertyList(name, fieldName, type, desc, isImmutable, enums, collectionType, defaultValues, indexed); }