Package org.jboss.fresh.ctx

Examples of org.jboss.fresh.ctx.Context


      error(sb.toString());
      return;
    }

    History h = null;
    Context context = getShell().getContext();
    if(project) {
      context = (Context) context.get("AppContext");
    } else if(global) {
      context = (Context) context.get("GlobalContext");
    }

    if(context == null) {
      if(project)
        error("AppContext not available");
      else if(global)
        error("GlobalContext not available");
      else
        error("Context not available");
      return;
    }

    h = (History) context.get("History");

    if(h == null) return;

    BufferObjectWriter oout = null;
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
View Full Code Here


          log.debug("CtxDelegateExe done.");
          return;
        }
      }

      Context ctx0 = (Context) obj;
      // now shell.getContext()
      if(log.isDebugEnabled()) {
        log.debug("shell: " + shell + ", ctx: "  + shell.getContext());
      }
      shell.getContext().registerDelegate(ctx0);
      shell.getContext().put("AppContext", ctx0);

      Context gctx = null;
      try {
        tmp = "java:/FRESH/GlobalContext";
        gctx = (Context) ctx.lookup(tmp);
      } catch (Exception ex) {
        if (canThrowEx()) {
View Full Code Here

        }
      }

    }

    Context c = getShell().getContext();

    EventCentral ec = (EventCentral) c.get("EventCentral");

    if (ec == null) {
      error("EventCentral not bound in context.");
      return;
    }
