コード例 #1
0
  private BECodec getBECodec(String serviceName) {
    if (serviceBECodecs == null) {
      serviceBECodecs = new HashMap(2);
    }
    BECodec codec = (BECodec) serviceBECodecs.get(serviceName);
    if (codec == null) {
      try {
        codec = (BECodec) Class.forName(serviceName + "BECodec").newInstance();
      } catch (Exception e) {
        // The service does not have a BECodec --> Use a dummy one
        codec =
            new BECodec() {
              public Object[] decodeParams(String methodName, Object[] methodParams) {
                return methodParams;
              }

              public Object encodeResult(String methodName, Object result) {
                return result;
              }
            };
      }
      serviceBECodecs.put(serviceName, codec);
    }
    return codec;
  }
コード例 #2
0
  Object processInformation(Information info) {
    // -------------------------------------------

    Account acc = (Account) accounts.get(info.getAccountId());
    if (acc == null) return newProblem(ACCOUNT_NOT_FOUND);

    java.util.Date date = new java.util.Date();
    Operation op = new Operation(); // <-- Apply admin charge
    op.setType(ADMIN);
    op.setAmount(info.getType() == BALANCE ? BAL_CHARGE : OPER_CHARGE);
    acc.setBalance(acc.getBalance() - op.getAmount());
    op.setBalance(acc.getBalance());
    op.setAccountId(acc.getId());
    op.setDate(date);
    List l = (List) operations.get(acc.getId());
    l.add(op);
    operations.put(acc.getId(), l);

    if (info.getType() == BALANCE) return acc;
    if (info.getType() == OPERATIONS) return l;
    return null;
  }
コード例 #3
0
  Object processOperation(MakeOperation mo) {
    // -------------------------------------------

    Account acc = (Account) accounts.get(mo.getAccountId());
    if (acc == null) return newProblem(ACCOUNT_NOT_FOUND);
    if (mo.getAmount() <= 0) return newProblem(ILLEGAL_OPERATION);

    if (mo.getType() != DEPOSIT && mo.getType() != WITHDRAWAL) return null;
    if (mo.getType() == DEPOSIT) acc.setBalance(acc.getBalance() + mo.getAmount());
    else if (mo.getType() == WITHDRAWAL) {
      if (mo.getAmount() > acc.getBalance()) return newProblem(NOT_ENOUGH_MONEY);
      acc.setBalance(acc.getBalance() - mo.getAmount());
    }
    Operation op = new Operation();
    op.setType(mo.getType());
    op.setAmount(mo.getAmount());
    op.setAccountId(acc.getId());
    op.setDate(new java.util.Date());
    List l = (List) operations.get(acc.getId());
    l.add(op);
    operations.put(acc.getId(), l);
    return acc;
  }
コード例 #4
0
 public AgentImage addAgentImage(AID id, AgentImage img) {
   return (AgentImage) agentImages.put(id, img);
 }
コード例 #5
0
 /**
  * Register the bounding between an handler and a key.
  *
  * @param key this is the key that must be later returned by the method <code>getSelectionKey
  *     </code> when the passed Behaviour must be selected
  * @param h the handler for this key
  */
 public void registerHandler(Object key, Behaviour h) {
   handlers.put(key, h);
 }