package ibase.webitm.ejb.mfg;

import java.rmi.RemoteException;
import java.text.*;
import java.util.Date;
import java.sql.*;

import org.w3c.dom.*;

import javax.ejb.*;

import ibase.webitm.utility.ITMException;
import ibase.webitm.utility.*;
import ibase.system.config.*;
import ibase.webitm.ejb.*;
import javax.ejb.Stateless; // added for ejb3

@Stateless // added for ejb3

public class ForecastTechIC extends ValidatorEJB implements ForecastTechICLocal,ForecastTechICRemote// SessionBean
{
	GenericUtility genericUtility = GenericUtility.getInstance(); 

	/*public void ejbCreate() throws RemoteException, CreateException 
	{
		System.out.println("EpaymentICEJB is in Process..........");
	}
	public void ejbRemove()
	{
	}
	public void ejbActivate() 
	{
	}
	public void ejbPassivate() 
	{
	}
	public String wfValData() throws RemoteException,ITMException
	{
		return "";
	}*/

	public String itemChanged() throws RemoteException,ITMException
	{
		return "";
	}
	public String wfValData(String xmlString, String xmlString1,String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
	{
		Document dom = null;
		Document dom1 = null;
		Document dom2 = null;
		String  errString = null;
		System.out.println("Validation Start..........");
		try
		{
			System.out.println("xmlString:::"+xmlString);
			dom = parseString(xmlString);
			dom1 = parseString(xmlString1); 
			if (xmlString2.trim().length() > 0 )
			{
				dom2 = parseString(xmlString2);
			}
			errString = wfValData(dom,dom1,dom2,objContext,editFlag,xtraParams);
		}
		catch(Exception e)
		{
			System.out.println("Exception : EpaymentICEJB : wfValData(String xmlString) : ==>\n"+e.getMessage());
		}
		return (errString);
	}
	public String wfValData(Document dom, Document dom1,Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
	{
		String errString = " ";
		NodeList parentNodeList = null;
		NodeList childNodeList = null;
		Node parentNode = null;
		Node childNode = null;
		int ctr = 0;
		String startDate = null,endDate = null;
		String columnValue = null;
		String childNodeName = null;
		
		String errCode = null;
		String userId = null,loginSite = null;
		String prdtCode = null;
		
		int cnt = 0;
		int currentFormNo = 0;
		int childNodeListLength;
		Connection conn = null;
		PreparedStatement pstmt=null;
		ResultSet rs = null;
		String sql = null;
		
		String orderDateStr = null;
		String tranDateStr =  null;
		
		int resultCount = 0;
		String templateFile = null;
		String exprNo = null;

		
	    ConnDriver connDriver = new ConnDriver();
    	try
		{
			System.out.println( "wfValData called" );
			conn = connDriver.getConnectDB("DriverITM");
			userId = getValueFromXTRA_PARAMS(xtraParams,"loginCode");
			loginSite = getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
			genericUtility = GenericUtility.getInstance(); 
			if(objContext != null && objContext.trim().length()>0)
			{
				currentFormNo = Integer.parseInt(objContext);
			}
			switch(currentFormNo)
			{
				case 1 :
					System.out.println("VALIDATION FOR DETAIL [ 1 ]..........");
					parentNodeList = dom.getElementsByTagName("Detail1");
					parentNode = parentNodeList.item(0);
					childNodeList = parentNode.getChildNodes();
					childNodeListLength = childNodeList.getLength();
					for(ctr = 0; ctr < childNodeListLength; ctr++)
					{
						childNode = childNodeList.item(ctr);
						childNodeName = childNode.getNodeName();
						if ( childNodeName.equalsIgnoreCase( "site_code" ) )
						{
							String siteCode = null;
							siteCode = genericUtility.getColumnValue( "site_code", dom, "1" );
							
							if(	siteCode != null && siteCode.trim().length() > 0 )
							{
								sql = " SELECT COUNT(*) FROM site WHERE site_code ='" + siteCode.trim() + "'";
								System.out.println( " SQL FOR custCode ====> " + sql );
								pstmt = conn.prepareStatement( sql );
								rs = pstmt.executeQuery();
								if( rs.next() )
								{
									cnt = rs.getInt( 1 );
								} 
								System.out.println(" COUNT =====> [" + cnt + "]");
								if( cnt == 0 )
								{
									System.out.println(" ====> Site invalid or not found <==== ");
									errCode = "VMINVSITE";
									errString = getErrorString( "SITE_CODE", errCode, userId );
								}
								rs.close();
								rs = null;

								pstmt.close();
								pstmt = null;
							}
							else
							{
								errCode = "VMSITEBLK";
								errString = getErrorString( "SITE_CODE", errCode, userId );
							}
						}
						if ( childNodeName.equalsIgnoreCase( "valid_upto" ) )
						{
							java.util.Date effFrom = null;
							java.util.Date validUpto = null;
							String effFromStr = null;
							String validUptoStr = null;
							SimpleDateFormat sdf = null;
							sdf = new SimpleDateFormat( genericUtility.getApplDateFormat() );
							
							validUptoStr = getColumnValue( "valid_upto", dom );
							effFromStr = getColumnValue( "eff_from", dom );
							if( effFromStr == null || effFromStr.trim().length() == 0 )
							{
								errCode = "VMEFFDTBLK";
								errString = getErrorString("eff_from",errCode,userId);
								break;								
							}
							if( validUptoStr == null || validUptoStr.trim().length() == 0 )
							{
								errCode = "VMVLDUPBLK";
								errString = getErrorString("valid_upto",errCode,userId);
								break;								
							}							
							if( effFromStr != null  && validUptoStr != null )
							{	
								effFrom = sdf.parse( effFromStr );
								validUpto = sdf.parse( validUptoStr );
								if( validUpto.before( effFrom ))
								{	
									errCode = "VMVALUPTGT";
									errString = getErrorString("valid_upto",errCode,userId);
									break;
								}	
							}
						}
						if ( childNodeName.equalsIgnoreCase( "eff_from" ) )
						{
							java.util.Date effFrom = null;
							java.util.Date tranDt = null;
							String effFromStr = null;
							
							SimpleDateFormat sdf = null;
							sdf = new SimpleDateFormat( genericUtility.getApplDateFormat() );
							
							effFromStr = getColumnValue( "eff_from", dom );
							tranDateStr = getColumnValue( "tran_date", dom );
							if( effFromStr == null || effFromStr.trim().length() == 0 )
							{
								errCode = "VMEFFDTBLK";
								errString = getErrorString( "eff_from", errCode, userId);
								break;								
							}
							
							if( effFromStr != null  && tranDateStr != null )
							{	
								effFrom = sdf.parse( effFromStr );
								tranDt = sdf.parse( tranDateStr );
								
								if( effFrom.before( tranDt ) )
								{	
									errCode = "VMEFFDTLS";
									errString = getErrorString( "eff_from", errCode, userId );
									break;
								}	
							}
						}					
					} 
					//END OF CASE1
					break;
				case 2 :
					System.out.println("VALIDATION FOR DETAIL [ 2 ]..........");
					parentNodeList = dom.getElementsByTagName("Detail2");
					parentNode = parentNodeList.item(0);
					childNodeList = parentNode.getChildNodes();
					childNodeListLength = childNodeList.getLength();
					for(ctr = 0; ctr < childNodeListLength; ctr++)
					{
						cnt = 0;
						childNode = childNodeList.item(ctr);
						childNodeName = childNode.getNodeName();
						
						if ( childNodeName.equalsIgnoreCase( "item_code" ) )
						{
							String itemCode = null;
							itemCode = genericUtility.getColumnValue( "item_code", dom, "2" );
							errCode = null;
							System.out.println(" itemCode =====> [" + itemCode + "]");
							if(	itemCode != null && itemCode.trim().length() > 0 )
							{
								sql = " SELECT COUNT(*) FROM item WHERE item_code ='" + itemCode.trim() + "'";
								System.out.println( " SQL FOR item ====> " + sql );
								pstmt = conn.prepareStatement( sql );
								rs = pstmt.executeQuery();
								if( rs.next() )
								{
									cnt = rs.getInt( 1 );
								} 
								System.out.println(" COUNT =====> [" + cnt + "]");
								if( cnt == 0 )
								{
									System.out.println(" ====> Item Code Invalid <==== ");
									errCode = "VMINVITEM";
								}
								rs.close();
								rs = null;

								pstmt.close();
								pstmt = null;
							} 
							if( errCode != null )
							{
								errString = getErrorString( "item_code", errCode, userId );
							}
						}else if( childNodeName.equalsIgnoreCase( "site_code" ) )
						{
							String siteCode = null;
							siteCode = genericUtility.getColumnValue( "site_code", dom, "2" );
							
							if(	siteCode != null && siteCode.trim().length() > 0 )
							{
								sql = " SELECT COUNT(*) cnt FROM site WHERE site_code ='" + siteCode.trim() + "'";
								System.out.println( " SQL FOR siteCode ====> " + sql );
								pstmt = conn.prepareStatement( sql );
								rs = pstmt.executeQuery();
								if( rs.next() )
								{
									cnt = rs.getInt( "cnt" );
								} 
								System.out.println(" COUNT =====> [" + cnt + "]");
								if( cnt == 0 )
								{
									System.out.println(" ====> Site invalid or not found <==== ");
									errCode = "VMINVSITE";
									errString = getErrorString( "SITE_CODE", errCode, userId );
								}
								rs.close();
								rs = null;

								pstmt.close();
								pstmt = null;
							}
						}else if( childNodeName.equalsIgnoreCase( "qty_perc" ) )
						{
							String qtyPerc = null;
							String calcType = null;
							double totalPerc = 0.0;
							double percVal = 0.0;
							qtyPerc = genericUtility.getColumnValue( "qty_perc", dom, "2" );
							calcType = genericUtility.getColumnValue( "calc_type", dom, "2" );
							calcType = calcType == null ? "" : calcType;
							if(	qtyPerc != null && qtyPerc.trim().length() > 0 && !( calcType.indexOf( "U" ) > -1 || calcType.indexOf( "A" ) > -1 ) )
							{
								String qtyPercArr[] = null;
								qtyPercArr = qtyPerc.split( "," );
								
								int qtyPercArrLen = qtyPercArr.length;
								
								for( int percIdx = 0; percIdx < qtyPercArrLen; percIdx++ )
								{
									try
									{
										percVal = Double.parseDouble( qtyPercArr[ percIdx ].trim() );
										if( percVal < 0 )
										{
											errCode = "VMNEGPERC";
										}
										else
										{
											totalPerc += percVal;
										}
										
									}
									catch( Exception ex )
									{
										errCode = "VMINVPERC";
									}
								}

								if( totalPerc > 100 )
								{
									errCode = "VMPERCGT";
								}
								if( errCode != null )
								{
									errString = getErrorString( "qty_perc", errCode, userId );
								}
							}
							if(	qtyPerc != null && qtyPerc.trim().length() > 0 && ( calcType.indexOf( "U" ) > -1 || calcType.indexOf( "A" ) > -1 ) )
							{
								errCode = "VMNOPERC";
								errString = getErrorString( "qty_perc", errCode, userId );
							}
						}else if ( childNodeName.trim().equals( "calc_type" ) )
						{
							String calcType = null;
							String qtyPerc = null;
							qtyPerc = genericUtility.getColumnValue( "qty_perc", dom, "2" );
							calcType = genericUtility.getColumnValue( "calc_type", dom, "2" );						
							if( calcType != null && ( calcType.indexOf( "P" ) > -1 || calcType.indexOf( "W" ) > -1 ) && ( qtyPerc == null || qtyPerc.trim().length() == 0 ))
							{
								errCode = "VMPERCBLK";
								errString = getErrorString( "qty_perc", errCode, userId );
							}
							else if( calcType == null || calcType.trim().length() == 0 )
							{
								errCode = "VMCALCBLK";
								errString = getErrorString( "calc_type", errCode, userId );							
							}
						}else if ( childNodeName.trim().equals( "cal_method" ) )
						{
							String calcType = null;
							String calMethod = null;
							
							calMethod = genericUtility.getColumnValue( "cal_method", dom, "2" );
							calcType = genericUtility.getColumnValue( "calc_type", dom, "2" );						
							if( calcType != null && !( calcType.indexOf( "U" ) > -1 ) 
												 && ( calMethod != null && calMethod.trim().length() > 0 ) )
							{
								errCode = "VMNOCALM";
								errString = getErrorString( "cal_method", errCode, userId );
							}
							else if( calcType == null || calcType.trim().length() == 0 )
							{
								errCode = "VMCALCBLK";
								errString = getErrorString( "calc_type", errCode, userId );							
							}
						}else if ( childNodeName.trim().equals( "cal_input" ) )
						{
							String calcType = null;
							String calInput = null;
							
							calInput = genericUtility.getColumnValue( "cal_input", dom, "2" );
							calcType = genericUtility.getColumnValue( "calc_type", dom, "2" );						
							if( calcType != null && !( calcType.indexOf( "U" ) > -1 ) 
												 && ( calInput != null && calInput.trim().length() > 0 ) )
							{
								errCode = "VMNOCALI";
								errString = getErrorString( "cal_input", errCode, userId );
							}
							else if( calcType == null || calcType.trim().length() == 0 )
							{
								errCode = "VMCALCBLK";
								errString = getErrorString( "calc_type", errCode, userId );							
							}
						}
					}//END FOR OF CASE2
					break;
			}//END SWITCH
		}//END TRY
		catch(Exception e)
		{
			System.out.println("Exception ::" +e);
			e.printStackTrace();
			errCode = "VALEXCEP";
			errString = getErrorString( "", errCode, userId );									
		}
		finally
		{
			try
			{
				if(conn != null)
				{
					if( pstmt != null )
					{
						pstmt.close();
						pstmt = null;
					}
					
					if( rs != null )
					{
						rs.close();
						rs = null;
					}
					conn.close();
				}
				conn = null;
			}
			catch(Exception d)
				{
				  d.printStackTrace();
				}			
			System.out.println(" < ExprProcessIcEJB > CONNECTION IS CLOSED");
		}
		System.out.println("ErrString ::" + errString);

		return errString;
	}//END OF VALIDATION 

	public String itemChanged(String xmlString, String xmlString1,String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException
	{
		Document dom = null;
		Document dom1 = null;
		Document dom2 = null;
		String valueXmlString = null;
		try
		{
			dom = parseString(xmlString); 
			System.out.println("xmlString" + xmlString);
			dom1 = parseString(xmlString1); 
			System.out.println("xmlString1" + xmlString1);
			if (xmlString2.trim().length() > 0 )
			{
				System.out.println("xmlString2" + xmlString2);
				dom2 = parseString("<Root>" + xmlString2+ "</Root>");
			}
			valueXmlString = itemChanged(dom,dom1,dom2,objContext,currentColumn,editFlag,xtraParams);
		}
		catch(Exception e)
		{
			System.out.println("Exception : [EpaymentICEJB][itemChanged(String,String)] :==>\n"+e.getMessage());
		}
        return valueXmlString; 
	}
	
	public String itemChanged(Document dom, Document dom1,Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException
	{
		Connection conn = null;
		ConnDriver connDriver = new ConnDriver();
		PreparedStatement pStmt = null;
		ResultSet rs = null;
		String sql = null;
		int currentFormNo = 0;
		StringBuffer valueXmlString = new StringBuffer();
		String columnValue = null;

		NodeList parentNodeList = null;
		Node parentNode = null; 
		Node childNode = null;
		NodeList childNodeList = null;
		String childNodeName = null;
		int childNodeListLength = 0;
		int ctr = 0;
		
		String  loginSite = null; 
		
		try
		{
			conn = connDriver.getConnectDB("DriverITM");
			connDriver = null;
			if(objContext != null && objContext.trim().length()>0)
			{
				currentFormNo = Integer.parseInt(objContext);
			}
			
			loginSite = getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
			
			System.out.println("[EpaymentICEJB] [itemChanged] :currentFormNo ....." +currentFormNo);
			valueXmlString = new StringBuffer("<?xml version=\"1.0\"?><Root><header><editFlag>");
			valueXmlString.append(editFlag).append("</editFlag></header>");
			
			System.out.println("Current Form No ["+currentFormNo+"]");							
			switch (currentFormNo)
			{
				case 1:
					valueXmlString.append("<Detail1>");	
					//SEARCHING THE DOM FOR THE INCOMING COLUMN VALUE START
					parentNodeList = dom.getElementsByTagName("Detail1");
					parentNode = parentNodeList.item(0);
					childNodeList = parentNode.getChildNodes();
					ctr = 0;
					childNodeListLength = childNodeList.getLength();
					do
					{
						childNode = childNodeList.item(ctr);
						childNodeName = childNode.getNodeName();
						if(childNodeName.equals(currentColumn))
						{
							if (childNode.getFirstChild() != null)
							{
								columnValue=childNode.getFirstChild().getNodeValue().trim();
							}
						}
						ctr++;
					}while(ctr < childNodeListLength  && !childNodeName.equals(currentColumn));
					System.out.println("[" + currentColumn + "] ==> '" + columnValue + "'");
					if (currentColumn.trim().equals( "itm_default" ))
					{
						String loginSiteCode = null;
						String siteDescr = null;
						loginSiteCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
						sql = "select s.descr site_descr from site s "
								+" where s.site_code = '" + loginSiteCode + "'";

						pStmt = conn.prepareStatement( sql );
						rs = pStmt.executeQuery();
						if( rs.next() )
						{
							siteDescr = rs.getString( "site_descr" );
						}
						rs.close();
						rs = null;
						pStmt.close();
						pStmt = null;
						
						valueXmlString.append("<tran_date>").append("<![CDATA[" + getCurrdateAppFormat() + "]]>").append("</tran_date>");
						valueXmlString.append("<site_code>").append("<![CDATA[" + ( loginSiteCode != null ? loginSiteCode.trim() : ""  )+ "]]>").append("</site_code>");
						valueXmlString.append("<descr>").append("<![CDATA[" + ( siteDescr != null ? siteDescr.trim() : ""  )+ "]]>").append("</descr>");
					}
					
					if ( currentColumn.trim().equals( "site_code" ) )
					{
						String siteDescr = null;
						if( columnValue != null )
						{
							sql = "select s.descr site_descr from site s "
									+" where s.site_code = '" + columnValue + "'";

							pStmt = conn.prepareStatement( sql );
							rs = pStmt.executeQuery();
							if( rs.next() )
							{
								siteDescr = rs.getString( "site_descr" );
							}
							rs.close();
							rs = null;
							pStmt.close();
							pStmt = null;
						}
						valueXmlString.append("<descr>").append("<![CDATA[" + ( siteDescr != null ? siteDescr.trim() : ""  )+ "]]>").append("</descr>");
					}	
					valueXmlString.append("</Detail1>");
					valueXmlString.append("</Root>");	
					break;
				///////////////
				case 2:
					valueXmlString.append("<Detail2>");	
					//SEARCHING THE DOM FOR THE INCOMING COLUMN VALUE START
					parentNodeList = dom.getElementsByTagName("Detail2");
					parentNode = parentNodeList.item(0);
					childNodeList = parentNode.getChildNodes();
					ctr = 0;
					childNodeListLength = childNodeList.getLength();
					do
					{
						childNode = childNodeList.item(ctr);
						childNodeName = childNode.getNodeName();
						if(childNodeName.equals(currentColumn))
						{
							if (childNode.getFirstChild() != null)
							{
								columnValue=childNode.getFirstChild().getNodeValue().trim();
							}
						}
						ctr++;
					}while(ctr < childNodeListLength  && !childNodeName.equals(currentColumn));
					System.out.println("[" + currentColumn + "] ==> '" + columnValue + "'");
					if (currentColumn.trim().equals( "itm_default" ))
					{
						valueXmlString.append("<qty_perc isSrvCallOnChg='0'>").append("<![CDATA[]]>").append("</qty_perc>");											
					}
					if (currentColumn.trim().equals( "itm_defaultedit" ))
					{
						String calcType = genericUtility.getColumnValue( "calc_type", dom );
						String qtyPerc = genericUtility.getColumnValue( "qty_perc", dom ); 
						String calMethod = genericUtility.getColumnValue( "cal_method", dom );
						String calInput = genericUtility.getColumnValue( "cal_input", dom );
						if( calcType != null && ( calcType.indexOf( "P" ) > -1 || calcType.indexOf( "W" ) > -1 ) )
						{
							valueXmlString.append("<qty_perc protect='0'>").append("<![CDATA[" + qtyPerc + "]]>").append("</qty_perc>");
						}
						else
						{
							valueXmlString.append("<qty_perc protect='0'>").append("<![CDATA[" + qtyPerc + "]]>").append("</qty_perc>");						
						}
						if( calcType != null && calcType.indexOf( "U" ) > -1  )
						{
							valueXmlString.append("<cal_method protect='0'>").append("<![CDATA[" + calMethod + "]]>").append("</cal_method>");
							valueXmlString.append("<cal_input protect='0'>").append("<![CDATA[" + calInput + "]]>").append("</cal_input>");
						}						
						else
						{
							valueXmlString.append("<cal_method protect='1'>").append("<![CDATA[]]>").append("</cal_method>");
							valueXmlString.append("<cal_input protect='1'>").append("<![CDATA[]]>").append("</cal_input>");
						}
					}
					if (currentColumn.trim().equals( "item_code" ))
					{
						String descr = null;
						sql = "select descr from item where item_code = '" + ( columnValue != null ? columnValue.trim() : "" ) + "'";
						pStmt = conn.prepareStatement( sql );
						rs = pStmt.executeQuery();
						if( rs.next() )
						{
							descr = rs.getString( "descr" );
						}
						rs.close();
						rs = null;
						pStmt.close();
						pStmt = null;
						valueXmlString.append("<item_descr>").append("<![CDATA[" + ( descr != null ? descr.trim() : ""  )+ "]]>").append("</item_descr>");
					}	
					if (currentColumn.trim().equals( "site_code" ))
					{
						String descr = null;
						sql = "select descr from site where site_code = '" + ( columnValue != null ? columnValue.trim() : "" ) + "'";
						pStmt = conn.prepareStatement( sql );
						rs = pStmt.executeQuery();
						if( rs.next() )
						{
							descr = rs.getString( "descr" );
						}
						rs.close();
						rs = null;
						pStmt.close();
						pStmt = null;
						valueXmlString.append("<site_descr>").append("<![CDATA[" + ( descr != null ? descr.trim() : ""  )+ "]]>").append("</site_descr>");
					}	
					if (currentColumn.trim().equals( "calc_type" ))
					{
						System.out.println( "calc_type :: " + columnValue );
						String calcType = genericUtility.getColumnValue( "calc_type", dom );
						System.out.println( "calc_type :: " + calcType );
						String qtyPerc = genericUtility.getColumnValue( "qty_perc", dom ); 
						System.out.println( "qtyPerc :: " + qtyPerc );
						String calMethod = genericUtility.getColumnValue( "cal_method", dom );
						System.out.println( "calMethod :: " + calMethod );
						String calInput = genericUtility.getColumnValue( "cal_input", dom );
						System.out.println( "calInput :: " + calInput );
						
						if( currentColumn != null && ( columnValue.indexOf( "P" ) > -1 || columnValue.indexOf( "W" ) > -1 ) )
						{
							valueXmlString.append("<qty_perc protect='0'>").append("<![CDATA[" + (qtyPerc == null?"":qtyPerc) + "]]>").append("</qty_perc>");
						}
						else
						{
							valueXmlString.append("<qty_perc protect='1'>").append("<![CDATA[]]>").append("</qty_perc>");						
						}
						if( currentColumn != null && columnValue.indexOf( "U" ) > -1  )
						{
							valueXmlString.append("<cal_method protect='0'>").append("<![CDATA[" + (calMethod == null?"":calMethod) + "]]>").append("</cal_method>");
							valueXmlString.append("<cal_input protect='0'>").append("<![CDATA[" + (calInput == null?"":calInput) + "]]>").append("</cal_input>");
						}						
						else
						{
							valueXmlString.append("<cal_method protect='1'>").append("<![CDATA[]]>").append("</cal_method>");
							valueXmlString.append("<cal_input protect='1'>").append("<![CDATA[]]>").append("</cal_input>");
						}						
					}	
					valueXmlString.append("</Detail2>");					
					valueXmlString.append("</Root>");					
				////////////////
			}//END OF TRY
		}
		catch(Exception e)
		{
			System.out.println("Exception ::"+ e.getMessage());
			e.printStackTrace();
		}
		finally
		{
			try
			{
				if ( rs != null )
				{
					rs.close();
					rs = null;
				}
				if ( pStmt != null )
				{
					pStmt.close();
					pStmt = null;					
				}
				if ( conn != null )
				{
					conn.close();
					conn = null;
				}
			}
			catch(Exception e)
			{
				System.out.println("Exception ::" + e);
				e.printStackTrace();
			}			
		}
		return valueXmlString.toString();
	}//END OF ITEMCHANGE	
	private String getCurrdateAppFormat()
	{
		String s = "";
		GenericUtility genericUtility = GenericUtility.getInstance();
		try
		{
			java.util.Date date = null;
			Timestamp timestamp = new Timestamp(System.currentTimeMillis());
			System.out.println(genericUtility.getDBDateFormat());

			SimpleDateFormat simpledateformat = new SimpleDateFormat(genericUtility.getDBDateFormat());
			date = simpledateformat.parse(timestamp.toString());
			timestamp = Timestamp.valueOf(simpledateformat.format(date).toString() + " 00:00:00.0");
			s = (new SimpleDateFormat(genericUtility.getApplDateFormat())).format(timestamp).toString();
		}
		catch(Exception exception)
		{
			System.out.println("Exception in  getCurrdateAppFormat " + exception.getMessage());
		}
		return s;
	}
}
