/**
   * Generates code to cast an OJ expression as another type. The target type is limited to being an
   * AssignableValue. See class description for an explanation of the arguments.
   *
   * @return resulting expression. If lhsExp was provided, assigns this expression to lhsExp.
   */
  public Expression convertCastToAssignableValue(
      FarragoRexToOJTranslator translator,
      StatementList stmtList,
      RelDataType lhsType,
      RelDataType rhsType,
      Expression lhsExp,
      Expression rhsExp) {
    CastHelper helper =
        new CastHelper(translator, stmtList, null, lhsType, rhsType, lhsExp, rhsExp);

    return helper.castToAssignableValue();
  }
  /**
   * Generates code to cast an OJ expression as another type. See class description for an
   * explanation of arguments.
   *
   * @return resulting expression. If lhsExp was provided, assigns this expression to lhsExp.
   */
  public Expression convertCastOrAssignment(
      FarragoRexToOJTranslator translator,
      StatementList stmtList,
      String targetName,
      RelDataType lhsType,
      RelDataType rhsType,
      Expression lhsExp,
      Expression rhsExp) {
    CastHelper helper =
        new CastHelper(translator, stmtList, targetName, lhsType, rhsType, lhsExp, rhsExp);

    return helper.implement();
  }
Beispiel #3
0
 public void processPacket(List<?> dp) {
   this.debug("processPacket(" + dp + ")");
   if (dp.size() < 1) {
     this.log("processPacket(..) decoded data is too small: " + dp);
     return;
   }
   assert dp.size() >= 1;
   String type = CastHelper.cast(dp.get(0), String.class);
   Method m = this.handlers.get(type);
   if (m == null) {
     this.log("processPacket(..) unhandled packet: " + type);
     return;
   }
   Class<?>[] paramTypes = m.getParameterTypes();
   assert dp.size() == (paramTypes.length + 1);
   Object[] params = new Object[paramTypes.length];
   int index = 0;
   for (Class<?> paramType : paramTypes) {
     assert paramType != null;
     Object v = dp.get(1 + index);
     params[index] = this.cast(v, paramType);
     index++;
   }
   this.invokePacketMethod(m, params);
 }
Beispiel #4
0
 /** 校验IC卡密码 每次写卡之前都需要校验密码 */
 public void chkPwd(String cardPwd) {
   byte[] key_buffer = new byte[50];
   int rc;
   CastHelper.AsciiToHex(cardPwd, key_buffer);
   rc = reader.csc_4442(0, 3, key_buffer);
   if (rc == 0) {
     ToastHelper.showShort(mActivity, "密码正确");
   } else {
     ToastHelper.showShort(mActivity, "密码错误");
   }
 }
  // implement FarragoOJRexImplementor
  public Expression implementFarrago(
      FarragoRexToOJTranslator translator, RexCall call, Expression[] operands) {
    RelDataType lhsType = call.getType();
    RelDataType rhsType = call.operands[0].getType();
    Expression rhsExp = operands[0];

    SqlTypeName lhsTypeName = lhsType.getSqlTypeName();
    if ((lhsTypeName == SqlTypeName.CURSOR) || (lhsTypeName == SqlTypeName.COLUMN_LIST)) {
      // Conversion should already have been taken care of outside.
      return rhsExp;
    }

    // NOTE jvs 19-Nov-2008:  In some cases (e.g. FRG-273) a cast
    // may be illegal at the SQL level, but allowable as part of
    // implementation, so don't try to enforce
    // SqlTypeUtil.canCastFrom here.  Anything which was supposed
    // to have been prevented should already have been caught
    // by the validator.

    CastHelper helper =
        new CastHelper(translator, null, call.toString(), lhsType, rhsType, null, rhsExp);

    return helper.implement();
  }
Beispiel #6
0
  /**
   * 将给定字符串写入到IC卡中指定位置
   *
   * @param offset
   * @param cardData
   */
  public void writeCard(int offset, String cardData, String cardPwd) {
    if (reader.ic_init(mActivity, 0, 0) == 0) {
      chkPwd(cardPwd);

      byte[] data_buffer = new byte[256];

      CastHelper.AsciiToHex(cardData, data_buffer);
      int rc;
      rc = reader.swr_4442(0, offset, cardData.length() / 2, data_buffer);
      if (0 == rc) {
        ToastHelper.showShort(mActivity, "写卡成功");
      } else {
        ToastHelper.showShort(mActivity, "写卡失败");
      }
    }
    reader.ic_exit(0);
  }
Beispiel #7
0
  public String readCard(int offset, int len) {
    String result = null;
    if (reader.ic_init(mActivity, 0, 0) == 0) {
      ToastHelper.showShort(mActivity, "连接成功");

      byte[] data_buffer = new byte[256];
      for (int i = 0; i < data_buffer.length; i++) {
        data_buffer[i] = (byte) 0;
      }
      int rc;
      rc = reader.srd_4442(0, offset, len, data_buffer);

      if (0 == rc) {
        result = CastHelper.get_recv_data_str(data_buffer, len);
      } else {
        ToastHelper.showShort(mActivity, "读卡失败");
      }
    } else {
      ToastHelper.showShort(mActivity, "写卡器连接失败");
    }
    return result;
  }