package it.micegroup.voila2.cartridge.library.javaservice;

import java.util.ArrayList;
import java.util.Collection;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.PackageableElement;
import org.eclipse.uml2.uml.Stereotype;
import org.eclipse.uml2.uml.Class;

public class SubjectAreaUtils {

	/**
	 * Ritorna la lista delle entity relative a una Subject Area
	 * 
	 * @author Vittorio Niespolo <vittorio.niespolo@micegroup.it>
	 *
	 * @param subjectArea
	 * @return
	 */
	public static Collection<Class> getEntitiesForSA(Package subjectArea) {
		Collection<Class> result = new ArrayList<Class>();
		for (PackageableElement element : subjectArea.getPackagedElements()) {
			if (element instanceof Class && EntityUtils.isEntityStereotype((Class) element)) {
				result.add((Class) element);
			}
		}
		return result;
	}
	
	/**
	 * Controlla se il package è una subjectArea
	 * @author Vittorio Niespolo <vittorio.niespolo@micegroup.it>
	 *
	 * @param pack
	 * @return
	 */
	public static boolean isSubjectAreaStereotype(Package pack) {
		Stereotype stereotype = pack.getAppliedStereotype(StereotypeName.SUBJECT_AREA);
		if (stereotype != null)
			return true;
		return false;
	}
}
