/* 
	Developed by : HATIM LAXMIDHAR
	Discription	 : Post Save for the Adjustment Issue.
	Date		 : 01/01/2006
*/

package ibase.webitm.ejb.sys;

import java.rmi.RemoteException;
import java.lang.String;
import java.sql.*;
import javax.ejb.*;
import javax.naming.InitialContext;
import java.util.HashMap;
import org.w3c.dom.*;

import ibase.webitm.utility.ITMException;
import ibase.webitm.ejb.*;
import ibase.webitm.utility.GenericUtility;
import ibase.system.config.*;
//public class AdjIssPosEJB extends ValidatorEJB implements SessionBean // commented for ejb3
import javax.ejb.Stateless; // added for ejb3

@Stateless // added for ejb3
public class E12CreateBatch extends ValidatorEJB implements E12CreateBatchLocal, E12CreateBatchRemote  //added for ejb3
{

	public String postSaveRec()throws RemoteException,ITMException
	{
		return "";
	}
	public String createBatchLoad( String xmlString,  String editOpt, String xtraParams, Connection connRemote ) throws Exception, ITMException
	{
		Document dom = null;
		String winName = "", retString = "";
		NodeList parentNodeList = null;
		Node parentNode = null;

		System.out.println("AdjIssPosEJB called");
		try
		{
			if (xmlString != null && xmlString.trim().length() > 0)
			{
				dom = GenericUtility.getInstance().parseString(xmlString);
				parentNodeList = dom.getElementsByTagName("Detail1");
				parentNode = parentNodeList.item( 0 );

				
				winName = getObjName(parentNode);
				E12CreateBatchLoadEjb e12CreateBatchLoad = new E12CreateBatchLoadEjb();

				retString = e12CreateBatchLoad.createBatchLoad( dom, winName, editOpt, xtraParams, connRemote );
				e12CreateBatchLoad = null;
				if( retString != null && "SUCCESS".equals(retString) )
				{
					System.out.println("retString from batchload = ["+retString+"]");
				}
			}			

		}
	   	catch(Exception e)
		{
			System.out.println("Exception :AdjIssPosEJB ::" + e.getMessage() + ":");
			e.printStackTrace();
			throw new ITMException(e);
		}
		return "";
	}
	private String getObjName(Node node) throws Exception
	{
		String objName = null;
		NodeList nodeList = null;
		Node detaulNode = null;
		Node detailNode = null;
		nodeList = node.getChildNodes();
		NamedNodeMap attrMap = node.getAttributes();
		objName = attrMap.getNamedItem( "objName" ).getNodeValue();
		return "w_" + objName;

	}

}