String delimiter = new String("&&&");
     public void  returnVal( OutputStream out)     {          System.out.println("[GenericQueryXML.returnVal] Called.");          HashMap myObjectProviderMap = (HashMap)this.getParam(this.paramkey_XML_SERVICE);          // XMLObjectProvider   myObjectProvider = (XMLObjectProvider)this.getParam(this.paramkey_XML_SERVICE);          XSLTInputSource  myXSL = null;          String mySAXContentHandlerClassName = null;          //StringBuffer sbuf_xsl = (StringBuffer)preConfiguredParameters.get(this.paramkey_XSL);          //if( sbuf_xsl != null) myXSL =  new XSLTInputSource(new StringReader(sbuf_xsl.toString()));          //System.out.println(" myXSL=" + myXSL);          //          // SAX CONTENTHANDLER PARAMETER?          //          String sbuf_sax = (String)this.getParam(this.paramkey_SAX);          if( sbuf_sax != null) mySAXContentHandlerClassName = sbuf_sax.toString();          if( mySAXContentHandlerClassName != null) {              System.out.println("[GenericQueryXML.returnVal] SAX HANDLER USED:" + mySAXContentHandlerClassName);          }          else {              System.out.println("[GenericQueryXML.returnVal] SAX HANDLER NOT USED." );          }          //#################################          // XSL PROCESSING  (DOM)          // ################################          //          //  Potentially, sending multiple documents (1 per subscription event type          //  for which objects are available...          //          //   <LogPlan>...</LogPlan>          //   <LogPlan>...</LogPlan>          //   <LogPlan>...</LogPlan>          //          if( existsXSLParameter() )          {              try {                  myXSL=getXSLFromParameter();                  boolean output = false;                  String delimiter = new String("&&&");                  XMLObjectProvider myObjectProvider =                      (XMLObjectProvider)myObjectProviderMap.get(GenericLogic.collectionType_ADD);                  if( myObjectProvider.size() > 0)                  {                      System.out.println("[GenericQueryXML.returnVal] XSL (collectionType_ADD)");                      if( output == true ) {                                         out.write(delimiter.getBytes());                                         out.flush();                       }                      output = true;                      processContainerXSL(                               myObjectProvider, myXSL, out, GenericLogic.collectionType_ADD );                  }                  myXSL=getXSLFromParameter();                  myObjectProvider =                      (XMLObjectProvider)myObjectProviderMap.get(GenericLogic.collectionType_CHANGE);                  if( myObjectProvider.size() > 0 )                  {                      System.out.println("[GenericQueryXML.returnVal] XSL (collectionType_CHANGE)");                      if( output == true ) {                                         out.write(delimiter.getBytes());                                         out.flush();                       }                       output = true;                       processContainerXSL(myObjectProvider, myXSL, out, GenericLogic.collectionType_CHANGE );                  }                  myXSL=getXSLFromParameter();                  myObjectProvider =                      (XMLObjectProvider)myObjectProviderMap.get(GenericLogic.collectionType_REMOVE);                  if( myObjectProvider.size() > 0 )                  {                       System.out.println("[GenericQueryXML.returnVal] XSL (collectionType_REMOVE)");                       if( output == true ) {                                         out.write(delimiter.getBytes());                                         out.flush();                       }                       output = true;                       processContainerXSL(myObjectProvider, myXSL, out, GenericLogic.collectionType_REMOVE );                  }              } catch (Exception ex ){                    ex.printStackTrace();              }          }          //#################################          // SAX PROCESSING          // ################################          else if ( mySAXContentHandlerClassName != null ) {              //              // Set from mySAXContentHandlerClassName...              //              BContentHandler myContentHandler=null;              try{                 Class klass = Class.forName(mySAXContentHandlerClassName);                 myContentHandler = (BContentHandler)klass.newInstance();              } catch (ClassNotFoundException cex ) {                 System.err.println("[GenericQueryXML.returnVal()]  Class NOT FOUND trying to create new Content Handler instance.");                 System.err.println("[[GenericQueryXML.returnVal()]  Be sure handler is in classpath.");                 cex.printStackTrace();              } catch (ClassCastException cex) {                 System.err.println("[GenericQueryXML.returnVal()]  Class CAST EXCEPTION creating new Content Handler instance.");                 System.err.println("[[GenericQueryXML.returnVal()]  Be sure handler implements interface BContentHandler!");                 cex.printStackTrace();              } catch (Exception ex) {                 ex.printStackTrace();              }              //BContentHandler myContentHandler = new BContentHandler();              if( mySaxParser == null) {                    mySaxParser = new SAXParser();                    try {                         // try to activate validation                         mySaxParser.setFeature("http://xml.org/sax/features/validation", true);                    } catch (SAXException e) {                         System.err.println("Cannot activate validation.");                    }              } // end create SAX parser              if( mySaxParser != null)              {                  mySaxParser.setContentHandler(myContentHandler);                  mySaxParser.setErrorHandler(new BErrorHandler());              }              XMLObjectProvider myObjectProvider =                      (XMLObjectProvider)myObjectProviderMap.get(GenericLogic.collectionType_ADD);              if( myObjectProvider.size() > 0) {                    processContainerSAX(myObjectProvider, myContentHandler, mySaxParser, out,                                   GenericLogic.collectionType_ADD );              }              myObjectProvider =                      (XMLObjectProvider)myObjectProviderMap.get(GenericLogic.collectionType_CHANGE);              if( myObjectProvider.size() > 0 ) {                   processContainerSAX(myObjectProvider, myContentHandler, mySaxParser, out,                                   GenericLogic.collectionType_CHANGE );              }              myObjectProvider =                      (XMLObjectProvider)myObjectProviderMap.get(GenericLogic.collectionType_REMOVE);              if( myObjectProvider.size() > 0 ) {                   processContainerSAX(myObjectProvider, myContentHandler, mySaxParser, out,                                   GenericLogic.collectionType_REMOVE );              }              /**              TXDocument doc = null;              synchronized( myObjectProvider)              {                     Object odoc= getDocument(myObjectProvider);                     if( odoc instanceof TXDocument) doc = (TXDocument)odoc;              }              if( ( doc != null) )              {                    StringWriter sw = new StringWriter();                    try{                        doc.print(sw);                    } catch( IOException ex ) {                        ex.printStackTrace();                    }                    StringBuffer sb = sw.getBuffer();                    StringReader str_reader = new StringReader(sb.toString() );                    try {                        InputSource in = new InputSource(str_reader);                        mySaxParser.parse(in);                    } catch (IOException e) {                        System.err.println("I/O exception reading XML document. " + e);                        e.printStackTrace();                    } catch (SAXException e) {                        System.err.println("SAX exception parsing document. " + e);                        e.printStackTrace();                    }                   //-----------------------------------------------------------------                   // Traverse and "write" the tree                   // Start from the root object                   //-----------------------------------------------------------------                   PrintWriter pw = new PrintWriter(out);                   pw.println("<?xml version=\"1.0\"?>");                   Iterator it3 = myContentHandler.getRootElements().iterator();                   while(it3.hasNext()){                      BElement be = (BElement)it3.next();                      be.print(pw);                   }                   pw.flush();                   System.out.println("[GenericQueryXML] pw.toString()=" + pw.toString() );              }              **/          }          // ##############################          // FLUSH! object cache after we've consumed data          // ##############################          XMLObjectProvider myObjectProvider =                      (XMLObjectProvider)myObjectProviderMap.get(GenericLogic.collectionType_ADD);          synchronized( myObjectProvider ) {              reset(myObjectProvider);          }          myObjectProvider =                      (XMLObjectProvider)myObjectProviderMap.get(GenericLogic.collectionType_CHANGE);          synchronized( myObjectProvider ) {              reset(myObjectProvider);          }          myObjectProvider =                      (XMLObjectProvider)myObjectProviderMap.get(GenericLogic.collectionType_REMOVE);          synchronized( myObjectProvider ) {              reset(myObjectProvider);          }  }