View Full Code Here

      }
   }

   private EventBroadcaster getEventBroadcaster() {

    Context ctx = getContext();
    EventCentral evc = (EventCentral) ctx.get("EventCentral");
    if (evc == ec) {
      return eb;
    }

    synchronized(this) {
View Full Code Here

            ctx.put("History", h);
        }

        h.add(hitem);

        Context actx = (Context) ctx.get("AppContext");
        if(actx == null) {
            log.debug("AppContext not available");
        } else {
            h = (History) actx.get("History");
            if(h == null) {
                h = new History();
                actx.put("History", h);
            }

            h.add(hitem);
        }

        // would be nice to have a wrapper that returns null and throws no exceptions
        try {
            actx = (Context) new RegistryContext().lookup("java:/FRESH/GlobalContext");
        } catch(Exception ex) {
        }

        if(actx == null) {
            log.debug("GlobalContext not available");
        } else {
            h = (History) actx.get("History");
            if(h == null) {
                h = new History();
                actx.put("History", h);
            }

            h.add(hitem);
        }
View Full Code Here

    }

  public HistoryItem getHistoryItem(String id) {
log.info("id: " + id);
    HistoryItem ti = null;
    Context c = ctx;
    for(int i=0; i<3; i++) {
log.info("i: " + i + ", ctx: " + c);
          HashMap map = new HashMap();

          c.loadMappings(map);

          java.util.TreeMap sm = new java.util.TreeMap(map);
          Iterator it0 = sm.entrySet().iterator();
          while (it0.hasNext()) {
            Map.Entry ent = (Map.Entry) it0.next();
            log.info(ent.getKey() + "\t=\t" + ent.getValue() + "\t" + ent.getValue().getClass().getName());
          }


      History h = (History) c.get("History");
      Iterator it = h.list().iterator();
      while(it.hasNext()) {
        HistoryItem hi = (HistoryItem) it.next();
        log.info("compare: " + hi.getProcessID() + "  vs. " + id);
        if(hi.getProcessID().equals(id)) {
View Full Code Here

        log.error("Failed to retrieve EventCentral: ", ex);
        error("Failed to find EventCentral with registry name: " + name);
        return;
      }
    } else {
      Context ctx = getShell().getContext();
      ec = (EventCentral) ctx.get("EventCentral");
    }

    if(ec == null) {
      error("Failed to locate EventCentral (make sure you specify EventCentral lookup name, or make sure instance is available in shell context under 'EventCentral')");
      return;
View Full Code Here

    //Variables to be declared to the BSFManager (are available in scripts under aliases)
    Writer out = null;
    Reader in = null;
    BufferInputStream inStream = null;
    BufferOutputStream outStream = null;
    Context context = null;
    Properties props = null;

    boolean isFile = false;

    if (helpRequested()) {
      printHelp();
      return;
    }


    PrintWriter err = new PrintWriter(new BufferWriter(getStdOut()), true);

    // now lookup ScriptingServices
    ScriptingCentral sc = (ScriptingCentral) getShell().getContext().get("ScriptingServices");
    if (sc == null) {
      if (canThrowEx()) {
        throw new RuntimeException("ScriptingServices not bound in context.");
      } else {
        err.println("ScriptingServices not bound in context.");
        return;
      }
    }

        String file = null;
        String vfile = null;
    Reader reader = null;
    String enc = shell.getEnvProperty("ENCODING");

    String [] args = null;


        if(params.length >0) {
            int i = 0;
            String temp = params[i];

            if("-f".equals(temp) || "--file".equals(temp)) {
                if(i<params.length-1) {
                    file = params[++i];
                } else {
                    error("File name missing after parameter: " + temp);
                    return;
                }
            } else if("-v".equals(params[0]) || "--vfile".equals(params[0])) {
                if(i<params.length-1) {
                    vfile = params[++i];
                } else {
                    error("File name missing after parameter: " + temp);
                    return;
                }
            }
        }


        if(file != null || vfile != null) {
            args = new String[params.length-2];
            for(int i=2; i<params.length; i++) {
                args[i-2] = params[i];
            }


            fname = file != null ? file : vfile;

            String ext = IOUtils.getExt(fname);
            if (ext == null) {
                if (canThrowEx()) {
                    throw new RuntimeException("Can't determine scripting language - file has no extension.");
                } else {
                    err.println("Can't determine scripting language - file has no extension.");
                    return;
                }
            }


            langName = sc.getLanguageForExtension(ext);
            if (langName == null) {
                if (canThrowEx()) {
                    throw new RuntimeException("No scripting language registered for the specified extensions: " + ext);
                } else {
                    err.println("No scripting language registered for the specified extensions: " + ext);
                    return;
                }
            }

            InputStream ins = null;
            if(file != null) {
                ins = new FileInputStream(file);
            } else {
                VFS vfs = shell.getVFS();
                FileName pwd = new FileName(shell.getEnvProperty("PWD"));
                FileName path = new FileName(vfile);
                if (path.isRelative())
                    path = pwd.absolutize(path);

                path = vfs.resolve(shell.getUserCtx(), path, false);

                ins = new VFSInputStream(new SecureVFS(vfs, shell.getUserCtx()), path.toString());
            }

            if (enc == null || enc.trim().length() == 0) {
                reader = new BufferedReader(new InputStreamReader(ins));
            } else {
                reader = new BufferedReader(new InputStreamReader(ins, enc));
            }

            isFile = true;

        } else {
            args = params;

            InputStream ins = new BufferInputStream(getStdIn());
            if (enc == null || enc.trim().length() == 0) {
                reader = new BufferedReader(new InputStreamReader(ins));
            } else {
                reader = new BufferedReader(new InputStreamReader(ins, enc));
            }

            langName = ((BufferedReader) reader).readLine();

            if (langName.length() > 2)
                langName = langName.substring(2).trim();

            String lngName = sc.getLanguageForName(langName);
            if (lngName == null) {
                if (canThrowEx()) {
                    throw new RuntimeException("Scripting language is not supported: " + langName);
                } else {
                    err.println("Scripting language is not supported: " + langName);
                    return;
                }
            }

            langName = lngName;
        }


    BSFManager manager = sc.getManager(langName);

    inStream = getStdInStream();
    outStream = getStdOutStream();
    context = shell.getContext();
    props = shell.getEnvProperties();
    out = new PrintWriter(new BufferedWriter(new BufferWriter(getStdOut())), true);
    in = new BufferedReader(new BufferReader(getStdIn()));
    InBuffer stdin = getStdIn();
    OutBuffer stdout = getStdOut();

    manager.declareBean("args", args, args.getClass());
    manager.declareBean("shell", shell, shell.getClass());
    manager.declareBean("instream", inStream, inStream.getClass());
    manager.declareBean("outstream", outStream, outStream.getClass());
    manager.declareBean("context", context, context.getClass());
    manager.declareBean("props", props, props.getClass());
    manager.declareBean("out", out, out.getClass());
    manager.declareBean("cin", in, in.getClass());
    manager.declareBean("stdin", stdin, stdin.getClass());
    manager.declareBean("stdout", stdout, stdout.getClass());
View Full Code Here

//      error("Parameter(s) missing. Use --help for usage information.");
//      return;
//    }

    // get ref to EventCentral
    Context ctx = getShell().getContext();

    // we could also specify lookup name on cmdline or as ENV variable
    EventCentral ec = (EventCentral) ctx.get("EventCentral");

    if(ec == null) {
      error(new org.jboss.fresh.shell.UninitializedEnvironmentException("EventCentral not bound in context"));
      return;
    }
View Full Code Here

    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;
              }
            }

            ctx.put(name, obj);
          }

        }
        break;


      case UNBIND:
        {
          // unbind one by one
          Iterator it = names.iterator();
          while (it.hasNext()) {
            String name = String.valueOf(it.next());
            ctx.remove(name);
          }

        }
        break;

      case GET:
        {
          // unbind one by one
          BufferObjectWriter objout = new BufferObjectWriter(getStdOut());

          Iterator it = names.iterator();
          while (it.hasNext()) {
            String name = String.valueOf(it.next());
            Object obj = ctx.get(name);

            objout.writeObject(obj);
          }

          objout.close();
        }
        break;


      case LIST:
        {

          HashMap map = new HashMap();

          ctx.loadMappings(map);

          TreeMap sm = new TreeMap(map);
          Iterator it = sm.entrySet().iterator();
          while (it.hasNext()) {
            Map.Entry ent = (Map.Entry) it.next();
View Full Code Here

TOP

Related Classes of org.jboss.fresh.ctx.Context

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.