Exemplo n.º 1
0
 /** Generates the code for the checker. */
 protected void addChecker(
     Context ctxt,
     MibNode node,
     String description,
     String syntax,
     String var,
     StringBuffer buff) {
   buff.append(
       Def.TAB
           + "/**\n"
           + Def.TAB
           + " * "
           + MessageHandler.getMessage("generate.mbean.comment.checker", var)
           + "\n"
           + Def.TAB
           + " */\n");
   buff.append(
       Def.TAB + Def.PUBLIC + Def.VOID + Def.CHECK + var + "(" + syntax + "x) " + accessThrows);
   buff.append(
       Def.TAB2
           + "//\n"
           + Def.TAB2
           + "// "
           + MessageHandler.getMessage("generate.mbean.comment.checker.policy")
           + "\n"
           + Def.TAB2
           + "//\n");
   buff.append(Def.TAB + Def.RBRACE + "\n");
 }
Exemplo n.º 2
0
 private void addRowStatusSetter(
     Context ctxt,
     MibNode node,
     String description,
     String syntax,
     String var,
     StringBuffer buff) {
   buff.append(
       Def.TAB
           + "/**\n"
           + Def.TAB
           + " * "
           + MessageHandler.getMessage("generate.mbean.comment.setter", var)
           + "\n"
           + Def.TAB
           + " * "
           + MessageHandler.getMessage("generate.mbean.comment." + "setter.rs.nochecker")
           + "\n"
           + Def.TAB
           + " * "
           + MessageHandler.getMessage("generate.mbean.comment." + "checker.rs.override")
           + "\n"
           + Def.TAB
           + " */\n");
   buff.append(
       Def.TAB + Def.PUBLIC + Def.VOID + Def.SET + var + "(" + syntax + "x) " + accessThrows);
   buff.append(Def.TAB2 + var + " = x" + Def.SEMICOLON);
   buff.append(Def.TAB + Def.RBRACE + "\n");
 }
Exemplo n.º 3
0
  protected void buildConstructorHeader() throws IOException {
    constructor1.append(
        "\n"
            + Def.TAB
            + "/**\n"
            + Def.TAB
            + " * "
            + MessageHandler.getMessage("generate.mbean.comment.constr", symboleName)
            + "\n"
            + Def.TAB
            + " * "
            + MessageHandler.getMessage("generate.mbean.comment.noRegistration")
            + "\n"
            + Def.TAB
            + " */\n");
    constructor1.append(Def.TAB + Def.PUBLIC + symboleName + "(SnmpMib myMib)" + Def.LBRACE);

    constructor2.append(
        "\n"
            + Def.TAB
            + "/**\n"
            + Def.TAB
            + " * "
            + MessageHandler.getMessage("generate.mbean.comment.constr", symboleName)
            + "\n"
            + Def.TAB
            + " * "
            + MessageHandler.getMessage("generate.mbean.comment.registration")
            + "\n"
            + Def.TAB
            + " */\n");
    constructor2.append(
        Def.TAB + Def.PUBLIC + symboleName + "(SnmpMib myMib, MBeanServer server)" + Def.LBRACE);
  }
Exemplo n.º 4
0
    @Override
    public void close() throws IOException {
      bout.close();
      output.close();

      Iterator<MessageHandler> it = config.getMessagerHandlers();

      while (it.hasNext()) {
        MessageHandler handler = it.next();
        handler.handleRequest(url, bout.toByteArray());
      }
    }
Exemplo n.º 5
0
  @Override
  public InputStream getContent() throws IOException {
    InputStream in;

    try {
      successful = true;
      in = connection.getInputStream();
    } catch (IOException e) {
      successful = false;
      in = connection.getErrorStream();
      if (in == null) {
        throw e;
      }
    }

    String encoding = connection.getHeaderField("Content-Encoding");

    if (config.getMaxResponseSize() > 0) {
      in = new LimitingInputStream(config.getMaxResponseSize(), in);
    }

    if ("gzip".equals(encoding)) {
      in = new GZIPInputStream(in);
    }

    if (config.hasMessageHandlers() || config.isTraceMessage()) {
      byte[] bytes = FileUtil.toBytes(in);
      in = new ByteArrayInputStream(bytes);

      if (config.hasMessageHandlers()) {
        Iterator<MessageHandler> it = config.getMessagerHandlers();
        while (it.hasNext()) {
          MessageHandler handler = it.next();
          if (handler instanceof MessageHandlerWithHeaders) {
            ((MessageHandlerWithHeaders) handler)
                .handleResponse(url, bytes, connection.getHeaderFields());
          } else {
            handler.handleResponse(url, bytes);
          }
        }
      }

      if (config.isTraceMessage()) {
        new TeeInputStream(config, bytes);
      }
    }

    return in;
  }
