All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.regnosys.rosetta.translate.datamodel.SchemaSerialise Maven / Gradle / Ivy

There is a newer version: 11.25.1
Show newest version
package com.regnosys.rosetta.translate.datamodel;

import java.util.function.BiConsumer;

import com.regnosys.rosetta.translate.CustomSerialise;
import com.regnosys.rosetta.translate.datamodel.json.JsonAttribute;
import com.regnosys.rosetta.translate.datamodel.json.JsonEntity;

public class SchemaSerialise extends CustomSerialise{
	
	public SchemaSerialise() {
		serialiseMethods.put(AttributeImpl.class, (BiConsumer) this::serialiseAtt);
		serialiseMethods.put(JsonAttribute.class, (BiConsumer) this::serialiseAtt);
		serialiseMethods.put(Schema.class, (BiConsumer) this::serialiseSchema);
		serialiseMethods.put(EntityImpl.class, (BiConsumer) this::serialiseEntity);
		serialiseMethods.put(JsonEntity.class, (BiConsumer) this::serialiseEntity);
		serialiseMethods.put(SimpleType.class, (BiConsumer) this::serialiseSimpleType);
	}
	
	private void serialiseSchema(Schema schema, SerialiseContext context) {
		writeCollection("attributes:", schema.getAttributes(), context);
		writeCollection("entities:", schema.getGlobalTypes(), context);
	}
	
	private void serialiseAtt(Attribute att, SerialiseContext context) {
		print("name:", att.getName(), context);
		print("cardinality:", att.getCardinality().toString(), context);
		print("type:", "", context);
		writeObjOrRef(att.getType(), context);
	}
	
	private void serialiseEntity(Entity ent, SerialiseContext context) {
		print("namespace:", ent.getName().getNamespace(), context);
		print("name:", ent.getName().getName(), context);
		print("hasData:", ent.hasData(), context);
		print("extends:", "", context);
		writeObjOrRef(ent.getExtendedEntity(), context);

		writeCollection("attributes:", ent.getAttributes(), context);

		print("extending:", "[", context);
		for (Entity ext : ent.getKnownExtendingEntities()) {
			writeObjOrRef(ext, context);
		}
		print("]", context);
		print("child:", ent.hasChild(), context);
	}
	
	private void serialiseSimpleType(SimpleType type, SerialiseContext context) {
		print("namespace:", type.getName().getNamespace(), context);
		print("name:", type.getName().getName(), context);
		print("type:", type.getType().toString(), context);

		print("extending:", "[", context);
		for (Entity ext : type.getKnownExtendingEntities()) {
			writeObjOrRef(ext, context);
		}
		print("]", context);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy