Beispiel #1
0
  /** Create a new exception API object. */
  public static Value __construct(
      Env env, @This ObjectValue value, @Optional StringValue message, @Optional("0") int code) {
    value.putField(env, "message", message);
    value.putField(env, "code", LongValue.create(code));

    Location location = env.getLocation();

    if (location != null) {
      if (location.getFileName() != null) {
        value.putField(env, "file", env.createString(location.getFileName()));
      } else {
        value.putField(env, "file", env.createString("unknown"));
      }

      value.putField(env, "line", LongValue.create(location.getLineNumber()));
    }

    value.putField(env, "trace", ErrorModule.debug_backtrace(env, false));
    BiancaException e = new BiancaException();
    e.fillInStackTrace();

    value.putField(env, "_biancaException", env.wrapJava(e));

    return value;
  }
Beispiel #2
0
  @Test
  public void testCursorSeekRange() throws Exception {
    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(8);
    k1.putLong(0, 18);
    v1.putLong(0, 19);
    k2.putLong(0, 20);
    v2.putLong(0, 21);

    try (Transaction tx = env.createWriteTransaction()) {
      try (Cursor cursor = db.openCursor(tx)) {
        cursor.put(k1, v1, 0);
        cursor.put(k2, v2, 0);
      }
      tx.commit();
    }

    try (Transaction tx = env.createReadTransaction()) {
      try (Cursor cursor = db.openCursor(tx)) {
        DirectBuffer k = new DirectBuffer(byteBuffer);
        DirectBuffer v = new DirectBuffer();
        k.putLong(0, 10);

        cursor.seekPosition(k, v, SeekOp.RANGE);
        assertThat(k.getLong(0), is(18L));
        assertThat(v.getLong(0), is(19L));

        k.wrap(byteBuffer);
        k.putLong(0, 19);
        cursor.seekPosition(k, v, SeekOp.RANGE);
        assertThat(k.getLong(0), is(20L));
        assertThat(v.getLong(0), is(21L));
      }
    }
  }
Beispiel #3
0
  @Test
  public void testCursorPutAndGet() throws Exception {
    k1.putLong(0, 14);
    v1.putLong(0, 15);
    k2.putLong(0, 16);
    v2.putLong(0, 17);

    try (Transaction tx = env.createWriteTransaction()) {
      try (Cursor cursor = db.openCursor(tx)) {
        cursor.put(k1, v1, 0);
        cursor.put(k2, v2, 0);
      }
      tx.commit();
    }

    DirectBuffer k = new DirectBuffer();
    DirectBuffer v = new DirectBuffer();

    try (Transaction tx = env.createReadTransaction()) {
      try (Cursor cursor = db.openCursor(tx)) {
        cursor.position(k, v, GetOp.FIRST);
        assertThat(k.getLong(0), is(14L));
        assertThat(v.getLong(0), is(15L));

        cursor.position(k, v, GetOp.NEXT);
        assertThat(k.getLong(0), is(16L));
        assertThat(v.getLong(0), is(17L));
      }
    }
  }
 public Construct exec(Target t, Env environment, Construct... args)
     throws ConfigRuntimeException {
   int x;
   int z;
   MCWorld w;
   if (args.length == 2) {
     MCWorld defaultWorld =
         environment.GetPlayer() == null ? null : environment.GetPlayer().getWorld();
     MCLocation l = ObjectGenerator.GetGenerator().location(args[0], defaultWorld, t);
     x = l.getBlockX();
     z = l.getBlockZ();
     w = l.getWorld();
   } else {
     x = (int) Static.getInt(args[0]);
     z = (int) Static.getInt(args[1]);
     if (args.length == 3) {
       w = environment.GetPlayer().getWorld();
     } else {
       w = Static.getServer().getWorld(args[2].val());
     }
   }
   MCBiomeType bt;
   try {
     bt = MCBiomeType.valueOf(args[args.length - 1].val());
   } catch (IllegalArgumentException e) {
     throw new ConfigRuntimeException(
         "The biome type \"" + args[1].val() + "\" does not exist.",
         ExceptionType.FormatException,
         t);
   }
   w.setBiome(x, z, bt);
   return new CVoid(t);
 }
  /**
   * Get/Put Error Info in String
   *
   * @param ctx context
   * @param errorsOnly if true errors otherwise log
   * @return error info
   */
  public String getErrorInfo(Properties ctx, boolean errorsOnly) {
    checkContext();

    StringBuffer sb = new StringBuffer();
    //
    if (errorsOnly) {
      LinkedList<LogRecord[]> m_history = (LinkedList<LogRecord[]>) Env.getCtx().get(HISTORY_KEY);
      for (int i = 0; i < m_history.size(); i++) {
        sb.append("-------------------------------\n");
        LogRecord[] records = (LogRecord[]) m_history.get(i);
        for (int j = 0; j < records.length; j++) {
          LogRecord record = records[j];
          sb.append(getFormatter().format(record));
        }
      }
    } else {
      LinkedList<LogRecord> m_logs = (LinkedList<LogRecord>) Env.getCtx().get(LOGS_KEY);
      for (int i = 0; i < m_logs.size(); i++) {
        LogRecord record = (LogRecord) m_logs.get(i);
        sb.append(getFormatter().format(record));
      }
    }
    sb.append("\n");
    CLogMgt.getInfo(sb);
    CLogMgt.getInfoDetail(sb, ctx);
    //
    return sb.toString();
  } //	getErrorInfo
