opendap.dap
Class BaseType

java.lang.Object
  extended by opendap.dap.BaseType
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
DByte, DConstructor, DFloat32, DFloat64, DInt16, DInt32, DString, DVector

public abstract class BaseType
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

This abstract class defines the basic data type features for the OPeNDAP data access protocol (DAP) data types. All of the DAP type classes (DFloat64, DArray, etc.) subclass it or one of its two abstract descendents, DVector or DConstructor.

These classes and their methods give a user the capacity to set up sophisticated data types. They do not provide sophisticated ways to access and use this data. On the server side, in many cases, the class instances will have no data in them at all until the serialize method is called to send data to the client. On the client side, most OPeNDAP application programs will unpack the data promptly into whatever local data structure the programmer deems the most useful.

Descendents of this class should implement the ClientIO interface. That interface defines a deserialize method used by a OPeNDAP client to retrieve the variable's declaration and value(s) from a OPeNDAP server.

Version:
$Revision: 23881 $
Author:
jehamby
See Also:
DDS, ClientIO, Serialized Form

Constructor Summary
BaseType()
          Constructs a new BaseType with no name.
BaseType(java.lang.String n)
          Constructs a new BaseType with name n.
BaseType(java.lang.String n, boolean decodeName)
          Constructs a new BaseType with name n.
 
Method Summary
 void addAttributeAlias(java.lang.String alias, java.lang.String attributeName)
           
 void addAttributeContainer(AttributeTable at)
           
 void appendAttribute(java.lang.String name, int type, java.lang.String value)
           
 void appendAttribute(java.lang.String name, int type, java.lang.String value, boolean check)
           
 AttributeTable appendAttributeContainer(java.lang.String name)
           
 void checkSemantics()
          Check semantics.
 void checkSemantics(boolean all)
          Checks for internal consistency.
 java.lang.Object clone()
          Returns a clone of this BaseType.
 void delAttribute(java.lang.String name)
           
 void delAttribute(java.lang.String name, int i)
           
 int elementCount()
          Returns the number of variables contained in this object.
 int elementCount(boolean leaves)
          Returns the number of variables contained in this object.
 Attribute getAttribute()
           
 Attribute getAttribute(java.lang.String name)
           
 java.util.Enumeration getAttributeNames()
           
 AttributeTable getAttributeTable()
           
 java.lang.String getClearName()
          Returns the unencoded name of the class instance.
 java.lang.String getLongName()
           
 java.lang.String getName()
          Returns the WWW encoded name of the class instance.
 BaseType getParent()
           
abstract  java.lang.String getTypeName()
          Returns the OPeNDAP type name of the class instance as a String.
 boolean hasAttributes()
           
 PrimitiveVector newPrimitiveVector()
          Constructs a new PrimitiveVector object optimized for the particular data type of this BaseType.
 void printAttributes(java.io.OutputStream os)
           
 void printAttributes(java.io.OutputStream os, java.lang.String pad)
           
 void printAttributes(java.io.PrintWriter pw)
           
 void printAttributes(java.io.PrintWriter pw, java.lang.String pad)
           
 void printDecl(java.io.OutputStream os)
          Print the variable's declaration.
 void printDecl(java.io.OutputStream os, java.lang.String space)
          Print the variable's declaration.
 void printDecl(java.io.OutputStream os, java.lang.String space, boolean print_semi)
          Print the variable's declaration using OutputStream.
 void printDecl(java.io.OutputStream os, java.lang.String space, boolean print_semi, boolean constrained)
          Print the variable's declaration using OutputStream.
 void printDecl(java.io.PrintWriter os)
          Print the variable's declaration.
 void printDecl(java.io.PrintWriter os, java.lang.String space)
          Print the variable's declaration.
 void printDecl(java.io.PrintWriter os, java.lang.String space, boolean print_semi)
          Write the variable's declaration in a C-style syntax.
 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.OutputStream os, java.lang.String space)
          Print the variable's value using OutputStream.
 void printVal(java.io.OutputStream os, java.lang.String space, boolean print_decl_p)
          Print the variable's value using OutputStream.
 void printVal(java.io.PrintWriter os, java.lang.String space)
          Print the variable's value.
