Data Request Broker
2-3-release

fr.gael.drb.value
Class DateTime

java.lang.Object
  extended by fr.gael.drb.value.DateTime
All Implemented Interfaces:
DrbItem, Arithmetic, Comparison, Sumable, Value, ValueFormat, Serializable

public class DateTime
extends Object
implements Value, Arithmetic, Comparison, ValueFormat

The DateTime class is a generic wrapper for Date values.

See Also:
Serialized Form

Field Summary
protected  Timestamp dateTime
          The DateTime value.
 
Fields inherited from interface fr.gael.drb.value.Value
ARRAY_ID, BINARY_ID, BINARY_INTEGER_ID, BOOLEAN_ID, BYTE_ID, DATE_ID, DATE_TIME_ID, DAY_ID, DAY_TIME_DURATION_ID, DECIMAL_ID, DOUBLE_ID, DURATION_ID, FLOAT_ID, INT_ID, INTEGER_ID, LONG_ID, MONTH_DAY_ID, MONTH_ID, NULL_ID, NUMERIC_ID, OTHER_ID, SHORT_ID, STRING_ID, TIME_ID, UNKNOWN_ID, UNSIGNED_BYTE_ID, UNSIGNED_INT_ID, UNSIGNED_LONG_ID, UNSIGNED_SHORT_ID, YEAR_ID, YEAR_MONTH_DURATION_ID, YEAR_MONTH_ID
 
Fields inherited from interface fr.gael.drb.DrbItem
ATTRIBUTE_ITEM, NODE_ITEM, UNDEFINED_ITEM, VALUE_ITEM
 
Constructor Summary
DateTime()
          Constructs an DateTime object initialized to the current system time.
DateTime(byte[] buffer)
          Attempts to interpret the binary buffer as a representation of a date and time (MJD format).
DateTime(long dt)
          Allocates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.
DateTime(String s)
          Attempts to interpret the string s as a representation of a date and time.
 
Method Summary
 Value add(Value x)
          Compute an addition.
 void assign(Value v)
          Assign a new Value.
 int compareTo(Value x)
          Compare this value with another value.
 Value convertTo(int type)
          Convert the value into the specified type.
 Value divide(Value x)
          Compute a division (not supported).
 byte[] getFormattedBuffer()
          Return a byte buffer containing the value in a fixed format.
 String getFormattedString(int length)
          Return a string containing the value with a fixed format.
 int getItemType()
          A code that identifies the value items.
 String getName()
          Name of the item.
 String getNamespaceURI()
          Get namespace URI.
 int getNanos()
          Gets this DateTime object's nanos value.
 int getPriority()
          Returns the DateTime priority
 long getTime()
          Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this DateTime object.
 int getType()
          The type identifier of this DateTime value.
 Value getValue()
          The value of the item.
static void main(String[] args)
          Unitary tests operation.
 Value modulus(Value x)
          Compute a modulus (not supported).
 Value multiply(Value x)
          Compute a multiplication.
 void rename(String name)
          Changes the name of the item.
 void setNamespaceURI(String namespace_uri)
          Sets a namespace resource identifier.
 void setNanos(int nanos)
          Sets this DateTime object's nanos field to the given value.
 void setTime(long time)
          Sets this Timestamp object to represent a point in time that is time milliseconds after January 1, 1970 00:00:00 GMT.
 Value setValue(Value value)
          Changes the value of the item.
 Value sub(Value x)
          Compute a substraction.
 Numeric toNumeric()
          Convert the value into the numeric type.
 String toString()
          Return the date in a string.
 Value unaryMinus()
          Compute an unary minus (not supported).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface fr.gael.drb.DrbItem
getItemType, getName, getNamespaceURI, getValue, rename, setNamespaceURI, setValue
 

Field Detail

dateTime

protected Timestamp dateTime
The DateTime value.

Constructor Detail

DateTime

public DateTime()
Constructs an DateTime object initialized to the current system time.


DateTime

public DateTime(long dt)
Allocates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.

