opendap.dap
Class DVector

java.lang.Object
  extended by opendap.dap.BaseType
      extended by opendap.dap.DVector
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, ClientIO
Direct Known Subclasses:
DArray, DList

public abstract class DVector
extends BaseType
implements ClientIO

This class holds a one-dimensional array of OPeNDAP data types. It is the parent of both DList and DArray. This class uses a PrimitiveVector to hold the data and deserialize it, thus allowing more efficient storage to be used for the primitive types.

Version:
$Revision: 23881 $
Author:
jehamby
See Also:
BaseType, DArray, PrimitiveVector, Serialized Form

Constructor Summary
DVector()
          Constructs a new DVector.
DVector(java.lang.String n)
          Constructs a new DVector with name n.
 
Method Summary
 void addVariable(BaseType v)
          Adds a variable to the container.
 java.lang.Object clone()
          Returns a clone of this DVector.
 void deserialize(java.io.DataInputStream source, ServerVersion sv, StatusUI statusUI)
          Reads data from a DataInputStream.
 void externalize(java.io.DataOutputStream sink)
          Writes data to a DataOutputStream.
 int getLength()
          Returns the number of elements in the vector.
 PrimitiveVector getPrimitiveVector()
          Returns the PrimitiveVector for this vector.
 java.lang.String getTypeName()
          Returns the OPeNDAP type name of the class instance as a String.
 void printDecl(java.io.PrintWriter os, java.lang.String space, boolean print_semi, boolean constrained)
          Write the variable's declaration in a C-style syntax.
 void printVal(java.io.PrintWriter os, java.lang.String space, boolean print_decl_p)
          Prints the value of the variable, with its declaration.
 void setLength(int len)
          Sets the number of elements in the vector.
 
Methods inherited from class opendap.dap.BaseType
addAttributeAlias, addAttributeContainer, appendAttribute, appendAttribute, appendAttributeContainer, checkSemantics, checkSemantics, delAttribute, delAttribute, elementCount, elementCount, getAttribute, getAttribute, getAttributeNames, getAttributeTable, getClearName, getLongName, getName, getParent, hasAttributes, newPrimitiveVector, printAttributes, printAttributes, printAttributes, printAttributes, printDecl, printDecl, printDecl, printDecl, printDecl, printDecl, printDecl, printVal, printVal, printVal, printXML, printXML, printXML, printXML, printXML, setClearName, setName, setParent
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DVector

public DVector()
Constructs a new DVector.


DVector

public DVector(java.lang.String n)
Constructs a new DVector with name n.

Parameters:
n - the name of the variable.
Method Detail

getTypeName

public java.lang.String getTypeName()
Returns the OPeNDAP type name of the class instance as a String.

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

clone

public java.lang.Object clone()
Returns a clone of this DVector. A deep copy is performed on all variables inside the DVector.

Overrides:
clone in class BaseType
Returns:
a clone of this DVector.

getLength

public int getLength()
Returns the number of elements in the vector.

Returns:
the number of elements in the vector.

setLength

public void setLength(int len)
Sets the number of elements in the vector. Allocates a new array of the desired size. Note that if this is called multiple times, the old array and its contents will be lost!

Only called inside of deserialize method or in derived classes on server.

Parameters:
len - the number of elements in the array.

addVariable

public void addVariable(BaseType v)
Adds a variable to the container.

Parameters:
v - the variable to add.

getPrimitiveVector

public PrimitiveVector getPrimitiveVector()
Returns the PrimitiveVector for this vector. This can be cast to the appropriate type and used by a OPeNDAP client to read or set individual values in the vector.

Returns:
the attached PrimitiveVector.

printDecl

public void printDecl(java.io.PrintWriter os,
                      java.lang.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 OPeNDAP 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(java.io.PrintWriter os,
                     java.lang.String space,
                     boolean print_decl_p)
Prints the value of the variable, with its declaration. This function is primarily intended for debugging OPeNDAP 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(java.io.DataInputStream source,
                        ServerVersion sv,
                        StatusUI statusUI)
                 throws java.io.IOException,
                        java.io.EOFException,
                        DataReadException
Reads data from a DataInputStream. This method is only used on the client side of the OPeNDAP 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:
java.io.EOFException - if EOF is found before the variable is completely deserialized.
java.io.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(java.io.DataOutputStream sink)
                 throws java.io.IOException
Writes data to a DataOutputStream. This method is used primarily by GUI clients which need to download OPeNDAP 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:
java.io.IOException - thrown on any OutputStream exception.