public class OMTGAttribute implements Cloneable {

	private String name, type, length, scale, defaultt, size;
	private boolean isKey, isNotNull;
	private List<String> domain;

	public OMTGAttribute(String name, String type) {
		this.name = name;
		this.type = type;
		this.isKey = false;
		this.isNotNull = false;
		this.domain = null;
	}

	public String getDefaultValue() {
		return defaultt;
	}

	public void setDefaultt(String defaultt) {
		this.defaultt = defaultt;
	}

	public String getName() {
		return name;
	}

	public String getType() {
		return type;
	}

	public void setIsKey() {
		this.isKey = true;
	}

	public void setIsNotNull() {
		this.isNotNull = true;
	}

	public boolean isKey() {
		return isKey;
	}

	public String getSize() {
		return size;
	}

	public void setSize(String size) {
		this.size = size;
	}

	public String getLength() {
		return length;
	}

	public void setLength(String length) {
		this.length = length;
	}

	public String getScale() {
		return scale;
	}

	public void setScale(String scale) {
		this.scale = scale;
	}

	public boolean isNotNull() {
		return isNotNull;
	}

	public void setNotNull(boolean notNull) {
		this.isNotNull = notNull;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setType(String type) {
		this.type = type;
	}

	public void setKey(boolean isKey) {
		this.isKey = isKey;
	}

	public boolean hasDomain() {
		return domain != null;
	}

	public List<String> getDomain() {
		return domain;
	}

	public void setDomain(List<String> enumeration) {
		this.domain = enumeration;
	}

	public Object clone() throws CloneNotSupportedException {
		return super.clone();
	}
} public class OMTGCardinality {

	public static final String ONE_TO_ONE = "(1,1)";
	public static final String ONE_TO_MANY = "(1,*)";
	public static final String MANY_TO_ONE = "(*,1)";
	public static final String MANY_TO_MANY = "(*,*)";
	public static final int PARTIAL = 0;
	public static final int TOTAL = 1;

	private String min;
	private String max;
	private int participation;

	public OMTGCardinality(String cardString) {
		Scanner in = new Scanner(cardString);
		in.useDelimiter(",");
		this.min = in.next();
		this.max = in.next();
		if (min.equals("0")) 
			this.participation = 0; //partial
		else this.participation = 1; //total
		
		in.close();
	}

	public OMTGCardinality(String min, String max) {
		this.min = min;
		this.max = max;
		if (min.equals("0")) 
			this.participation = 0; //partial
		else this.participation = 1; //total
	}

	public int getParticipation() {
		return participation;
	}

	public String getMin() {
		return min;
	}

	public String getMax() {
		return max;
	}

	public boolean isEqual(OMTGCardinality card) {
		if ((min.equals(card.getMin()) && max.equals(card.getMax())) ||
				(min.equals(card.getMax()) && max.equals(card.getMin()))) {
			return true;
		}
		return false;
	}

	public String toString() {
		return "(" + min + "," + max + ")";
	}
} public class OMTGClass implements Cloneable {

	public static final String PLANAR_SUBDIVISION = "planar-subdivision";
	public static final String ISOLINES = "isolines";
	public static final String TESSELATION = "tesselation";
	public static final String TIN = "TIN";

	private String name, type;
	private List<OMTGRelationship> relationships;
	private List<OMTGAttribute> attributes;
	private OMTGGeneralization generalization;
	private boolean isSuperClass;

	public OMTGClass(String name, String type, List<OMTGAttribute> attributes) {
		this.name = name;
		this.type = type;
		this.attributes = attributes;
		this.relationships = new ArrayList<OMTGRelationship>();
		this.isSuperClass = false;
	}

	public String getName() {
		return name;
	}

	public List<OMTGAttribute> getAttributes() {
		return attributes;
	}

	public List<OMTGAttribute> getAttributesWithPrefix(String prefix) {

		prefix += "_";

		List<OMTGAttribute> attributesAux = new ArrayList<OMTGAttribute>();
		for (int i = 0; i < attributes.size(); i++) {

			OMTGAttribute newAttribute;
			try {
				newAttribute = (OMTGAttribute) attributes.get(i).clone();
				newAttribute.setName(prefix + newAttribute.getName());
				attributesAux.add(newAttribute);
			} catch (CloneNotSupportedException e) {
				e.printStackTrace();
			}
		}

		return attributesAux;
	}

	public void addRelationship(OMTGRelationship r) {
		relationships.add(r);
	}

	public List<OMTGRelationship> getRelationships() {
		return relationships;
	}

	public void addAttribute(OMTGAttribute a) {
		attributes.add(a);
	}

	public String toString() {
		return name;
	}

	public OMTGGeneralization getGeneralization() {
		return generalization;
	}

	public boolean hasGeneralization() {
		return generalization != null;
	}

	public void setGeneralization(OMTGGeneralization i) {
		generalization = i;
	}

	public boolean isSuperClass() {
		return isSuperClass;
	}

	public void setSuperClass(boolean isSuperClass) {
		this.isSuperClass = isSuperClass;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public boolean typeEquals(String type) {
		return this.type.equalsIgnoreCase(type);
	}

	public boolean isSpatial() {
		return !typeEquals("conventional");
	}

	public boolean isPlanarSubdivision() {
		return type.equalsIgnoreCase(PLANAR_SUBDIVISION);
	}

	public boolean isIsoline() {
		return type.equalsIgnoreCase(ISOLINES);
	}

	public boolean isTesselation() {
		return type.equalsIgnoreCase(TESSELATION);
	}

	public boolean isTIN() {
		return type.equalsIgnoreCase(TIN);
	}

	public void setAttributes(List<OMTGAttribute> attributes) {
		this.attributes = attributes;
	}

	public List<String> getAttributesName() {
		List<String> attributesName = new ArrayList<String>();
		for (OMTGAttribute attribute : attributes) {
			attributesName.add(attribute.getName());
		}
		return attributesName;
	}

	public List<String> getAttributesType() {
		List<String> attributesType = new ArrayList<String>();
		for (OMTGAttribute attribute : attributes) {
			attributesType.add(attribute.getType());
		}
		return attributesType;
	}

	public List<String> getKeysName() {
		List<String> keys = new ArrayList<String>();
		for (OMTGAttribute attribute : attributes) {
			if (attribute.isKey() == true) {
				keys.add(attribute.getName());
			}
		}
		return keys;
	}

	public List<String> getKeysType() {
		List<String> keysType = new ArrayList<String>();
		for (OMTGAttribute attribute : attributes) {
			if (attribute.isKey() == true) {
				keysType.add(attribute.getType());
			}
		}
		return keysType;
	}

	public List<String> getKeysLength() {
		List<String> keysType = new ArrayList<String>();
		for (OMTGAttribute attribute : attributes) {
			if (attribute.isKey() == true) {
				keysType.add(attribute.getLength());
			}
		}
		return keysType;
	}

	public List<String> getKeysScale() {
		List<String> keysType = new ArrayList<String>();
		for (OMTGAttribute attribute : attributes) {
			if (attribute.isKey() == true) {
				keysType.add(attribute.getScale());
			}
		}
		return keysType;
	}

	public List<OMTGAttribute> getAttributeKeys() {
		List<OMTGAttribute> keys = new ArrayList<OMTGAttribute>();
		for (OMTGAttribute attribute : attributes) {
			if (attribute.isKey() == true) {
				keys.add(attribute);
			}
		}
		return keys;
	}

	public List<String> getAttributeLength() {
		List<String> lengthAttributes = new ArrayList<String>();
		for (OMTGAttribute attribute : attributes) {
			lengthAttributes.add(attribute.getLength());
		}
		return lengthAttributes;
	}

	public List<String> getAttributeScale() {
		List<String> scaleAttributes = new ArrayList<String>();
		for (OMTGAttribute attribute : attributes) {
			scaleAttributes.add(attribute.getScale());
		}
		return scaleAttributes;
	}

	public List<Boolean> getAttributeNotNulls() {
		List<Boolean> notNullsAttributes = new ArrayList<Boolean>();
		for (OMTGAttribute attribute : attributes) {
			notNullsAttributes.add(attribute.isNotNull());
		}
		return notNullsAttributes;
	}

	public List<String> getAttributeDefault() {
		List<String> defaultAttribute = new ArrayList<String>();
		for (OMTGAttribute attribute : attributes) {
			defaultAttribute.add(attribute.getDefaultValue());
		}
		return defaultAttribute;
	}

	public List<String> getAttributeSize() {
		List<String> sizeAttribute = new ArrayList<String>();
		for (OMTGAttribute attribute : attributes) {
			sizeAttribute.add(attribute.getSize());
		}
		return sizeAttribute;
	}

	public List<List<String>> getAttributeDomain() {
		List<List<String>> domain = new ArrayList<List<String>>();
		for (OMTGAttribute attribute : attributes) {
			domain.add(attribute.getDomain());
		}
		return domain;
	}

	public boolean hasAttributeWithDomain() {

		for (OMTGAttribute attribute : attributes) {
			if (attribute.getDomain() != null) {
				return true;
			}
		}
		return false;
	}

	public Object clone() throws CloneNotSupportedException {
		return super.clone();
	}
} public class OMTGSchema {

	private Map<String, OMTGClass> classes;
	private Map<String, OMTGRelationship> relationships;

	public OMTGSchema(Map<String, OMTGClass> classes, Map<String, OMTGRelationship> relationships) throws CloneNotSupportedException {
		this.classes = classes;
		this.relationships = relationships;
	}

	public OMTGClass getClass(String className) {
		return classes.get(className);
	}

	public List<OMTGClass> getClassesNotInGeneralization() {

		List<OMTGClass> classesNotInGeneralization = new ArrayList<OMTGClass>();
		List<OMTGClass> generalizationClasses = getClassesInGeneralization();

		for (OMTGClass omtgClass : classes.values()) {

			if (!generalizationClasses.contains(omtgClass)) {
				classesNotInGeneralization.add(omtgClass);
			}
		}

		return classesNotInGeneralization;
	}

	public List<OMTGClass> getClassesInGeneralization() {

		List<OMTGClass> generalizationClasses = new ArrayList<OMTGClass>();
		generalizationClasses.addAll(getSubClasses());
		generalizationClasses.addAll(getSuperClasses());

		return generalizationClasses;
	}

	public List<OMTGClass> getSuperClasses() {

		List<OMTGClass> superClasses = new ArrayList<OMTGClass>();

		for (OMTGRelationship omtgRel : relationships.values()) {
			if (omtgRel.typeEquals("conventional-generalization") || omtgRel.typeEquals("conceptual-generalization")) {

				OMTGClass superClass = getClass(((OMTGGeneralization)omtgRel).getSuperClass());
				superClasses.add(superClass);
			}
		}

		return superClasses;
	}

	public List<OMTGClass> getSuperClassesOfTotalGeneralization() {

		List<OMTGClass> superClasses = new ArrayList<OMTGClass>();

		for (OMTGRelationship omtgRel : relationships.values()) {
			
			if (omtgRel.typeEquals("conventional-generalization")) {

				if (((OMTGConventionalGeneralization)omtgRel).isTotal()) {
					OMTGClass superClass = getClass(((OMTGGeneralization)omtgRel).getSuperClass());
					superClasses.add(superClass);
				}

				if (omtgRel.typeEquals("conceptual-generalization")) {

					OMTGClass superClass = getClass(((OMTGGeneralization)omtgRel).getSuperClass());
					superClasses.add(superClass);
				}
			}
		}

		return superClasses;
	}

	public List<OMTGClass> getSubClasses() {

		List<OMTGClass> subClasses = new ArrayList<OMTGClass>();

		for (OMTGRelationship omtgRel : relationships.values()) {
			if (omtgRel.typeEquals("conventional-generalization") || omtgRel.typeEquals("conceptual-generalization")) {

				subClasses.addAll(getSubClasses((OMTGGeneralization)omtgRel));
			}
		}

		return subClasses;
	}

	public List<OMTGClass> getSubClasses(OMTGGeneralization rel) {

		List<OMTGClass> subClasses = new ArrayList<OMTGClass>();
		List<String> subClassesName = rel.getSubclasses();

		for (int i = 0; i < subClassesName.size(); i++) {

			subClasses.add(getClass(subClassesName.get(i)));
		}

		return subClasses;
	}

	public List<OMTGClass> getSubClasses(OMTGClass superClass) {

		for (OMTGRelationship omtgRel : relationships.values()) {
			if (omtgRel.typeEquals("conventional-generalization") || omtgRel.typeEquals("conceptual-generalization")) {

				if (((OMTGGeneralization)omtgRel).getSuperClass().equalsIgnoreCase(superClass.getName())) {

					return getSubClasses((OMTGGeneralization)omtgRel);
				}
			}
		}

		return null;
	}

	public OMTGRelationship getRelationship(String relationshipName) {
		return relationships.get(relationshipName);
	}

	public List<OMTGClass> getClasses(String relationshipName) {

		OMTGRelationship rel = relationships.get(relationshipName);
		List<OMTGClass> classesList = new ArrayList<OMTGClass>();

		classesList.add(classes.get(rel.getClass1()));
		if (rel.getClass2() != null) { // in generalization and conceptual-generalization class2 is null
			classesList.add(classes.get(rel.getClass2()));
			return classesList;
		}
		return null;
	}

	public List<OMTGRelationship> getRelationshipsWithoutGeneralization() {

		List<OMTGRelationship> r = new ArrayList<OMTGRelationship>();
		for (OMTGRelationship omtgRel : relationships.values()) {

			if (!omtgRel.typeEquals("conventional-generalization") && !omtgRel.typeEquals("conceptual-generalization")) {

				r.add(omtgRel);
			}
		}
		return r;
	}

	public List<OMTGClass> getClasses() {
		return new ArrayList<OMTGClass>(classes.values());
	}

	public List<OMTGRelationship> getRelationships() {
		return new ArrayList<OMTGRelationship>(relationships.values());
	}

	public List<OMTGRelationship> getRelationships(String className) {
		return classes.get(className).getRelationships();
	}

	public List<String> getClassesNames() {
		return new ArrayList<String>(classes.keySet());
	}

	public List<String> getRelationshipsNames() {
		return new ArrayList<String>(relationships.keySet());
	}
} public class OMTGConceptualGeneralization extends OMTGGeneralization {

//	private static final String DISJOINT = "disjoint";
//	private static final String OVERLAPPING = "overlapping";

	/*
	 * completeness = (t)/(p) total, partial disjointness = (d)/(o) disjoint,
	 * overlapping
	 */
	private String disjointness, scaleShape;

	public OMTGConceptualGeneralization(String scaleShape, String disjointness,
			String superClass, List<String> subclasses) {
		super(disjointness, "conceptual-generalization", superClass, subclasses);
		this.scaleShape = scaleShape;
		this.disjointness = disjointness;
	}

	public String getDisjointness() {
		return disjointness;
	}

	public void setDisjointness(String disjointness) {
		this.disjointness = disjointness;
	}

	public String getScaleShape() {
		return scaleShape;
	}

	public void setScaleShape(String scaleShape) {
		this.scaleShape = scaleShape;
	}
} public class OMTGConventionalAggregation extends OMTGRelationship {
	
	private OMTGCardinality cardinality1, cardinality2;
	
	public OMTGConventionalAggregation(String class1, String class2) {
		super("conventional-aggregation-" + class1 + "-" + class2, "conventional-aggregation", class1, class2);
		this.cardinality1 = new OMTGCardinality("1", "1");
		this.cardinality2 = new OMTGCardinality("n", "n");
	}

	public OMTGCardinality getCardinality1() {
		return cardinality1;
	}

	public void setCardinality1(OMTGCardinality cardinality1) {
		this.cardinality1 = cardinality1;
	}

	public OMTGCardinality getCardinality2() {
		return cardinality2;
	}

	public void setCardinality2(OMTGCardinality cardinality2) {
		this.cardinality2 = cardinality2;
	}
} public class OMTGConventionalGeneralization extends OMTGGeneralization {

	/*
	 * completeness = (t)/(p) total, partial
	 * disjointness = (d)/(o) disjoint, overlapping
	 */
	private String completeness;

	public OMTGConventionalGeneralization(String completeness, String disjointness, String superClass, List<String> subclasses) {
		super(disjointness, "conventional-generalization", superClass, subclasses);
		this.completeness = completeness;
	}
	
	public boolean isTotal() {
		return completeness.equalsIgnoreCase("total");
	}
	
	public boolean isPartial() {
		return completeness.equalsIgnoreCase("partial");
	}
	
	public String getCompleteness() {
		return completeness;
	}

	public void setCompleteness(String completeness) {
		this.completeness = completeness;
	}
} public class OMTGConventionalRelationship extends OMTGRelationship {
	
	private OMTGCardinality cardinality1, cardinality2;
	
	public OMTGConventionalRelationship(String name, String class1, OMTGCardinality cardinality1, String class2, OMTGCardinality cardinality2) {
		super("conventional-relationship-" + class1 + "-" + name + "-" + class2, "conventional-relationship", class1, class2);
		this.cardinality1 = cardinality1;
		this.cardinality2 = cardinality2;
	}
	
	public String getCardinality() {
		return "(" + cardinality1.getMax() + "," + cardinality2.getMax() + ")";
	}
	
	public boolean cardinalityIsEqual(String card) {
		return getCardinality().equalsIgnoreCase(card);
	}

	public OMTGCardinality getCardinality1() {
		return cardinality1;
	}

	public void setCardinality1(OMTGCardinality cardinality1) {
		this.cardinality1 = cardinality1;
	}

	public OMTGCardinality getCardinality2() {
		return cardinality2;
	}

	public void setCardinality2(OMTGCardinality cardinality2) {
		this.cardinality2 = cardinality2;
	}

}
 public class OMTGNetwork extends OMTGRelationship {
	
	public OMTGNetwork(String name, String class1, String class2) {
		super("network-" + name + "-" + class1 + "-" + class2, "network", class1, class2);
	}
} public abstract class OMTGRelationship implements Cloneable {

	private String name;
	private String type;
	private String class1, class2;
	
	public OMTGRelationship(String name, String type, String class1, String class2) {
		this.name = name;
		this.type = type;
		this.class1 = class1;
		this.class2 = class2;
	}

	public String getName() {
		return name;
	}
	
	public String getType() {
		return type;
	}
	
	public boolean typeEquals(String type) {
		return this.type.equalsIgnoreCase(type);
	}
	
	public String getClass1() {
		return class1;
	}

	public void setClass1(String class1) {
		this.class1 = class1;
	}

	public String getClass2() {
		return class2;
	}

	public void setClass2(String class2) {
		this.class2 = class2;
	}
	
	public Object clone() throws CloneNotSupportedException {
		return super.clone();
	}
} public class OMTGSpatialAggregation extends OMTGRelationship {
	
	private OMTGCardinality cardinality1, cardinality2;
	
	public OMTGSpatialAggregation(String class1, String class2) {
		super("spatial-aggregation-" + class1 + "-" + class2, "spatial-aggregation", class1, class2);
		this.cardinality1 = new OMTGCardinality("1", "1");
		this.cardinality2 = new OMTGCardinality("n", "n");
	}

	public OMTGCardinality getCardinality1() {
		return cardinality1;
	}

	public void setCardinality1(OMTGCardinality cardinality1) {
		this.cardinality1 = cardinality1;
	}

	public OMTGCardinality getCardinality2() {
		return cardinality2;
	}

	public void setCardinality2(OMTGCardinality cardinality2) {
		this.cardinality2 = cardinality2;
	}
} public class OMTGTopologicalRelationship extends OMTGRelationship {
	
	private List<String> spatialRelation; 
	private String distance, unit;
	private OMTGCardinality cardinality1, cardinality2;

	public OMTGTopologicalRelationship(List<String> spatialRelation, String distance, String unit, String class1, OMTGCardinality cardinality1, String class2, OMTGCardinality cardinality2) {
		super("topological-relationship-" + spatialRelation + "-" + class1 + "-" + class2, "topological-relationship", class1, class2);
		this.spatialRelation = spatialRelation;
		this.distance = distance;
		this.unit = unit;
		this.cardinality1 = cardinality1;
		this.cardinality2 = cardinality2;
	}

	public List<String> getSpatialRelation() {
		return spatialRelation;
	}

	public void setSpatialRelation(List<String> spatialRelation) {
		this.spatialRelation = spatialRelation;
	}

	public String getDistance() {
		return distance;
	}

	public void setDistance(String distance) {
		this.distance = distance;
	}

	public String getUnit() {
		return unit;
	}

	public void setUnit(String unit) {
		this.unit = unit;
	}

	public OMTGCardinality getCardinality1() {
		return cardinality1;
	}

	public void setCardinality1(OMTGCardinality cardinality1) {
		this.cardinality1 = cardinality1;
	}

	public OMTGCardinality getCardinality2() {
		return cardinality2;
	}

	public void setCardinality2(OMTGCardinality cardinality2) {
		this.cardinality2 = cardinality2;
	}
} public class OMTGUserRestriction extends OMTGRelationship {

	private List<String> spatialRelation;
	private String distance, unit;
	private boolean spatialRelationCanOccur;

	public OMTGUserRestriction(String class1, String class2,
			List<String> spatialRelation, boolean spatialRelationCanOccur) {
		super(class1 + "-" + spatialRelation + "-" + class2, "user-restriction", class1, class2);
		this.spatialRelation = spatialRelation;
		this.spatialRelationCanOccur = spatialRelationCanOccur;
	}

	public boolean isSpatialRelationCanOccur() {
		return spatialRelationCanOccur;
	}

	public void setSpatialRelationCanOccur(boolean spatialRelationCanOccur) {
		this.spatialRelationCanOccur = spatialRelationCanOccur;
	}

	public List<String> getSpatialRelation() {
		return spatialRelation;
	}

	public void setSpatialRelation(List<String> spatialRelation) {
		this.spatialRelation = spatialRelation;
	}

	public String getDistance() {
		return distance;
	}

	public void setDistance(String distance) {
		this.distance = distance;
	}

	public String getUnit() {
		return unit;
	}

	public void setUnit(String unit) {
		this.unit = unit;
	}
}

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.xml.sax.InputSource;
import com.omtg2sql.omtg.classes.OMTGAttribute;
import com.omtg2sql.omtg.classes.OMTGCardinality;
import com.omtg2sql.omtg.classes.OMTGClass;
import com.omtg2sql.omtg.model.OMTGSchema;
import com.omtg2sql.omtg.relationships.OMTGConceptualGeneralization;
import com.omtg2sql.omtg.relationships.OMTGConventionalAggregation;
import com.omtg2sql.omtg.relationships.OMTGConventionalGeneralization;
import com.omtg2sql.omtg.relationships.OMTGConventionalRelationship;
import com.omtg2sql.omtg.relationships.OMTGNetwork;
import com.omtg2sql.omtg.relationships.OMTGRelationship;
import com.omtg2sql.omtg.relationships.OMTGSpatialAggregation;
import com.omtg2sql.omtg.relationships.OMTGTopologicalRelationship;
import com.omtg2sql.omtg.relationships.OMTGUserRestriction;

		String class1Name = element.getChildTextTrim("class1");
		String cardinality1Min = element.getChild("cardinality1").getChildText(
				"min");
		String cardinality1Max = element.getChild("cardinality1").getChildText(
				"max");
		OMTGCardinality cardinality1 = new OMTGCardinality(cardinality1Min,
				cardinality1Max);

//		System.out.println("name: " + name);
//		System.out.println("class1Name: " + class1Name);
//		System.out.println("cardinality1Min: " + cardinality1Min);
//		System.out.println("cardinality1Max: " + cardinality1Max);
//		System.out.println("cardinality1: " + cardinality1);

		String class2Name = element.getChildTextTrim("class2");
		String cardinality2Min = element.getChild("cardinality2").getChildText(
				"min");
		String cardinality2Max = element.getChild("cardinality2").getChildText(
				"max");
		OMTGCardinality cardinality2 = new OMTGCardinality(cardinality2Min,
				cardinality2Max);

//		System.out.println("class2Name: " + class2Name);
//		System.out.println("cardinality2Min: " + cardinality2Min);
//		System.out.println("cardinality2Max: " + cardinality2Max);
//		System.out.println("cardinality2: " + cardinality2);

		return new OMTGConventionalRelationship(name, class1Name, cardinality1,
				class2Name, cardinality2);
	}

