gt: 				filterString += ims.dto.NASMessageCodes.PAIRSEPARATOR;
context: //#############################################################################
  //#                                                                           #
  //#  Copyright (C) <2014>  <IMS MAXIMS>                                       #
  //#                                                                           #
  //#  This program is free software: you can redistribute it and/or modify     #
  //#  it under the terms of the GNU Affero General Public License as           #
  //#  published by the Free Software Foundation, either version 3 of the       #
  //#  License, or (at your option) any later version.                          # 
  //#                                                                           #
  //#  This program is distributed 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.  See the            #
  //#  GNU Affero General Public License for more details.                      #
  //#                                                                           #
  //#  You should have received a copy of the GNU Affero General Public License #
  //#  along with this program.  If not, see <http://www.gnu.org/licenses/>.    #
  //#                                                                           #
  //#############################################################################
  //#EOH
  // Template ver. 1.0.6 - Last modified on 25/05/2004 15:00 by Marius Mihalec
  
  package ims.dto.client;
  
  public final class Ward
  {
  	private WardFilter lastGetFilter = null;
  	private final String serviceName = "WARD";
  	private boolean listInProgress = false;
  	/**
  	 * Represents the Data Transfer Object Connection used for this client object.
  	 */ 
  	public ims.dto.Connection Connection = null;
  	/**
  	 * Represents the filter used by the current Data Transfer Object.
  	 */ 
  	public WardFilter Filter = new WardFilter();			
  	/**
  	 * Represents the filter used by the current Data Transfer Object to Insert/Update data.
  	 */ 
  	public WardEditFilter EditFilter = new WardEditFilter();
  	/**
  	 * Contains the data records for the current Data Transfer Object
  	 */ 
  	public WardCollection DataCollection = new WardCollection();
  
  	/**
  	 * Creates a new Ward Data Transfer Object.
  	 */ 
  	public Ward(ims.dto.Connection connection) throws ims.dto.Exception
  	{	
  		if(connection == null)
  			throw new ims.dto.Exception("Invalid Data Transfer Object Connection");
  		this.Connection = connection;
  	}
  	/**
  	 * Creates a new copy of the current Data Transfer Object
  	 */
  	public Ward cloneObject() throws ims.dto.Exception
  	{
  		Ward cloneObject = new Ward(Connection);
  			
  		if(Filter != null)
  			cloneObject.Filter = Filter.cloneObject();			
  					
  		if(lastGetFilter != null)
  			cloneObject.lastGetFilter = lastGetFilter.cloneObject();
  		else
  			cloneObject.lastGetFilter = null;
  				
  		for(int x = 0; x < DataCollection.count(); x++)
  		{
  			int index = cloneObject.DataCollection.add();
  			
  			cloneObject.DataCollection.get(index).Rsno = DataCollection.get(x).Rsno;
  			cloneObject.DataCollection.get(index).Hpcd = DataCollection.get(x).Hpcd;
  			cloneObject.DataCollection.get(index).Site = DataCollection.get(x).Site;
  			cloneObject.DataCollection.get(index).Pdate = DataCollection.get(x).Pdate;
  			cloneObject.DataCollection.get(index).Mtot = DataCollection.get(x).Mtot;
  			cloneObject.DataCollection.get(index).Mocc = DataCollection.get(x).Mocc;
  			cloneObject.DataCollection.get(index).Mphd = DataCollection.get(x).Mphd;
  			cloneObject.DataCollection.get(index).Mohd = DataCollection.get(x).Mohd;
  			cloneObject.DataCollection.get(index).Stot = DataCollection.get(x).Stot;
  			cloneObject.DataCollection.get(index).Socc = DataCollection.get(x).Socc;
  			cloneObject.DataCollection.get(index).Sphd = DataCollection.get(x).Sphd;
  			cloneObject.DataCollection.get(index).Sohd = DataCollection.get(x).Sohd;
  			cloneObject.DataCollection.get(index).Name = DataCollection.get(x).Name;
  			cloneObject.DataCollection.get(index).Stat = DataCollection.get(x).Stat;
  			cloneObject.DataCollection.get(index).At01 = DataCollection.get(x).At01;
  			cloneObject.DataCollection.get(index).Mavl = DataCollection.get(x).Mavl;
  			cloneObject.DataCollection.get(index).Savl = DataCollection.get(x).Savl;
  			cloneObject.DataCollection.get(index).Total = DataCollection.get(x).Total;
  			cloneObject.DataCollection.get(index).Avail = DataCollection.get(x).Avail;
  			cloneObject.DataCollection.get(index).Closed = DataCollection.get(x).Closed;
  			cloneObject.DataCollection.get(index).Tci = DataCollection.get(x).Tci;
  			cloneObject.DataCollection.get(index).Disc = DataCollection.get(x).Disc;
  			cloneObject.DataCollection.get(index).Hltotal = DataCollection.get(x).Hltotal;
  			cloneObject.DataCollection.get(index).Allstat = DataCollection.get(x).Allstat;
  			cloneObject.DataCollection.get(index).Maxno = DataCollection.get(x).Maxno;
  							
  			
  			for(int iSeqno = 0; iSeqno < DataCollection.get(x).SeqnoCollection.count(); iSeqno++)
  			{
  				int rIndex = cloneObject.DataCollection.get(index).SeqnoCollection.add();
  					
  				cloneObject.DataCollection.get(index).SeqnoCollection.get(rIndex).Seqno = DataCollection.get(x).SeqnoCollection.get(iSeqno).Seqno;
  				cloneObject.DataCollection.get(index).SeqnoCollection.get(rIndex).Btyp = DataCollection.get(x).SeqnoCollection.get(iSeqno).Btyp;
  				cloneObject.DataCollection.get(index).SeqnoCollection.get(rIndex).Mors = DataCollection.get(x).SeqnoCollection.get(iSeqno).Mors;
  				cloneObject.DataCollection.get(index).SeqnoCollection.get(rIndex).Dofw = DataCollection.get(x).SeqnoCollection.get(iSeqno).Dofw;
  				cloneObject.DataCollection.get(index).SeqnoCollection.get(rIndex).Nbed = DataCollection.get(x).SeqnoCollection.get(iSeqno).Nbed;
  				cloneObject.DataCollection.get(index).SeqnoCollection.get(rIndex).Occp = DataCollection.get(x).SeqnoCollection.get(iSeqno).Occp;
  				cloneObject.DataCollection.get(index).SeqnoCollection.get(rIndex).Phld = DataCollection.get(x).SeqnoCollection.get(iSeqno).Phld;
  				cloneObject.DataCollection.get(index).SeqnoCollection.get(rIndex).Ohld = DataCollection.get(x).SeqnoCollection.get(iSeqno).Ohld;
  										
  			}
  			
  		}
  		
  		return cloneObject;
  	}
  	/**
  	 * Returns the Imx version
  	 */	
  	public String getImxVersion()
  	{
  		return "0";
  	}
  	/**
  	 * Returns the Imx name
  	 */	
  	public String getImxName()
  	{
  		return "Ward.imx".toLowerCase();
  	}
  	/**
  	 * Returns the number of records using the specified filter. This method always returns a non null result. The ID field holds the count result (when greater or equal to zero) or the error number (when less than zero).
  	 */
  	public ims.dto.Result count()
  	{
  		ims.dto.Result reLoginResult = Connection.reLogin();
  		if(reLoginResult != null)
  			return new ims.dto.Result(reLoginResult.getMessage(), "DTO.Client.Ward.Count");
  			
  		int result = Connection.count(serviceName, encodeNASFilter());
  		if(result >= 0)
  			return new ims.dto.Result(result, "No error detected. The count result is held in the ID field", "DTO.Client.Ward.Count");
  				
  		return Connection.getLastError();				
  	}		
  	/**
  	 * Returns the list of records using the specified filter. Use maxRecords to limit the number of records returned. If the result returned is not null an error occured.
  	 */
  	public ims.dto.Result list(int maxRecords)
  	{
  		if(maxRecords <= 0)
  			return list();		
  				
  		return list(false, maxRecords);
  	}	
  	/**
  	* Returns the list of records using the specified filter. If the result returned is not null an error occured.
  	*/
  	public ims.dto.Result list()
  	{	
  		return list(true, 0);
  	}				
  	/**
  	* Returns one record using the specified filter. If the result returned is not null an error occured.
  	*/
  	public ims.dto.Result get()
  	{	
  		DataCollection.clear();
  			
  		ims.dto.Result reLoginResult = Connection.reLogin();
  		if(reLoginResult != null)
  			return new ims.dto.Result(reLoginResult.getMessage(), "DTO.Client.Ward.Get");
  			
  		ims.dto.Result result = Connection.get(serviceName, encodeNASFilter());
  		if(result != null)
  			return result;
  			
  		lastGetFilter = Filter.cloneObject();						
  		decodeNASMessageWithRepeatingGroups();		
  			
  		return null;
  	}	
  	/**
  	* Returns one record using the specified filter. If the result returned is not null an error occured.
  	*/
  	public ims.dto.Result getLast()
  	{	
  		DataCollection.clear();
  			
  		ims.dto.Result reLoginResult = Connection.reLogin();
  		if(reLoginResult != null)
  			return new ims.dto.Result(reLoginResult.getMessage(), "DTO.Client.Ward.Get");
  			
  		ims.dto.Result result = Connection.getLast(serviceName, encodeNASFilter());
  		if(result != null)
  			return result;
  			
  		lastGetFilter = Filter.cloneObject();						
  		decodeNASMessageWithRepeatingGroups();	
  			
  		return null;
  	}					
  	/**
  	* Performs data validation prior to update. If the result returned is not null an error occured.
  	*/
  	public ims.dto.Result getForUpdate()
  	{						
  		ims.dto.Result reLoginResult = Connection.reLogin();
  		if(reLoginResult != null)
  			return new ims.dto.Result(reLoginResult.getMessage(), "DTO.Client.Ward.GetForUpdate");
  							
  		if(lastGetFilter == null)	
  			return new ims.dto.Result("Last get method failed or not called", "DTO.Client.Ward.GetForUpdate");
  			
  		ims.dto.Result result = Connection.getForUpdate(serviceName, encodeNASFilter(lastGetFilter));
  		if(result != null)
  			return result;
  			
  		if(Connection.countResponseItems(Connection.getValueAt(6)) == 0)
  			return null;
  			
  		DataCollection.clear();	
  		decodeNASMessageWithRepeatingGroups();
  				
  		return new ims.dto.Result("The data was changed by another user", "DTO.Client.Ward.GetForUpdate");
  	}		
  	/**
  	* Inserts a new record. This method always returns a non null result. The ID field holds the Unique ID for the inserted record (when greater than zero) or the error number (when less than zero). If the ID is zero, the record was inserted but the server did not returned the Unique ID.
  	*/
  	public ims.dto.Result insert()
  	{
  		ims.dto.Result reLoginResult = Connection.reLogin();
  		if(reLoginResult != null)
  			return new ims.dto.Result(reLoginResult.getMessage(), "DTO.Client.Ward.Insert");
  					
  		if(DataCollection.count() == 0)
  			return new ims.dto.Result("No data to insert", "DTO.Client.Ward.Insert");
  			
  		if(DataCollection.count() > 1)
  			return new ims.dto.Result("Multiple object insert not allowed", "DTO.Client.Ward.Insert");
  			
  		ims.dto.Result result = Connection.insert(serviceName, encodeNASMessage());
  		if(result != null)
  			return result;
  					
  		int recordID = 0;
  					
  		try
  		{
  			recordID = new Integer(Connection.getValueAt(2)).intValue();
  		}
  		catch(NumberFormatException ex)
  		{
  			return new ims.dto.Result("Invalid record ID returned", "DTO.Client.Ward.Insert");
  		}
  		
  		return new ims.dto.Result(recordID, "No error. The ID of the new record is in the ID field", "DTO.Client.Ward.Insert");
  	}
  	/**
  	 * Executes a specific action. This method always returns a non null result.
  	 */
  	public ims.dto.Result executeAction(String action)
  	{
  		if(action.length() == 0)
  			return new ims.dto.Result("Invalid action name", "DTO.Client.Ward.ExecuteAction");
  			
  		ims.dto.Result reLoginResult = Connection.reLogin();
  		if(reLoginResult != null)
  			return new ims.dto.Result(reLoginResult.getMessage(), "DTO.Client.Ward.ExecuteAction");
  		
  		if(DataCollection.count() == 0)
  			return new ims.dto.Result("Data container is empty", "DTO.Client.Ward.ExecuteAction");
  			
  		if(DataCollection.count() > 1)
  			return new ims.dto.Result("Multiple objects are not allowed", "DTO.Client.Ward.ExecuteAction");
  			
  		ims.dto.Result result = Connection.executeAction(serviceName, encodeNASMessage(), action);
  		if(result != null)
  			return result;
  			
  		try
  		{
  			return new ims.dto.Result(new Integer(Connection.getValueAt(2)).intValue(), "No error", "DTO.Client.Ward.ExecuteAction");	
  		}
  		catch(NumberFormatException ex)
  		{
  			return new ims.dto.Result("Invalid server response", "DTO.Client.Ward.ExecuteAction");
  		}
  	}
  	/**
  	 * Transfers a record. If the result returned is not null an error occured.
  	 */
  	public ims.dto.Result transferData(String action)
  	{
  		if(action.length() == 0)
  			return new ims.dto.Result("Invalid action name", "DTO.Client.Ward.TransferData");
  			
  		ims.dto.Result reLoginResult = Connection.reLogin();
  		if(reLoginResult != null)
  			return new ims.dto.Result(reLoginResult.getMessage(), "DTO.Client.Ward.TransferData");
  		
  		if(DataCollection.count() == 0)
  			return new ims.dto.Result("No data to transfer", "DTO.Client.Ward.TransferData");
  			
  		if(DataCollection.count() > 1)
  			return new ims.dto.Result("Multiple objects not allowed", "DTO.Client.Ward.TransferData");
  			
  		ims.dto.Result result = Connection.transferData(serviceName, encodeNASMessage(), action.toUpperCase());
  		if(result != null)
  			return result;
  		
  		DataCollection.clear();
  		decodeNASMessageWithRepeatingGroups();	
  		
  		return null;
  	}
  	/**
  	 * Updates a record. If the result returned is not null an error occured.
  	 */
  	public ims.dto.Result update()
  	{			
  		ims.dto.Result reLoginResult = Connection.reLogin();
  		if(reLoginResult != null)
  			return new ims.dto.Result(reLoginResult.getMessage(), "DTO.Client.Ward.Update");
  				
  		if(DataCollection.count() == 0)
  			return new ims.dto.Result("No data to update", "DTO.Client.Ward.Update");	
  			
  		if(DataCollection.count() > 1)
  			return new ims.dto.Result("Multiple object update not allowed", "DTO.Client.Ward.Update");
  			
  		return Connection.update(serviceName, encodeNASMessage());
  	}
  			
  	private ims.dto.Result stopList()
  	{
  		if(!listInProgress)
  			return new ims.dto.Result("No active list running", "DTO.Client.Ward.StopList");
  				
  		listInProgress = false;				
  		return null;
  	}
  	
  	private ims.dto.Result nextList()
  	{				
  		ims.dto.Result result = Connection.nextList(serviceName);
  		if(result != null)
  			return result;
  					
  		decodeNASMessage();		
  		return null;
  	}
  		
  	private boolean canContinueToList(boolean loadAllRecords, int maxRecords)
  	{
  		if(!listInProgress)
  			return false;				
  		if(loadAllRecords)
  			return true;			
  		return DataCollection.count() < maxRecords;
  	}
  	
  	private ims.dto.Result list(boolean loadAllRecords, int maxRecords)
  	{	
  		DataCollection.clear();
  			
  		ims.dto.Result reLoginResult = Connection.reLogin();
  		if(reLoginResult != null)
  			return new ims.dto.Result(reLoginResult.getMessage(), "DTO.Client.Ward.List");
  							
  		listInProgress = true;	
  		ims.dto.Result result = Connection.list(serviceName, encodeNASFilter());
  		if(result != null)
  		{
  			listInProgress = false;
  			if(result.getId() == -2) // NAS list empty
  				return null;
  			return result;
  		}
  					
  		if(decodeNASMessage() == 0)
  		{
  			listInProgress = false;
  			return null;
  		}
  						
  		ims.dto.Result execResult = null;
  		while(execResult == null && canContinueToList(loadAllRecords, maxRecords))
  			execResult = nextList();
  						
  		if(execResult != null)
  		{
  			if(execResult.getId() != -3) 
  			{
  				listInProgress = false;
  				return execResult;
  			}
  		}
  		else // NAS next list empty
  		{
  			listInProgress = false;
  			return null;
  		}				
  					
  		if(!loadAllRecords || !listInProgress)
  		{
  			listInProgress = false;
  			return Connection.stopList(serviceName);
  		}
  		
  		listInProgress = false;
  		return null;
  	}	
  
  	private String encodeNASFilter()
  	{
  		return encodeNASFilter(Filter);
  	}
  	private String encodeNASFilter(WardFilter filter)
  	{
  		if(filter == null)
  			return "";
  			
  		String filterString = "";
  		
  		if(Filter.Rsno != null && filter.Rsno.length()> 0)
  		{
  			if(filterString.length() > 0)
  				filterString += ims.dto.NASMessageCodes.PAIRSEPARATOR;
  			filterString += "RSNO" + ims.dto.NASMessageCodes.ATTRIBUTEVALUESEPARATOR + filter.Rsno;
  		}
  		
  		if(Filter.Hpcd != null && filter.Hpcd.length()> 0)
  		{
  			if(filterString.length() > 0)
  				filterString += ims.dto.NASMessageCodes.PAIRSEPARATOR;
  			filterString += "HPCD" + ims.dto.NASMessageCodes.ATTRIBUTEVALUESEPARATOR + filter.Hpcd;
  		}
  		
  		if(Filter.Site != null && filter.Site.length()> 0)
  		{
  			if(filterString.length() > 0)
  				filterString += ims.dto.NASMessageCodes.PAIRSEPARATOR;
  			filterString += "SITE" + ims.dto.NASMessageCodes.ATTRIBUTEVALUESEPARATOR + filter.Site;
  		}
  		
  		if(Filter.Pdate != null && filter.Pdate.length()> 0)
  		{
  			if(filterString.length() > 0)
  				filterString += ims.dto.NASMessageCodes.PAIRSEPARATOR;
  			filterString += "PDATE" + ims.dto.NASMessageCodes.ATTRIBUTEVALUESEPARATOR + filter.Pdate;
  		}
  		
  		if(Filter.Mtot != null && filter.Mtot.length()> 0)
  		{
  			if(filterString.length() > 0)
  				filterString += ims.dto.NASMessageCodes.PAIRSEPARATOR;
  			filterString += "MTOT" + ims.dto.NASMessageCodes.ATTRIBUTEVALUESEPARATOR + filter.Mtot;
  		}
  		
  		if(Filter.Mocc != null && filter.Mocc.length()> 0)
  		{
  			if(filterString.length() > 0)
  				filterString += ims.dto.NASMessageCodes.PAIRSEPARATOR;
  			filterString += "MOCC" + ims.dto.NASMessageCodes.ATTRIBUTEVALUESEPARATOR + filter.Mocc;
  		}
  		
  		if(Filter.Mphd != null && filter.Mphd.length()> 0)
  		{
  			if(filterString.length() > 0)
  				filterString += ims.dto.NASMessageCodes.PAIRSEPARATOR;
  			filterString += "MPHD" + ims.dto.NASMessageCodes.ATTRIBUTEVALUESEPARATOR + filter.Mphd;
  		}
  		
  		if(Filter.Mohd != null && filter.Mohd.length()> 0)
  		{
  			if(filterString.length() > 0)
  				filterString += ims.dto.NASMessageCodes.PAIRSEPARATOR;
  			filterString += "MOHD" + ims.dto.NASMessageCodes.ATTRIBUTEVALUESEPARATOR + filter.Mohd;
  		}
  		
  		if(Filter.Stot != null && filter.Stot.length()> 0)
  		{
  			if(filterString.length() > 0)
  				filterString += ims.dto.NASMessageCodes.PAIRSEPARATOR;
  			filterString += "STOT" + ims.dto.NASMessageCodes.ATTRIBUTEVALUESEPARATOR + filter.Stot;
  		}
  		
  		if(Filter.Socc != null && filter.Socc.length()> 0)
  		{
  			if(filterString.length() > 0)
  				filterString += ims.dto.NASMessageCodes.PAIRSEPARATOR;
  			filterString += "SOCC" + ims.dto.NASMessageCodes.ATTRIBUTEVALUESEPARATOR + filter.Socc;
  		}
  		
  		if(Filter.Sphd != null && filter.Sphd.length()> 0)
  		{
  			if(filterString.length() > 0)
  				filterString += ims.dto.NASMessageCodes.PAIRSEPARATOR;
  			filterString += "SPHD" + ims.dto.NASMessageCodes.ATTRIBUTEVALUESEPARATOR + filter.Sphd;
  		}
  		
  		if(Filter.Sohd != null && filter.Sohd.length()> 0)
  		{
  			if(filterString.length() > 0)
  				filterString += ims.dto.NASMessageCodes.PAIRSEPARATOR;
  			filterString += "SOHD" + ims.dto.NASMessageCodes.ATTRIBUTEVALUESEPARATOR + filter.Sohd;
  		}
  		
  		if(Filter.Name != null && filter.Name.length()> 0)
  		{
  			if(filterString.length() > 0)
  				filterString += ims.dto.NASMessageCodes.PAIRSEPARATOR;
  			filterString += "NAME" + ims.dto.NASMessageCodes.ATTRIBUTEVALUESEPARATOR + filter.Name;
  		}
  		
  		if(Filter.Stat != null && filter.Stat.length()> 0)
  		{
  			if(filterString.length() > 0)
  				filterString += ims.dto.NASMessageCodes.PAIRSEPARATOR;
  			filterString += "STAT" + ims.dto.NASMessageCodes.ATTRIBUTEVALUESEPARATOR + filter.Stat;
  		}
  		
  		if(Filter.At01 != null && filter.At01.length()> 0)
  		{
  			if(filterString.length() > 0)
  				filterString += ims.dto.NASMessageCodes.PAIRSEPARATOR;
  			filterString += "AT01" + ims.dto.NASMessageCodes.ATTRIBUTEVALUESEPARATOR + filter.At01;
  		}
  		
  		if(Filter.Mavl != null && filter.Mavl.length()> 0)
  		{
  			if(filterString.length() > 0)
  				filterString += ims.dto.NASMessageCodes.PAIRSEPARATOR;
  			filterString += "MAVL" + ims.dto.NASMessageCodes.ATTRIBUTEVALUESEPARATOR + filter.Mavl;
  		}
  		
  		if(Filter.Savl != null && filter.Savl.length()> 0)
  		{
  			if(filterString.length() > 0)
  				filterString += ims.dto.NASMessageCodes.PAIRSEPARATOR;
  			filterString += "SAVL" + ims.dto.NASMessageCodes.ATTRIBUTEVALUESEPARATOR + filter.Savl;
  		}
  		
  		if(Filter.Total != null && filter.Total.length()> 0)
  		{
  			if(filterString.length() > 0)
  				filterString += ims.dto.NASMessageCodes.PAIRSEPARATOR;
  			filterString += "TOTAL" + ims.dto.NASMessageCodes.ATTRIBUTEVALUESEPARATOR + filter.Total;
  		}
  		
  		if(Filter.Avail != null && filter.Avail.length()> 0)
  		{
  			if(filterString.length() > 0)
  				filterString += ims.dto.NASMessageCodes.PAIRSEPARATOR;
  			filterString += "AVAIL" + ims.dto.NASMessageCodes.ATTRIBUTEVALUESEPARATOR + filter.Avail;
  		}
  		
  		if(Filter.Closed != null && filter.Closed.length()> 0)
  		{
  			if(filterString.length() > 0)
  