Beispiel #6
0
  synchronized VirtualMachine open() {
    if (connector instanceof LaunchingConnector) {
      vm = launchTarget();
    } else if (connector instanceof AttachingConnector) {
      vm = attachTarget();
    } else if (connector instanceof ListeningConnector) {
      vm = listenTarget();
    } else {
      throw new InternalError(MessageOutput.format("Invalid connect type"));
    }
    vm.setDebugTraceMode(traceFlags);
    if (vm.canBeModified()) {
      setEventRequests(vm);
      resolveEventRequests();
    }
    /*
     * Now that the vm connection is open, fetch the debugee
     * classpath and set up a default sourcepath.
     * (Unless user supplied a sourcepath on the command line)
     * (Bug ID 4186582)
     */
    if (Env.getSourcePath().length() == 0) {
      if (vm instanceof PathSearchingVirtualMachine) {
        PathSearchingVirtualMachine psvm = (PathSearchingVirtualMachine) vm;
        Env.setSourcePath(psvm.classPath());
      } else {
        Env.setSourcePath(".");
      }
    }

    return vm;
  }
Beispiel #7
0
 @Before
 public void before() throws IOException {
   String path = tmp.newFolder().getCanonicalPath();
   env = new Env();
   env.setMapSize(16 * 4096);
   env.open(path);
   db = env.openDatabase();
 }
Beispiel #8
0
 public Env<AttrContext> getTopLevelEnv(JCCompilationUnit tree) {
   Env<AttrContext> localEnv = new Env<AttrContext>(tree, new AttrContext());
   localEnv.toplevel = tree;
   localEnv.enclClass = predefClassDef;
   localEnv.info.scope = tree.namedImportScope;
   localEnv.info.lint = lint;
   return localEnv;
 }
Beispiel #9
0
 void checkStr(String s, double d) {
   Env env = Exec2.exec(s);
   assertFalse("Should be scalar result not Frame: " + s, env.isAry());
   assertFalse(env.isFcn());
   double res = env.popDbl();
   assertEquals(d, res, d / 1e8);
   env.remove_and_unlock();
   debug_print(s);
 }
