edu.stanford.slac.aida.lib.util.common
Class DaValue

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.Vector
              extended by edu.stanford.slac.aida.lib.util.common.DaValue
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable, java.util.Collection, java.util.List, java.util.RandomAccess

public class DaValue
extends java.util.Vector
implements java.lang.Cloneable

DaValue is the AIDA overloaded data type, similar to a CORBA Any but easier to use. DaValue makes it easy to construct and pass complex data types through Aida. For instance a DaValue may be used by an Aida Data Provider servant as a convenient way to construct structured data to be returned by the servant's get - Any method. Also DaValue may be returned by methods in DaObject or DaReference that return data values. DaValue extends the Java Vector class, and is organised as follows:

  1. If this DaValue's type is STRUCT - then the elements() of this vector are themselves DaValues.
  2. If this DaValue's type is an Array type - the elements() of this vector are objects of the base type of the array. toArray() returns an array of these base types.
  3. If this DaValue's type is a base type - this vector contains exactly one element of that type. firstElement() returns the object of this base type.
  4. Arrays of structures are represented as an array of DaValues containing structures.
See the dpTest Data Provider get - Any method for example of using DaValue on a server, and test.Tests for example of the use of DaValue in an Aida client.

Version:
29-Sep-2004, Greg White (greg): Added exception handling, 15-Jun-2004, Greg White (greg): Bugfix for changed length array of strings.
Author:
gsm
See Also:
Serialized Form

Nested Class Summary
static class DaValue.Type
          These are the types understood by AIDA.
 
Field Summary
 java.lang.String name
          Some DaValues can be named, notably when they are the elements of the structure form of DaValues.
 int type
          The type of this vector of the DaValue.
 
Fields inherited from class java.util.Vector
capacityIncrement, elementCount, elementData
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
DaValue()
          Create an empty DaValue
DaValue(org.omg.CORBA.Any a)
          Construct a DaValue from an Any
DaValue(java.lang.Boolean theValue)
          Construct a DaValue from a Boolean
DaValue(boolean[] theArray)
          Construct a DaValue from an Array of boolean
DaValue(java.lang.Boolean[] theArray)
          Construct a DaValue from an Array of Boolean objects
DaValue(java.lang.Byte theValue)
          Construct a DaValue from a Byte
DaValue(byte[] theArray)
          Construct a DaValue from an Array of byte
DaValue(java.lang.Byte[] theArray)
          Construct a DaValue from an Array of byte
DaValue(char[] theArray)
          Construct a DaValue from an Array of char
DaValue(java.lang.Character theValue)
          Construct a DaValue from a Character
DaValue(java.lang.Character[] theArray)
          Construct a DaValue from an Array of Character objects
DaValue(java.lang.Double theValue)
          Construct a DaValue from a Double
DaValue(double[] theArray)
          Construct a DaValue from an Array of doubles
DaValue(java.lang.Double[] theArray)
          Construct a DaValue from an Array of Double objects
DaValue(java.lang.Float theValue)
          Construct a DaValue from a Float
DaValue(float[] theArray)
          Construct a DaValue from an Array of floats
DaValue(java.lang.Float[] theArray)
          Construct a DaValue from an Array of Float objects
DaValue(int initialCapacity)
          As with the super class, this constructor creates a DaValue with initial capacity for storing the given number of elements in its Vector.
DaValue(int[] theArray)
          Construct a DaValue from an Array of integers
DaValue(java.lang.Integer[] theArray)
          Construct a DaValue from an Array of Integer objects
DaValue(int initialCapacity, int capacityIncrement)
          As with the super class, this constructor creates a DaValue with initial capacity for storing the given number of elements in its Vector and capacity increases in increments of the given capacity Increment
DaValue(java.lang.Long theValue)
          Construct a DaValue from a Long
DaValue(long[] theArray)
          Construct a DaValue from an Array of long
DaValue(java.lang.Long[] theArray)
          Construct a DaValue from an Array of Long objects
DaValue(java.lang.Short theValue)
          Construct a DaValue from a Short
DaValue(short[] theArray)
          Construct a DaValue from an Array of shorts
DaValue(java.lang.Short[] theArray)
          Construct a DaValue from an Array of Short objects
DaValue(java.lang.String theValue)
          Construct a DaValue from a String