Exemplo n.º 6
0
  public MbeanGenerator(ResourceManager mgr, MibNode aGroup, Context ctxt) throws IOException {
    super(mgr, aGroup, ctxt);

    gentype = ctxt.gentype;

    // Specify oid of the current bean ...
    //
    oid = node.getComputedOid();

    // Try to find a symbol to associate to the group
    //
    varName = node.getSymbolName();
    if (varName == null) varName = getClassName(node.getComputedOid());
    symboleName = getNodeSymbolName(node);

    Trace.info(MessageHandler.getMessage("generate.info.var", varName));

    // Open the file which will represent the M-bean.
    //
    out = openFile(symboleName + Def.JAVA);

    // Write generic header ...
    //
    writeHeader();

    // write our own header ...
    //
    writeClassDeclaration();

    // write the beginning of the constructor
    //
    buildConstructorHeader();
  }
Exemplo n.º 7
0
 private void addRowStatusChecker(
     Context ctxt,
     MibNode node,
     String description,
     String syntax,
     String var,
     StringBuffer buff) {
   buff.append(
       Def.TAB
           + "/**\n"
           + Def.TAB
           + " * "
           + MessageHandler.getMessage("generate.mbean.comment.checker", var)
           + "\n"
           + Def.TAB
           + " * "
           + MessageHandler.getMessage("generate.mbean.comment.checker.rs.deprecated")
           + "\n"
           + Def.TAB
           + " * "
           + MessageHandler.getMessage("generate.mbean.comment.checker.rs.override")
           + "\n"
           + Def.TAB
           + " */\n");
   buff.append(
       Def.TAB
           + Def.PUBLIC
           + Def.VOID
           + Def.CHECK
           + var
           + "("
           + syntax
           + "x) "
           + BeanGenerator.accessThrows);
   buff.append(
       Def.TAB2
           + "//\n"
           + Def.TAB2
           + "// "
           + MessageHandler.getMessage("generate.mbean.comment.checker.rs.policy")
           + "\n"
           + Def.TAB2
           + "//\n");
   buff.append(Def.TAB + Def.RBRACE + "\n");
 }
Exemplo n.º 8
0
  protected void addCacheVar(MibNode node, String syntax, long fixed, String init, String var)
      throws IOException {
    // Put some comments ...
    //
    var_list.append(
        Def.TAB
            + "/**\n"
            + Def.TAB
            + " * "
            + MessageHandler.getMessage("generate.mbean.comment.varUse", var)
            + "\n"
            + Def.TAB
            + " * "
            + MessageHandler.getMessage("generate.mbean.comment.varOid", node.getOid())
            + "\n"
            + Def.TAB);
    if (fixed != -1) {
      var_list.append(
          " * "
              + MessageHandler.getMessage("generate.mbean.comment.varFix", String.valueOf(fixed))
              + "\n"
              + Def.TAB);
    }

    // Shall we put the description in the generated code ?
    // if yes call the formatDescription method ...
    // The answer is yes if requested !
    if (mib.isDescriptionOn()) {
      // Get the object definition associated to the node
      //
      ASTObjectTypeDefinition definition = node.getObjectType();
      String description = definition.getDefinition().getDescription();
      var_list.append(formatDescription(description));
    }
    var_list.append(" */\n");

    if (init == null) init = "";

    // Declare the variable
    //
    var_list.append(Def.TAB + Def.PROTECTED + syntax + var + init + Def.SEMICOLON + "\n");
  }
Exemplo n.º 9
0
 protected void writeClassDeclaration() throws IOException {
   // Add some comments
   //
   write(
       "/**\n"
           + " * "
           + MessageHandler.getMessage("generate.mbean.comment.desc", varName)
           + "\n"
           + " * "
           + MessageHandler.getMessage("generate.mbean.comment.oid", oid)
           + "\n"
           + " */\n");
   write(
       Def.PUBLIC
           + Def.CLASS
           + symboleName
           + Def.IMPLEMENT
           + symboleName
           + Def.MBEANSUFFIX
           + ", "
           + Def.SERIALIZABLE
           + Def.LBRACE
           + "\n");
 }
