## net.percederberg.mib.symbol
Class Symbol

    java.lang.Object
      |
      +--net.percederberg.mib.symbol.Symbol

Direct Known Subclasses:
  TypeSymbol, ValueSymbol

public abstract class Symbol
extends java.lang.Object

The base class for all symbols in the MIB file. Each symbol is typically identified by it's name, which must be unique within each MIB file.

All symbols are also present in a tree structure of symbols, each symbol having references to both it's parent and all it's children. This symbol tree should not be changed once it's created, and is intended to be created on the basis of the object identifiers.

The object identifiers are only present in some symbols, but an interface is provided for accessing it for all symbols (in order to avoid some casting and case splitting). For symbols not having object identifiers, an error should be generated runtime.

Author:
  Per Cederberg, per@percederberg.net

Field Summary
`protected java.util.Vector` `children` The child symbols.
`protected int` `id` The object identifier number.
`protected java.lang.String` `name` The symbol name.
`protected Symbol` `parent` The parent symbol.
`protected Type` `type` The symbol type.

Constructor Summary
`Symbol()`

Method Summary
`protected void` `addChild(Symbol child)` Adds a child to this symbol.
`Symbol` `childAt(int index)` Returns the child at a given position.
`int` `children()` Returns the number of children to this symbol.
`boolean` `equals(java.lang.Object obj)` Checks for equality with an object.
`protected Symbol` `findChild(java.lang.String name)` Searches for a child with a given name.
`java.lang.String` `getName()` Returns the symbol name.
`java.lang.String` `getOID()` Returns the object identifier string for this object.
`Symbol` `getParent()` Returns the parent symbol.
`Type` `getType()` Returns the type of this symbol.
`boolean` `isField()` Checks if this symbol represents a data field in the model.
`boolean` `isTopField()` Checks if this symbol represents a top data field in the hierarchy.
`protected void` `removeChild(Symbol child)` Removes a child from this symbol.
`void` `setOID(int id)` Sets this symbols object identifier.
`void` `setParent(Symbol parent)` Sets the symbol parent.
`void` `setType(Type type)` Sets the type of this symbol.
`java.lang.String` `toString()` Returns a description of the symbol.

Methods inherited from class java.lang.Object
`clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### name

    protected java.lang.String name

  The symbol name.

### type

    protected Type type

  The symbol type.

### id

    protected int id

  The object identifier number.

### parent

    protected Symbol parent

  The parent symbol.

### children

    protected java.util.Vector children

  The child symbols.

Constructor Detail

### Symbol

    public Symbol()

Method Detail

### isField

    public boolean isField()

  Checks if this symbol represents a data field in the model.
  Returns:
    true if this symbol represents a data field, or false otherwise

### isTopField

    public boolean isTopField()

  Checks if this symbol represents a top data field in the hierarchy. Typically data fields contained within arrays and composed types will return false for this method.
  Returns:
    true if this symbol represents a top data field, or false otherwise

### childAt

    public Symbol childAt(int index)

  Returns the child at a given position.
  Parameters:
    `index` - the child position, 0 <= index < children()
  Returns:
    the child at the position, or null if not present

### children

    public int children()

  Returns the number of children to this symbol.
  Returns:
    the number of children

### getName

    public java.lang.String getName()

  Returns the symbol name.
  Returns:
    the symbol name

### getOID

    public java.lang.String getOID()

  Returns the object identifier string for this object. Typically this method traverses the parent nodes for retrieving their object identifiers. Note that if some symbol in the symbol hierachy doesn't support object identifiers, a runtime exception is thrown.
  Returns:
    a string containing the numeric object identifier

### getParent

    public Symbol getParent()

  Returns the parent symbol.
  Returns:
    the parent symbol, or null for no parent.

### getType

    public Type getType()

  Returns the type of this symbol.
  Returns:
    the type of the symbol, or null for unknown type

### setOID

    public void setOID(int id)

  Sets this symbols object identifier. To be able to retrieve the full object identifier, all ancestor nodes must also have been assigned object identifiers. For symbols not supporting object identifiers, this method may be overridden to throw a runtime exception.
  Parameters:
    `id` - the object identifier number, 0 <= id

### setParent

    public void setParent(Symbol parent)

  Sets the symbol parent. Also registers this symbol as a child to the new parent. The method guarantees consistency by removing the reference in case of parent change.
  Parameters:
    `parent` - the new symbol parent

### setType

    public void setType(Type type)

  Sets the type of this symbol.
  Parameters:
    `type` - the symbol type information

### equals

    public boolean equals(java.lang.Object obj)

  Checks for equality with an object. Returns true for symbol objects with the same name.
  Overrides:
    `equals` in class `java.lang.Object`
  Parameters:
    `obj` - any object
  Returns:
    true if the objects are equal, otherwise false

### toString

    public java.lang.String toString()

  Returns a description of the symbol.
  Overrides:
    `toString` in class `java.lang.Object`
  Returns:
    a symbol description (the symbol name)

### addChild

    protected void addChild(Symbol child)

  Adds a child to this symbol. For symbols not accepting child nodes this method can be overridden to throw a runtime exception.
  Parameters:
    `child` - a child symbol

### removeChild

    protected void removeChild(Symbol child)

  Removes a child from this symbol.
  Parameters:
    `child` - a child symbol

### findChild

    protected Symbol findChild(java.lang.String name)

  Searches for a child with a given name. The current node can be returned if it has the name searched for.
  Parameters:
    `name` - the child name
  Returns:
    the child, or null if not found