DaValue(java.lang.String[] theArray)
          Construct a DaValue from an Array of String objects
DaValue(java.lang.String name, DaValue.Type type)
          Create an empty DaValue of specified name and type
DaValue(org.omg.CORBA.TypeCode tc, org.omg.CORBA.portable.InputStream inputStream)
          Constuctor from a structure member
 
Method Summary
 void addArray(java.lang.Object[] o, int theType)
          Construct a DaValue from an arbitrary Array of objects
static java.util.Vector booleansToNumbers(java.util.Vector booleans)
           
static DaValue fromAny(DaValue v, org.omg.CORBA.Any a)
          Static method that fills a DaValue from a CORBA Any.
static DaValue fromAnyHeteroArray(DaValue v, org.omg.CORBA.Any a, org.omg.CORBA.TypeCode tc)
          Static method that fills a DaValue from a CORBA Any that contains a HOMOgenous array of Any's or strings.
static DaValue fromAnyHomoArray(DaValue v, org.omg.CORBA.Any a, org.omg.CORBA.TypeCode tc)
          Static method that fills a DaValue from a CORBA Any that contains a HOMOgenous array of Basic types.
static void fromStreamArray(DaValue v, org.omg.CORBA.portable.InputStream inputStream, org.omg.CORBA.TypeCode ptc)
          Static method that fills a DaValue from a CORBA Any that contains a HOMOgenous array of Basic types.
protected  void generateNamedValues(NamedValues namedValues, java.lang.String prefix)
           
 boolean[] getAsBooleans()
           
 byte[] getAsBytes()
           
 double[] getAsDoubles()
           
 float[] getAsFloats()
           
 int[] getAsInts()
           
 long[] getAsLongs()
           
 short[] getAsShorts()
           
 java.lang.String[] getAsStrings()
           
 boolean getBoolean(int i)
           
 boolean[] getBooleans()
           
 byte getByte(int i)
           
 byte[] getBytes()
           
 double getDouble()
           
 double getDouble(int i)
           
 double[] getDoubles()
           
 float getFloat()
           
 float getFloat(int i)
           
 float[] getFloats()
           
 int getInt()
           
 int getInt(int i)
           
 int[] getInts()
           
 long getLong()
           
 long getLong(int i)
           
 long[] getLongs()
           
 NamedValues getNamedValues()
           
 DaValue getPrimaryElement()
          Returns the basic element of this DaValue that is considered the "primary" one.
 short getShort(int i)
           
 short[] getShorts()
           
 java.lang.String getString()
           
 java.lang.String getString(int i)
           
 java.lang.String[] getStrings()
           
 boolean isBoolean()
           
 boolean isByte()
           
 boolean isDouble()
           
 boolean isFloat()
           
 boolean isInt()
           
 boolean isLong()
           
 boolean isNumeric()
           
 boolean isShort()
           
 boolean isString()
           
static boolean[] numbersToBooleans(java.util.Vector numbers)
           
static byte[] numbersToBytes(java.util.Vector numbers)
           
static double[] numbersToDoubles(java.util.Vector numbers)
           
static float[] numbersToFloats(java.util.Vector numbers)
           
static int[] numbersToInts(java.util.Vector numbers)
           
static long[] numbersToLongs(java.util.Vector numbers)
           
static short[] numbersToShorts(java.util.Vector numbers)
           
 void setName(java.lang.String theName)
          Set the name of this vector of the DaValue
static boolean[] stringsToBooleans(java.util.Vector strings)
           
static java.util.Vector stringsToDoubleNumbers(java.util.Vector strings)
           
static java.util.Vector stringsToFloatNumbers(java.util.Vector strings)
           
 org.omg.CORBA.Any toAny()
          Create an Any from this DaValue Encodes this DaValue into a CORBA Any
static org.omg.CORBA.Any toAny(DaValue v, org.omg.CORBA.Any a)
          Static method to create an Any that represents an arbitrary DaValue
 
Methods inherited from class java.util.Vector
add, add, addAll, addAll, addElement, capacity, clear, clone, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, equals, firstElement, get, hashCode, indexOf, indexOf, insertElementAt, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, remove, removeAll, removeAllElements, removeElement, removeElementAt, removeRange, retainAll, set, setElementAt, setSize, size, subList, toArray, toArray, toString, trimToSize
 
