/*
 * $RCSfile: ModelTypeChecker.java,v $
 * $Date: 2006/01/26 14:48:59 $
 * $Revision: 1.1.2.1 $
 * $Author: andreys $
 */
 
/*
 * Copyright (c) 2002-2003 IST-2004-2006-511731 ModelWare - ModelBus.
 * All rights reserved.
 *
 * This software is published under the terms of the ModelBus Software License
 * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * A copy of ModelBus Software License is provided with this distribution in
 * doc/LICENSE.txt file.
 */
 
/*
 * ModelTypeChecker.java Add description 
 * 
 * @author Prawee Sriplakich (LIP6)
 * @version $Revision: 1.1.2.1 $ $Date: 2006/01/26 14:48:59 $
 * @see Add references
 *
 * TODO Add description
 * TODO Add references
 */
package org.eclipse.mddi.modelbus.adapter.infrastructure.model_manipulation;

import java.util.Collection;
import java.util.Iterator;

import org.activemq.ws.xmlbeans.servicegroup.AddDocument.Add;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.mddi.modelbus.description.abstract_.MetaclassSpecification;
import org.eclipse.mddi.modelbus.description.abstract_.ModelType;

public class ModelTypeChecker {
    
    
    /**
     * isTypeOf Add description 
     * 
     * @param model
     * @param modelType
     * @return
     * 
     * @see Add references
     *
     * TODO Add description
     */
    public static boolean isTypeOf(Collection model, ModelType type) {
        Iterator it = type.getContent().iterator();
        while(it.hasNext()) {
          MetaclassSpecification spec = (MetaclassSpecification) it.next(); 
          int u = spec.getUpper();
          if(u==-1) u = Integer.MAX_VALUE;
          int l = spec.getLower();
          EClass c = spec.getMetaClass();
          Collection instances = ModelUtil.findElementByType_considerSubtypes(model, c);
          int count = instances.size();
          if(count>u || count<l) return false;  
        }
        return true;
    }
    
    
    /**
     * conforms Add description 
     * 
     * @param subtype
     * @param supertype
     * @return
     * 
     */
    public static boolean conforms(ModelType subtype, ModelType supertype) {
      // TODO
    
      return false;
    }

}
