pasn
Class ASN1Time

java.lang.Object
  extended by pasn.ASN1Object
      extended by pasn.ASN1SimpleObject<ASN1TimeValue>
          extended by pasn.ASN1Time
All Implemented Interfaces:
ASN1DefaultValuedObject, ASN1EncodingSpecificObject, ASN1GenericObject, ASN1PrimitiveObject<ASN1TimeValue>, ASN1Resetable
Direct Known Subclasses:
ASN1GeneralizedTime, ASN1UTCTime

public abstract class ASN1Time
extends ASN1SimpleObject<ASN1TimeValue>

Generic class that manipulates ASN.1 time objects common operations

Author:
N. Cottin - http://www.ncottin.net

Constructor Summary
ASN1Time(int type, boolean shortYear)
           
 
Method Summary
 ASN1TimeValue createValue()
           
static ASN1Time getAppropriateTime()
           Returns either an UTC time or a Generalized time depending on date constraints.
static ASN1Time getAppropriateTime(java.util.Date value)
           Returns either an UTC time or a Generalized time depending on date constraints.
static ASN1Time getAppropriateTime(java.lang.String value)
           Given a string representation of a time value, returns the appropriate ASN.1 time object depending on the number of digits used to express the given value
 ASN1TimeFormat getTimeFormat()
           
 boolean hasDefaultValue()
           
 boolean hasValue()
           Indicates whether this TIME object is initialized with a time value or not
 boolean isTimeValidated()
           
 boolean isValueDefault()
           
 void reset()
           Resets this ASN.1 time object.
 void setDecodedValue(java.lang.Object value)
           
 void setTimeFormat(ASN1TimeFormat tf)
           
 void setTimeValidation(boolean validate)
           
 void setValue()
           
abstract  void setValue(java.lang.String value)
          Initializes this ASN.1 time object with a string representation of a date and time
 java.lang.String toString()
          Expresses this time object as a string, according to the current time format (default format is ASN1TimeFormat.FORMAT_0)
 java.lang.String toString(ASN1TimeFormat format)
           
 void validateConstraints(ASN1TimeValue value)
           
 
Methods inherited from class pasn.ASN1SimpleObject
equals, getDefaultValue, getValue, getValueOrDefault, hasValueOrDefault, setDefaultValue, setValue
 
Methods inherited from class pasn.ASN1Object
getAsnClass, getSpecificEncoding, getSpecificEncoding, getType, hasSpecificEncodings, setSpecificEncoding
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface pasn.ASN1GenericObject
getASN1Name, getAsnClass, getType
 
Methods inherited from interface pasn.ASN1EncodingSpecificObject
getSpecificEncoding, hasSpecificEncodings
 

Constructor Detail

ASN1Time

public ASN1Time(int type,
                boolean shortYear)
Method Detail

setTimeValidation

public final void setTimeValidation(boolean validate)

isTimeValidated

public boolean isTimeValidated()

isValueDefault

public final boolean isValueDefault()

getAppropriateTime

public static final ASN1Time getAppropriateTime()
                                         throws ASN1ConstraintException

Returns either an UTC time or a Generalized time depending on date constraints. The enclosed date value corresponds to the current date and time. Indeed, UTC time should not be used to manipulate dates prior to 1949 or later than 2049. It is commonly adopted that other date values sould be represented by generalized times

Returns:
A UTC time instance in case the current date is in range [1950;2049]. A generalized time if this date is out of this range
Throws:
ASN1ConstraintException

getAppropriateTime

public static final ASN1Time getAppropriateTime(java.util.Date value)
                                         throws ASN1ConstraintException

Returns either an UTC time or a Generalized time depending on date constraints. Indeed, UTC time should not be used to manipulate dates prior to 1949 or later than 2049. It is commonly accepted that other dates sould be represented by generalized times

Parameters:
value - Any date. A null date is considered as the current date
Returns:
A UTC time instance in case the given date is in range [1950;2049]. A generalized time if this date is out of this range
Throws:
ASN1ConstraintException

getAppropriateTime

public static final ASN1Time getAppropriateTime(java.lang.String value)
                                         throws ASN1FormatException,
                                                ASN1ConstraintException

Given a string representation of a time value, returns the appropriate ASN.1 time object depending on the number of digits used to express the given value

Parameters:
value - A string representation of a time value. This value must conform to one of the available representation formats
Returns:
A UTC time instance in case the year is expressed using 2 digits, or a Generalized time instance if the given year value is represented by 4 digits
Throws:
ASN1FormatException
ASN1ConstraintException - The given value does not represent a valid time value or does not conform to the supported time formats

validateConstraints

public final void validateConstraints(ASN1TimeValue value)
                               throws ASN1ConstraintException
Throws:
ASN1ConstraintException

hasValue

public final boolean hasValue()

Indicates whether this TIME object is initialized with a time value or not

Returns:
True if this ASN.1 TIME holds a time value (which is mostly the case) or false if no value is currently associated with this TIME object (after a call to reset() for example

hasDefaultValue

public final boolean hasDefaultValue()

reset

public void reset()

Resets this ASN.1 time object. Note that this operation does not initialize the current time zone to its default value ("GMT+0000") nor the current time format.

Any call to hasValue() returns false


createValue

public final ASN1TimeValue createValue()

setValue

public final void setValue()

setTimeFormat

public final void setTimeFormat(ASN1TimeFormat tf)

getTimeFormat

public final ASN1TimeFormat getTimeFormat()

setDecodedValue

public final void setDecodedValue(java.lang.Object value)
                           throws ASN1FormatException,
                                  ASN1ConstraintException
Throws:
ASN1FormatException
ASN1ConstraintException

setValue

public abstract void setValue(java.lang.String value)
                       throws ASN1FormatException,
                              ASN1ConstraintException
Initializes this ASN.1 time object with a string representation of a date and time

Parameters:
value - A time value. A null or empty ("") value leads to assign the current time value using local time zone
Throws:
ASN1FormatException - The given value does not correspond to a valid time representation
ASN1ConstraintException

toString

public final java.lang.String toString(ASN1TimeFormat format)

toString

public final java.lang.String toString()
Expresses this time object as a string, according to the current time format (default format is ASN1TimeFormat.FORMAT_0)

Overrides:
toString in class java.lang.Object
Returns:
The "stringified" value of the current internal time value of this time object. Note that this returned value must not be null