Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.sun.xacml.attr
Class DateTimeAttribute  view DateTimeAttribute download DateTimeAttribute.java

java.lang.Object
  extended bycom.sun.xacml.attr.AttributeValue
      extended bycom.sun.xacml.attr.DateTimeAttribute
All Implemented Interfaces:
com.sun.xacml.cond.Evaluatable

public class DateTimeAttribute
extends AttributeValue

Representation of an xs:dateTime value. This class supports parsing xs:dateTime values. All objects of this class are immutable and thread-safe. The Date objects returned are not, but these objects are cloned before being returned.

Since:
1.0

Field Summary
private  int defaultedTimeZone
          The time zone actually used for this object (if it was originally unspecified, the default time zone used).
private static java.lang.RuntimeException earlyException
          RuntimeException that wraps an Exception thrown during the creation of identifierURI, null if none.
private  java.lang.String encodedValue
          Cached encoded value (null if not cached yet).
private static java.util.Calendar gmtCalendar
          Calendar for GMT
static java.lang.String identifier
          Official name of this type
private static java.net.URI identifierURI
          URI version of name for this type
private  int nanoseconds
          The number of nanoseconds beyond the Date given by the value field.
private static java.text.DateFormat simpleParser
          Parser for dates with no time zones
private  int timeZone
          The time zone specified for this object (or TZ_UNSPECIFIED if unspecified).
static int TZ_UNSPECIFIED
          Time zone value that indicates that the time zone was not specified.
private  java.util.Date value
          The actual date and time that this object represents (in GMT, as with all Date objects).
private static java.text.DateFormat zoneParser
          Parser for dates with RFC 822 time zones (like +0300)
 
Fields inherited from class com.sun.xacml.attr.AttributeValue
 
Constructor Summary
DateTimeAttribute()
          Creates a new DateTimeAttribute that represents the current date in the default time zone.
DateTimeAttribute(java.util.Date date, int nanoseconds, int timeZone, int defaultedTimeZone)
          Creates a new DateTimeAttribute that represents the date supplied.
 
Method Summary
(package private) static int combineNanos(java.util.Date date, int nanoseconds)
          Combines a number of nanoseconds with a Date so that the Date has no fractional seconds and the number of nanoseconds is non-negative and less than a second.
 java.lang.String encode()
          Encodes the value in a form suitable for including in XML data like a request or an obligation.
 boolean equals(java.lang.Object o)
          Returns true if the input is an instance of this class and if its value equals the value contained in this class.
private  java.lang.String formatDateTimeWithTZ()
          Encodes the value of this object as an xsi:dateTime.
 int getDefaultedTimeZone()
          Gets the time zone actually used for this object (if it was originally unspecified, the default time zone used).
(package private) static int getDefaultTZOffset(java.util.Date date)
          Gets the offset in minutes between the default time zone and UTC for the specified date.
static DateTimeAttribute getInstance(org.w3c.dom.Node root)
          Returns a new DateTimeAttribute that represents the xs:dateTime at a particular DOM node.
static DateTimeAttribute getInstance(java.lang.String value)
          Returns a new DateTimeAttribute that represents the xs:dateTime value indicated by the string provided.
 int getNanoseconds()
          Gets the nanoseconds of this object.
 int getTimeZone()
          Gets the time zone of this object (or TZ_UNSPECIFIED if unspecified).
 java.util.Date getValue()
          Gets the date and time represented by this object.
 int hashCode()
          Returns the hashcode value used to index and compare this object with others of the same type.
private  void init(java.util.Date date, int nanoseconds, int timeZone, int defaultedTimeZone)
          Initialization code shared by constructors.
private static void initParsers()
          Initialize the parser objects.
private static java.util.Date strictParse(java.text.DateFormat parser, java.lang.String str)
          Parse a String using a DateFormat parser, requiring that the entire String be consumed by the parser.
 java.lang.String toString()
          Converts to a String representation.
 
Methods inherited from class com.sun.xacml.attr.AttributeValue
encode, encode, encodeWithTags, evaluate, evaluatesToBag, getChildren, getType, isBag
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

identifier

public static final java.lang.String identifier
Official name of this type

See Also:
Constant Field Values

identifierURI

private static java.net.URI identifierURI
URI version of name for this type

This field is initialized by a static initializer so that we can catch any exceptions thrown by URI(String) and transform them into a RuntimeException, since this should never happen but should be reported properly if it ever does.

This object is used for synchronization whenever we need protection across this whole class.


earlyException

private static java.lang.RuntimeException earlyException
RuntimeException that wraps an Exception thrown during the creation of identifierURI, null if none.


simpleParser

private static java.text.DateFormat simpleParser
Parser for dates with no time zones

This field is only initialized if needed (by initParsers()).

NOTE: This object should only be accessed from code that has synchronized on it, since SimpleDateFormat objects are not thread-safe. If this is causing performance problems, we could easily make this a method variable in methods that use it instead of a class field. But that would mean we'd need to spend a lot more time creating these objects.


