gt: 		java.util.Set removedSet = new java.util.HashSet();
context: //#############################################################################
  //#                                                                           #
  //#  Copyright (C) <2015>  <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/>.    #
  //#                                                                           #
  //#  IMS MAXIMS provides absolutely NO GUARANTEE OF THE CLINICAL SAFTEY of    #
  //#  this program.  Users of this software do so entirely at their own risk.  #
  //#  IMS MAXIMS only ensures the Clinical Safety of unaltered run-time        #
  //#  software that it builds, deploys and maintains.                          #
  //#                                                                           #
  //#############################################################################
  //#EOH
  /*
   * This code was generated
   * Copyright (C) 1995-2004 IMS MAXIMS plc. All rights reserved.
   * IMS Development Environment (version 1.80 build 5589.25814)
   * WARNING: DO NOT MODIFY the content of this file
   * Generated: 12/10/2015, 13:28
   *
   */
  package ims.ocrr.configuration.domain.objects;
  
  /**
   * 
   * @author Neil McAnaspie
   * Generated.
   */
  
  
  public class ServiceQuestion extends ims.domain.DomainObject implements ims.domain.SystemInformationRetainer, java.io.Serializable {
  	public static final int CLASSID = 1061100008;
  	private static final long serialVersionUID = 1061100008L;
  	public static final String CLASSVERSION = "${ClassVersion}";
  
  	@Override
  	public boolean shouldCapQuery()
  	{
  		return true;
  	}
  
  	/** Service */
  	private ims.core.clinical.domain.objects.Service service;
  	/** isMandatory */
  	private Boolean isMandatory;
  	/** QuestionInformation */
  	private ims.core.clinical.domain.objects.QuestionInformation questionInformation;
  	/** Ask For Investigations */
  	private Boolean askForInvestigations;
  	/** SystemInformation */
  	private ims.domain.SystemInformation systemInformation = new ims.domain.SystemInformation();
      public ServiceQuestion (Integer id, int ver)
      {
      	super(id, ver);
      }
      public ServiceQuestion ()
      {
      	super();
      }
      public ServiceQuestion (Integer id, int ver, Boolean includeRecord)
      {
      	super(id, ver, includeRecord);
      }
  	public Class getRealDomainClass()
  	{
  		return ims.ocrr.configuration.domain.objects.ServiceQuestion.class;
  	}
  
  
  	public ims.core.clinical.domain.objects.Service getService() {
  		return service;
  	}
  	public void setService(ims.core.clinical.domain.objects.Service service) {
  		this.service = service;
  	}
  
  	public Boolean isIsMandatory() {
  		return isMandatory;
  	}
  	public void setIsMandatory(Boolean isMandatory) {
  		this.isMandatory = isMandatory;
  	}
  
  	public ims.core.clinical.domain.objects.QuestionInformation getQuestionInformation() {
  		return questionInformation;
  	}
  	public void setQuestionInformation(ims.core.clinical.domain.objects.QuestionInformation questionInformation) {
  		this.questionInformation = questionInformation;
  	}
  
  	public Boolean isAskForInvestigations() {
  		return askForInvestigations;
  	}
  	public void setAskForInvestigations(Boolean askForInvestigations) {
  		this.askForInvestigations = askForInvestigations;
  	}
  
  	public ims.domain.SystemInformation getSystemInformation() {
  		if (systemInformation == null) systemInformation = new ims.domain.SystemInformation();
  		return systemInformation;
  	}
  
  
  	/**
  	 * isConfigurationObject
  	 * Taken from the Usage property of the business object, this method will return
  	 * a boolean indicating whether this is a configuration object or not
  	 * Configuration = true, Instantiation = false
  	 */
  	public static boolean isConfigurationObject()
  	{
  		if ( "Configuration".equals("Configuration") )
  			return true;
  		else
  			return false;
  	}
  	// method generated based on 'ocrr_servicequest_unq1' unique index.
  	public static boolean recordExistForServiceAndQuestionInformation(ims.domain.ILightweightDomainFactory factory,
  		 ims.core.clinical.domain.objects.Service service
  	,
  	 ims.core.clinical.domain.objects.QuestionInformation questionInformation
  	)	
  	{
  		return recordExistForServiceAndQuestionInformation(factory, service, questionInformation, null);
  	}	
  
  	// method generated based on 'ocrr_servicequest_unq1' unique index.
  	public static boolean recordExistForServiceAndQuestionInformation(ims.domain.ILightweightDomainFactory factory,
  		 ims.core.clinical.domain.objects.Service service
  	,
  	 ims.core.clinical.domain.objects.QuestionInformation questionInformation
  	, Integer recordId)	
  	{
  		String[] names = new String[2];
  		Object[] values = new Object[2];
  		StringBuffer hql = new StringBuffer();
  		
  		hql.append("from ServiceQuestion c where ");
  		hql.append(" c.service = :service ");
  		names[0] = "service";
  		values[0] = service;		
  		hql.append(" and "); 
  		hql.append(" c.questionInformation = :questionInformation ");
  		names[1] = "questionInformation";
  		values[1] = questionInformation;		
  		if(recordId != null)
  		{
  			hql.append(" and c.id <> " + recordId);
  		}
  		
  		return factory.count(hql.toString(), names, values) > 0;				
  	}	
  
  	// method generated based on 'ocrr_servicequest_unq1' unique index.
  	public static ServiceQuestion getRecordByServiceAndQuestionInformation(ims.domain.ILightweightDomainFactory factory,
  	 ims.core.clinical.domain.objects.Service service
  	,
  	 ims.core.clinical.domain.objects.QuestionInformation questionInformation
  	)
  	{
  		String[] names = new String[2];
  		Object[] values = new Object[2];
  		StringBuffer hql = new StringBuffer();
  		hql.append("from ServiceQuestion c where ");
  		hql.append(" c.service = :service ");
  		names[0] = "service";
  		values[0] = service;		
  		hql.append(" and "); 
  		hql.append(" c.questionInformation = :questionInformation ");
  		names[1] = "questionInformation";
  		values[1] = questionInformation;		
  		java.util.List l = factory.find(hql.toString(), names, values);
  		if (l == null || l.size() == 0) return null;
  		if (l.size() > 1) throw new ims.domain.exceptions.DomainRuntimeException("Non-unique get call. " + hql + " returned " + l.size() + " records. " );
  		return (ServiceQuestion)l.get(0);
  	}
  
  	public static ServiceQuestion getServiceQuestionFromocrr_servicequest_unq1(ims.domain.ILightweightDomainFactory factory,
  	 ims.core.clinical.domain.objects.Service service
  	,
  	 ims.core.clinical.domain.objects.QuestionInformation questionInformation
  	)
  	{
  		String[] names = new String[2];
  		Object[] values = new Object[2];
  		StringBuffer hql = new StringBuffer();
  		hql.append("from ServiceQuestion c where ");
  		hql.append(" c.service = :service ");
  		names[0] = "service";
  		values[0] = service;		
  		hql.append(" and "); 
  		hql.append(" c.questionInformation = :questionInformation ");
  		names[1] = "questionInformation";
  		values[1] = questionInformation;		
  		java.util.List l = factory.find(hql.toString(), names, values);
  		if (l == null || l.size() == 0) return null;
  		if (l.size() > 1) throw new ims.domain.exceptions.DomainRuntimeException("Non-unique get call. " + hql + " returned " + l.size() + " records. " );
  		return (ServiceQuestion)l.get(0);
  	}
  
  
  	public int getClassId() {
  		return CLASSID;
  	}
  
  	public String getClassVersion()
  	{
  		return CLASSVERSION;
  	}
  
  	public String toAuditString()
  	{
  		StringBuffer auditStr = new StringBuffer();
  		
  		auditStr.append("\r\n*service* :");
  		if (service != null)
  		{
  			auditStr.append(toShortClassName(service));
  				
  		    auditStr.append(service.getId());
  		}
  	    auditStr.append("; ");
  		auditStr.append("\r\n*isMandatory* :");
  		auditStr.append(isMandatory);
  	    auditStr.append("; ");
  		auditStr.append("\r\n*questionInformation* :");
  		if (questionInformation != null)
  		{
  			auditStr.append(toShortClassName(questionInformation));
  				
  		    auditStr.append(questionInformation.getId());
  		}
  	    auditStr.append("; ");
  		auditStr.append("\r\n*askForInvestigations* :");
  		auditStr.append(askForInvestigations);
  	    auditStr.append("; ");
  		return auditStr.toString();
  	}
  	
  	public String toXMLString()
  	{
  		return toXMLString(new java.util.HashMap());
  	}
  	
  	public String toXMLString(java.util.HashMap domMap)
  	{
  		StringBuffer sb = new StringBuffer();
  		sb.append("<class type=\"" + this.getClass().getName() + "\" ");		
  		sb.append(" id=\"" + this.getId() + "\""); 
  		sb.append(" source=\"" + ims.configuration.EnvironmentConfig.getImportExportSourceName() + "\" ");
  		sb.append(" classVersion=\"" + this.getClassVersion() + "\" ");
  		sb.append(" component=\"" + this.getIsComponentClass() + "\" >");
  		
  		if (domMap.get(this) == null)
  		{
  			domMap.put(this, this);
  			sb.append(this.fieldsToXMLString(domMap));
  		}
  		sb.append("</class>");
  		
  		String keyClassName = "ServiceQuestion";
  		String externalSource = ims.configuration.EnvironmentConfig.getImportExportSourceName();
  		ims.configuration.ImportedObject impObj = (ims.configuration.ImportedObject)domMap.get(keyClassName + "_" + externalSource + "_" + this.getId());
  		if (impObj == null)
  		{
      		impObj = new ims.configuration.ImportedObject();
      		impObj.setExternalId(this.getId());
      		impObj.setExternalSource(externalSource);
      		impObj.setDomainObject(this);
  			impObj.setLocalId(this.getId()); 
      		impObj.setClassName(keyClassName); 
  			domMap.put(keyClassName + "_" + externalSource + "_" + this.getId(), impObj);
  		}
  		
  		return sb.toString();
  	}
  
  	public String fieldsToXMLString(java.util.HashMap domMap)
  	{
  		StringBuffer sb = new StringBuffer();
  		if (this.getService() != null)
  		{
  			sb.append("<service>");
  			sb.append(this.getService().toXMLString(domMap)); 	
  			sb.append("</service>");		
  		}
  		if (this.isIsMandatory() != null)
  		{
  			sb.append("<isMandatory>");
  			sb.append(ims.framework.utils.StringUtils.encodeXML(this.isIsMandatory().toString()));
  			sb.append("</isMandatory>");		
  		}
  		if (this.getQuestionInformation() != null)
  		{
  			sb.append("<questionInformation>");
  			sb.append(this.getQuestionInformation().toXMLString(domMap)); 	
  			sb.append("</questionInformation>");		
  		}
  		if (this.isAskForInvestigations() != null)
  		{
  			sb.append("<askForInvestigations>");
  			sb.append(ims.framework.utils.StringUtils.encodeXML(this.isAskForInvestigations().toString()));
  			sb.append("</askForInvestigations>");		
  		}
  		return sb.toString();
  	}
  		
  	public static java.util.List fromListXMLString(org.dom4j.Element el, ims.domain.DomainFactory factory, java.util.List list, java.util.HashMap domMap) throws Exception
  	{
  		if (list == null)
  		 list = new java.util.ArrayList();
  		fillListFromXMLString(list, el, factory, domMap);
  		return list;
  	}
  	
  	public static java.util.Set fromSetXMLString(org.dom4j.Element el, ims.domain.DomainFactory factory, java.util.Set set, java.util.HashMap domMap) throws Exception
  	{
  		if (set == null)
  			 set = new java.util.HashSet();
  		fillSetFromXMLString(set, el, factory, domMap);
  		return set;
  	}
  	
  	private static void fillSetFromXMLString(java.util.Set set, org.dom4j.Element el, ims.domain.DomainFactory factory, java.util.HashMap domMap) throws Exception
  	{
  		if (el == null)
  			return;
  		
  		java.util.List cl = el.elements("class");
  		int size = cl.size();
  		
  		java.util.Set newSet = new java.util.HashSet();
  		for(int i=0; i<size; i++) 
  		{
  			org.dom4j.Element itemEl = (org.dom4j.Element)cl.get(i);
  			ServiceQuestion domainObject = getServiceQuestionfromXML(itemEl, factory, domMap);
  
  			if (domainObject == null)
  			{
  				continue;
  			}
  			
  			//Trying to avoid the hibernate collection being marked as dirty via its public interface methods. (like add)
  			if (!set.contains(domainObject)) 
  				set.add(domainObject);
  			newSet.add(domainObject);			
  		}
  		
  