	/**
	 * @param element
	 * @return
	 */
	@SuppressWarnings("unchecked")
	private OMTGRelationship parseOMTGTopologicalRelationship(Element element) {

		String spatialRelation = null;
		String distance = null;
		String unit = null;

		List<String> spatialRelations = new ArrayList<String>();
		List<Element> spatialRelationList = element.getChild(
				"spatial-relations").getChildren("spatial-relation");
		for (Element spatialRelationElement : spatialRelationList) {

			spatialRelation = spatialRelationElement.getTextTrim();
			spatialRelations.add(spatialRelation);
		}
//		System.out.println("spatialRelations: " + spatialRelations);

		List<Element> spatialRelationList2 = element
				.getChildren("spatial-relations");
		for (Element spatialRelationElement : spatialRelationList2) {

			distance = spatialRelationElement.getChildTextTrim("distance");
			unit = spatialRelationElement.getChildTextTrim("unit");
		}
//		System.out.println("distance: " + distance);
//		System.out.println("unit: " + unit);

		String class1Name = element.getChildTextTrim("class1");
		String cardinality1Min = element.getChild("cardinality1").getChildText(
				"min");
		String cardinality1Max = element.getChild("cardinality1").getChildText(
				"max");
		OMTGCardinality cardinality1 = new OMTGCardinality(cardinality1Min,
				cardinality1Max);

//		System.out.println("class1Name: " + class1Name);
//		System.out.println("cardinality1Min: " + cardinality1Min);
//		System.out.println("cardinality1Max: " + cardinality1Max);
//		System.out.println("cardinality1: " + cardinality1);

		String class2Name = element.getChildTextTrim("class2");
		String cardinality2Min = element.getChild("cardinality2").getChildText(
				"min");
		String cardinality2Max = element.getChild("cardinality2").getChildText(
				"max");
		OMTGCardinality cardinality2 = new OMTGCardinality(cardinality2Min,
				cardinality2Max);

//		System.out.println("class2Name: " + class2Name);
//		System.out.println("cardinality2Min: " + cardinality2Min);
//		System.out.println("cardinality2Max: " + cardinality2Max);
//		System.out.println("cardinality2: " + cardinality2);

		return new OMTGTopologicalRelationship(spatialRelations, distance,
				unit, class1Name, cardinality1, class2Name, cardinality2);
	}

	/**
	 * @param element
	 * @return
	 */
	private OMTGRelationship parseOMTGConventionalAggregation(Element element) {

		String class1Name = element.getChildTextTrim("class1");
		String class2Name = element.getChildTextTrim("class2");

//		System.out.println("class1Name: " + class1Name);
//		System.out.println("class2Name: " + class2Name);

		return new OMTGConventionalAggregation(class1Name, class2Name);
	}

	/**
	 * @param element
	 * @return
	 */
	private OMTGRelationship parseOMTGSpatialAggregation(Element element) {

		String class1Name = element.getChildTextTrim("class1");
		String class2Name = element.getChildTextTrim("class2");

//		System.out.println("class1Name: " + class1Name);
//		System.out.println("class2Name: " + class2Name);

		return new OMTGSpatialAggregation(class1Name, class2Name);