abstract  void printVal(java.io.PrintWriter os, java.lang.String space, boolean print_decl_p)
          Prints the value of the variable, with its declaration.
 void printXML(java.io.OutputStream os)
           
 void printXML(java.io.OutputStream os, java.lang.String pad)
           
 void printXML(java.io.PrintWriter pw)
           
 void printXML(java.io.PrintWriter pw, java.lang.String pad)
           
 void printXML(java.io.PrintWriter pw, java.lang.String pad, boolean constrained)
           
 void setClearName(java.lang.String n)
          Sets the unencoded name of the class instance.
 void setName(java.lang.String n)
          Sets the name of the class instance.
 void setParent(BaseType bt)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseType

public BaseType()
Constructs a new BaseType with no name.


BaseType

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

Parameters:
n - the name of the variable.

BaseType

public BaseType(java.lang.String n,
                boolean decodeName)
Constructs a new BaseType with name n.

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

clone

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

Overrides:
clone in class java.lang.Object
Returns:
a clone of this BaseType.

getClearName

public final java.lang.String getClearName()
Returns the unencoded name of the class instance.

Returns:
the name of the class instance.

getName

public final java.lang.String getName()
Returns the WWW encoded name of the class instance.

Returns:
the name of the class instance.

setName

public final void setName(java.lang.String n)
Sets the name of the class instance.

Parameters:
n - the name of the class instance.

setClearName

public final void setClearName(java.lang.String n)
Sets the unencoded name of the class instance.

Parameters:
n - the unencoded name of the class instance.

getTypeName

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

Returns:
the OPeNDAP 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.

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

elementCount

public final int elementCount()
Returns the number of variables contained in this object. For simple and vector type variables, it always returns 1.

Returns:
the number of contained variables.

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.

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:
DDS

printDecl

public void printDecl(java.io.PrintWriter os,
                      java.lang.String space,
                      boolean print_semi)
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.

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.
See Also:
DDS

printDecl

public final void printDecl(java.io.PrintWriter os,
                            java.lang.String space)
Print the variable's declaration. Same as printDecl(os, space, true).

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.
See Also:
DDS.print(PrintWriter)

printDecl

public final void printDecl(java.io.PrintWriter os)
Print the variable's declaration. Same as printDecl(os, " ", true).

Parameters:
os - The PrintWriter on which to print the declaration.
See Also:
DDS.print(PrintWriter)

printDecl

public final void printDecl(java.io.OutputStream os,
                            java.lang.String space,
                            boolean print_semi,
                            boolean constrained)
Print the variable's declaration using OutputStream.

Parameters:
os - The OutputStream 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.
See Also:
DDS.print(PrintWriter)

printDecl

public final void printDecl(java.io.OutputStream os,
                            java.lang.String space,
                            boolean print_semi)
Print the variable's declaration using OutputStream.

Parameters:
os - The OutputStream 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.
See Also:
DDS.print(PrintWriter)

printDecl

public final void printDecl(java.io.OutputStream os,
                            java.lang.String space)
Print the variable's declaration. Same as printDecl(os, space, true).

Parameters:
os - The OutputStream 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.
See Also:
DDS.print(PrintWriter)

printDecl

public final void printDecl(java.io.OutputStream os)
Print the variable's declaration. Same as printDecl(os, " ", true).

Parameters:
os - The OutputStream on which to print the declaration.
See Also:
DDS.print(PrintWriter)

printVal

public abstract 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.

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.

printVal

public final void printVal(java.io.PrintWriter os,
                           java.lang.String space)
Print the variable's value. Same as printVal(os, space, true).

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.
See Also:
DataDDS.printVal(PrintWriter)

printVal

public final void printVal(java.io.OutputStream os,
                           java.lang.String space,
                           boolean print_decl_p)
Print the variable's value using OutputStream.

Parameters:
os - the OutputStream 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:
DataDDS.printVal(PrintWriter)

printVal

public final void printVal(java.io.OutputStream os,
                           java.lang.String space)
Print the variable's value using OutputStream.

Parameters:
os - the OutputStream on which to print the value.
space - this value is passed to the printDecl method, and controls the leading spaces of the output.
See Also:
DataDDS.printVal(PrintWriter)

