package br.uem.din.architectureEvolution.representation;

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

import com.sdmetrics.model.ModelElement;

public class DependencyComponentInterfaceRelationship extends InterElementRelationship {

	private Component component;
	private Interface interface_;

	public DependencyComponentInterfaceRelationship(ModelElement element, Architecture architecture) throws Exception {
		super(element);
		
		ModelElement modelInterface = getModelElement().getRefAttribute("depsupplier");
		ModelElement modelComponent = getModelElement().getRefAttribute("depclient");
		
		setInterface(architecture.findInterfaceByXMIID(modelInterface.getXMIID()));
		setComponent(architecture.findComponentByXMIID(modelComponent.getXMIID()));		
		
		getComponent().addRequiredInterface(getInterface());
	}
	
	public DependencyComponentInterfaceRelationship(Interface interface_, Component component, Architecture architecture) throws Exception {
		super(new ModelElement(architecture.getMetaModel().getType(DEPENDENCY)));
		
		getModelElement().setRefAttribute("depsupplier", interface_.getModelElement());
		getModelElement().setRefAttribute("depclient", component.getModelElement());
		
		setInterface(interface_);
		setComponent(component);
		
		component.addRequiredInterface(interface_);
	}

	public Component getComponent() {
		return component;
	}

	public void setComponent(Component component) {
		this.component = component;
	}

	public Interface getInterface() {
		return interface_;
	}

	public void setInterface(Interface interface_) {
		this.interface_ = interface_;
	}

}