zoneParser

private static java.text.DateFormat zoneParser
Parser for dates with RFC 822 time zones (like +0300)

This field is only initialized if needed (by initParsers()).

NOTE: This object should only be accessed from code that has synchronized on it, since SimpleDateFormat objects are not thread-safe.


gmtCalendar

private static java.util.Calendar gmtCalendar
Calendar for GMT

NOTE: This object should only be accessed from code that has a lock on it, since Calendar objects are not generally thread-safe.


TZ_UNSPECIFIED

public static final int TZ_UNSPECIFIED
Time zone value that indicates that the time zone was not specified.

See Also:
Constant Field Values

value

private java.util.Date value
The actual date and time that this object represents (in GMT, as with all Date objects). If no time zone was specified, the local time zone is used to convert to GMT.

This Date does not include fractions of a second. Those are handled by the separate nanoseconds field, since Date only provides millisecond accuracy and the XML Query spec requires at least 100 nanosecond accuracy.


nanoseconds

private int nanoseconds
The number of nanoseconds beyond the Date given by the value field. The XML Query document says that fractional seconds must be supported down to at least 100 nanosecond resolution. The Date class only supports milliseconds, so we include here support for nanosecond resolution.


timeZone

private int timeZone
The time zone specified for this object (or TZ_UNSPECIFIED if unspecified). The offset to GMT, in minutes.


defaultedTimeZone

private int defaultedTimeZone
The time zone actually used for this object (if it was originally unspecified, the default time zone used). The offset to GMT, in minutes.


encodedValue

private java.lang.String encodedValue
Cached encoded value (null if not cached yet).

Constructor Detail

DateTimeAttribute

public DateTimeAttribute()
Creates a new DateTimeAttribute that represents the current date in the default time zone.


DateTimeAttribute

public DateTimeAttribute(java.util.Date date,
                         int nanoseconds,
                         int timeZone,
                         int defaultedTimeZone)
Creates a new DateTimeAttribute that represents the date supplied.

Method Detail

init

private void init(java.util.Date date,
                  int nanoseconds,
                  int timeZone,
                  int defaultedTimeZone)
Initialization code shared by constructors.


getInstance

public static DateTimeAttribute getInstance(org.w3c.dom.Node root)
                                     throws com.sun.xacml.ParsingException,
                                            java.lang.NumberFormatException,
                                            java.text.ParseException
Returns a new DateTimeAttribute that represents the xs:dateTime at a particular DOM node.


getInstance

public static DateTimeAttribute getInstance(java.lang.String value)
                                     throws com.sun.xacml.ParsingException,
                                            java.lang.NumberFormatException,
                                            java.text.ParseException
Returns a new DateTimeAttribute that represents the xs:dateTime value indicated by the string provided.


strictParse

private static java.util.Date strictParse(java.text.DateFormat parser,
                                          java.lang.String str)
                                   throws java.text.ParseException
Parse a String using a DateFormat parser, requiring that the entire String be consumed by the parser. On success, return a Date. On failure, throw a ParseException.

Synchronize on the parser object when using it, since we assume they're the shared static objects in this class.


initParsers

private static void initParsers()
Initialize the parser objects.


getValue

public java.util.Date getValue()
Gets the date and time represented by this object. The return value is a Date object representing the specified date and time down to second resolution. Subsecond values are handled by the getNanoseconds 55 method.

NOTE: The Date object is cloned before it is returned to avoid unauthorized changes.


getNanoseconds

public int getNanoseconds()
Gets the nanoseconds of this object.


getTimeZone

public int getTimeZone()
Gets the time zone of this object (or TZ_UNSPECIFIED if unspecified).


getDefaultedTimeZone

public int getDefaultedTimeZone()
Gets the time zone actually used for this object (if it was originally unspecified, the default time zone used).


equals

public boolean equals(java.lang.Object o)
Returns true if the input is an instance of this class and if its value equals the value contained in this class.

Two DateTimeAttributes are equal if and only if the dates and times represented are identical (down to the nanosecond).


hashCode

public int hashCode()
Returns the hashcode value used to index and compare this object with others of the same type.


toString

public java.lang.String toString()
Converts to a String representation.


encode

public java.lang.String encode()
Encodes the value in a form suitable for including in XML data like a request or an obligation. This must return a value that could in turn be used by the factory to create a new instance with the same value.

Specified by:
encode in class AttributeValue

formatDateTimeWithTZ

private java.lang.String formatDateTimeWithTZ()
Encodes the value of this object as an xsi:dateTime. Only for use when the time zone is specified.


getDefaultTZOffset

static int getDefaultTZOffset(java.util.Date date)
Gets the offset in minutes between the default time zone and UTC for the specified date.


combineNanos

static int combineNanos(java.util.Date date,
                        int nanoseconds)
Combines a number of nanoseconds with a Date so that the Date has no fractional seconds and the number of nanoseconds is non-negative and less than a second.

WARNING: This function changes the value stored in the date parameter!