@Override
 public CompiledScript compile(Reader script) throws ScriptException {
   try {
     InputStream is = new Utf8Encoder(script);
     try {
       final Globals g = context.globals;
       final LuaFunction f = g.load(script, "script").checkfunction();
       return new LuajCompiledScript(f, g);
     } catch (LuaError lee) {
       throw new ScriptException(lee.getMessage());
     } finally {
       is.close();
     }
   } catch (Exception e) {
     throw new ScriptException("eval threw " + e.toString());
   }
 }
 Object eval(Globals g, Bindings b) throws ScriptException {
   g.setmetatable(new BindingsMetatable(b));
   LuaFunction f = function;
   if (f.isclosure()) f = new LuaClosure(f.checkclosure().p, g);
   else {
     try {
       f = f.getClass().newInstance();
     } catch (Exception e) {
       throw new ScriptException(e);
     }
     f.initupvalue1(g);
   }
   return toJava(f.invoke(LuaValue.NONE));
 }
Beispiel #3
0
  /**
   * Check if a tuple attribute reference is valid. Disambiguate if needed. Also set the
   * RelationSchema for the TupleAttribute. *
   */
  boolean analyzeTupleAttribute(TupleAttribute ta) {
    if (ta.tableName == null) {
      BaseRelationSchema found_in = null;
      for (BaseRelationSchema rs : query_relations) {
        // System.out.println("searching for " + ta.attributeName + " in " + rs);
        if (rs.hasAttribute(ta.attributeName)) {
          if (found_in == null) {
            found_in = rs;
          } else {
            System.out.println("=========> Attribute " + ta.attributeName + " ambiguous");
            return false;
          }
        }
      }

      if (found_in != null) {
        ta.tableName = found_in.getName();
        ta.setRelationSchema(found_in);
        return true;
      } else {
        System.out.println(
            "=========> Attribute "
                + ta.attributeName
                + " not found in any of the tables in the FROM clause");
        return false;
      }
    } else {
      if (!checkRelationContainedInFromClause(ta.tableName)) {
        System.out.println("=========> Relation " + ta.tableName + " not in the From Clause");
        return false;
      }
      ta.setRelationSchema(Globals.getRelationSchema(ta.tableName));
      if (!ta.rs.hasAttribute(ta.attributeName)) {
        System.out.println(
            "=========> Attribute "
                + ta.attributeName
                + " not present in the relation "
                + ta.tableName);
        return false;
      }
      return true;
    }
  }