Beispiel #10
0
 /**
  * Create a fresh environment for class bodies. This will create a fresh scope for local symbols
  * of a class, referred to by the environments info.scope field. This scope will contain - symbols
  * for this and super - symbols for any type parameters In addition, it serves as an anchor for
  * scopes of methods and initializers which are nested in this scope via Scope.dup(). This scope
  * should not be confused with the members scope of a class.
  *
  * @param tree The class definition.
  * @param env The environment current outside of the class definition.
  */
 public Env<AttrContext> classEnv(JCClassDecl tree, Env<AttrContext> env) {
   Env<AttrContext> localEnv = env.dup(tree, env.info.dup(new Scope(tree.sym)));
   localEnv.enclClass = tree;
   localEnv.outer = env;
   localEnv.info.isSelfCall = false;
   localEnv.info.lint = null; // leave this to be filled in by Attr,
   // when annotations have been processed
   return localEnv;
 }
  private void fullAssociated() {

    boolean associated = true;

    String SQL =
        "Select * "
            + "from XX_VMR_REFERENCEMATRIX "
            + "where M_product IS NULL AND XX_VMR_PO_LINEREFPROV_ID="
            + LineRefProv.get_ID();

    try {
      PreparedStatement pstmt = DB.prepareStatement(SQL, null);
      ResultSet rs = pstmt.executeQuery();

      while (rs.next()) {
        associated = false;
      }

      rs.close();
      pstmt.close();

    } catch (Exception a) {
      log.log(Level.SEVERE, SQL, a);
    }

    if (associated == true) {
      String SQL10 =
          "UPDATE XX_VMR_PO_LineRefProv "
              + " SET XX_ReferenceIsAssociated='Y'"
              + " WHERE XX_VMR_PO_LineRefProv_ID="
              + LineRefProv.getXX_VMR_PO_LineRefProv_ID();

      DB.executeUpdate(null, SQL10);

      //			LineRefProv.setXX_ReferenceIsAssociated(true);
      //			LineRefProv.save();

      int dialog = Env.getCtx().getContextAsInt("#Dialog_Associate_Aux");

      if (dialog == 1) {
        ADialog.info(m_WindowNo, m_frame, "MustRefresh");
        Env.getCtx().remove("#Dialog_Associate_Aux");
      }

    } else {
      String SQL10 =
          "UPDATE XX_VMR_PO_LineRefProv "
              + " SET XX_ReferenceIsAssociated='N'"
              + " WHERE XX_VMR_PO_LineRefProv_ID="
              + LineRefProv.getXX_VMR_PO_LineRefProv_ID();

      DB.executeUpdate(null, SQL10);
      //			LineRefProv.setXX_ReferenceIsAssociated(false);
      //			LineRefProv.save();
    }
  }
Beispiel #12
0
  public static Value __construct(Env env, @Optional String queueName) {
    JMSQueue queue = JMSModule.message_get_queue(env, queueName, null);

    if (queue == null) {
      env.warning(L.l("'{0}' is an unknown JMSQueue", queueName));
      return NullValue.NULL;
    }

    return env.wrapJava(queue);
  }
Beispiel #13
0
 public Construct exec(Target t, Env environment, Construct... args)
     throws ConfigRuntimeException {
   MCLocation l =
       ObjectGenerator.GetGenerator()
           .location(
               args[0],
               environment.GetPlayer() == null ? null : environment.GetPlayer().getWorld(),
               t);
   return new CBoolean(l.getBlock().isSign(), t);
 }
Beispiel #14
0
 /**
  * Create a fresh environment for toplevels.
  *
  * @param tree The toplevel tree.
  */
 Env<AttrContext> topLevelEnv(JCCompilationUnit tree) {
   Env<AttrContext> localEnv = new Env<AttrContext>(tree, new AttrContext());
   localEnv.toplevel = tree;
   localEnv.enclClass = predefClassDef;
   tree.namedImportScope = new Scope.ImportScope(tree.packge);
   tree.starImportScope = new Scope.ImportScope(tree.packge);
   localEnv.info.scope = tree.namedImportScope;
   localEnv.info.lint = lint;
   return localEnv;
 }
Beispiel #15
0
  private void readObject(ObjectInputStream in) throws ClassNotFoundException, IOException {
    _env = Env.getInstance();

    _classDef = _env.getJavaClassDefinition((String) in.readObject());

    int id = _env.getQuercus().getClassId(_classDef.getName());

    setQuercusClass(_env.createQuercusClass(id, _classDef, null));

    _object = in.readObject();
  }
