/*
 * Created on 19-apr-2004
 */
package convFramework.domain;

import convFramework.exceptions.*;

/**
 * @author Lompa
 */
public class BasicConversationIDFactory implements IConversationIDFactory {
	
	/* stato di istanziazione */
	//static boolean instantiated = false;
	
	/* campi */
	int counter = 0;
	
	public BasicConversationIDFactory() throws InstantiationRuleBrokenException{
		//if (instantiated)
		//	throw new InstantiationRuleBrokenException("Cannot instantiate more than one BasicConversationIDFactory");
		
		//instantiated = true;
	}
	
	
	/* (non-Javadoc)
	 * @see convFramework.domain.IConversationIDFactory#decode(java.lang.String)
	 */
	public IConversationID decode(String encodedConvID) {
		//TODO si potrebbe controllare che l'id non sia gà stato utilizzato
		return new BasicConversationID(encodedConvID);
	}
	
	/**
	 * Crea un nuovo id di conversazione
	 * @param starter il nodo che inizia la conversazione
	 * @return l'id
	 */
	public IConversationID newConversationID(Node starter){
		IConversationID convID = new BasicConversationID("#"+starter.getAddress().getHostAddress()+"#"+starter.getPort()+"#"+counter+"#");
		counter++;
		return convID;
	}
}
