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); } }
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 SchemaPropertyRefList)) { return false; } SchemaPropertyRefList o = (SchemaPropertyRefList) obj; return equals(o) && equal(getCollectionType(), o.getCollectionType()) && 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; }
return SchemaPropertyRefList.create(name, fieldName, getSchemaName(type), type, desc, source.isFinal(), source.getCollRawType().getName(), indexed); } else if (source.isMap()) {
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(forName(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(forName(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); } }
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 SchemaPropertyRefList create(final String name, final String fieldName, final String schemaName, final Class<?> classType, final String desc, final boolean isImmutable, final String collectionType, final boolean indexed) { return new SchemaPropertyRefList(name, fieldName, schemaName, classType, desc, isImmutable, collectionType, indexed); }
@Override public final String toString() { return toStringHelper(SchemaPropertyRefList.class) .add("collectionType", getCollectionType()).add("schema-name", getSchemaName()) .toString(); } }
public XmlSchemaRefCollection(SchemaPropertyRefList p) { this.name = p.getName(); this.fieldName = p.getFieldName(); this.schemaName = p.getSchemaName(); this.collectionType = p.getCollectionType(); this.desc = p.getDesc(); this.isImmutable = p.isImmutable(); } }