Package org.jboss.fresh.io

Examples of org.jboss.fresh.io.PrintWriter2


  public void process(String exepath, String[] params) throws Exception {
    log.debug("entered");

    if (helpRequested()) {
      PrintWriter2 out = new PrintWriter2(new BufferWriter(getStdOut()));
      out.println("Usage: antbuild [--help] [-o] path param1, param2, ..., paramN");
      out.println("        -o : display output of the building process.");
      out.println("      path : path to the \"build.xml\" file.");
      out.println();
      out.println(" --help : this help.");
      out.flush();
      out.close();
      log.debug("done");
      return;
    }


    pout = new PrintWriter2(new BufferedWriter(new BufferWriter(getStdOut())));

    String buildPath = null;
    boolean displayOutput = false;

    StringBuffer args = new StringBuffer();
View Full Code Here


  public void process(String exepath, String[] params) throws Exception {
    log.debug("entered");


    PrintWriter2 out = new PrintWriter2(new BufferWriter(getStdOut()));

    boolean g = false;
    boolean l = false;
    boolean b = false;
    boolean help = false;
    boolean tex = false;

    String name = null;
    String factory = null;
    String host = null;
    Hashtable env = null;

    // see what to do:
    for (int i = 0; i < params.length; i++) {
      String val = params[i];

      if (val.equals("-g") || val.equals("--get")) {
        g = true;
      } else if (val.equals("-l") || val.equals("--list")) {
        l = true;
      } else if (val.equals("-b") || val.equals("--bind")) {
        b = true;
      } else if (val.equals("-h") || val.equals("--help")) {
        help = true;
      } else if (val.equals("--ex")) {
        tex = true;
      } else if (val.equals("--factory")) {
        try {
          factory = params[++i];
        } catch (Exception ex) {
        }
      } else if (val.equals("--host")) {
        try {
          host = params[++i];
        } catch (Exception ex) {
        }
      } else {
        name = val;
      }
    }

    if (params.length == 0 || help) {

      out.println("Usage: jndi [-glbh] <lookup name>");
      out.println("    lookup name : lookup name i.e. java:UserTransaction");
      out.println("    -g, --get : get the object for the specified name");
      out.println("    -l, --list : list the contents of the context");
      out.println("    -b, --bind : bind an object passed on stdin under the specified name");
      out.println("    -h, --help : this help");
      out.close();
      log.debug("done");
      return;
    }

    RegistryContext ctx = new RegistryContext();


    if (g) {
      BufferObjectWriter oout = new BufferObjectWriter(getStdOut());
      Object o = null;

      try {
        o = ctx.lookup(name);
      } catch (NamingException ex) {
        if (tex)
          throw new RuntimeException(ex);
        else
          out.print("Name not bound: " + name);
        return;
      }

      oout.writeObject(o);
      oout.close();
      return;
    }

    if (l) {
      BufferObjectWriter oout = new BufferObjectWriter(getStdOut());
      Object o = ctx.lookup(name);
      if (!(o instanceof Context)) {
        if (tex)
          throw new RuntimeException("Object is not instance of Context. Can't list it. : " + name);
        else
          out.print("Object is not instance of Context. Can't list it. : " + name);
        return;
      }

      NamingEnumeration it = ctx.listBindings(name);
      while (it.hasMore()) {
        Binding bing = (Binding) it.next();
        out.println(bing.toString());
      }
      out.close();
      return;
    }


    if (b) {
      out.println("Not implemented yet.");
      out.close();
      return;
    }


    log.debug("done");
View Full Code Here

  // ctx -b bindname1 bindname2 bindname3
  // Will read 3 objects from shell-in and bind them under the specified names
  public void process(String exename, String[] params) throws Exception {
    log.debug("entered");
    if (helpRequested()) {
      PrintWriter2 out = new PrintWriter2(new BufferWriter(getStdOut()));

      out.print("Usage:\n");
      out.print("  BIND some objects in the context under their respective names:\n");
      out.print("      <OBJ_GEN> | ctx [-ex] -b name1, name2, name3\n\n");
      out.print("  UNBIND some objects from the context:\n");
      out.print("      ctx [-ex] -u name1, name2, name3\n\n");
      out.print("  GET some objects from the context:\n");
      out.print("      ctx [-ex] -g name1, name2, name3 | <OBJ_CONSUMER>\n\n");
      out.print("  LIST children of an existing object to some other existing object:\n");
      out.print("      ctx [-ex] -l\n\n");
      out.print("    --help : this help\n");
      out.close();
      log.debug("done");
      return;
    }

    int action = -1;

    PrintWriter2 err = new PrintWriter2(new BufferWriter(getStdOut())), pout = err;


    LinkedList names = new LinkedList();

    Context ctx = shell.getContext();

    if (params.length == 0) {
      if (canThrowEx()) {
        throw new Exception("Need to specify some parameters.");
      } else {
        printUsage();
        log.debug("done");
        return;
      }
    }

    for (int i = 0; i < params.length; i++) {

      String tmp = params[i];

      if (tmp.equals("-b")) {
        action = BIND;

        // zdaj bere� dokler je:
        for (int j = i + 1; j < params.length; j++, i++) {
          names.add(params[j]);
        }

        if (names.size() == 0) {
          if (canThrowEx()) {
            throw new Exception("No bind name specified.");
          } else {
            err.println("No bind name specified.");
            printUsage();
            log.debug("done");
            return;
          }
        }

      } else if (tmp.equals("-u")) {
        action = UNBIND;

        // zdaj bere� dokler je:
        for (int j = i + 1; j < params.length; j++, i++) {
          names.add(params[j]);
        }


        if (names.size() == 0) {
          if (canThrowEx()) {
            throw new Exception("No unbind name specified.");
          } else {
            err.println("No unbind name specified.");
            printUsage();
            log.debug("done");
            return;
          }
        }

      } else if (tmp.equals("-g")) {
        action = GET;

        for (int j = i + 1; j < params.length; j++, i++) {
          names.add(params[j]);
        }

        if (names.size() == 0) {
          if (canThrowEx()) {
            throw new Exception("No get name specified.");
          } else {
            err.println("No get name specified.");
            printUsage();
            log.debug("done");
            return;
          }
        }

      } else if (tmp.equals("-l")) {
        action = LIST;

      } else {
        printUsage();
        log.debug("done");
        return;
      }
    }


    switch (action) {

      case BIND:
        {
          BufferObjectReader objin = new BufferObjectReader(getStdIn());
          // read from input names.length() objects
          // bind each one as you go
          Iterator it = names.iterator();
          while (it.hasNext()) {
            String name = String.valueOf(it.next());
            Object obj = null;
            if (!objin.isFinished()) obj = objin.readObject();

            if (obj == null) {
              if (canThrowEx()) {
                throw new Exception("Could not read object from std-in for name: " + name);
              } else {
                err.println("Could not read object from std-in for name: " + name);
                printUsage();
                log.debug("done");
                return;
              }
            }
View Full Code Here

  }


  private void printUsage() {

    PrintWriter2 pout = new PrintWriter2(new BufferedWriter(new BufferWriter(getStdOut())));

    pout.println("Usage:\n");
    pout.println("  BIND some objects in the context under their respective names:");
    pout.println("      <OBJ_GEN> | ctx [-ex] -b name1, name2, name3");
    pout.println();
    pout.println("  UNBIND some objects from the context:");
    pout.println("      ctx [-ex] -u name1, name2, name3");
    pout.println();
    pout.println("  GET some objects from the context:");
    pout.println("      ctx [-ex] -g name1, name2, name3 | <OBJ_CONSUMER>");
    pout.println();
    pout.println("  LIST children of an existing object to some other existing object:");
    pout.println("      ctx [-ex] -l");
    pout.println();
    pout.flush();
  }
View Full Code Here

TOP

Related Classes of org.jboss.fresh.io.PrintWriter2

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.