checkSemantics

public void checkSemantics(boolean all)
                    throws BadSemanticsException
Checks for internal consistency. This is important to check for complex constructor classes. For example, an DInt32 instance would return false if it had no name defined. A DGrid instance might return false for more complex reasons, such as having Map arrays of the wrong size or shape.

This method is used by the DDS class, and will rarely, if ever, be explicitly called by a OPeNDAP application program. A variable must pass this test before it is sent, but there may be many other stages in a retrieve operation where it would fail.

Parameters:
all - For complex constructor types ( DGrid, DSequence, DStructure), this flag indicates whether to check the semantics of the member variables, too.
Throws:
BadSemanticsException - if semantics are bad, explains why.
See Also:
DDS.checkSemantics(boolean)

checkSemantics

public final void checkSemantics()
                          throws BadSemanticsException
Check semantics. Same as checkSemantics(false).

Throws:
BadSemanticsException - if semantics are bad, explains why.
See Also:
checkSemantics(boolean)

newPrimitiveVector

public PrimitiveVector newPrimitiveVector()
Constructs a new PrimitiveVector object optimized for the particular data type of this BaseType. For example, a DByte class would create a new BytePrimitiveVector in this call. This allows for a very optimized, yet type-safe, implementation of DVector functionality. For non-primitive types, such as DArray, DGrid, DSequence, and DStructure, the default implementation returns a BaseTypePrimitiveVector object which can deserialize an array of complex types.

Returns:
a new PrimitiveVector object for the variable type.

setParent

public void setParent(BaseType bt)

getParent

public BaseType getParent()

getLongName

public java.lang.String getLongName()

hasAttributes

public boolean hasAttributes()

getAttribute

public Attribute getAttribute()

getAttributeTable

public AttributeTable getAttributeTable()

addAttributeAlias

public void addAttributeAlias(java.lang.String alias,
                              java.lang.String attributeName)
                       throws DASException
Throws:
DASException

appendAttribute

public void appendAttribute(java.lang.String name,
                            int type,
                            java.lang.String value,
                            boolean check)
                     throws DASException
Throws:
DASException

appendAttribute

public void appendAttribute(java.lang.String name,
                            int type,
                            java.lang.String value)
                     throws DASException
Throws:
DASException

addAttributeContainer

public void addAttributeContainer(AttributeTable at)
                           throws AttributeExistsException
Throws:
AttributeExistsException

appendAttributeContainer

public AttributeTable appendAttributeContainer(java.lang.String name)

delAttribute

public void delAttribute(java.lang.String name)

delAttribute

public void delAttribute(java.lang.String name,
                         int i)
                  throws DASException
Throws:
DASException

getAttribute

public Attribute getAttribute(java.lang.String name)

getAttributeNames

public java.util.Enumeration getAttributeNames()

printAttributes

public void printAttributes(java.io.OutputStream os)

printAttributes

public void printAttributes(java.io.OutputStream os,
                            java.lang.String pad)

printAttributes

public void printAttributes(java.io.PrintWriter pw)

printAttributes

public void printAttributes(java.io.PrintWriter pw,
                            java.lang.String pad)

printXML

public void printXML(java.io.OutputStream os)
Parameters:
os -

This class/method is associated with pre-release version of the DDX API. It is experimental and is subject to (significant) change.


printXML

public void printXML(java.io.OutputStream os,
                     java.lang.String pad)
Parameters:
os -
pad -

This class/method is associated with pre-release version of the DDX API. It is experimental and is subject to (significant) change.


printXML

public void printXML(java.io.PrintWriter pw)
Parameters:
pw -

This class/method is associated with pre-release version of the DDX API. It is experimental and is subject to (significant) change.


printXML

public void printXML(java.io.PrintWriter pw,
                     java.lang.String pad)
Parameters:
pw -
pad -

This class/method is associated with pre-release version of the DDX API. It is experimental and is subject to (significant) change.


printXML

public void printXML(java.io.PrintWriter pw,
                     java.lang.String pad,
                     boolean constrained)
Parameters:
pw -
pad -
constrained -

This class/method is associated with pre-release version of the DDX API. It is experimental and is subject to (significant) change.