コード例 #1
0
 private void writeDoCommand(PrintWriter pw, String indent) {
   String str = indent + "fCommandStatus = fUMart.do" + fCmdDef.getCmdName() + "(";
   str += Utility.makeFieldString((String) fCmdDef.getReturnData().get("NAME"));
   str += ", userID";
   Iterator itr = fCmdDef.getArgList().iterator();
   while (itr.hasNext()) {
     HashMap argInfo = (HashMap) itr.next();
     String argName = Utility.makeFieldString((String) argInfo.get("NAME"));
     str += ", " + argName;
   }
   str += ");";
   pw.println(str);
 }
コード例 #2
0
 private void writeDataClear(PrintWriter pw, String indent) {
   String str = indent;
   str += Utility.makeFieldString((String) fCmdDef.getReturnData().get("NAME"));
   str += ".clear();";
   pw.println(str);
 }
コード例 #3
0
  public void writeCommandServer() throws FileNotFoundException {
    String className = "USC" + fCmdDef.getCmdName();
    PrintWriter pw = new PrintWriter(new FileOutputStream(className + ".java"));
    System.out.println("Writing " + className + ".java ...");
    pw.println("package cmdServer;");
    pw.println();
    pw.println("import java.util.ArrayList;");
    pw.println("import java.util.HashMap;");
    pw.println("import java.util.Iterator;");
    pw.println("import serverNet.UAgent;");
    pw.println("import serverNet.UMartNetwork;");
    pw.println("import cmdCore.ICommand;");
    String coreClassName = "UC" + fCmdDef.getCmdName() + "Core";
    pw.println("import cmdCore." + coreClassName + ";");
    pw.println("import cmdCore.UCommandStatus;");
    pw.println();
    pw.println(
        "public class "
            + className
            + " extends UC"
            + fCmdDef.getCmdName()
            + "Core implements IServerCmd {");
    pw.println();
    pw.println("  /** このコマンドを実行したエージェント */");
    pw.println("  private UAgent fAgent;");
    pw.println();
    pw.println("  /** サーバーへの参照 */");
    pw.println("  UMartNetwork fUMart;");
    pw.println();
    pw.println("  /** コンストラクタ */");
    pw.println("  public " + className + "() {");
    pw.println("    super();");
    pw.println("    fAgent = null;");
    pw.println("    fUMart = null;");
    pw.println("  }");
    pw.println();
    pw.println("  public void setConnection(UAgent agent, UMartNetwork umart) {");
    pw.println("    fAgent = agent;");
    pw.println("    fUMart = umart;");
    pw.println("  }");
    pw.println();
    pw.println("  public UCommandStatus doIt() {");
    pw.println("    try {");
    pw.println("      int userID = fAgent.getOffice().getUserID();");
    writeDataClear(pw, "      ");
    writeDoCommand(pw, "      ");
    pw.println("      if ( fCommandStatus.getStatus() ) {");
    pw.println("        fAgent.sendMessage(\"+ACCEPT\");");
    String type = (String) fCmdDef.getReturnData().get("TYPE");
    String fieldName = Utility.makeFieldString((String) fCmdDef.getReturnData().get("NAME"));
    if (type.equals("HashMap")) {
      writeSendingHashMap(pw, "        ", fCmdDef.getReturnData(), fieldName);
    } else if (type.equals("ArrayList")) {
      writeSendingArrayList(pw, "        ", fCmdDef.getReturnData(), fieldName);
    }
    pw.println("      } else {");
    pw.println("        fAgent.sendMessage(\"+ERROR \" + fCommandStatus.getErrorCode());");
    pw.println("        fAgent.sendMessage(fCommandStatus.getErrorMessage());");
    pw.println("      }");

    pw.println("    } catch (Exception e) {");
    pw.println("      fAgent.sendMessage(\"+ERROR \" + ICommand.INVALID_ARGUMENTS);");
    pw.println("      fAgent.sendMessage(\"USAGE: " + fCmdDef.getCmdName().toUpperCase() + "\");");
    pw.println("    }");
    pw.println("    fAgent.flushMessage();");
    pw.println("    return fCommandStatus;");
    pw.println("  }");
    pw.println();
    pw.println("}");
    pw.close();
  }