Beispiel #4
0
  /* Construct the query object. Analyze, check for errors etc. */
  boolean analyze() {
    /* Get the relation schemas, and make sure the relations exist. */
    query_relations = new Vector<BaseRelationSchema>();

    for (String name : query_relation_names) {
      BaseRelationSchema rs;
      if ((rs = Globals.getRelationSchema(name)) == null) {
        System.out.println("=========> Relation " + name + " does not exist");
        return false;
      }
      query_relations.add(rs);
    }

    /* Now check all the predicates. */
    for (Predicate p : query_predicates) {
      /* Check the validity of the attributes. */
      if ((p.lhs() instanceof TupleAttribute) && (!analyzeTupleAttribute((TupleAttribute) p.lhs())))
        return false;
      if ((p.rhs() instanceof TupleAttribute) && (!analyzeTupleAttribute((TupleAttribute) p.rhs())))
        return false;
    }

    /* Finally check the select list. */
    if (select_attributes.size() != 0) {
      for (TupleAttribute ta : select_attributes) {
        /* Check the validity of the attribute. */
        if (!analyzeTupleAttribute(ta)) return false;
      }
    } else {
      for (BaseRelationSchema rs : query_relations) {
        for (String attrName : rs.attributeNames) {
          TupleAttribute ta = new TupleAttribute(rs.getName(), attrName);
          ta.setRelationSchema(rs);
          select_attributes.add(ta);
        }
      }
    }

    return true;
  }
  /**
   * Draws the GUI that allows a user to select assets to be updated.
   *
   * @return true if the user made a valid choice of assets to replace.
   * @throws PipelineException
   */
  private boolean buildUpdateGUI() throws PipelineException {
    Box finalBox = new Box(BoxLayout.Y_AXIS);
    top = new Box(BoxLayout.Y_AXIS);

    JScrollPane scroll;

    {
      scroll = new JScrollPane(finalBox);

      scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
      scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

      Dimension size = new Dimension(sVSize + sVSize + sTSize + 52, 500);
      scroll.setMinimumSize(size);
      scroll.setPreferredSize(size);
      scroll.getViewport().setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE);
    }

    /* query the user */
    diag = new JToolDialog("Propagate Asset", scroll, "Continue");

    areas = mclient.getWorkingAreas();
    {
      Box hbox = new Box(BoxLayout.X_AXIS);
      Component comps[] = UIFactory.createTitledPanels();
      JPanel tpanel = (JPanel) comps[0];
      JPanel vpanel = (JPanel) comps[1];
      {
        userField =
            UIFactory.createTitledCollectionField(
                tpanel,
                "User:"******"The user whose area the node is being created in.");
        userField.setActionCommand("user");
        userField.setSelected(PackageInfo.sUser);
        userField.addActionListener(this);
      }
      UIFactory.addVerticalSpacer(tpanel, vpanel, 3);
      {
        viewField =
            UIFactory.createTitledCollectionField(
                tpanel,
                "View:",
                sTSize,
                vpanel,
                areas.get(PackageInfo.sUser),
                diag,
                sVSize,
                "The working area to create the nodes in.");
        viewField.setActionCommand("wrap");
        viewField.addActionListener(this);
      }
      UIFactory.addVerticalSpacer(tpanel, vpanel, 3);
      {
        toolsetField =
            UIFactory.createTitledCollectionField(
                tpanel,
                "Toolset:",
                sTSize,
                vpanel,
                mclient.getActiveToolsetNames(),
                diag,
                sVSize,
                "The toolset to set on all the nodes.");
        toolsetField.setSelected(mclient.getDefaultToolsetName());
        toolsetField.setActionCommand("wrap");
        toolsetField.addActionListener(this);
      }
      UIFactory.addVerticalSpacer(tpanel, vpanel, 3);

      w =
          new Wrapper(
              userField.getSelected(),
              viewField.getSelected(),
              toolsetField.getSelected(),
              mclient);

      charList = SonyConstants.getAssetList(w, project, AssetType.CHARACTER);
      setsList = SonyConstants.getAssetList(w, project, AssetType.SET);
      propsList = SonyConstants.getAssetList(w, project, AssetType.PROP);

      {
        projectField =
            UIFactory.createTitledCollectionField(
                tpanel,
                "Project:",
                sTSize,
                vpanel,
                Globals.getChildrenDirs(w, "/projects"),
                diag,
                sVSize,
                "All the projects in pipeline.");
        projectField.setActionCommand("proj");
        projectField.addActionListener(this);
      }
      hbox.add(comps[2]);
      top.add(hbox);
    }

    {
      Box vbox = new Box(BoxLayout.Y_AXIS);
      Box hbox = new Box(BoxLayout.X_AXIS);
      JButton button = new JButton("Propagate Additional Asset");
      button.setName("ValuePanelButton");
      button.setRolloverEnabled(false);
      button.setFocusable(false);
      Dimension d = new Dimension(sVSize, 25);
      button.setPreferredSize(d);
      button.setMinimumSize(d);
      button.setMaximumSize(new Dimension(Integer.MAX_VALUE, 25));

      vbox.add(Box.createRigidArea(new Dimension(0, 5)));
      hbox.add(button);
      hbox.add(Box.createRigidArea(new Dimension(4, 0)));
      vbox.add(hbox);
      vbox.add(Box.createRigidArea(new Dimension(0, 5)));

      button.setActionCommand("add");
      button.addActionListener(this);

      top.add(vbox);
    }

    list = new Box(BoxLayout.Y_AXIS);
    test = new JDrawer("Propagate Additional Asset", list, false);

    top.add(test);
    list.add(assetChoiceBox());

    finalBox.add(top);

    {
      JPanel spanel = new JPanel();
      spanel.setName("Spacer");
      spanel.setMinimumSize(new Dimension(sTSize + sVSize, 7));
      spanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
      spanel.setPreferredSize(new Dimension(sTSize + sVSize, 7));
      finalBox.add(spanel);
    }

    diag.setVisible(true);
    if (diag.wasConfirmed()) {
      // get list of things to change.
      for (Component comp : list.getComponents()) {
        if (comp instanceof Box) {
          Box can = (Box) comp;
          JCollectionField oldOne = (JCollectionField) can.getComponent(2);
          JCollectionField newOne = (JCollectionField) can.getComponent(4);

          TreeMap<String, String> assetList = new TreeMap<String, String>();
          assetList.putAll(charList);
          assetList.putAll(propsList);
          assetList.putAll(setsList);

          String key = assetList.get(oldOne.getSelected()) + lr;
          String value = assetList.get(newOne.getSelected()) + lr;
          if (!key.equals(value)) {
            potentialUpdates.add(key);
            pAssetManager.put(key, new AssetInfo(key, value));
          }
          // System.err.println("bUG: "+pAssetManager.get(key).getHiLoResShots());
        }
      }

      if (!pAssetManager.isEmpty()) return true;
    }
    return false;
  } // end buildReplacementGUI
  //
  // Visitor generation methods
  //
  public void generateDepthFirstVisitor() throws FileExistsException {
    try {
      File file = new File(visitorDir, outFilename);

      if (Globals.noOverwrite && file.exists()) throw new FileExistsException(outFilename);

      PrintWriter out = new PrintWriter(new FileOutputStream(file), false);
      Spacing spc = new Spacing(INDENT_AMT);

      out.println(Globals.fileHeader(spc));
      out.println();
      out.println(spc.spc + "package " + Globals.visitorPackage + ";");
      if (!Globals.visitorPackage.equals(Globals.nodePackage))
        out.println(spc.spc + "import " + Globals.nodePackage + ".*;");
      out.println(spc.spc + "import java.util.*;\n");
      out.println(spc.spc + "/**");
      out.println(
          spc.spc
              + " * Provides default methods which visit each "
              + "node in the tree in depth-first");
      out.println(spc.spc + " * order.  Your visitors may extend this class.");
      out.println(spc.spc + " */");
      out.println(
          spc.spc
              + "public class "
              + visitorName
              + "<R,A> implements "
              + Globals.GJVisitorName
              + "<R,A> {");
      printAutoVisitorMethods(out);

      spc.updateSpc(+1);
      out.println(spc.spc + "//");
      out.println(spc.spc + "// User-generated visitor methods below");
      out.println(spc.spc + "//");
      out.println();

      for (Enumeration e = classList.elements(); e.hasMoreElements(); ) {
        ClassInfo cur = (ClassInfo) e.nextElement();
        String name = cur.getName();

        out.println(spc.spc + "/**");
        if (Globals.javaDocComments) out.println(spc.spc + " * <PRE>");
        out.println(cur.getEbnfProduction(spc));
        if (Globals.javaDocComments) out.println(spc.spc + " * </PRE>");
        out.println(spc.spc + " */");
        out.print(spc.spc + "public R visit");
        out.println("(" + name + " n, A argu) {");

        spc.updateSpc(+1);
        out.println(spc.spc + "R _ret=null;");
        for (Enumeration f = cur.getNameList().elements(); f.hasMoreElements(); )
          out.println(spc.spc + "n." + (String) f.nextElement() + ".accept(this, argu);");
        out.println(spc.spc + "return _ret;");
        spc.updateSpc(-1);
        out.println(spc.spc + "}\n");
      }

      spc.updateSpc(-1);
      out.println(spc.spc + "}");

      out.flush();
      out.close();
    } catch (IOException e) {
      Errors.hardErr("Could not generate " + outFilename);
    }
  }
 /**
  * Set file status. Also updates menu state accordingly.
  *
  * @param newStatus New status: EDITED, RUNNABLE, etc, see list above.
  */
 public static void set(int newStatus) {
   systemStatus = newStatus;
   Globals.getGui().setMenuState(systemStatus);
 }