package br.uem.din.architectureEvolution.representation;

import static br.uem.din.architectureEvolution.helpers.ElementTypeNames.*;

import com.sdmetrics.model.ModelElement;

public class GeneralizationInterClassRelationship extends
		InterClassRelationship {

	private Class parent;
	private Class child;
	
	public GeneralizationInterClassRelationship(ModelElement element, Architecture architecture) throws Exception {		
		super(element);
		
		ModelElement modelParent = getModelElement().getRefAttribute("genparent");
		ModelElement modelChild = getModelElement().getRefAttribute("genchild");
		
		setParent(architecture.getClasses().get(modelParent.getXMIID()));
		setChild(architecture.getClasses().get(modelChild.getXMIID()));
	}
	
	public GeneralizationInterClassRelationship(Class parentClass, Class childClass, Architecture architecture) throws Exception {
		super(new ModelElement(architecture.getMetaModel().getType(GENERALIZATION)));

		getModelElement().setRefAttribute("genparent", parentClass.getModelElement());
		getModelElement().setRefAttribute("genchild", childClass.getModelElement());
		
		setParent(parentClass);
		setChild(childClass);
	}

	public Class getParent() {
		return parent;
	}

	private void setParent(Class parent) {
		this.parent = parent;
	}

	public Class getChild() {
		return child;
	}

	private void setChild(Class child) {
		this.child = child;
	}
}
