package br.uem.din.architectureEvolution.representation;

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

import com.sdmetrics.model.ModelElement;

public class AbstractionInterElementRelationship extends InterElementRelationship {

	private Interface parent;
	private Component child;

	public AbstractionInterElementRelationship(ModelElement element, Architecture architecture) throws Exception {
		super(element);

		ModelElement modelParent = getModelElement().getRefAttribute("abssupplier");
		ModelElement modelChild = getModelElement().getRefAttribute("absclient");
		
		setParent(architecture.getInterfaces().get(modelParent.getXMIID()));
		setChild(architecture.getComponents().get(modelChild.getXMIID()));
		
		if (getChild() != null && getParent() != null)
			getChild().addImplementedInterface(getParent());
	}
	
	public AbstractionInterElementRelationship(Interface interface_, Component component, Architecture architecture) throws Exception {
		super(new ModelElement(architecture.getMetaModel().getType(ABSTRACTION)));
		
		getModelElement().setRefAttribute("abssupplier", interface_.getModelElement());
		getModelElement().setRefAttribute("absclient", component.getModelElement());
		
		setParent(interface_);
		setChild(component);
		
		component.addImplementedInterface(interface_);
	}

	public Interface getParent() {
		return parent;
	}

	public void setParent(Interface parent) {
		this.parent = parent;
	}

	public Component getChild() {
		return child;
	}

	public void setChild(Component child) {
		this.child = child;
	}
}
