1.2 Invocation Interfaces

<..static void main(String [])..>
 public static void main(String args[]) throws Exception {
   <.init fields.>
   mainMethod(args);
 }
 -_-_-

<..static void xtpipes(String [], OutputStream, PrintWriter)..>
 public static void xtpipes(String [] args,
                            OutputStream out,
                            PrintWriter log)
                                                 throws Exception {
   <.init fields.>
   outPrintWriter = new XtpipesPrintWriter( out, true );
   logWriter = (log==null)? (new PrintWriter( System.err )) : log;
   mainMethod(args);
   outPrintWriter.flush();
 }
 -_-_-

<..static void xtpipes(String [], OutputStreamWriter, PrintWriter)..>
 public static void xtpipes(String [] args,
                            OutputStreamWriter out,
                            PrintWriter log)
                                                 throws Exception {
   <.init fields.>
   outPrintWriter = new XtpipesPrintWriter( out );
   logWriter = (log==null)? (new PrintWriter( System.err )) : log;
   mainMethod(args);
   outPrintWriter.flush();
 }
 -_-_-

<..static void xtpipes(String [], XtpipesPrintWriter, PrintWriter)..>
 public static void xtpipes(String [] args,
                            XtpipesPrintWriter out,
                            PrintWriter log)
                                                 throws Exception {
   <.init fields.>
   outPrintWriter = out;
   logWriter = (log==null)? (new PrintWriter( System.err )) : log;
   mainMethod(args);
   outPrintWriter.flush();
 }
 -_-_-

<..xtpipes fields..>+
 private static boolean returnDom;
 private static String result;
 -_-_-

<..init fields..>+
 returnDom = false;
 result = null;
 -_-_-

<..static Document getDOM(...)..>
 public static Document getDOM(String args[])
                                throws Exception {
   <.init fields.>
    returnDom = true;
    mainMethod(args);
    Document dom = null;
    if( result == null ){
      System.err.println(
        "--- xtpipes warning --- getDOM without <return name=\"...\"> from 4xt file: "
          + scriptFile );
    } else {
       try{
          byte [] bytes = result.getBytes("UTF-8");
          InputStream is =  new ByteArrayInputStream( bytes );
          dom = domBuilder.parse (is);
       } catch ( org.xml.sax.SAXParseException e ){
          if( Xtpipes.trace ){
             Xtpipes.logWriter.println(
                "\n---------------------------------------------------\n"
                         + result +
                "\n---------------------------------------------------\n" );
          }
          String s = "";
          <.s += input file name within args.>
          if( scriptFile != null ){ s += "    script file: " + scriptFile; }
          instructionErr( null,
             "parsing error: " + e.getMessage() +s, 21 );
       } catch ( Exception e ){
          instructionErr( null, e.toString(), 5 );
       }
       <.close ml2xml files.>
    }
    return dom;
 }
 -_-_-

<..static Document getDOM(...)..>+
 public static Document getDOM(String s, String args[])
                                            throws Exception {
    <.init fields.>
    returnDom = true;
    inData = s;
    mainMethod(args);
    Document dom = null;
    if( result == null ){
      System.err.println(
        "--- xtpipes warning --- getDOM without"
          + " <return name=\"...\"> from 4xt file: "
          + scriptFile );
    } else {
       try{
          byte [] bytes = result.getBytes("UTF-8");
          InputStream is =  new ByteArrayInputStream( bytes );
          dom = domBuilder.parse (is);
       } catch ( org.xml.sax.SAXParseException e ){
          instructionErr( null, "improper xml: " + e.getMessage()
            + "\n code starts with: "
            + result.substring(0, Math.min(100,result.length()))
          , 17 );
       } catch ( Exception e ){
          instructionErr( null, e.toString(), 6 );
       }
       <.close ml2xml files.>
    }
    return dom;
 }
 -_-_-

<..static Document getDOM(...)..>+
 public static Document getDOM(String args[], PrintWriter log)
                                throws Exception {
    logWriter = (log==null)? new PrintWriter( System.err ) : log;
    return getDOM(args);
 }
 -_-_-

<..static Document getDOM(...)..>+
 public static Document getDOM(String s, String args[], PrintWriter log)
                                            throws Exception {
    logWriter = (log==null)? (new PrintWriter( System.err )) : log;
    return getDOM(s, args);
 }
 -_-_-

<..xtpipes fields..>+
 static PrintWriter logWriter = new PrintWriter( System.err );
 -_-_-