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(forName(prop.getMapType())); for (BeanId beanId : beans) { Bean b = beanId.getBean(); if (b != null) { Object beanInstance = instanceCache.get(beanId); if (beanInstance == null) { try { beanInstance = newInstance(forName(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 String getReferenceSchemaName(String propertyName) { for (AbstractSchemaProperty schema : properties.values()) { if (!schema.getFieldName().equals(propertyName)) { continue; } if (schema instanceof SchemaPropertyRef) { return ((SchemaPropertyRef) schema).getSchemaName(); } if (schema instanceof SchemaPropertyRefList) { return ((SchemaPropertyRefList) schema).getSchemaName(); } if (schema instanceof SchemaPropertyRefMap) { return ((SchemaPropertyRefMap) schema).getSchemaName(); } } return null; }
@Override public boolean equals(Object obj) { if (!(obj instanceof SchemaPropertyRefMap)) { return false; } SchemaPropertyRefMap o = (SchemaPropertyRefMap) obj; return equals(o) && equal(getMapType(), o.getMapType()) && equal(getSchemaName(), o.getSchemaName()); }
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 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); } }
return SchemaPropertyRefMap.create(name, fieldName, getSchemaName(type), type, desc, source.isFinal(), source.getMapRawType().getName(), indexed); } else {
private AbstractSchemaProperty convertReferences(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(); if (source.isCollection()) { return SchemaPropertyRefList.create(name, fieldName, getSchemaName(type), desc, source.isFinal(), source.getCollRawType().getName()); } else if (source.isMap()) { // type is contained in parameterized value of the map type = source.getMapParamTypes().get(1); return SchemaPropertyRefMap.create(name, fieldName, getSchemaName(type), desc, source.isFinal(), source.getMapRawType().getName()); } else { return SchemaPropertyRef.create(name, fieldName, getSchemaName(type), desc, source.isFinal(), isSingleton(type)); } }
/** * Not to be used by users. */ public static SchemaPropertyRefMap create(final String name, final String fieldName, final String schemaName, final Class<?> classType, final String desc, final boolean isImmutable, final String mapType, final boolean indexed) { return new SchemaPropertyRefMap(name, fieldName, schemaName, classType, desc, isImmutable, mapType, indexed); }
@Override public String toString() { return toStringHelper(SchemaPropertyRefList.class).add("mapType", getMapType()) .add("schema-name", getSchemaName()).toString(); }
public XmlSchemaRefMap(SchemaPropertyRefMap p) { this.name = p.getName(); this.fieldName = p.getFieldName(); this.schemaName = p.getSchemaName(); this.mapType = p.getMapType(); this.desc = p.getDesc(); this.isImmutable = p.isImmutable(); } }