package br.uem.din.architectureEvolution.representation;

import java.util.Collection;
import java.util.HashMap;

import com.sdmetrics.model.ModelElement;

public class Operation extends Element {
	private String returnType;
	private HashMap<String, String> parameters;
	
	public Operation(ModelElement element, Architecture architecture) throws Exception{
		setParameters(new HashMap<String, String>()); 
		this.setModelElement(element, architecture);
	}
	
	@Override
	protected void loadFields() {
		Collection<ModelElement> ownedElements = getModelElement().getOwnedElements();
		if (ownedElements == null) return;
		for (ModelElement ownedElement : ownedElements) {
			if (ownedElement.getName().equalsIgnoreCase("return")) {
				ModelElement type = ownedElement.getRefAttribute("parametertype");
				if (type != null)
					setReturnType(type.getName());
			} else if (ownedElement.getType().getName().equalsIgnoreCase("parameter")) {
				ModelElement type = ownedElement.getRefAttribute("parametertype");
				if (type != null)
					getParameters().put(ownedElement.getName(), type.getName());
			}
		}
	}

	public String getReturnType() {
		return returnType;
	}

	private void setReturnType(String returnType) {
		this.returnType = returnType;
	}

	public HashMap<String, String> getParameters() {
		return parameters;
	}

	private void setParameters(HashMap<String, String> parameters) {
		this.parameters = parameters;
	}
}