Beispiel #16
0
 void checkStr(String s, String err) {
   Env env = null;
   try {
     env = Exec2.exec(s);
     env.remove_and_unlock();
     fail(); // Supposed to throw; reaching here is an error
   } catch (IllegalArgumentException e) {
     assertEquals(err, e.getMessage());
   }
   debug_print(s);
 }
Beispiel #17
0
  private GettextDomainMap getDomains(Env env)
  {
    Object val = env.getSpecialValue("caucho.gettext_domains");

    if (val == null) {
      val = new GettextDomainMap();

      env.setSpecialValue("caucho.gettext_domains", val);
    }
    
    return (GettextDomainMap) val;
  }
Beispiel #18
0
    public Construct exec(Target t, Env environment, Construct... args)
        throws ConfigRuntimeException {
      MCLocation l =
          ObjectGenerator.GetGenerator()
              .location(
                  args[0],
                  environment.GetPlayer() == null ? null : environment.GetPlayer().getWorld(),
                  t);
      if (l.getBlock().isSign()) {
        String line1 = "";
        String line2 = "";
        String line3 = "";
        String line4 = "";
        if (args.length == 2 && args[1] instanceof CArray) {
          CArray ca = (CArray) args[1];
          if (ca.size() >= 1) {
            line1 = ca.get(0, t).val();
          }
          if (ca.size() >= 2) {
            line2 = ca.get(1, t).val();
          }
          if (ca.size() >= 3) {
            line3 = ca.get(2, t).val();
          }
          if (ca.size() >= 4) {
            line4 = ca.get(3, t).val();
          }

        } else {
          if (args.length >= 2) {
            line1 = args[1].val();
          }
          if (args.length >= 3) {
            line2 = args[2].val();
          }
          if (args.length >= 4) {
            line3 = args[3].val();
          }
          if (args.length >= 5) {
            line4 = args[4].val();
          }
        }
        MCSign s = l.getBlock().getSign();
        s.setLine(0, line1);
        s.setLine(1, line2);
        s.setLine(2, line3);
        s.setLine(3, line4);
        return new CVoid(t);
      } else {
        throw new ConfigRuntimeException(
            "The block at the specified location is not a sign", ExceptionType.RangeException, t);
      }
    }
Beispiel #19
0
    public String toString() {
      String s = "defVer=" + _defaultVersion + " :: ";

      for (String ver : _versions.keySet()) {

        Env env = _versions.get(ver);

        s = s + env.toString() + "|";
      }

      return s;
    }
Beispiel #20
0
  @Override
  protected void varDumpImpl(
      Env env, WriteStream out, int depth, IdentityHashMap<Value, String> valueSet)
      throws IOException {
    Value oldThis = env.setThis(this);

    try {
      if (!_classDef.varDumpImpl(env, this, _object, out, depth, valueSet))
        out.print("resource(" + toString(env) + ")"); // XXX:
    } finally {
      env.setThis(oldThis);
    }
  }
Beispiel #21
0
  @Test
  public void shouldBuildRequestForSimpleGet() throws Exception {
    Env env = new Env();

    env.REQUEST_METHOD = "GET";
    env.PATH_INFO = "/test";
    env.QUERY_STRING = "id=99";

    RackRequest result = new RackRequest(env);
    assertEquals("GET", result.requestMethod());
    assertEquals("/test", result.pathInfo());
    assertEquals(jsonMap("{\"id\":\"99\"}"), result.params());
  }
Beispiel #22
0
 @Before
 public void before() throws IOException {
   String path = dir.newFolder().getCanonicalPath();
   if (db != null) {
     db.close();
   }
   if (env != null) {
     env.close();
   }
   env = new Env();
   env.open(path);
   db = env.openDatabase("test");
 }
