예제 #1
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");
  }
예제 #2
0
  public void handleNode(MibNode aNode) throws IOException {

    // Check if the node is a nested group or not. A nested group
    // has some children but is not a associated.
    if (aNode.isGroup() || aNode.hasNestedGroups()) {
      // The node is a nested group !
      //
      handleNestedGroups(aNode);
      return;
    }
    // Check if the node is a table or not. A table has some children
    // but is not a group.
    if (aNode.isTable()) {
      // The node is a table !
      //
      handleTable(aNode);
      return;
    }

    // Name of the symbol
    //
    String varName = aNode.getSymbolName();

    // Get the object definition associated to the node
    //
    ASTObjectTypeDefinition definition = aNode.getObjectType();
    if (definition == null) return;
    // get the syntax ...
    //
    ASTNamedType syntax = definition.getSyntax();
    String strSyntax = "";

    // Get the default MIB variable value
    //
    ASTValue defValue = definition.getDefValue();

    String init = "";
    if (syntax.isEnumeratedType()) {
      // get the access mode of the node
      //
      EnumGenerator enumgen =
          new EnumGenerator(manager, varName, syntax.getEnumeratedDef(), context);
      strSyntax = enumgen.getTypeName();

      // Now get the SNMP syntax in order to get a valid init value ...
      //  - if a default value is defined, just take it
      //  - otherwise, get a valid init value defined in the syntax mapper
      //

      // There is a default value for this variable.
      //
      if (defValue != null) {
        init = defValue.getDefValInitializer(strSyntax, syntax, varName);
      }
      // There is no default value for this variable or the default value cannot be resolved.
      //
      if ((defValue == null) || (init.equals(""))) {
        init = " = new " + strSyntax.trim() + "()";
      }

      aNode.setEnumerated(true);
      aNode.setEnumeratedType(strSyntax);
    } else {
      // Get the real syntax to use for the node
      //
      strSyntax = syntax.getMbeanSyntax();

      // Now get the SNMP syntax in order to get a valid init value ...
      //  - if a default value is defined, just take it
      //  - otherwise, get a valid init value defined in the syntax mapper
      //

      // There is a default value for this variable.
      //
      if (defValue != null) {
        init = defValue.getDefValInitializer(strSyntax, syntax, varName);
      }
      // There is no default value for this variable or the default value cannot be resolved.
      //
      if ((defValue == null) || (init.equals(""))) {
        init = SyntaxMapper.getInitializer(syntax.getSnmpSyntax());
      }
    }

    // Add a Java variable for representing the snmp variable ...
    //
    long length = syntax.getFixedLength();
    aNode.setFixedLength(length);
    addCacheVar(aNode, strSyntax, length, init, varName);

    // Generate getter and setter
    //
    addAccessors(aNode, strSyntax, varName);
  }