Parameters:
dt - the value of the Double.
See Also:
Date

DateTime

public DateTime(String s)
Attempts to interpret the string s as a representation of a date and time. The representation is assumed as "UTC" time (27 bytes) with format : "DD-MMM-YYYY HH:mm:ss.tttttt".

Parameters:
s - string to be parsed as a date.
See Also:
Date

DateTime

public DateTime(byte[] buffer)
Attempts to interpret the binary buffer as a representation of a date and time (MJD format). It assumes that buffer.length is 12. 946684800000L is the offset of 01/01/2000 00:00:00.000000 (MJD origin). It is added to MJD values for setTime() operation.

Parameters:
buffer - buffer to be parsed as a date.
See Also:
Date
Method Detail

getTime

public long getTime()
Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this DateTime object.

Returns:
the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this date.

getNanos

public int getNanos()
Gets this DateTime object's nanos value.

Returns:
this DateTime object's fractional seconds component

setTime

public void setTime(long time)
Sets this Timestamp object to represent a point in time that is time milliseconds after January 1, 1970 00:00:00 GMT.

Parameters:
time - the number of milliseconds.

setNanos

public void setNanos(int nanos)
Sets this DateTime object's nanos field to the given value.

Parameters:
nanos - the new fractional seconds component

getType

public final int getType()
The type identifier of this DateTime value.

Specified by:
getType in interface Value
Returns:
an identifier of the DateTime type.

getPriority

public final int getPriority()
Returns the DateTime priority

Specified by:
getPriority in interface Value
Returns:
the DateTime priority

convertTo

public final Value convertTo(int type)
                      throws ClassCastException
Convert the value into the specified type. In case of identity conversion the value itself is returned. If the conversion is not allowed a ClassCastException is thrown.

Specified by:
convertTo in interface Value
Parameters:
type - The target type.
Returns:
The converted value.
Throws:
ClassCastException - the conversion is impossible

assign

public void assign(Value v)
Assign a new Value. An implicit conversion may be performed to make the assignment.

Specified by:
assign in interface Value
Parameters:
v - the value to be assigned.

add

public Value add(Value x)
Compute an addition.

Specified by:
add in interface Sumable
Parameters:
x - another value.
Returns:
the sum of this date/time with a duration.

unaryMinus

public Value unaryMinus()
Compute an unary minus (not supported).

Specified by:
unaryMinus in interface Arithmetic
Returns:
always null

sub

public Value sub(Value x)
Compute a substraction.

Specified by:
sub in interface Arithmetic
Parameters:
x - a date/time or a duration.
Returns:
the difference between the two values.

multiply

public Value multiply(Value x)
Compute a multiplication.

Specified by:
multiply in interface Arithmetic
Parameters:
x - another value.
Returns:
always null.

divide

public Value divide(Value x)
Compute a division (not supported).

Specified by:
divide in interface Arithmetic
Parameters:
x - another value.
Returns:
always null.

modulus

public Value modulus(Value x)
Compute a modulus (not supported).

Specified by:
modulus in interface Arithmetic
Parameters:
x - another value.
Returns:
always null.

compareTo

public final int compareTo(Value x)
Compare this value with another value.

Specified by:
compareTo in interface Comparison
Parameters:
x - another value.
Returns:
The returned value is :
  • negative if this value is lower than another value
  • zero if the two values are equal
  • positive if this value is greater than another value

getFormattedString

public String getFormattedString(int length)
Return a string containing the value with a fixed format. The representation is assumed as "UTC" time (27 bytes) with format : "DD-MMM-YYYY HH:mm:ss.tttttt".

Specified by:
getFormattedString in interface ValueFormat
Parameters:
length - The expected length of the output string
Returns:
The formatted string.

getFormattedBuffer

public byte[] getFormattedBuffer()
Return a byte buffer containing the value in a fixed format. 946684800000L is the offset of the MJD origin : 01/01/2000 00:00:00.000000 (MJD origin).
The representation is assumed as "mjd" (3 * 4 bytes) :
int numDays : nb of days since Jan 1, 2000
unsigned int seconds : nb of seconds since the last day
unsigned int microseconds : nb of microseconds since the last second