Exemplo n.º 10
0
  private void outputMessage(String msg, int msgType) {
    if (isInterrupted()) {
      return;
    }

    if (m_msgHandler != null) {
      m_msgHandler.outputMessage(msg + "\n", msgType);
    } else {
      try {
        m_outWriter.write(msg);
        m_outWriter.newLine();
      } catch (Exception ex) {
        System.err.println(msg);
      }
    }
  }
Exemplo n.º 11
0
 public void run() {
   try {
     setConfig(ConfigManager.getCurrentConfig());
     if (m_outWriter == null && m_msgHandler == null) {
       useLocalWriter = true;
     } else {
       useLocalWriter = false;
     }
     if (useLocalWriter) {
       openOutputFile();
     }
     checkRules();
     if (useLocalWriter) {
       closeOutputFile();
     }
   } finally {
     if (m_msgHandler != null) {
       m_msgHandler.close();
     }
   }
 }
Exemplo n.º 12
0
  /** Generates the code for the getter. */
  protected void addGetter(
      Context ctxt,
      MibNode node,
      String description,
      String syntax,
      String var,
      StringBuffer buff) {

    buff.append(
        Def.TAB
            + "/**\n"
            + Def.TAB
            + " * "
            + MessageHandler.getMessage("generate.mbean.comment.getter", var)
            + "\n"
            + Def.TAB
            + " */\n");
    buff.append(Def.TAB + Def.PUBLIC + syntax + Def.GET + var + "() " + accessThrows);
    buff.append(Def.TAB2 + Def.RETURN + var + Def.SEMICOLON);
    buff.append(Def.TAB + Def.RBRACE + "\n");
  }
Exemplo n.º 13
0
  /** Process table. */
  protected void handleTable(MibNode node) throws IOException {
    // create a table generator
    //
    TableBeanGenerator table = new TableBeanGenerator(manager, node, context);

    // The meta table generator is now created by the
    // MetaBeanGenerator, which is more logic.
    //
    // // MetaTableGenerator metatable=
    // //   new MetaTableGenerator(manager, node, context);

    // create a table generator interface
    //
    // TableBeanIfGenerator tableIf= new TableBeanIfGenerator(manager, packageName, prefix,
    // targetDir, node, mib);

    // Get the entry name
    //
    String entry = table.getEntryName();

    // Get the table name
    //
    String tableName = table.getTableClassName();

    // Name of the symbol
    //
    String variable = table.getSymbolName();

    // Add cache variable for storing table
    //
    addCacheVar(node, tableName, (long) -1, null, variable);

    // Initialize the table in the constructor
    //
    constructor1.append(
        Def.TAB2 + variable + " = " + Def.NEW + tableName + "(myMib)" + Def.SEMICOLON);
    constructor2.append(
        Def.TAB2 + variable + " = " + Def.NEW + tableName + "(myMib, server)" + Def.SEMICOLON);

    // Add access method on the table
    //
    accessors.append(
        Def.TAB
            + "/**\n"
            + Def.TAB
            + " * "
            + MessageHandler.getMessage("generate.mbean.comment.table.access", variable)
            + "\n"
            + Def.TAB
            + " */\n");
    accessors.append(
        Def.TAB + Def.PUBLIC + tableName + Def.ACCESS + variable + "() " + accessThrows);
    accessors.append(
        Def.TAB2 + Def.RETURN + variable + Def.SEMICOLON + Def.TAB + Def.RBRACE + "\n");

    // Show the table as an indexed property...
    //
    accessors.append(
        Def.TAB
            + "/**\n"
            + Def.TAB
            + " * "
            + MessageHandler.getMessage("generate.mbean.comment.table.entry", variable)
            + "\n"
            + Def.TAB
            + " */\n");
    accessors.append(
        Def.TAB
            + Def.PUBLIC
            + entry
            + Def.MBEANSUFFIX
            + "[] "
            + Def.GET
            + variable
            + "() "
            + accessThrows);
    accessors.append(
        Def.TAB2
            + Def.RETURN
            + variable
            + ".getEntries()"
            + Def.SEMICOLON
            + Def.TAB
            + Def.RBRACE
            + "\n");
  }
Exemplo n.º 14
0
  // Specify the version of mibgen used for generating the code
  //
  protected void writeVersion() throws IOException {
    String msgid = "generate.version";

    write("\n//\n// " + MessageHandler.getMessage(msgid, mib.getModuleName()) + "\n//\n\n");
  }