Methods inherited from class java.util.AbstractList
iterator, listIterator, listIterator
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
iterator, listIterator, listIterator
 

Field Detail

type

public int type
The type of this vector of the DaValue. This is used as the discriminator when evaluating a DaValue.


name

public java.lang.String name
Some DaValues can be named, notably when they are the elements of the structure form of DaValues. In this case this field stores the name of this element. Applications should use setName(String) to set the name for a node even though the name field is public. Null means that this vector is unnamed.

Constructor Detail

DaValue

public DaValue()
Create an empty DaValue


DaValue

public DaValue(java.lang.String name,
               DaValue.Type type)
Create an empty DaValue of specified name and type


DaValue

public DaValue(int initialCapacity)
As with the super class, this constructor creates a DaValue with initial capacity for storing the given number of elements in its Vector. Do not confuse with the Constructor taking a Long argument.

Parameters:
initialCapacity - Initial capacity. Vector initially has capacity for this number of elements
See Also:
Vector(int)

DaValue

public DaValue(int initialCapacity,
               int capacityIncrement)
As with the super class, this constructor creates a DaValue with initial capacity for storing the given number of elements in its Vector and capacity increases in increments of the given capacity Increment

Parameters:
initialCapacity - The initial capacity. Vector initially has capacity for this number of elements
capacityIncrement - Each time capacity needs to be increased increase by this amount.
See Also:
Vector.Vector(int, int)

DaValue

public DaValue(java.lang.Boolean theValue)
Construct a DaValue from a Boolean

Parameters:
theValue - Boolean value to be copied into the new DaValue's first and only element

DaValue

public DaValue(java.lang.Byte theValue)
Construct a DaValue from a Byte

Parameters:
theValue - Byte value to be copied into the new DaValue's first and only element

DaValue

public DaValue(java.lang.Character theValue)
Construct a DaValue from a Character

Parameters:
theValue - Character value to be copied into the new DaValue's first and only element

DaValue

public DaValue(java.lang.Double theValue)
Construct a DaValue from a Double

Parameters:
theValue - Double value to be copied into the new DaValue's first and only element

DaValue

public DaValue(java.lang.Float theValue)
Construct a DaValue from a Float

Parameters:
theValue - Float value to be copied into the new DaValue's first and only element

DaValue

public DaValue(java.lang.Long theValue)
Construct a DaValue from a Long

Parameters:
theValue - Long value to be copied into the new DaValue's first and only element

DaValue

public DaValue(java.lang.Short theValue)
Construct a DaValue from a Short

Parameters:
theValue - Short value to be copied into the new DaValue's first and only element

DaValue

public DaValue(java.lang.String theValue)
Construct a DaValue from a String

Parameters:
theValue - String value to be copied into the new DaValue's first and only element

DaValue

public DaValue(org.omg.CORBA.Any a)
Construct a DaValue from an Any

Parameters:
a - CORBA Any that will be used to construct this new DaValue

DaValue

public DaValue(boolean[] theArray)
Construct a DaValue from an Array of boolean

Parameters:
theArray - boolean array whose elements are copied into corresponding Boolean elements in the Vector of this new DaValue

DaValue

public DaValue(byte[] theArray)
Construct a DaValue from an Array of byte

Parameters:
theArray - byte array whose elements are copied into corresponding Byte elements in the Vector of this new DaValue

DaValue

public DaValue(char[] theArray)
Construct a DaValue from an Array of char

Parameters:
theArray - char array whose elements are copied into corresponding Character elements in the Vector of this new DaValue

DaValue

public DaValue(double[] theArray)
Construct a DaValue from an Array of doubles

Parameters:
theArray - double array whose elements are copied into corresponding Double elements in the Vector of this new DaValue

DaValue

public DaValue(float[] theArray)
Construct a DaValue from an Array of floats

Parameters:
theArray - float array whose elements are copied into corresponding Float elements in the Vector of this new DaValue

DaValue

public DaValue(long[] theArray)
Construct a DaValue from an Array of long

Parameters:
theArray - long array whose elements are copied into corresponding Long elements in the Vector of this new DaValue

DaValue

public DaValue(int[] theArray)
Construct a DaValue from an Array of integers

Parameters:
theArray - int array whose elements are copied into corresponding Long elements in the Vector of this new DaValue

DaValue

public DaValue(short[] theArray)
Construct a DaValue from an Array of shorts

