    private void FindAvail() throws ParserConfigurationException, SQLException {
        Savepoint sp1;
        String availsql = "select xmlquery('$c/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]' ";
        availsql += "passing hp_administrator.availability.AVAIL as \"c\") ";
        availsql += " from hp_administrator.availability ";
        availsql += " where date = '" + booking_details.getDate() + "' and train_no like '" + booking_details.getTrain_no() + "'";
        System.out.println(availsql);
        String availxml = "";
        String seatxml = "";
        String navailstr = "";
        String nspavailstr = "";
        String currentcoachstr = "";
        String srctillstr = "", srcavailstr = "", srcmaxstr = "";
        Integer srctill, srcavail, srcmax;
        Integer navailcoach;
        Integer nspavailcoach, seatstart, seatcnt, alloccnt;
        String routesrcstr = "", routedeststr = "";
        PreparedStatement pstseat;
        Statement stavail, stavailupd, stseatupd, stseat;
        ResultSet rsavail, rsseat;
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document docavail, docseattmp, docseatfin, docseat;
        Element rootavail, rootseat;
        Node n;
        try {
            stavail = conn.createStatement();
            sp1 = conn.setSavepoint();
            rsavail = stavail.executeQuery(availsql);
            if (rsavail.next()) availxml = rsavail.getString(1);
            System.out.println(availxml);
            StringBuffer StringBuffer1 = new StringBuffer(availxml);
            ByteArrayInputStream Bis1 = new ByteArrayInputStream(StringBuffer1.toString().getBytes("UTF-16"));
            docavail = db.parse(Bis1);
            StringWriter sw;
            OutputFormat formatter;
            formatter = new OutputFormat();
            formatter.setPreserveSpace(true);
            formatter.setEncoding("UTF-8");
            formatter.setOmitXMLDeclaration(true);
            XMLSerializer serializer;
            rootavail = docavail.getDocumentElement();
            NodeList coachlist = rootavail.getElementsByTagName("coach");
            Element currentcoach, minseat;
            Element routesrc, routedest, nextstn, dest, user, agent;
            NodeList nl, nl1;
            number_of_tickets_rem = booking_details.getNoOfPersons();
            int tickpos = 0;
            firsttime = true;
            boolean enterloop;
            for (int i = 0; i < coachlist.getLength(); i++) {
                currentcoach = (Element) coachlist.item(i);
                currentcoachstr = currentcoach.getAttribute("number");
                String coachmaxstr = currentcoach.getAttribute("coachmax");
                Integer coachmax = Integer.parseInt(coachmaxstr.trim());
                routesrc = (Element) currentcoach.getFirstChild();
                routedest = (Element) currentcoach.getLastChild();
                routedest = (Element) routedest.getPreviousSibling().getPreviousSibling().getPreviousSibling();
                routesrcstr = routesrc.getNodeName();
                routedeststr = routedest.getNodeName();
                String seatsql = "select xmlquery('$c/status/class[@type=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]' ";
                seatsql += " passing hp_administrator.book_tickets.SEAT as \"c\") from hp_administrator.book_tickets ";
                seatsql += " where  date = '" + booking_details.getDate() + "' and train_no like '" + booking_details.getTrain_no() + "' ";
                System.out.println("route  :" + sourcenws);
                System.out.println("route  :" + destnnws);
                System.out.println("route src :" + routesrcstr);
                System.out.println("route dest :" + routedeststr);
                System.out.println(seatsql);
                stseat = conn.createStatement();
                rsseat = stseat.executeQuery(seatsql);
                if (rsseat.next()) seatxml = rsseat.getString(1);
                StringBuffer StringBuffer2 = new StringBuffer(seatxml);
                ByteArrayInputStream Bis2 = new ByteArrayInputStream(StringBuffer2.toString().getBytes("UTF-16"));
                docseat = db.parse(Bis2);
                rootseat = docseat.getDocumentElement();
                enterloop = false;
                if (routesrcstr.equals(sourcenws) && routedeststr.equals(destnnws)) {
                    System.out.println("case 1");
                    navailstr = routesrc.getTextContent();
                    navailcoach = Integer.parseInt(navailstr.trim());
                    if (useragent) nspavailstr = routesrc.getAttribute("agent"); else nspavailstr = routesrc.getAttribute("user");
                    nspavailcoach = Integer.parseInt(nspavailstr.trim());
                    srctillstr = routesrc.getAttribute(sourcenws + "TILL");
                    srctill = Integer.parseInt(srctillstr.trim());
                    srcmaxstr = routesrc.getAttribute(sourcenws);
                    srcmax = Integer.parseInt(srcmaxstr.trim());
                    srcavailstr = routesrc.getTextContent();
                    srcavail = Integer.parseInt(srcavailstr.trim());
                    seatstart = coachmax - srctill + 1;
                    seatcnt = srcmax;
                    alloccnt = srcmax - srcavail;
                    seatstart += alloccnt;
                    seatcnt -= alloccnt;
                    Element seat, stn;
                    NodeList nl3 = rootseat.getElementsByTagName("seat");
                    seat = (Element) nl3.item(0);
                    if (booking_details.getNoOfPersons() <= navailcoach && booking_details.getNoOfPersons() <= nspavailcoach) {
                        coach.clear();
                        booking_details.coachlist.clear();
                        booking_details.seatlist.clear();
                        seatno.clear();
                        for (tickpos = 0; tickpos < booking_details.getNoOfPersons(); tickpos++) {
                            coach.add(currentcoachstr);
                            booking_details.coachlist.add(currentcoachstr);
                            while (Integer.parseInt(seat.getFirstChild().getTextContent().trim()) < seatstart) {
                                seat = (Element) seat.getNextSibling();
                            }
                            seatstart++;
                            System.out.println(seat.getFirstChild().getTextContent().trim());
                            seatno.add(seat.getFirstChild().getTextContent().trim());
                            booking_details.seatlist.add(seat.getFirstChild().getTextContent().trim());
                            nl3 = seat.getElementsByTagName(sourcenws);
                            stn = (Element) nl3.item(0);
                            while (!stn.getNodeName().equals(destnnws)) {
                                stn.setTextContent("0");
                                stn = (Element) stn.getNextSibling();
                            }
                        }
                        number_of_tickets_rem = 0;
                        navailcoach -= booking_details.getNoOfPersons();
                        nspavailcoach -= booking_details.getNoOfPersons();
                        if (!firsttime) conn.rollback(sp1);
                        String availupdstr = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL  modify do ";
                        availupdstr += " replace value of $new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + sourcenws + " with \"" + navailcoach + "\"";
                        availupdstr += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                        stavailupd = conn.createStatement();
                        int updvar = stavailupd.executeUpdate(availupdstr);
                        if (updvar > 0) System.out.println("upda avail success");
                        sw = new StringWriter();
                        serializer = new XMLSerializer(sw, formatter);
                        serializer.serialize(docseat);
                        String seatupdstr = "update hp_administrator.book_tickets set SEAT = xmlquery( 'transform copy $new := $SEAT ";
                        seatupdstr += " modify do replace $new/status/class[@type=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"] with " + sw.toString();
                        seatupdstr += " return $new') where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "'  ";
                        System.out.println(seatupdstr);
                        stseatupd = conn.createStatement();
                        updvar = stseatupd.executeUpdate(seatupdstr);
                        if (updvar > 0) System.out.println("upda seat success");
                        String sp = "";
                        if (useragent) sp = "agent"; else sp = "user";
                        availupdstr = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL  modify do ";
                        availupdstr += " replace value of $new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + sourcenws + "/@" + sp + " with \"" + nspavailcoach + "\"";
                        availupdstr += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                        System.out.println(availupdstr);
                        stavailupd = conn.createStatement();
                        updvar = stavailupd.executeUpdate(availupdstr);
                        if (updvar > 0) System.out.println("upda" + sp + " success");
                        break;
                    }
                    while (navailcoach > 0 && nspavailcoach > 0 && number_of_tickets_rem > 0) {
                        if (firsttime) {
                            sp1 = conn.setSavepoint();
                            firsttime = false;
                        }
                        enterloop = true;
                        coach.add(currentcoachstr);
                        booking_details.coachlist.add(currentcoachstr);
                        tickpos++;
                        number_of_tickets_rem--;
                        navailcoach--;
                        nspavailcoach--;
                        while (Integer.parseInt(seat.getFirstChild().getTextContent().trim()) < seatstart) {
                            seat = (Element) seat.getNextSibling();
                        }
                        seatstart++;
                        System.out.println(seat.getFirstChild().getTextContent().trim());
                        seatno.add(seat.getFirstChild().getTextContent().trim());
                        booking_details.seatlist.add(seat.getFirstChild().getTextContent().trim());
                        nl3 = seat.getElementsByTagName(sourcenws);
                        stn = (Element) nl3.item(0);
                        while (!stn.getNodeName().equals(destnnws)) {
                            stn.setTextContent("0");
                            stn = (Element) stn.getNextSibling();
                        }
                        String availupdstr = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL  modify do ";
                        availupdstr += " replace value of $new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + sourcenws + " with \"" + navailcoach + "\"";
                        availupdstr += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                        stavailupd = conn.createStatement();
                        stavailupd.executeUpdate(availupdstr);
                        String sp = "";
                        if (useragent) sp = "agent"; else sp = "user";
                        availupdstr = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL  modify do ";
                        availupdstr += " replace value of $new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + sp + "\"]/" + sourcenws + "/@" + sp + " with \"" + nspavailcoach + "\"";
                        availupdstr += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                        stavailupd = conn.createStatement();
                        stavailupd.executeUpdate(availupdstr);
                    }
                    if (enterloop) {
                        sw = new StringWriter();
                        serializer = new XMLSerializer(sw, formatter);
                        serializer.serialize(docseat);
                        String seatupdstr = "update hp_administrator.book_tickets set SEAT = xmlquery( 'transform copy $new := $SEAT ";
                        seatupdstr += " modify do replace $new/status/class[@type=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"] with " + sw.toString();
                        seatupdstr += " return $new') where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "'  ";
                        stseatupd = conn.createStatement();
                        stseatupd.executeUpdate(seatupdstr);
                    }
                } else if (routesrcstr.equals(sourcenws) && !routedeststr.equals(destnnws)) {
                    System.out.println("case 2");
                    String excesssrcstr = routesrc.getTextContent();
                    System.out.println(excesssrcstr);
                    Integer excesssrc = Integer.parseInt(excesssrcstr.trim());
                    NodeList nl2 = currentcoach.getElementsByTagName(destnnws);
                    Element e2 = (Element) nl2.item(0);
                    String desttillstr = e2.getAttribute(destnnws + "TILL");
                    System.out.println(desttillstr);
                    Integer desttillcnt = Integer.parseInt(desttillstr.trim());
                    srcmaxstr = routesrc.getAttribute(sourcenws);
                    System.out.println(srcmaxstr);
                    srcmax = Integer.parseInt(srcmaxstr.trim());
                    String spexcesssrcstr = "", spdesttillstr = "";
                    if (useragent) {
                        spexcesssrcstr = routesrc.getAttribute("agent");
                        spdesttillstr = e2.getAttribute("agenttill");
                    } else {
                        spexcesssrcstr = routesrc.getAttribute("user");
                        spdesttillstr = e2.getAttribute("usertill");
                    }
                    System.out.println(spdesttillstr);
                    System.out.println(spexcesssrcstr);
                    Integer spdesttillcnt = Integer.parseInt(spdesttillstr.trim());
                    Integer spexcesssrc = Integer.parseInt(spexcesssrcstr.trim());
                    Element seat, stn;
                    if (booking_details.getNoOfPersons() <= desttillcnt && booking_details.getNoOfPersons() <= spdesttillcnt) {
                        seatstart = coachmax - desttillcnt + 1;
                        seatcnt = desttillcnt;
                        NodeList nl3 = rootseat.getElementsByTagName("seat");
                        seat = (Element) nl3.item(0);
                        coach.clear();
                        seatno.clear();
                        booking_details.coachlist.clear();
                        booking_details.seatlist.clear();
                        for (tickpos = 0; tickpos < booking_details.getNoOfPersons(); tickpos++) {
                            coach.add(currentcoachstr);
                            booking_details.coachlist.add(currentcoachstr);
                            while (Integer.parseInt(seat.getFirstChild().getTextContent().trim()) < seatstart) {
                                seat = (Element) seat.getNextSibling();
                            }
                            seatstart++;
                            System.out.println(seat.getFirstChild().getTextContent().trim());
                            seatno.add(seat.getFirstChild().getTextContent().trim());
                            booking_details.seatlist.add(seat.getFirstChild().getTextContent().trim());
                            nl3 = seat.getElementsByTagName(sourcenws);
                            stn = (Element) nl3.item(0);
                            while (!stn.getNodeName().equals(destnnws)) {
                                stn.setTextContent("0");
                                stn = (Element) stn.getNextSibling();
                            }
                        }
                        number_of_tickets_rem = 0;
                        desttillcnt -= booking_details.getNoOfPersons();
                        spdesttillcnt -= booking_details.getNoOfPersons();
                        if (!firsttime) conn.rollback(sp1);
                        String availupd = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL modify do replace value of ";
                        availupd += "$new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + destnnws + "/@" + destnnws + "TILL" + " with \"" + desttillcnt + "\" ";
                        availupd += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                        System.out.println(availupd);
                        stavailupd = conn.createStatement();
                        int upst = stavailupd.executeUpdate(availupd);
                        if (upst > 0) System.out.println("update avail success");
                        sw = new StringWriter();
                        serializer = new XMLSerializer(sw, formatter);
                        serializer.serialize(docseat);
                        String seatupdstr = "update hp_administrator.book_tickets set SEAT = xmlquery( 'transform copy $new := $SEAT ";
                        seatupdstr += " modify do replace $new/status/class[@type=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"] with " + sw.toString();
                        seatupdstr += " return $new') where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "'  ";
                        System.out.println(seatupdstr);
                        stseatupd = conn.createStatement();
                        upst = stseatupd.executeUpdate(seatupdstr);
                        if (upst > 0) System.out.println("update seat success");
                        String sp = "";
                        if (useragent) sp = "agent"; else sp = "user";
                        availupd = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL modify do replace value of ";
                        availupd += "$new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + destnnws + "/@" + sp + "till" + " with \"" + spdesttillcnt + "\" ";
                        availupd += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                        System.out.println(availupd);
                        stavailupd = conn.createStatement();
                        upst = stavailupd.executeUpdate(availupd);
                        if (upst > 0) System.out.println("update " + sp + " success");
                        break;
                    } else if (booking_details.getNoOfPersons() > spdesttillcnt && spdesttillcnt > 0 && booking_details.getNoOfPersons() <= spdesttillcnt + spexcesssrc) {
                        int diff = 0;
                        if (booking_details.getNoOfPersons() > spdesttillcnt) diff = booking_details.getNoOfPersons() - spdesttillcnt;
                        tickpos = 0;
                        boolean initflg = true;
                        seatstart = coachmax - desttillcnt + 1;
                        seatcnt = desttillcnt;
                        NodeList nl3 = rootseat.getElementsByTagName("seat");
                        seat = (Element) nl3.item(0);
                        coach.clear();
                        seatno.clear();
                        booking_details.coachlist.clear();
                        booking_details.seatlist.clear();
                        for (tickpos = 0; tickpos < booking_details.getNoOfPersons(); tickpos++) {
                            coach.add(currentcoachstr);
                            booking_details.coachlist.add(currentcoachstr);
                            while (Integer.parseInt(seat.getFirstChild().getTextContent().trim()) < seatstart) {
                                seat = (Element) seat.getNextSibling();
                            }
                            seatstart++;
                            System.out.println(seat.getFirstChild().getTextContent().trim());
                            seatno.add(seat.getFirstChild().getTextContent().trim());
                            booking_details.seatlist.add(seat.getFirstChild().getTextContent().trim());
                            nl3 = seat.getElementsByTagName(sourcenws);
                            stn = (Element) nl3.item(0);
                            while (!stn.getNodeName().equals(destnnws)) {
                                stn.setTextContent("0");
                                stn = (Element) stn.getNextSibling();
                            }
                            if (spdesttillcnt != 0) {
                                desttillcnt--;
                                spdesttillcnt--;
                            }
                            System.out.println("desttillcnt=" + desttillcnt + " spdes = " + desttillcnt + "initflg =" + initflg);
                            if (spdesttillcnt == 0 && initflg == true) {
                                alloccnt = srcmax - excesssrc;
                                seatstart = 1 + alloccnt;
                                initflg = false;
                                seat = (Element) seat.getParentNode().getFirstChild();
                            }
                        }
                        excesssrc -= diff;
                        spexcesssrc -= diff;
                        number_of_tickets_rem = 0;
                        if (!firsttime) conn.rollback(sp1);
                        String availupd = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL modify do replace value of ";
                        availupd += "$new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + destnnws + "/@" + destnnws + "TILL" + " with \"" + desttillcnt + "\" ";
                        availupd += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                        System.out.println(availupd);
                        stavailupd = conn.createStatement();
                        int upst = stavailupd.executeUpdate(availupd);
                        if (upst > 0) System.out.println("update avail success");
                        availupd = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL  modify do ";
                        availupd += " replace value of $new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + sourcenws + " with \"" + excesssrc + "\"";
                        availupd += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                        System.out.println(availupd);
                        stavailupd = conn.createStatement();
                        upst = stavailupd.executeUpdate(availupd);
                        if (upst > 0) System.out.println("update avail success");
                        sw = new StringWriter();
                        serializer = new XMLSerializer(sw, formatter);
                        serializer.serialize(docseat);
                        String seatupdstr = "update hp_administrator.book_tickets set SEAT = xmlquery( 'transform copy $new := $SEAT ";
                        seatupdstr += " modify do replace $new/status/class[@type=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"] with " + sw.toString();
                        seatupdstr += " return $new') where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "'  ";
                        System.out.println(seatupdstr);
                        stseatupd = conn.createStatement();
                        upst = stseatupd.executeUpdate(seatupdstr);
                        if (upst > 0) System.out.println("update seat success");
                        String sp = "";
                        if (useragent) sp = "agent"; else sp = "user";
                        availupd = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL modify do replace value of ";
                        availupd += "$new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + destnnws + "/@" + sp + "till" + " with \"" + spdesttillcnt + "\" ";
                        availupd += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                        System.out.println(availupd);
                        stavailupd = conn.createStatement();
                        upst = stavailupd.executeUpdate(availupd);
                        if (upst > 0) System.out.println("update " + sp + " success");
                        availupd = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL  modify do ";
                        availupd += " replace value of $new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + sourcenws + "/@" + sp + " with \"" + spexcesssrc + "\"";
                        availupd += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                        System.out.println(availupd);
                        stavailupd = conn.createStatement();
                        upst = stavailupd.executeUpdate(availupd);
                        if (upst > 0) System.out.println("update " + sp + " success");
                        break;
                    } else if (booking_details.getNoOfPersons() > spdesttillcnt && spdesttillcnt == 0 && booking_details.getNoOfPersons() <= spexcesssrc) {
                        alloccnt = srcmax - excesssrc;
                        seatstart = 1 + alloccnt;
                        tickpos = 0;
                        boolean initflg = true;
                        NodeList nl3 = rootseat.getElementsByTagName("seat");
                        seat = (Element) nl3.item(0);
                        coach.clear();
                        seatno.clear();
                        booking_details.coachlist.clear();
                        booking_details.seatlist.clear();
                        for (tickpos = 0; tickpos < booking_details.getNoOfPersons(); tickpos++) {
                            coach.add(currentcoachstr);
                            booking_details.coachlist.add(currentcoachstr);
                            while (Integer.parseInt(seat.getFirstChild().getTextContent().trim()) < seatstart) {
                                seat = (Element) seat.getNextSibling();
                            }
                            seatstart++;
                            System.out.println(seat.getFirstChild().getTextContent().trim());
                            seatno.add(seat.getFirstChild().getTextContent().trim());
                            booking_details.seatlist.add(seat.getFirstChild().getTextContent().trim());
                            nl3 = seat.getElementsByTagName(sourcenws);
                            stn = (Element) nl3.item(0);
                            while (!stn.getNodeName().equals(destnnws)) {
                                stn.setTextContent("0");
                                stn = (Element) stn.getNextSibling();
                            }
                            System.out.println("desttillcnt=" + desttillcnt + " spdes = " + desttillcnt + "initflg =" + initflg);
                        }
                        excesssrc -= booking_details.getNoOfPersons();
                        spexcesssrc -= booking_details.getNoOfPersons();
                        ;
                        number_of_tickets_rem = 0;
                        if (!firsttime) conn.rollback(sp1);
                        String availupd = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL  modify do ";
                        availupd += " replace value of $new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + sourcenws + " with \"" + excesssrc + "\"";
                        availupd += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                        System.out.println(availupd);
                        stavailupd = conn.createStatement();
                        int upst = stavailupd.executeUpdate(availupd);
                        if (upst > 0) System.out.println("update avail success");
                        sw = new StringWriter();
                        serializer = new XMLSerializer(sw, formatter);
                        serializer.serialize(docseat);
                        String seatupdstr = "update hp_administrator.book_tickets set SEAT = xmlquery( 'transform copy $new := $SEAT ";
                        seatupdstr += " modify do replace $new/status/class[@type=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"] with " + sw.toString();
                        seatupdstr += " return $new') where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "'  ";
                        System.out.println(seatupdstr);
                        stseatupd = conn.createStatement();
                        upst = stseatupd.executeUpdate(seatupdstr);
                        if (upst > 0) System.out.println("update seat success");
                        String sp = "";
                        if (useragent) sp = "agent"; else sp = "user";
                        availupd = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL  modify do ";
                        availupd += " replace value of $new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + sourcenws + "/@" + sp + " with \"" + spexcesssrc + "\"";
                        availupd += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                        System.out.println(availupd);
                        stavailupd = conn.createStatement();
                        upst = stavailupd.executeUpdate(availupd);
                        if (upst > 0) System.out.println("update " + sp + " success");
                        break;
                    }
                    NodeList nl3 = rootseat.getElementsByTagName("seat");
                    seat = (Element) nl3.item(0);
                    seatstart = 1;
                    String sp = "";
                    if (useragent) sp = "agent"; else sp = "user";
                    while (spexcesssrc + spdesttillcnt > 0 && number_of_tickets_rem > 0) {
                        if (firsttime) {
                            sp1 = conn.setSavepoint();
                            firsttime = false;
                        }
                        enterloop = true;
                        if (spdesttillcnt > 0) {
                            seatstart = coachmax - desttillcnt + 1;
                            desttillcnt--;
                            spdesttillcnt--;
                            String availupd = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL modify do replace value of ";
                            availupd += "$new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + destnnws + "/@" + destnnws + "TILL" + " with \"" + desttillcnt + "\" ";
                            availupd += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                            stavailupd = conn.createStatement();
                            stavailupd.executeUpdate(availupd);
                            availupd = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL modify do replace value of ";
                            availupd += "$new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + destnnws + "/@" + sp + "till" + " with \"" + spdesttillcnt + "\" ";
                            availupd += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                            stavailupd = conn.createStatement();
                            stavailupd.executeUpdate(availupd);
                        } else if (spdesttillcnt == 0) {
                            alloccnt = srcmax - excesssrc;
                            seatstart = 1 + alloccnt;
                            excesssrc--;
                            spexcesssrc--;
                            String availupd = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL  modify do ";
                            availupd += " replace value of $new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + sourcenws + " with \"" + excesssrc + "\"";
                            availupd += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                            stavailupd = conn.createStatement();
                            stavailupd.executeUpdate(availupd);
                            availupd = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL  modify do ";
                            availupd += " replace value of $new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + sourcenws + "/@" + sp + " with \"" + spexcesssrc + "\"";
                            availupd += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                            stavailupd = conn.createStatement();
                            stavailupd.executeUpdate(availupd);
                        }
                        while (Integer.parseInt(seat.getFirstChild().getTextContent().trim()) < seatstart) {
                            seat = (Element) seat.getNextSibling();
                        }
                        nl3 = seat.getElementsByTagName(sourcenws);
                        stn = (Element) nl3.item(0);
                        while (!stn.getNodeName().equals(destnnws)) {
                            stn.setTextContent("0");
                            stn = (Element) stn.getNextSibling();
                        }
                        coach.add(currentcoachstr);
                        booking_details.coachlist.add(currentcoachstr);
                        tickpos++;
                        number_of_tickets_rem--;
                    }
                    if (enterloop) {
                        sw = new StringWriter();
                        serializer = new XMLSerializer(sw, formatter);
                        serializer.serialize(docseat);
                        String seatupdstr = "update hp_administrator.book_tickets set SEAT = xmlquery( 'transform copy $new := $SEAT ";
                        seatupdstr += " modify do replace $new/status/class[@type=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"] with " + sw.toString();
                        seatupdstr += " return $new') where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "'  ";
                        stseatupd = conn.createStatement();
                        stseatupd.executeUpdate(seatupdstr);
                    }
                } else if (!routesrcstr.equals(sourcenws) && routedeststr.equals(destnnws)) {
                    System.out.println("case 3");
                    NodeList nl2 = currentcoach.getElementsByTagName(sourcenws);
                    Element e2 = (Element) nl2.item(0);
                    navailstr = e2.getTextContent();
                    System.out.println(navailstr);
                    navailcoach = Integer.parseInt(navailstr.trim());
                    if (useragent) nspavailstr = e2.getAttribute("agent"); else nspavailstr = e2.getAttribute("user");
                    System.out.println(nspavailstr);
                    nspavailcoach = Integer.parseInt(nspavailstr.trim());
                    srctillstr = e2.getAttribute(sourcenws + "TILL");
                    System.out.println(srctillstr);
                    srctill = Integer.parseInt(srctillstr.trim());
                    srcmaxstr = e2.getAttribute(sourcenws);
                    System.out.println(srcmaxstr);
                    srcmax = Integer.parseInt(srcmaxstr.trim());
                    seatstart = coachmax - srctill + 1;
                    seatcnt = srcmax;
                    alloccnt = srcmax - navailcoach;
                    seatstart += alloccnt;
                    seatcnt -= alloccnt;
                    Element seat, stn;
                    NodeList nl3 = rootseat.getElementsByTagName("seat");
                    seat = (Element) nl3.item(0);
                    if (booking_details.getNoOfPersons() <= navailcoach && booking_details.getNoOfPersons() <= nspavailcoach) {
                        coach.clear();
                        seatno.clear();
                        booking_details.coachlist.clear();
                        booking_details.seatlist.clear();
                        for (tickpos = 0; tickpos < booking_details.getNoOfPersons(); tickpos++) {
                            coach.add(currentcoachstr);
                            booking_details.coachlist.add(currentcoachstr);
                            while (Integer.parseInt(seat.getFirstChild().getTextContent().trim()) < seatstart) {
                                seat = (Element) seat.getNextSibling();
                            }
                            seatstart++;
                            System.out.println(seat.getFirstChild().getTextContent().trim());
                            seatno.add(seat.getFirstChild().getTextContent().trim());
                            booking_details.seatlist.add(seat.getFirstChild().getTextContent().trim());
                            nl3 = seat.getElementsByTagName(sourcenws);
                            stn = (Element) nl3.item(0);
                            while (!stn.getNodeName().equals(destnnws)) {
                                stn.setTextContent("0");
                                stn = (Element) stn.getNextSibling();
                            }
                        }
                        number_of_tickets_rem = 0;
                        navailcoach -= booking_details.getNoOfPersons();
                        nspavailcoach -= booking_details.getNoOfPersons();
                        String availupdstr = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL  modify do ";
                        availupdstr += " replace value of $new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + sourcenws + " with \"" + navailcoach + "\"";
                        availupdstr += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                        stavailupd = conn.createStatement();
                        stavailupd.executeUpdate(availupdstr);
                        sw = new StringWriter();
                        serializer = new XMLSerializer(sw, formatter);
                        serializer.serialize(docseat);
                        String seatupdstr = "update hp_administrator.book_tickets set SEAT = xmlquery( 'transform copy $new := $SEAT ";
                        seatupdstr += " modify do replace $new/status/class[@type=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"] with " + sw.toString();
                        seatupdstr += " return $new') where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "'  ";
                        stseatupd = conn.createStatement();
                        stseatupd.executeUpdate(seatupdstr);
                        String sp = "";
                        if (useragent) sp = "agent"; else sp = "user";
                        availupdstr = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL  modify do ";
                        availupdstr += " replace value of $new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + sourcenws + "/@" + sp + " with \"" + nspavailcoach + "\"";
                        availupdstr += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                        stavailupd = conn.createStatement();
                        stavailupd.executeUpdate(availupdstr);
                        break;
                    }
                    while (navailcoach > 0 && nspavailcoach > 0 && number_of_tickets_rem > 0) {
                        if (firsttime) {
                            sp1 = conn.setSavepoint();
                            firsttime = false;
                        }
                        enterloop = true;
                        coach.add(currentcoachstr);
                        booking_details.coachlist.add(currentcoachstr);
                        tickpos++;
                        number_of_tickets_rem--;
                        navailcoach--;
                        nspavailcoach--;
                        while (Integer.parseInt(seat.getFirstChild().getTextContent().trim()) < seatstart) {
                            seat = (Element) seat.getNextSibling();
                        }
                        seatstart++;
                        System.out.println(seat.getFirstChild().getTextContent().trim());
                        seatno.add(seat.getFirstChild().getTextContent().trim());
                        booking_details.seatlist.add(seat.getFirstChild().getTextContent().trim());
                        nl3 = seat.getElementsByTagName(sourcenws);
                        stn = (Element) nl3.item(0);
                        while (!stn.getNodeName().equals(destnnws)) {
                            stn.setTextContent("0");
                            stn = (Element) stn.getNextSibling();
                        }
                        String availupdstr = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL  modify do ";
                        availupdstr += " replace value of $new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + sourcenws + " with \"" + navailcoach + "\"";
                        availupdstr += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                        System.out.println(availupdstr);
                        stavailupd = conn.createStatement();
                        stavailupd.executeUpdate(availupdstr);
                        String sp = "";
                        if (useragent) sp = "agent"; else sp = "user";
                        availupdstr = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL  modify do ";
                        availupdstr += " replace value of $new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + sourcenws + "/@" + sp + " with \"" + nspavailcoach + "\"";
                        availupdstr += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                        System.out.println(availupdstr);
                        stavailupd = conn.createStatement();
                        stavailupd.executeUpdate(availupdstr);
                    }
                    if (enterloop) {
                        sw = new StringWriter();
                        serializer = new XMLSerializer(sw, formatter);
                        serializer.serialize(docseat);
                        String seatupdstr = "update hp_administrator.book_tickets set SEAT = xmlquery( 'transform copy $new := $SEAT ";
                        seatupdstr += " modify do replace $new/status/class[@type=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"] with " + sw.toString();
                        seatupdstr += " return $new') where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "'  ";
                        System.out.println("!@#------->" + seatupdstr);
                        stseatupd = conn.createStatement();
                    }
                } else if (!routesrcstr.equals(sourcenws) && !routedeststr.equals(destnnws)) {
                    System.out.println("case 4");
                    srcmaxstr = routesrc.getAttribute(sourcenws);
                    System.out.println(srcmaxstr);
                    srcmax = Integer.parseInt(srcmaxstr.trim());
                    Element seat, stn;
                    NodeList nl2 = currentcoach.getElementsByTagName(sourcenws);
                    Element e2 = (Element) nl2.item(0);
                    navailstr = e2.getTextContent();
                    Integer excesssrc = Integer.parseInt(navailstr.trim());
                    nl2 = currentcoach.getElementsByTagName(destnnws);
                    e2 = (Element) nl2.item(0);
                    navailstr = e2.getAttribute(destnnws + "TILL");
                    Integer desttillcnt = Integer.parseInt(navailstr.trim());
                    String spexcesssrcstr = "", spdesttillstr = "";
                    if (useragent) {
                        spexcesssrcstr = routesrc.getAttribute("agent");
                        spdesttillstr = e2.getAttribute("agenttill");
                    } else {
                        spexcesssrcstr = routesrc.getAttribute("user");
                        spdesttillstr = e2.getAttribute("usertill");
                    }
                    Integer spdesttillcnt = Integer.parseInt(spdesttillstr.trim());
                    Integer spexcesssrc = Integer.parseInt(spexcesssrcstr.trim());
                    NodeList nl3 = rootseat.getElementsByTagName("seat");
                    seat = (Element) nl3.item(0);
                    boolean initflg = true;
                    if (booking_details.getNoOfPersons() <= spdesttillcnt) {
                        seatstart = coachmax - desttillcnt + 1;
                        seatcnt = desttillcnt;
                        coach.clear();
                        seatno.clear();
                        booking_details.coachlist.clear();
                        booking_details.seatlist.clear();
                        for (tickpos = 0; tickpos < booking_details.getNoOfPersons(); tickpos++) {
                            coach.add(currentcoachstr);
                            booking_details.coachlist.add(currentcoachstr);
                            while (Integer.parseInt(seat.getFirstChild().getTextContent().trim()) < seatstart) {
                                seat = (Element) seat.getNextSibling();
                            }
                            seatstart++;
                            System.out.println(seat.getFirstChild().getTextContent().trim());
                            seatno.add(seat.getFirstChild().getTextContent().trim());
                            booking_details.seatlist.add(seat.getFirstChild().getTextContent().trim());
                            nl3 = seat.getElementsByTagName(sourcenws);
                            stn = (Element) nl3.item(0);
                            while (!stn.getNodeName().equals(destnnws)) {
                                stn.setTextContent("0");
                                stn = (Element) stn.getNextSibling();
                            }
                        }
                        number_of_tickets_rem = 0;
                        desttillcnt -= booking_details.getNoOfPersons();
                        spdesttillcnt -= booking_details.getNoOfPersons();
                        if (!firsttime) conn.rollback(sp1);
                        String availupd = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL modify do replace value of ";
                        availupd += "$new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + destnnws + "/@" + destnnws + "TILL" + " with \"" + desttillcnt + "\" ";
                        availupd += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                        stavailupd = conn.createStatement();
                        stavailupd.executeUpdate(availupd);
                        sw = new StringWriter();
                        serializer = new XMLSerializer(sw, formatter);
                        serializer.serialize(docseat);
                        String seatupdstr = "update hp_administrator.book_tickets set SEAT = xmlquery( 'transform copy $new := $SEAT ";
                        seatupdstr += " modify do replace $new/status/class[@type=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"] with " + sw.toString();
                        seatupdstr += " return $new') where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "'  ";
                        stseatupd = conn.createStatement();
                        stseatupd.executeUpdate(seatupdstr);
                        String sp = "";
                        if (useragent) sp = "agent"; else sp = "user";
                        availupd = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL modify do replace value of ";
                        availupd += "$new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + destnnws + "/@" + sp + "till" + " with \"" + spdesttillcnt + "\" ";
                        availupd += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                        stavailupd = conn.createStatement();
                        stavailupd.executeUpdate(availupd);
                        break;
                    } else if (booking_details.getNoOfPersons() > spdesttillcnt && spdesttillcnt > 0 && booking_details.getNoOfPersons() <= spdesttillcnt + spexcesssrc) {
                        int diff = 0;
                        if (booking_details.getNoOfPersons() > spdesttillcnt) diff = booking_details.getNoOfPersons() - spdesttillcnt;
                        seatstart = coachmax - desttillcnt + 1;
                        seatcnt = desttillcnt;
                        coach.clear();
                        seatno.clear();
                        booking_details.coachlist.clear();
                        booking_details.seatlist.clear();
                        for (tickpos = 0; tickpos < booking_details.getNoOfPersons(); tickpos++) {
                            coach.add(currentcoachstr);
                            booking_details.coachlist.add(currentcoachstr);
                            while (Integer.parseInt(seat.getFirstChild().getTextContent().trim()) < seatstart) {
                                seat = (Element) seat.getNextSibling();
                            }
                            seatstart++;
                            System.out.println(seat.getFirstChild().getTextContent().trim());
                            seatno.add(seat.getFirstChild().getTextContent().trim());
                            booking_details.seatlist.add(seat.getFirstChild().getTextContent().trim());
                            nl3 = seat.getElementsByTagName(sourcenws);
                            stn = (Element) nl3.item(0);
                            while (!stn.getNodeName().equals(destnnws)) {
                                stn.setTextContent("0");
                                stn = (Element) stn.getNextSibling();
                            }
                            if (spdesttillcnt != 0) {
                                desttillcnt--;
                                spdesttillcnt--;
                            }
                            if (spdesttillcnt == 0 && initflg == true) {
                                alloccnt = srcmax - excesssrc;
                                seatstart = 1 + alloccnt;
                                initflg = false;
                            }
                        }
                        excesssrc -= diff;
                        spexcesssrc -= diff;
                        number_of_tickets_rem = 0;
                        if (!firsttime) conn.rollback(sp1);
                        String availupd = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL modify do replace value of ";
                        availupd += "$new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + destnnws + "/@" + destnnws + "TILL" + " with \"" + desttillcnt + "\" ";
                        availupd += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                        stavailupd = conn.createStatement();
                        stavailupd.executeUpdate(availupd);
                        availupd = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL  modify do ";
                        availupd += " replace value of $new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + sourcenws + " with \"" + excesssrc + "\"";
                        availupd += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                        stavailupd = conn.createStatement();
                        stavailupd.executeUpdate(availupd);
                        sw = new StringWriter();
                        serializer = new XMLSerializer(sw, formatter);
                        serializer.serialize(docseat);
                        String seatupdstr = "update hp_administrator.book_tickets set SEAT = xmlquery( 'transform copy $new := $SEAT ";
                        seatupdstr += " modify do replace $new/status/class[@type=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"] with " + sw.toString();
                        seatupdstr += " return $new') where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "'  ";
                        stseatupd = conn.createStatement();
                        stseatupd.executeUpdate(seatupdstr);
                        String sp = "";
                        if (useragent) sp = "agent"; else sp = "user";
                        availupd = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL modify do replace value of ";
                        availupd += "$new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + destnnws + "/@" + sp + "till" + " with \"" + spdesttillcnt + "\" ";
                        availupd += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                        stavailupd = conn.createStatement();
                        stavailupd.executeUpdate(availupd);
                        availupd = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL  modify do ";
                        availupd += " replace value of $new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + sourcenws + "/@" + sp + " with \"" + spexcesssrc + "\"";
                        availupd += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                        stavailupd = conn.createStatement();
                        stavailupd.executeUpdate(availupd);
                        break;
                    } else if (spdesttillcnt == 0 && booking_details.getNoOfPersons() <= spexcesssrc) {
                        alloccnt = srcmax - excesssrc;
                        seatstart = 1 + alloccnt;
                        coach.clear();
                        seatno.clear();
                        booking_details.coachlist.clear();
                        booking_details.seatlist.clear();
                        for (tickpos = 0; tickpos < booking_details.getNoOfPersons(); tickpos++) {
                            coach.add(currentcoachstr);
                            booking_details.coachlist.add(currentcoachstr);
                            while (Integer.parseInt(seat.getFirstChild().getTextContent().trim()) < seatstart) {
                                seat = (Element) seat.getNextSibling();
                            }
                            seatstart++;
                            System.out.println(seat.getFirstChild().getTextContent().trim());
                            seatno.add(seat.getFirstChild().getTextContent().trim());
                            booking_details.seatlist.add(seat.getFirstChild().getTextContent().trim());
                            nl3 = seat.getElementsByTagName(sourcenws);
                            stn = (Element) nl3.item(0);
                            while (!stn.getNodeName().equals(destnnws)) {
                                stn.setTextContent("0");
                                stn = (Element) stn.getNextSibling();
                            }
                        }
                        excesssrc -= booking_details.getNoOfPersons();
                        spexcesssrc -= booking_details.getNoOfPersons();
                        number_of_tickets_rem = 0;
                        if (!firsttime) conn.rollback(sp1);
                        String availupd = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL  modify do ";
                        availupd += " replace value of $new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + sourcenws + " with \"" + excesssrc + "\"";
                        availupd += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                        stavailupd = conn.createStatement();
                        stavailupd.executeUpdate(availupd);
                        sw = new StringWriter();
                        serializer = new XMLSerializer(sw, formatter);
                        serializer.serialize(docseat);
                        String seatupdstr = "update hp_administrator.book_tickets set SEAT = xmlquery( 'transform copy $new := $SEAT ";
                        seatupdstr += " modify do replace $new/status/class[@type=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"] with " + sw.toString();
                        seatupdstr += " return $new') where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "'  ";
                        stseatupd = conn.createStatement();
                        stseatupd.executeUpdate(seatupdstr);
                        String sp = "";
                        if (useragent) sp = "agent"; else sp = "user";
                        availupd = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL  modify do ";
                        availupd += " replace value of $new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + sourcenws + "/@" + sp + " with \"" + spexcesssrc + "\"";
                        availupd += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                        stavailupd = conn.createStatement();
                        stavailupd.executeUpdate(availupd);
                        break;
                    }
                    seatstart = 1;
                    String sp = "";
                    if (useragent) sp = "agent"; else sp = "user";
                    while (spexcesssrc + spdesttillcnt > 0 && number_of_tickets_rem > 0) {
                        if (firsttime) {
                            sp1 = conn.setSavepoint();
                            firsttime = false;
                        }
                        enterloop = true;
                        if (spdesttillcnt > 0) {
                            seatstart = coachmax - desttillcnt + 1;
                            desttillcnt--;
                            spdesttillcnt--;
                            String availupd = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL modify do replace value of ";
                            availupd += "$new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + destnnws + "/@" + destnnws + "TILL" + " with \"" + desttillcnt + "\" ";
                            availupd += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                            stavailupd = conn.createStatement();
                            stavailupd.executeUpdate(availupd);
                            availupd = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL modify do replace value of ";
                            availupd += "$new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + destnnws + "/@" + sp + "till" + " with \"" + spdesttillcnt + "\" ";
                            availupd += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                            stavailupd = conn.createStatement();
                            stavailupd.executeUpdate(availupd);
                        } else if (spdesttillcnt == 0) {
                            alloccnt = srcmax - excesssrc;
                            seatstart = 1 + alloccnt;
                            excesssrc--;
                            spexcesssrc--;
                            String availupd = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL  modify do ";
                            availupd += " replace value of $new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + sourcenws + "/@" + sp + " with \"" + excesssrc + "\"";
                            availupd += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                            stavailupd = conn.createStatement();
                            stavailupd.executeUpdate(availupd);
                            availupd = "update hp_administrator.availability set AVAIL = xmlquery( 'transform copy $new := $AVAIL  modify do ";
                            availupd += " replace value of $new/coach_status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"]/" + sourcenws + " with \"" + spexcesssrc + "\"";
                            availupd += " return  $new')  where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                            stavailupd = conn.createStatement();
                            stavailupd.executeUpdate(availupd);
                        }
                        while (Integer.parseInt(seat.getFirstChild().getTextContent().trim()) < seatstart) {
                            seat = (Element) seat.getNextSibling();
                        }
                        nl3 = seat.getElementsByTagName(sourcenws);
                        stn = (Element) nl3.item(0);
                        while (!stn.getNodeName().equals(destnnws)) {
                            stn.setTextContent("0");
                            stn = (Element) stn.getNextSibling();
                        }
                        coach.add(currentcoachstr);
                        booking_details.coachlist.add(currentcoachstr);
                        tickpos++;
                        number_of_tickets_rem--;
                    }
                    if (enterloop) {
                        sw = new StringWriter();
                        serializer = new XMLSerializer(sw, formatter);
                        serializer.serialize(docseat);
                        String seatupdstr = "update hp_administrator.book_tickets set SEAT = xmlquery( 'transform copy $new := $SEAT ";
                        seatupdstr += " modify do replace $new/status/class[@type=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoachstr + "\"] with " + sw.toString();
                        seatupdstr += " return $new') where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "'  ";
                        stseatupd = conn.createStatement();
                        stseatupd.executeUpdate(seatupdstr);
                    }
                }
            }
            availfin = true;
        } catch (SQLException e) {
            conn.rollback();
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            conn.rollback();
            e.printStackTrace();
        } catch (SAXException e) {
            conn.rollback();
            e.printStackTrace();
        } catch (IOException e) {
            conn.rollback();
            e.printStackTrace();
        }
    }


    private void Reserve() throws SQLException {
        Statement stbookings, stchartwl;
        String sp = "";
        if (useragent) sp = "agent"; else sp = "user";
        String userbooksql = "";
        String agentbooksql = "";
        String bookingid = String.valueOf(System.currentTimeMillis());
        String currentcoach;
        String currentseat;
        try {
            if (useragent) {
                agentbooksql = "update hp_administrator.agent_bookings set BOOKINGS = xmlquery('copy $new := $BOOKINGS modify do insert ";
                agentbooksql += " <detail booking_id=\"" + booking_details.getTicketno() + "\" status=\"open\" train_no=\"" + booking_details.getTrain_no() + "\" source=\"" + booking_details.getSource() + "\" dest=\"" + booking_details.getDestination() + "\" dep_date=\"" + booking_details.getDate() + "\" > ";
            } else if (!useragent) {
                userbooksql = "update hp_administrator.user_bookings set BOOKINGS = xmlquery('copy $new := $BOOKINGS modify do insert ";
                userbooksql += " <detail booking_id=\"" + booking_details.getTicketno() + "\" status=\"open\" train_no=\"" + booking_details.getTrain_no() + "\" source=\"" + booking_details.getSource() + "\" dest=\"" + booking_details.getDestination() + "\" dep_date=\"" + booking_details.getDate() + "\" > ";
            }
            for (int tickpos = 0; tickpos < booking_details.getNoOfPersons(); tickpos++) {
                currentcoach = coach.get(tickpos);
                currentseat = seatno.get(tickpos);
                if (!currentcoach.equals("WL")) {
                    String chartavailupdsql = "update hp_administrator.chart_wl_order set AVAILABLE_BOOKED = xmlquery('copy $new := $AVAILABLE_BOOKED   modify do insert ";
                    chartavailupdsql += "<seat number=\"" + currentseat + "\"><details user_id=\"" + booking_details.getUserId() + "\" usertype=\"" + sp + "\" ticket_no=\"" + booking_details.getTicketno() + "\" name=\"" + booking_details.getNameAt(tickpos) + "\" age=\"" + booking_details.getAgeAt(tickpos) + "\" sex=\"" + booking_details.getSexAt(tickpos) + "\" type=\"primary\"  /></seat>";
                    chartavailupdsql += " into $new/status/class[@name=\"" + booking_details.getTclass() + "\"]/coach[@number=\"" + currentcoach + "\"] ";
                    chartavailupdsql += " return  $new' ) where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                    System.out.println(chartavailupdsql);
                    stchartwl = conn.createStatement();
                    int updstat = stchartwl.executeUpdate(chartavailupdsql);
                    if (updstat > 0) System.out.println("chart_wl  availability  updated");
                } else if (currentcoach.equals("WL")) {
                    String chartwlupdsql = "update hp_administrator.chart_wl_order set WAITLISTING = xmlquery('copy $new := $WAITLISTING modify do insert ";
                    chartwlupdsql += "<details user_id=\"" + booking_details.getUserId() + "\" usertype=\"" + sp + "\" ticket_no=\"" + booking_details.getTicketno() + "\" name=\"" + booking_details.getNameAt(tickpos) + "\" age=\"" + booking_details.getAgeAt(tickpos) + "\" sex=\"" + booking_details.getSexAt(tickpos) + "\" type=\"primary\" /></seat>";
                    chartwlupdsql += " into $new/status/class[@name=\"" + booking_details.getTclass() + "\"] ";
                    chartwlupdsql += " return  $new' ) where train_no like '" + booking_details.getTrain_no() + "' and date = '" + booking_details.getDate() + "' ";
                    System.out.println(chartwlupdsql);
                    stchartwl = conn.createStatement();
                    int updstat = stchartwl.executeUpdate(chartwlupdsql);
                    if (updstat > 0) System.out.println("chart_wl  waitlisting  updated");
                }
                if (useragent) agentbooksql += "<person><coach>" + currentcoach + "</coach><seat>" + currentseat + "</seat></person>"; else userbooksql += "<person><coach>" + currentcoach + "</coach><seat>" + currentseat + "</seat></person>";
            }
            if (useragent) {
                agentbooksql += "</detail>   as first into $new/book return  $new' ) where agent_id like '" + booking_details.getUserId() + "'";
                System.out.println(agentbooksql);
                stbookings = conn.createStatement();
                int updstat = stbookings.executeUpdate(agentbooksql);
                if (updstat > 0) System.out.println("agent bookings updated");
            } else {
                userbooksql += "</detail>   as first into $new/book return  $new' ) where user_id like '" + booking_details.getUserId() + "'";
                System.out.println(userbooksql);
                stbookings = conn.createStatement();
                int updstat = stbookings.executeUpdate(userbooksql);
                if (updstat > 0) System.out.println("user bookings  updated");
            }
        } catch (SQLException e) {
            conn.rollback();
            e.printStackTrace();
        }
    }


    private Drawable fetchImage(String iconUrl, Context ctx) {
        URL url;
        HttpClient httpClient = new DefaultHttpClient();
        try {
            if (PreferenceManager.getDefaultSharedPreferences(ctx).getBoolean("use.urlimg.com", true)) {
                iconUrl = iconUrl.substring(iconUrl.indexOf("//") + 2);
                iconUrl = "http://urlimg.com/width/100/" + iconUrl;
            }
            Log.d(ImageCache.class.getName(), "Loading image from: " + iconUrl);
            HttpGet httpGet = new HttpGet(iconUrl);
            HttpResponse response = httpClient.execute(httpGet);
            InputStream content = response.getEntity().getContent();
            Drawable d = Drawable.createFromStream(content, "src");
            content.close();
            httpGet.abort();
            return d;
        } catch (IOException e) {
            Log.e(ImageCache.class.getName(), "IOException while fetching: " + iconUrl);
            return TELKA;
        } finally {
        }
    }


    private void removeCollection(long oid, Connection conn) throws XMLDBException {
        try {
            String sql = "DELETE FROM X_DOCUMENT WHERE X_DOCUMENT.XDB_COLLECTION_OID = ?";
            PreparedStatement pstmt = conn.prepareStatement(sql);
            pstmt.setLong(1, oid);
            pstmt.executeUpdate();
            pstmt.close();
            sql = "DELETE FROM XDB_COLLECTION WHERE XDB_COLLECTION.XDB_COLLECTION_OID = ?";
            pstmt = conn.prepareStatement(sql);
            pstmt.setLong(1, oid);
            pstmt.executeUpdate();
            pstmt.close();
            removeChildCollection(oid, conn);
        } catch (java.sql.SQLException se) {
            try {
                conn.rollback();
            } catch (java.sql.SQLException se2) {
                se2.printStackTrace();
            }
            se.printStackTrace();
        }
    }


    private static void checkForUpgrade() {
        try {
            Log.out("Checking for updates...");
            URL u = ClassLoader.getSystemResource(Settings.readme);
            if (u == null) {
                u = HImage.class.getResource("/" + Settings.readme);
            }
            DataInputStream i = new DataInputStream(u.openStream());
            String tmp = i.readLine();
            tmp = tmp.substring(tmp.lastIndexOf(">"));
            tmp = tmp.substring(tmp.indexOf(".") + 1);
            tmp = tmp.substring(0, tmp.indexOf("<"));
            int x = Integer.parseInt(tmp) + 1;
            String nextVersion = "jftp-1.";
            if (x < 10) {
                nextVersion = nextVersion + "0";
            }
            nextVersion = nextVersion + x + ".tar.gz";
            File dl = new File(nextVersion);
            if (!dl.exists() || (dl.length() <= 0)) {
                URL url = new URL("http://osdn.dl.sourceforge.net/sourceforge/j-ftp/" + nextVersion);
                BufferedOutputStream f = new BufferedOutputStream(new FileOutputStream(dl));
                BufferedInputStream in = new BufferedInputStream(url.openStream());
                byte[] buf = new byte[4096];
                int stat = 1;
                Log.out("\ndownloading update: " + dl.getAbsolutePath() + "\n\n");
                while (stat > 0) {
                    stat = in.read(buf);
                    if (stat == -1) {
                        break;
                    }
                    f.write(buf, 0, stat);
                    System.out.print(".");
                }
                f.flush();
                f.close();
                in.close();
            }
            Log.out("\n\n\na newer version was found!\nplease install the File " + dl.getAbsolutePath() + " or even better visit the homepage to download the latest version...\n" + "you can turn this feature off if you don't like it (view readme for details)\n\nStarting anyway...\n\n");
        } catch (Exception ex) {
        }
        Log.out("finished check...");
    }


    public void testConvert() throws IOException, ConverterException {
        InputStreamReader reader = new InputStreamReader(new FileInputStream("test" + File.separator + "input" + File.separator + "A0851ohneex.dat"), CharsetUtil.forName("x-PICA"));
        FileWriter writer = new FileWriter("test" + File.separator + "output" + File.separator + "ddbInterToMarcxmlTest.out");
        Converter c = context.getConverter("ddb-intern", "MARC21-xml", "x-PICA", "UTF-8");
        ConversionParameters params = new ConversionParameters();
        params.setSourceCharset("x-PICA");
        params.setTargetCharset("UTF-8");
        params.setAddCollectionHeader(true);
        params.setAddCollectionFooter(true);
        c.convert(reader, writer, params);
    }


    @SuppressWarnings("static-access")
    public FastCollection<String> load(Link link) {
        URL url = null;
        FastCollection<String> links = new FastList<String>();
        FTPClient ftp = null;
        try {
            String address = link.getURI();
            address = JGetFileUtils.removeTrailingString(address, "/");
            url = new URL(address);
            host = url.getHost();
            String folder = url.getPath();
            logger.info("Traversing: " + address);
            ftp = new FTPClient(host);
            if (!ftp.connected()) {
                ftp.connect();
            }
            ftp.login("anonymous", "me@mymail.com");
            logger.info("Connected to " + host + ".");
            logger.debug("changing dir to " + folder);
            ftp.chdir(folder);
            String[] files = ftp.dir();
            for (String file : files) {
                links.add(address + "/" + file);
            }
        } catch (Exception e) {
            logger.error(e.getMessage());
            logger.debug(e.getStackTrace());
        } finally {
            try {
                ftp.quit();
            } catch (Exception e) {
                logger.error("Failed to logout or disconnect from the ftp server: ftp://" + host);
            }
        }
        return links;
    }


    public static Properties parse() {
        try {
            String userHome = System.getProperty("user.home");
            File dsigFolder = new File(userHome, ".dsig");
            if (!dsigFolder.exists() && !dsigFolder.mkdir()) {
                throw new IOException("Could not create .dsig folder in user home directory");
            }
            File settingsFile = new File(dsigFolder, "settings.properties");
            if (!settingsFile.exists()) {
                InputStream is = UserHomeSettingsParser.class.getResourceAsStream("/defaultSettings.properties");
                if (is != null) {
                    IOUtils.copy(is, new FileOutputStream(settingsFile));
                }
            }
            if (settingsFile.exists()) {
                Properties p = new Properties();
                FileInputStream fis = new FileInputStream(settingsFile);
                p.load(fis);
                IOUtils.closeQuietly(fis);
                return p;
            }
        } catch (IOException e) {
            logger.warn("Error while initialize settings", e);
        }
        return null;
    }


    private static FacesBean.Type _createType() {
        try {
            ClassLoader cl = _getClassLoader();
            URL url = cl.getResource("META-INF/faces-bean-type.properties");
            if (url != null) {
                Properties properties = new Properties();
                InputStream is = url.openStream();
                try {
                    properties.load(is);
                    String className = (String) properties.get(UIXComponentBase.class.getName());
                    return (FacesBean.Type) cl.loadClass(className).newInstance();
                } finally {
                    is.close();
                }
            }
        } catch (Exception e) {
            _LOG.severe("CANNOT_LOAD_TYPE_PROPERTIES", e);
        }
        return new FacesBean.Type();
    }


    public static void copy(Object arg1, Object arg2) {
        Writer writer = null;
        Reader reader = null;
        InputStream inStream = null;
        OutputStream outStream = null;
        try {
            if (arg2 instanceof Writer) {
                writer = (Writer) arg2;
                if (arg1 instanceof Reader) {
                    reader = (Reader) arg1;
                    copy(reader, writer);
                } else if (arg1 instanceof String) {
                    reader = new FileReader(new File((String) arg1));
                    copy(reader, writer);
                } else if (arg1 instanceof File) {
                    reader = new FileReader((File) arg1);
                    copy(reader, writer);
                } else if (arg1 instanceof URL) {
                    copy(((URL) arg1).openStream(), writer);
                } else if (arg1 instanceof InputStream) {
                    reader = new InputStreamReader((InputStream) arg1);
                    copy(reader, writer);
                } else if (arg1 instanceof RandomAccessFile) {
                    copy((RandomAccessFile) arg1, writer);
                } else {
                    throw new TypeError("Invalid first argument to copy()");
                }
            } else if (arg2 instanceof OutputStream) {
                outStream = (OutputStream) arg2;
                if (arg1 instanceof Reader) {
                    copy((Reader) arg1, new OutputStreamWriter(outStream));
                } else if (arg1 instanceof String) {
                    inStream = new FileInputStream(new File((String) arg1));
                    copy(inStream, outStream);
                } else if (arg1 instanceof File) {
                    inStream = new FileInputStream((File) arg1);
                    copy(inStream, outStream);
                } else if (arg1 instanceof URL) {
                    copy(((URL) arg1).openStream(), outStream);
                } else if (arg1 instanceof InputStream) {
                    copy((InputStream) arg1, outStream);
                } else if (arg1 instanceof RandomAccessFile) {
                    copy((RandomAccessFile) arg1, outStream);
                } else {
                    throw new TypeError("Invalid first argument to copy()");
                }
            } else if (arg2 instanceof RandomAccessFile) {
                RandomAccessFile out = (RandomAccessFile) arg2;
                if (arg1 instanceof Reader) {
                    copy((Reader) arg1, out);
                } else if (arg1 instanceof String) {
                    inStream = new FileInputStream(new File((String) arg1));
                    copy(inStream, out);
                } else if (arg1 instanceof File) {
                    inStream = new FileInputStream((File) arg1);
                    copy(inStream, out);
                } else if (arg1 instanceof URL) {
                    copy(((URL) arg1).openStream(), out);
                } else if (arg1 instanceof InputStream) {
                    copy((InputStream) arg1, out);
                } else if (arg1 instanceof RandomAccessFile) {
                    copy((RandomAccessFile) arg1, out);
                } else {
                    throw new TypeError("Invalid first argument to copy()");
                }
            } else if (arg2 instanceof File || arg2 instanceof String) {
                File outFile = null;
                if (arg2 instanceof File) {
                    outFile = (File) arg2;
                } else {
                    outFile = new File((String) arg2);
                }
                outStream = new FileOutputStream(outFile);
                if (arg1 instanceof Reader) {
                    copy((Reader) arg1, new OutputStreamWriter(outStream));
                } else if (arg1 instanceof String) {
                    inStream = new FileInputStream(new File((String) arg1));
                    copy(inStream, outStream);
                } else if (arg1 instanceof File) {
                    inStream = new FileInputStream((File) arg1);
                    copy(inStream, outStream);
                } else if (arg1 instanceof URL) {
                    copy(((URL) arg1).openStream(), outStream);
                } else if (arg1 instanceof InputStream) {
                    copy((InputStream) arg1, outStream);
                } else if (arg1 instanceof RandomAccessFile) {
                    copy((RandomAccessFile) arg1, outStream);
                } else {
                    throw new TypeError("Invalid first argument to copy()");
                }
            } else {
                throw new TypeError("Invalid second argument to copy()");
            }
        } catch (IOException e) {
            throw new IOError(e.getMessage(), e);
        }
    }


    public HttpURLConnection openConnection(String url) throws IOException {
        if (isDebugMode()) System.out.println("open: " + url);
        URL u = new URL(url);
        HttpURLConnection urlConnection;
        if (proxy != null) urlConnection = (HttpURLConnection) u.openConnection(proxy); else urlConnection = (HttpURLConnection) u.openConnection();
        urlConnection.setRequestProperty("User-Agent", userAgent);
        return urlConnection;
    }


    public Result request(URL url) {
        try {
            return xmlUtil.unmarshall(urlOpener.openStream(url));
        } catch (FileNotFoundException e) {
            log.info("File not found: " + url);
        } catch (IOException e) {
            log.error("Failed to read from url: " + url + ". " + e.getMessage(), e);
        }
        return null;
    }


    public static void parseConfigV2(List rootList, InputStream is, javax.servlet.ServletContext context, List configFileList) throws Exception {
        URL configUrl = CompositePageUtil.class.getResource("/cuttleConfigurationV2.xml");
        if (configUrl == null) configUrl = CompositePageUtil.class.getClassLoader().getResource("/cuttleConfigurationV2.xml");
        URL dtdUrl = CompositePageUtil.class.getResource("/dtd/cuttleConfiguration.dtd");
        if (dtdUrl == null) dtdUrl = CompositePageUtil.class.getClassLoader().getResource("/dtd/cuttleConfiguration.dtd");
        Digester digester = DigesterLoader.createDigester(configUrl);
        digester.setValidating(false);
        digester.register("-//Cuttle MVC Framework//DTD Cuttle Configuration 1.0//EN", dtdUrl.toString());
        XMLCuttleConfiguration cuttleConfiguration = (XMLCuttleConfiguration) digester.parse(is);
        ConfigureDigester.setXmlCuttleConfiguration(cuttleConfiguration);
        if (configFileList != null) {
            for (int i = 0; i < configFileList.size(); i++) {
                String file = (String) configFileList.get(i);
                URL url2 = CompositePageUtil.class.getResource(file);
                if (url2 == null) url2 = CompositePageUtil.class.getClassLoader().getResource(file);
                if (url2 == null) {
                    logger.error("file path:" + file + " not found!");
                }
                XMLRoot root = (XMLRoot) ConfigureDigester.parseXMLToObject(url2.openStream());
                rootList.add(root);
            }
        } else {
            for (int i = 0; i < cuttleConfiguration.getActionConfigs().size(); i++) {
                XMLActionConfig config = (XMLActionConfig) cuttleConfiguration.getActionConfigs().get(i);
                URL url2 = context.getResource(config.getResource());
                if (url2 == null) {
                    logger.error("file path:" + config.getResource() + " not found!");
                }
                XMLRoot root = (XMLRoot) ConfigureDigester.parseXMLToObject(url2.openStream());
                rootList.add(root);
            }
        }
        compositeXMLRoot(rootList);
        XMLCuttleConfiguration config = ConfigureDigester.getXmlCuttleConfiguration();
        if (config != null) {
            List processUnits = config.getProcessUnits();
            if (processUnits != null) {
                for (int i = 0; i < processUnits.size(); i++) {
                    XMLProcessUnit processUnit = (XMLProcessUnit) processUnits.get(i);
                    if (processUnit.getSpringMapping() == null || processUnit.getSpringMapping().equals("")) {
                        Class businessClass = Class.forName(processUnit.getClazz());
                        Object business = businessClass.newInstance();
                        ConfigureDigester.addObjectToPool(business);
                    }
                }
            }
        }
    }


    public static void initConfigurationV2(String cuttleConfiguration, javax.servlet.ServletContext context, List configFileList) throws Exception {
        ConfigureDigester.clearMap();
        List rootList = new ArrayList();
        InputStream is = null;
        if (cuttleConfiguration == null) {
            URL url = CompositePageUtil.class.getResource("/cuttle.xml");
            if (url == null) url = CompositePageUtil.class.getClassLoader().getResource("/cuttle.xml");
            is = url.openStream();
        } else {
            is = context.getResourceAsStream(cuttleConfiguration);
        }
        parseConfigV2(rootList, is, context, configFileList);
        if (ConfigureDigester.getXmlCuttleConfiguration() != null && ConfigureDigester.getXmlCuttleConfiguration().getPlugins() != null) {
            for (int i = 0; i < ConfigureDigester.getXmlCuttleConfiguration().getPlugins().size(); i++) {
                XMLPlugin plugin = (XMLPlugin) ConfigureDigester.getXmlCuttleConfiguration().getPlugins().get(i);
                if (plugin.getConfigurePlugable() != null && !plugin.getConfigurePlugable().equals("")) {
                    Class pluginable = Class.forName(plugin.getConfigurePlugable());
                    ConfigurePlugable pluginableObj = (ConfigurePlugable) pluginable.newInstance();
                    pluginableObj.initConfiguration(plugin.getConfigurationPath(), context);
                }
            }
        }
    }