## dods.dap
Class DStructure

    java.lang.Object
      dods.dap.BaseType
          dods.dap.DConstructor
              dods.dap.DStructure

All Implemented Interfaces:
  ClientIO, Cloneable

Direct Known Subclasses:
  SDStructure

public class DStructure
extends DConstructor
implements ClientIO

A `DStructure` in DODS can hold N instances of any of the other datatypes, including other structures.

See Also:
  `BaseType`, `DConstructor`

Field Summary
`protected Vector` `vars` The variables in this `DStructure`, stored in a `Vector` of `BaseType` objects.

Constructor Summary
`DStructure()` Constructs a new `DStructure`.
`DStructure(String n)` Constructs a new `DStructure` with name `n`.

Method Summary
`void` `addVariable(BaseType v, int part)` Adds a variable to the container.
`void` `checkSemantics(boolean all)` Checks for internal consistency.
`Object` `clone()` Returns a clone of this `DSequence`.
`void` `deserialize(DataInputStream source, ServerVersion sv, StatusUI statusUI)` Reads data from a `DataInputStream`.
`int` `elementCount(boolean leaves)` Returns the number of variables contained in this object.
`void` `externalize(DataOutputStream sink)` Writes data to a `DataOutputStream`.
`String` `getTypeName()` Returns the DODS type name of the class instance as a `String`.
`BaseType` `getVar(int index)` Gets the indexed variable.
`BaseType` `getVariable(String name)` Returns the named variable.
`Enumeration` `getVariables()` Return an Enumeration that can be used to iterate over the members of a Structure.
`void` `printDecl(PrintWriter os, String space, boolean print_semi, boolean constrained)` Write the variable's declaration in a C-style syntax.
`void` `printVal(PrintWriter os, String space, boolean print_decl_p)` Prints the value of the variable, with its declaration.

Methods inherited from class dods.dap.DConstructor
`addVariable`

Methods inherited from class dods.dap.BaseType
`checkSemantics, elementCount, getLongName, getName, getParent, newPrimitiveVector, printDecl, printDecl, printDecl, printDecl, printDecl, printDecl, printDecl, printVal, printVal, printVal, setName, setParent`

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

Field Detail

### vars

    protected Vector vars

  The variables in this `DStructure`, stored in a `Vector` of `BaseType` objects.

Constructor Detail

### DStructure

    public DStructure()

  Constructs a new `DStructure`.

### DStructure

    public DStructure(String n)

  Constructs a new `DStructure` with name `n`.

Parameters:
  `n` - the name of the variable.

Method Detail

### clone

    public Object clone()

  Returns a clone of this `DSequence`. A deep copy is performed on all data inside the variable.

  Overrides:
    `clone` in class `BaseType`
  Returns:
    a clone of this `DSequence`.

### getTypeName

    public String getTypeName()

  Returns the DODS type name of the class instance as a `String`.

  Specified by:
    `getTypeName` in class `BaseType`
  Returns:
    the DODS type name of the class instance as a `String`.

