String _desc = "propDesc" + j; String _defaultValue = "" + j; SchemaProperty prop = SchemaProperty.create(_name, _fieldName, _classType, _desc, true, new ArrayList<String>(), _defaultValue, false); schema.add(prop);
public String toString() { return super.toStringHelper(SchemaProperty.class).add("type", getType()) .add("defaultValue", getDefaultValue()).toString(); }
Object value = null; if (property instanceof SchemaProperty) { Class<?> cls = ((SchemaProperty) property).getClassType(); List<String> values = bean.getValues(propertyName); if (values != null && values.size() > 0) {
} else { return SchemaProperty.create(name, fieldName, type.getName(), desc, source.isFinal(), source.getEnums(), conversion.convert(source.getDefaultValue(), String.class), indexed);
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; }
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 validateProperties(Bean bean) { Schema schema = bean.getSchema(); ClassRepository repos = new ClassRepository(); for (SchemaProperty prop : schema.get(SchemaProperty.class)) { String value = validateSingle(bean, prop); if (value == null) { continue; } 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 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 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"); } }
/** * Not to be used by users. */ public static SchemaProperty create(final String name, final String fieldName, final String type, final String desc, final boolean isImmutable, final List<String> enums, final String defaultValue, final boolean indexed) { return new SchemaProperty(name, fieldName, type, desc, isImmutable, enums, defaultValue, indexed); }
@Override public boolean equals(Object obj) { if (!(obj instanceof SchemaProperty)) { return false; } SchemaProperty o = (SchemaProperty) obj; return super.equals(o) && equal(getDefaultValue(), o.getDefaultValue()) && equal(getType(), o.getType()); } }
@Override public int hashCode() { return Objects.hashCode(super.getHashCode(), getDefaultValue(), getType()); }
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 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, forName(prop.getType())); values.put(field, converted); } }
public XmlSchemaProperty(SchemaProperty p) { this.name = p.getName(); this.fieldName = p.getFieldName(); this.type = p.getType(); this.defaultValue = p.getDefaultValue(); this.desc = p.getDesc(); this.isImmutable = p.isImmutable(); this.isEnum = p.isEnum(); } }