/*
 * $RCSfile: SimpleIdGenerator.java,v $
 * $Date: 2006/01/26 14:48:59 $
 * $Revision: 1.1.2.2 $
 * $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.
 */
 
/*
 * SimpleIdGenerator.java Add description 
 * 
 * @author Prawee Sriplakich
 * @version $Revision: 1.1.2.2 $ $Date: 2006/01/26 14:48:59 $
 * @see Add references
 *
 * TODO Add description
 * TODO Add references
 */
package org.eclipse.mddi.modelbus.adapter.infrastructure.serialize.modelbus_xmi;

import java.util.Collection;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.mddi.modelbus.adapter.infrastructure.model_manipulation.ModelUtil;

public class SimpleIdGenerator implements IdGenerator {

    public String prefix = "";
      
    
    public String generateId(EObject o, Collection existingIds) {
        String begin = prefix + o.eClass().getName();
//        if(option_use_name) {
//            Object name = ModelUtil.getFeatureValue(o, "name");
//            if(name !=null && name instanceof String) {
//              begin = begin +"_" + name;   
//            }
//        } 
        int i = 0;
        String xmiid = begin +i;
        while(existingIds.contains(xmiid)) {
            i++;
            xmiid = begin +i;
        }
        return xmiid;
    }

    /**
     * @return Returns the prefix.
     */
    public String getPrefix() {
        return prefix;
    }

    /**
     * @param prefix The prefix to set.
     */
    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    public String generateId(EObject o, Collection existingIds1, Collection existingIds2) {
      String begin = prefix + o.eClass().getName();
      int i = 0;
      String xmiid = begin +i;
      while(existingIds1.contains(xmiid) || existingIds2.contains(xmiid)) {
          i++;
          xmiid = begin +i;
      }
      return xmiid;
    }



}
