package org.objectweb.proactive.core.component.adl.types;

import org.objectweb.fractal.adl.interfaces.Interface;
import org.objectweb.fractal.adl.types.TypeInterface;
import org.objectweb.fractal.adl.types.TypeInterfaceUtil;

/**
 * Utility methods about the properties of a PATypeInterface AST node (&lt;interface&gt;)
 * 
 * 
 * @author The ProActive Team
 *
 */
public class PATypeInterfaceUtil  {

	public static boolean isInternal(final Interface itf) {
		if(itf instanceof PATypeInterface) {
			final PATypeInterface paItf = (PATypeInterface) itf;
			String role = paItf.getRole();
			return PATypeInterface.INTERNAL_CLIENT_ROLE.equals(role) || PATypeInterface.INTERNAL_SERVER_ROLE.equals(role);
		}
		return false;
	}
	
	public static boolean isServer(final Interface itf) {
		if(itf instanceof PATypeInterface) {
			final PATypeInterface paItf = (PATypeInterface) itf;
			String role = paItf.getRole();
			return PATypeInterface.SERVER_ROLE.equals(role) || PATypeInterface.INTERNAL_SERVER_ROLE.equals(role);
		}
		else if(itf instanceof TypeInterface) {
			return TypeInterfaceUtil.isServer(itf);
		}
		return false;
	}
	
	public static boolean isClient(final Interface itf) {
		if(itf instanceof PATypeInterface) {
			final PATypeInterface paItf = (PATypeInterface) itf;
			String role = paItf.getRole();
			return PATypeInterface.CLIENT_ROLE.equals(role) || PATypeInterface.INTERNAL_CLIENT_ROLE.equals(role);
		}
		else if(itf instanceof TypeInterface) {
			return TypeInterfaceUtil.isClient(itf);
		}
		return false;
	}
	
	public static boolean isOptional(final Interface itf) {
		return TypeInterfaceUtil.isOptional(itf);
	}
	
	public static boolean isMandatory(final Interface itf) {
		return TypeInterfaceUtil.isMandatory(itf);
	}
	
	public static boolean isSingleton(final Interface itf) {
		return TypeInterfaceUtil.isSingleton(itf);
	}
	
	public static boolean isCollection(final Interface itf) {
		return TypeInterfaceUtil.isCollection(itf);
	}
	
	public static boolean isMulticast(final Interface itf) {
		if(itf instanceof PATypeInterface) {
			final PATypeInterface paItf = (PATypeInterface) itf;
			String cardinality = paItf.getCardinality();
			return PATypeInterface.MULTICAST_CARDINALITY.equals(cardinality);
		}
		return false;
	}
	
	public static boolean isGathercast(final Interface itf) {
		if(itf instanceof PATypeInterface) {
			final PATypeInterface paItf = (PATypeInterface) itf;
			String cardinality = paItf.getCardinality();
			return PATypeInterface.GATHERCAST_CARDINALITY.equals(cardinality);
		}
		return false;
	}
	
	public static boolean isCollective(final Interface itf) {
		if(itf instanceof PATypeInterface) {
			final PATypeInterface paItf = (PATypeInterface) itf;
			String cardinality = paItf.getCardinality();
			return PATypeInterface.MULTICAST_CARDINALITY.equals(cardinality) || PATypeInterface.GATHERCAST_CARDINALITY.equals(cardinality);
		}
		return false;
	}
	
}

@@ -1,8 +1,1444 @@
+/*%0A * ################################################################%0A *%0A * ProActive Parallel Suite(TM): The Java(TM) library for%0A *    Parallel, Distributed, Multi-Core Computing for%0A *    Enterprise Grids & Clouds%0A *%0A * Copyright (C) 1997-2011 INRIA/University of%0A *                 Nice-Sophia Antipolis/ActiveEon%0A * Contact: proactive@ow2.org or contact@activeeon.com%0A *%0A * This library is free software; you can redistribute it and/or%0A * modify it under the terms of the GNU Affero General Public License%0A * as published by the Free Software Foundation; version 3 of%0A * the License.%0A *%0A * This library is distributed in the hope that it will be useful,%0A * but WITHOUT ANY WARRANTY; without even the implied warranty of%0A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU%0A * Affero General Public License for more details.%0A *%0A * You should have received a copy of the GNU Affero General Public License%0A * along with this library; if not, write to the Free Software%0A * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307%0A * USA%0A *%0A * If needed, contact us to obtain a release under GPL Version 2 or 3%0A * or a different license than the AGPL.%0A *%0A *  Initial developer(s):               The ProActive Team%0A *                        http://proactive.inria.fr/team_members.htm%0A *  Contributor(s):%0A *%0A * ################################################################%0A * $$PROACTIVE_INITIAL_DEV$$%0A */%0A
 package 

Add copyright notice