Parameters:
theArray - short array whose elements are copied into corresponding Short elements in the Vector of this new DaValue

DaValue

public DaValue(java.lang.String[] theArray)
Construct a DaValue from an Array of String objects

Parameters:
theArray - String array whose elements are copied into corresponding String elements in the Vector of this new DaValue

DaValue

public DaValue(java.lang.Boolean[] theArray)
Construct a DaValue from an Array of Boolean objects

Parameters:
theArray - Boolean array whose elements are copied into corresponding Boolean elements in the Vector of this new DaValue

DaValue

public DaValue(java.lang.Byte[] theArray)
Construct a DaValue from an Array of byte

Parameters:
theArray - Byte array whose elements are copied into corresponding Byte elements in the Vector of this new DaValue

DaValue

public DaValue(java.lang.Character[] theArray)
Construct a DaValue from an Array of Character objects

Parameters:
theArray - Character array whose elements are copied into corresponding Character elements in the Vector of this new DaValue

DaValue

public DaValue(java.lang.Double[] theArray)
Construct a DaValue from an Array of Double objects

Parameters:
theArray - Double array whose elements are copied into corresponding Double elements in the Vector of this new DaValue

DaValue

public DaValue(java.lang.Float[] theArray)
Construct a DaValue from an Array of Float objects

Parameters:
theArray - Float array whose elements are copied into corresponding Float elements in the Vector of this new DaValue

DaValue

public DaValue(java.lang.Long[] theArray)
Construct a DaValue from an Array of Long objects

Parameters:
theArray - Long array whose elements are copied into corresponding Long elements in the Vector of this new DaValue

DaValue

public DaValue(java.lang.Integer[] theArray)
Construct a DaValue from an Array of Integer objects

Parameters:
theArray - Integer array whose elements are copied into corresponding Long elements in the Vector of this new DaValue

DaValue

public DaValue(java.lang.Short[] theArray)
Construct a DaValue from an Array of Short objects

Parameters:
theArray - Short array whose elements are copied into corresponding Short elements in the Vector of this new DaValue

DaValue

public DaValue(org.omg.CORBA.TypeCode tc,
               org.omg.CORBA.portable.InputStream inputStream)
Constuctor from a structure member

Parameters:
m - StructureMember
Method Detail

addArray

public void addArray(java.lang.Object[] o,
                     int theType)
Construct a DaValue from an arbitrary Array of objects

Parameters:
o - arbitrary array whose elements are copied into corresponding elements in the Vector of this DaValue
theType - the type of the elements of the array

setName

public void setName(java.lang.String theName)
Set the name of this vector of the DaValue

Parameters:
theName - name to set for this vector

getPrimaryElement

public DaValue getPrimaryElement()
Returns the basic element of this DaValue that is considered the "primary" one. Currently, this translates to the first scalar or vector of basic types discovered by iterating through the contents. In effect, this means that the first such element inserted into the container has primacy.


fromAnyHeteroArray

public static DaValue fromAnyHeteroArray(DaValue v,
                                         org.omg.CORBA.Any a,
                                         org.omg.CORBA.TypeCode tc)
Static method that fills a DaValue from a CORBA Any that contains a HOMOgenous array of Any's or strings. The function is HETERO because the Any's contains heterogenous types/structures.

Parameters:
v - DaValue to store decoded CORBA Any
a - CORBA Any to decode into the DaValue.
tc - CORBA TypeCode discriminator that describes the given CORBA Any
Returns:
DaValue that represents decoded CORBA Any
Throws:
java.lang.IllegalArgumentException - Error in string comparison operation on TypeCode.id

fromStreamArray

public static void fromStreamArray(DaValue v,
                                   org.omg.CORBA.portable.InputStream inputStream,
                                   org.omg.CORBA.TypeCode ptc)
Static method that fills a DaValue from a CORBA Any that contains a HOMOgenous array of Basic types.

Parameters:
v - DaValue to store decoded CORBA Any
a - CORBA Any to decode into the DaValue.
tc - CORBA TypeCode discriminator that describes the given CORBA Any

fromAnyHomoArray

public static DaValue fromAnyHomoArray(DaValue v,
                                       org.omg.CORBA.Any a,
                                       org.omg.CORBA.TypeCode tc)
