com.regnosys.rosetta.translate.datamodel.SchemaDeserialise Maven / Gradle / Ivy
package com.regnosys.rosetta.translate.datamodel;
import java.util.List;
import com.regnosys.rosetta.translate.CustomDeserialise;
import com.regnosys.rosetta.translate.datamodel.json.JsonAttribute;
import com.regnosys.rosetta.translate.datamodel.json.JsonEntity;
public class SchemaDeserialise extends CustomDeserialise {
public SchemaDeserialise() {
parseMethods.put(Schema.class.getName(), this::readSchema);
parseMethods.put(EntityImpl.class.getName(), this::readEntityImpl);
parseMethods.put(AttributeImpl.class.getName(), this::readAttributeImpl);
parseMethods.put(JsonAttribute.class.getName(), this::readAttributeImpl);
parseMethods.put(EntityImpl.class.getName(), this::readEntityImpl);
parseMethods.put(JsonEntity.class.getName(), this::readEntityImpl);
parseMethods.put(SimpleType.class.getName(), this::readSimpleType);
}
/**
* @param id required to achieve signature symmetry to the other methods on the map
*/
private Schema readSchema(Long id, DeserialiseContext context) {
context.read("attributes");
List atts = readList(context);
context.read("entities:");
List ents = readList(context);
return new Schema(atts, ents);
}
private EntityImpl readEntityImpl(Long objectId, DeserialiseContext context) {
String ns = context.read("namespace:");
String namename = context.read("name:");
boolean hasData = Boolean.valueOf(context.read("hasData:"));
NamespaceName name = new NamespaceName(ns, namename);
EntityImpl entityImpl = new EntityImpl(name, hasData);
context.addObjectId(objectId, entityImpl);
context.read("extends:");
Entity extendedEntity = readOne(context);
entityImpl.setExtended(extendedEntity);
context.read("attributes");
List atts = readList(context);
context.read("extending:");
List extendingEntities = readList(context);
atts.forEach(a -> entityImpl.addAttribute(a));
entityImpl.getKnownExtendingEntities().addAll(extendingEntities);
context.read("child:");
return entityImpl;
}
private AttributeImpl readAttributeImpl(long objectId, DeserialiseContext context) {
String name = context.read("name:");
Cardinality cardinality = Cardinality.valueOf(context.read("cardinality:"));
context.read("type:");
Entity type = readOne(context);
AttributeImpl attributeImpl = new AttributeImpl(name, cardinality, type);
context.addObjectId(objectId, attributeImpl);
return attributeImpl;
}
private SimpleType readSimpleType(long objectId, DeserialiseContext context) {
String ns = context.read("namespace:");
String namename = context.read("name:");
BasicType type = BasicType.valueOf(context.read("type:"));
NamespaceName name = new NamespaceName(ns, namename);
SimpleType simpleType = new SimpleType(name, type);
context.addObjectId(objectId, simpleType);
context.read("extending:");
List extendingEntities = readList(context);
simpleType.getKnownExtendingEntities().addAll(extendingEntities);
return simpleType;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy