/*******************************************************************************
 *  Copyright 2017 Centre for Development of Advanced Computing(C-DAC), Pune
 *  
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  
 *    http://www.apache.org/licenses/LICENSE-2.0
 *  
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *******************************************************************************/
package cdac.medinfo.sdk.hl7282.baselibs.messagedictionary;

import cdac.medinfo.sdk.hl7282.commoninterface.ISingleCollection;
import cdac.medinfo.sdk.hl7282.utils.EnumHL7System;
import cdac.medinfo.sdk.hl7282.utils.IMap;
import cdac.medinfo.sdk.hl7282.utils.IPairedCollection;
import cdac.medinfo.sdk.hl7282.utils.PairedCollection;
import cdac.medinfo.sdk.hl7282.utils.SingleCollection;

/**
 * This class implements a dictionary which contains entry for all the Messages.
 * This is a singleton class means only single instance can be created of this class.
 */
class MessageDictionary
{
	
	
	/* 
	 * PairedCollection of Message and its Associated Message Structure. 
	 */
	private IPairedCollection<String, IMap> objMessageMapCollection= null;

	private ISingleCollection<EnumHL7System> objHL7SystemCollection =null;

	private static MessageDictionary objMessageDictionary = null;

	/**
	 * Default private constructor for this class.
	 * It's a singleton class.
	 */
	private MessageDictionary()
	{
		objMessageMapCollection = new PairedCollection<String, IMap>();
		objHL7SystemCollection = new SingleCollection<EnumHL7System>();
		
	}

	/**
	 * Creates instane of singleton class.
	 * @return MessageDictionary - object of MessageDictionary.
	 */
	static MessageDictionary createInstance()
	{
		if(objMessageDictionary == null)
			objMessageDictionary = new MessageDictionary();
		return objMessageDictionary;
	}

	/*
	 * Adds entry for new Message in DataDictionary.
	 */
	boolean addMessageMap(String strCodeEvent,IMap objMessageMap)
	{
		objMessageMap.setLock(true);
		
		objMessageMapCollection.put(strCodeEvent,objMessageMap);
		return true;
	}
	
	/*
	 * Retrieves Message Map for given Code and Event
	 */
	IMap getMessageMap(String strCode_Event)
	{
		if(objMessageMapCollection.contains(strCode_Event))
			return objMessageMapCollection.get(strCode_Event);
		
		return null;
	}
	
	/*
	 * This checks that xml is populated for particular system. 
	 * @param objEnumHL7System object ofParticular type of system.
	 * @return true if present or false.
	 */
	boolean isSystemPopulated(EnumHL7System objEnumHL7System)
	{
		return objHL7SystemCollection.contains(objEnumHL7System);
	}
	
	/*
	 * This added to collection if any systen is populated. 
	 * 
	 */
	void addPopulatedSysetm(EnumHL7System objEnumHL7System)
	{
		objHL7SystemCollection.add(objEnumHL7System);
	}
}