Static method that fills a DaValue from a CORBA Any that contains a HOMOgenous array of Basic types.

Parameters:
v - DaValue to store decoded CORBA Any
a - CORBA Any to decode into the DaValue.
tc - CORBA TypeCode discriminator that describes the given CORBA Any
Returns:
DaValue that represents decoded CORBA Any

fromAny

public static DaValue fromAny(DaValue v,
                              org.omg.CORBA.Any a)
Static method that fills a DaValue from a CORBA Any. Used with the Any constructor to recursively add elements from an Any. This method understands Any's that are composed as follows: A node can contain either a simple type, a structure, or an array. Simple types are terminal and once processed execution pops a level. Arrays (TCKind._tk_array) have a fixed length and are monotype and are streamed into variables of corresponding type (NB arrays of structures are not allowed). They will appear as a structure of structures. Structures (TCKind._tk_struct) are structures with elements that are of any type including Any (recursive)

Parameters:
v - DaValue to store decoded CORBA Any
a - CORBA Any to decode into the DaValue.
Returns:
DaValue that represents decoded CORBA Any

toAny

public org.omg.CORBA.Any toAny()
Create an Any from this DaValue Encodes this DaValue into a CORBA Any

Returns:
Returns a new CORBA Any that is constituted from the elements of this DaValue

toAny

public static org.omg.CORBA.Any toAny(DaValue v,
                                      org.omg.CORBA.Any a)
Static method to create an Any that represents an arbitrary DaValue

Parameters:
v - DaValue to decode
a - CORBA Any to write decoded DaValue into.
Returns:
Returns a new CORBA Any that is constituted of the arbitrary contents of this DaValue's String array

numbersToBooleans

public static boolean[] numbersToBooleans(java.util.Vector numbers)

numbersToBytes

public static byte[] numbersToBytes(java.util.Vector numbers)

numbersToShorts

public static short[] numbersToShorts(java.util.Vector numbers)

numbersToInts

public static int[] numbersToInts(java.util.Vector numbers)

numbersToLongs

public static long[] numbersToLongs(java.util.Vector numbers)

numbersToFloats

public static float[] numbersToFloats(java.util.Vector numbers)

numbersToDoubles

public static double[] numbersToDoubles(java.util.Vector numbers)

stringsToFloatNumbers

public static java.util.Vector stringsToFloatNumbers(java.util.Vector strings)

stringsToDoubleNumbers

public static java.util.Vector stringsToDoubleNumbers(java.util.Vector strings)

stringsToBooleans

public static boolean[] stringsToBooleans(java.util.Vector strings)

booleansToNumbers

public static java.util.Vector booleansToNumbers(java.util.Vector booleans)

isNumeric

public boolean isNumeric()

isBoolean

public boolean isBoolean()

getBoolean

public boolean getBoolean(int i)

getBooleans

public boolean[] getBooleans()

getAsBooleans

public boolean[] getAsBooleans()

isByte

public boolean isByte()

getByte

public byte getByte(int i)

getBytes

public byte[] getBytes()

getAsBytes

public byte[] getAsBytes()

isShort

public boolean isShort()

getShort

public short getShort(int i)

getShorts

public short[] getShorts()

getAsShorts

public short[] getAsShorts()

isInt

public boolean isInt()

getInt

public int getInt(int i)

getInt

public int getInt()

getInts

public int[] getInts()

getAsInts

public int[] getAsInts()

isLong

public boolean isLong()

getLong

public long getLong(int i)

getLong

public long getLong()

getLongs

public long[] getLongs()

getAsLongs

public long[] getAsLongs()

isFloat

public boolean isFloat()

getFloat

public float getFloat(int i)

getFloat

public float getFloat()

getFloats

public float[] getFloats()

getAsFloats

public float[] getAsFloats()

isDouble

public boolean isDouble()

getDouble

public double getDouble(int i)

getDouble

public double getDouble()

getDoubles

public double[] getDoubles()

getAsDoubles

public double[] getAsDoubles()

isString

public boolean isString()

getString

public java.lang.String getString(int i)

getString

public java.lang.String getString()

getStrings

public java.lang.String[] getStrings()

getAsStrings

public java.lang.String[] getAsStrings()

getNamedValues

public NamedValues getNamedValues()

generateNamedValues

protected void generateNamedValues(NamedValues namedValues,
                                   java.lang.String prefix)