### elementCount

    public int elementCount(boolean leaves)

  Returns the number of variables contained in this object. For simple and vector type variables, it always returns 1. To count the number of simple-type variable in the variable tree rooted at this variable, set `leaves` to `true`.

  Overrides:
    `elementCount` in class `BaseType`
  Parameters:
    `leaves` - If true, count all the simple types in the `tree' of variables rooted at this variable.
  Returns:
    the number of contained variables.

### addVariable

    public void addVariable(BaseType v,
                            int part)

  Adds a variable to the container.

  Specified by:
    `addVariable` in class `DConstructor`
  Parameters:
    `v` - the variable to add.
    `part` - ignored for `DSequence`.

### getVariable

    public BaseType getVariable(String name)
                         throws NoSuchVariableException

  Returns the named variable.

  Specified by:
    `getVariable` in class `DConstructor`
  Parameters:
    `name` - the name of the variable.
  Returns:
    the named variable.
  Throws:
    `NoSuchVariableException` - if the named variable does not exist in this container.

### getVar

    public BaseType getVar(int index)
                    throws NoSuchVariableException

  Gets the indexed variable. For a DStructure this returns the `BaseType` from the `index`th column from the internal storage `Vector`.

  Specified by:
    `getVar` in class `DConstructor`
  Parameters:
    `index` - the index of the variable in the `Vector` Vars.
  Returns:
    the indexed variable.
  Throws:
    `NoSuchVariableException` - if the named variable does not exist in this container.

### getVariables

    public Enumeration getVariables()

  Return an Enumeration that can be used to iterate over the members of a Structure. This implementation provides access to the elements of the Structure. Each Object returned by the Enumeration can be cast to a BaseType.

  Specified by:
    `getVariables` in class `DConstructor`
  Returns:
    An Enumeration

### checkSemantics

    public void checkSemantics(boolean all)
                        throws BadSemanticsException

  Checks for internal consistency. For `DStructure`, verify that the variables have unique names.

  Overrides:
    `checkSemantics` in class `BaseType`
  Parameters:
    `all` - for complex constructor types, this flag indicates whether to check the semantics of the member variables, too.
  Throws:
    `BadSemanticsException` - if semantics are bad, explains why.
  See Also:
    `BaseType.checkSemantics(boolean)`

### printDecl

    public void printDecl(PrintWriter os,
                          String space,
                          boolean print_semi,
                          boolean constrained)

  Write the variable's declaration in a C-style syntax. This function is used to create textual representation of the Data Descriptor Structure (DDS). See The DODS User Manual for information about this structure.

  Overrides:
    `printDecl` in class `BaseType`
  Parameters:
    `os` - The `PrintWriter` on which to print the declaration.
    `space` - Each line of the declaration will begin with the characters in this string. Usually used for leading spaces.
    `print_semi` - a boolean value indicating whether to print a semicolon at the end of the declaration.
    `constrained` - a boolean value indicating whether to print the declartion dependent on the projection information. This is only used by Server side code.
  See Also:
    `BaseType.printDecl(PrintWriter, String, boolean)`

### printVal

    public void printVal(PrintWriter os,
                         String space,
                         boolean print_decl_p)

  Prints the value of the variable, with its declaration. This function is primarily intended for debugging DODS applications and text-based clients such as geturl.

  Specified by:
    `printVal` in class `BaseType`
  Parameters:
    `os` - the `PrintWriter` on which to print the value.
    `space` - this value is passed to the `printDecl` method, and controls the leading spaces of the output.
    `print_decl_p` - a boolean value controlling whether the variable declaration is printed as well as the value.
  See Also:
    `BaseType.printVal(PrintWriter, String, boolean)`

### deserialize

    public void deserialize(DataInputStream source,
                            ServerVersion sv,
                            StatusUI statusUI)
                     throws IOException,
                            EOFException,
                            DataReadException

  Reads data from a `DataInputStream`. This method is only used on the client side of the DODS client/server connection.

  Specified by:
    `deserialize` in interface `ClientIO`
  Parameters:
    `source` - a `DataInputStream` to read from.
    `sv` - the `ServerVersion` returned by the server.
    `statusUI` - the `StatusUI` object to use for GUI updates and user cancellation notification (may be null).
  Throws:
    `EOFException` - if EOF is found before the variable is completely deserialized.
    `IOException` - thrown on any other InputStream exception.
    `DataReadException` - if an unexpected value was read.
  See Also:
    `ClientIO.deserialize(DataInputStream, ServerVersion, StatusUI)`

### externalize

    public void externalize(DataOutputStream sink)
                     throws IOException

  Writes data to a `DataOutputStream`. This method is used primarily by GUI clients which need to download DODS data, manipulate it, and then re-save it as a binary file.

  Specified by:
    `externalize` in interface `ClientIO`
  Parameters:
    `sink` - a `DataOutputStream` to write to.
  Throws:
    `IOException` - thrown on any `OutputStream` exception.