Ejemplo n.º 1
0
  /** Build getter and setter for a variable ... */
  protected void addAccessors(MibNode node, String syntax, String var) throws IOException {

    // Get the object definition associated to the node
    //
    ASTObjectTypeDefinition definition = node.getObjectType();
    String description = definition.getDefinition().getDescription();

    addGetter(this.context, node, description, syntax, var, accessors);

    // If the variable is read-write, add a setter and a checker ...
    //
    int access = definition.getDefinition().getAccess();
    if ((access == ParserConstants.RW)
        || (access == ParserConstants.WO)
        || (access == ParserConstants.RC)) {
      addSetter(this.context, node, description, syntax, var, accessors);
      addChecker(this.context, node, description, syntax, var, accessors);
    }
  }
Ejemplo n.º 2
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");
  }
Ejemplo n.º 3
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);
  }