Specified by:
getFormattedBuffer in interface ValueFormat
Returns:
The formatted buffer.

toString

public String toString()
Return the date in a string. This operation return a string with the following pattern : "dd-MMM-yyyy HH:mm:ss.tttttt".

Overrides:
toString in class Object
Returns:
The formatted string.

main

public static void main(String[] args)
Unitary tests operation.

Parameters:
args - the string array argument

getItemType

public int getItemType()
A code that identifies the value items.

Specified by:
getItemType in interface DrbItem
Returns:
The code of value items.

getName

public String getName()
Name of the item. This method always returns null.

Specified by:
getName in interface DrbItem
Returns:
null

rename

public void rename(String name)
            throws NullPointerException,
                   UnsupportedOperationException
Changes the name of the item. This method always throw an UnsupportedOperationException.

Specified by:
rename in interface DrbItem
Parameters:
name - Reference to the new name.
Throws:
UnsupportedOperationException - This exception always raised because the name property is not defined for values.
NullPointerException - This exception is overriden by an UnsupportedOperationException.

getNamespaceURI

public String getNamespaceURI()
Get namespace URI. This method always returns null.

Specified by:
getNamespaceURI in interface DrbItem
Returns:
null.

setNamespaceURI

public void setNamespaceURI(String namespace_uri)
                     throws NullPointerException,
                            UnsupportedOperationException
Sets a namespace resource identifier. This method always throw an UnsupportedOperationException.

Specified by:
setNamespaceURI in interface DrbItem
Parameters:
namespace_uri - A reference to the new namespace identifier.
Throws:
UnsupportedOperationException - This exception always raised because the name property is not defined for values.
NullPointerException - This exception is overriden by an UnsupportedOperationException.

getValue

public Value getValue()
The value of the item. The value is expressed according to one of the types supported by the fr.gael.drb.value package. Generally these types correspond to primitive types (e.g. integer, floatting points, etc.) or very low level types (e.g. string, date, etc.). On the contrary to DOM implementation all the types are allowed even the arrays, date etc. Only the Value.NULL_ID type is forbidden.

Specified by:
getValue in interface DrbItem
Returns:
The value of the attribute.

setValue

public Value setValue(Value value)
               throws NullPointerException,
                      ClassCastException,
                      UnsupportedOperationException
Changes the value of the item. This operation sets a new value of the current item.The value type of the item shall be compatible with the item implementation. If the type does not match exactly it is casted to a compatible one based on the the fr.gael.drb.value capabilities. A reference to the effectivelly assigned value is returned by the operation so it is possible to check if a cast has been performed and therefore assess the accuracy of the assignement. If the cast is not possible the operation raises an UnsupportedOperationException. If the assignment is possible and the item implementation has a physical representation the value is updated in the physical source in order to persist among sessions. It therefore possible that this operation consumses an variable time.

Specified by:
setValue in interface DrbItem
Parameters:
value - The new value of the node. This value shall not be null.
Returns:
The effectivelly assigned value. The type of this value may differ from the input one.
Throws:
NullPointerException - This exception is raised when the passed reference to the value is null. This exception may be overriden by an UnsupportedOperationException.
ClassCastException - This exception is raised when the implementation has not succeeded to cast the input value in a type compatible with the current node.
UnsupportedOperationException - This exception is raised when the implementation does not support the requested assignment for any reason.

toNumeric

public Numeric toNumeric()
                  throws ClassCastException
Convert the value into the numeric type. In case of identity conversion the value itself should be returned. If the conversion is not allowed a ClassCastException is thrown.

Returns:
The converted value.
Throws:
ClassCastException - is the convertion is impossible

Data Request Broker - DRB API®
2-3-release

Copyright© 2001-2009 GAEL Consultant. All rights reserved. Use is subject to license terms .