package br.uem.din.architectureEvolution.representation;

import java.util.HashMap;

import com.sdmetrics.model.ModelElement;

public class Method extends Element {

	private String returnType;
	private final HashMap<String, String> parameters;
	
	public Method(ModelElement element, Architecture architecture) throws Exception{
		parameters = new HashMap<String, String>(); 
		this.setModelElement(element, architecture);
	}
	
	@Override
	protected void loadFields() {
		for (ModelElement ownedElement : getModelElement().getOwnedElements()) {
			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)
					parameters.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;
	}
}