Beispiel #23
0
  /**
   * Test
   *
   * @param args ignored
   */
  public static void main(String[] args) {

    Adempiere.startupEnvironment(false);
    CLogMgt.setLevel(Level.CONFIG);

    ColumnEncryption columnEncryption = new ColumnEncryption();

    int processId = 328; // AD_ColumnEncryption
    int columnId = 417; // AD_User - Password
    Env.setContext(Env.getCtx(), I_AD_Column.COLUMNNAME_AD_Column_ID, columnId);

    MPInstance instance;
    MPInstancePara instanceParameters;

    instance = new MPInstance(Env.getCtx(), processId, columnId);
    instance.saveEx();

    instanceParameters = new MPInstancePara(instance, 10);
    instanceParameters.setParameter(I_AD_Column.COLUMNNAME_IsEncrypted, true);
    instanceParameters.saveEx();

    instanceParameters = new MPInstancePara(instance, 20);
    instanceParameters.setParameter("ChangeSetting", true);
    instanceParameters.saveEx();

    ProcessInfo pi = new ProcessInfo("AD_ColumnEncryption", processId);
    pi.setRecord_ID(instance.getRecord_ID());
    pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());
    pi.setAD_Client_ID(0);
    pi.setAD_User_ID(100);

    columnEncryption.startProcess(Env.getCtx(), pi, null);

    /*List<MUser> users = new Query(Env.getCtx(), I_AD_User.Table_Name , "Password IS NOT NULL", null).list();
    for (MUser user : users)
    {
        user.setPassword(user.getPassword());
        user.saveEx();
    }*/

    processId = 53259; // Convert password to hashed

    pi = new ProcessInfo("AD_User_HashPassword", processId);
    pi.setAD_Client_ID(0);
    pi.setAD_User_ID(100);

    HashPasswords process = new HashPasswords();
    process.startProcess(Env.getCtx(), pi, null);
  }
Beispiel #24
0
    public Construct exec(Target t, Env env, Construct... args)
        throws CancelCommandException, ConfigRuntimeException {
      double x = 0;
      double y = 0;
      double z = 0;
      float size = 3;
      MCWorld w = null;
      MCPlayer m = null;

      if (args.length == 2 && args[1] instanceof CInt) {
        CInt temp = (CInt) args[1];
        size = temp.getInt();
      }

      if (size > 100) {
        throw new ConfigRuntimeException(
            "A bit excessive, don't you think? Let's scale that back some, huh?",
            ExceptionType.RangeException,
            t);
      }

      if (!(args[0] instanceof CArray)) {
        throw new ConfigRuntimeException(
            "Expecting an array at parameter 1 of explosion", ExceptionType.CastException, t);
      }

      MCLocation loc = ObjectGenerator.GetGenerator().location(args[0], w, t);
      w = loc.getWorld();
      x = loc.getX();
      z = loc.getZ();
      y = loc.getY();

      if (w == null) {
        if (!(env.GetCommandSender() instanceof MCPlayer)) {
          throw new ConfigRuntimeException(
              this.getName()
                  + " needs a world in the location array, or a player so it can take the current world of that player.",
              ExceptionType.PlayerOfflineException,
              t);
        }

        m = env.GetPlayer();
        w = m.getWorld();
      }

      w.explosion(x, y, z, size);
      return new CVoid(t);
    }
Beispiel #25
0
  private static void addFormFile(
      Env env,
      ArrayValue files,
      String fileName,
      String tmpName,
      String mimeType,
      long fileLength,
      boolean addSlashesToValues,
      long maxFileSize) {
    ArrayValue entry = new ArrayValueImpl();
    int error;

    // php/1667
    long uploadMaxFilesize = env.getIniBytes("upload_max_filesize", 2 * 1024 * 1024);

    if (fileName.length() == 0)
      // php/0864
      error = FileModule.UPLOAD_ERR_NO_FILE;
    else if (fileLength > uploadMaxFilesize) error = FileModule.UPLOAD_ERR_INI_SIZE;
    else if (fileLength > maxFileSize) error = FileModule.UPLOAD_ERR_FORM_SIZE;
    else error = FileModule.UPLOAD_ERR_OK;

    addFormValue(env, entry, "name", env.createString(fileName), null, addSlashesToValues);

    long size;

    if (error != FileModule.UPLOAD_ERR_INI_SIZE) {
      size = fileLength;
    } else {
      mimeType = "";
      tmpName = "";
      size = 0;
    }

    if (mimeType != null) {
      addFormValue(env, entry, "type", env.createString(mimeType), null, addSlashesToValues);

      entry.put("type", mimeType);
    }

    addFormValue(env, entry, "tmp_name", env.createString(tmpName), null, addSlashesToValues);

    addFormValue(env, entry, "error", LongValue.create(error), null, addSlashesToValues);

    addFormValue(env, entry, "size", LongValue.create(size), null, addSlashesToValues);

    addFormValue(env, files, null, entry, null, addSlashesToValues);
  }
Beispiel #26
0
 public Env dup() {
   Env env = new Env();
   env.next = this;
   env.outer = this.outer;
   env.packge = this.packge;
   env.enclosingClass = this.enclosingClass;
   env.scope = this.scope;
   env.namedImports = this.namedImports;
   env.starImports = this.starImports;
   env.staticStarImports = this.staticStarImports;
   return env;
 }
Beispiel #27
0
  /**
   * Sets the field metadata cursor to the given offset. The next call to mysqli_fetch_field() will
   * retrieve the field definition of the column associated with that offset.
   *
   * @param env the PHP executing environment
   * @return previous value of field cursor
   */
  public boolean field_seek(Env env, int offset) {
    boolean success = setFieldOffset(offset);

    if (!success) env.invalidArgument("field", offset);

    return success;
  }
Beispiel #28
0
  @Override
  public Value clone(Env env) {
    Object obj = null;

    if (_object != null) {
      if (!(_object instanceof Cloneable)) {
        return env.error(
            L.l("Java class {0} does not implement Cloneable", _object.getClass().getName()));
      }

      Class<?> cls = _classDef.getType();

      try {
        Method method = cls.getMethod("clone", new Class[0]);
        method.setAccessible(true);

        obj = method.invoke(_object);
      } catch (NoSuchMethodException e) {
        throw new QuercusException(e);
      } catch (InvocationTargetException e) {
        throw new QuercusException(e.getCause());
      } catch (IllegalAccessException e) {
        throw new QuercusException(e);
      }
    }

    return new JavaValue(env, obj, _classDef, getQuercusClass());
  }
Beispiel #29
0
 @Test
 public void testIteration() {
   k1.putLong(0, 18);
   v1.putLong(0, 19);
   k2.putLong(0, 20);
   v2.putLong(0, 21);
   db.put(k1, v1, 0);
   db.put(k2, v2, 0);
   List<Long> result = new ArrayList<>();
   try (Transaction tx = env.createWriteTransaction()) {
     try (Cursor cursor = db.openCursor(tx)) {
       DirectBuffer k = new DirectBuffer();
       DirectBuffer v = new DirectBuffer();
       for (int rc = cursor.position(k, v, FIRST);
           rc != NOTFOUND;
           rc = cursor.position(k, v, NEXT)) {
         result.add(k.getLong(0));
       }
     }
     tx.commit();
   }
   assertThat(result.size(), is(2));
   assertThat(result.get(0), is(18L));
   assertThat(result.get(1), is(20L));
 }
  @Override
  protected void onCreate(Env env) {
    for (Class<? extends ProfilerFrontEnd> frontEnd : installedFrontEnds) {
      try {
        frontEnd.newInstance().onAttach(this);
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    env.getInstrumenter()
        .attachFactory(
            SourceSectionFilter.newBuilder().tagIs(InstrumentationTestLanguage.STATEMENT).build(),
            new ExecutionEventNodeFactory() {
              public ExecutionEventNode create(final EventContext context) {
                return new ExecutionEventNode() {
                  private final Counter counter =
                      createCounter(context.getInstrumentedSourceSection());

                  @Override
                  public void onReturnValue(VirtualFrame vFrame, Object result) {
                    counter.increment();
                  }
                };
              }
            });
  }