Update of /cvsroot/sunxacml/sunxacml/com/sun/xacml/attr
In directory sc8-pr-cvs1:/tmp/cvs-serv21612
Modified Files:
TimeAttribute.java
Log Message:
fixed the encoding and removed some now no longer needed code
Index: TimeAttribute.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/attr/TimeAttribute.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** TimeAttribute.java 11 Aug 2003 20:48:45 -0000 1.2
--- TimeAttribute.java 25 Aug 2003 16:49:17 -0000 1.3
***************
*** 38,48 ****
import com.sun.xacml.ParsingException;
import java.net.URI;
- import java.text.DateFormat;
- import java.text.FieldPosition;
import java.text.ParseException;
- import java.text.SimpleDateFormat;
import java.util.ArrayList;
--- 38,46 ----
import com.sun.xacml.ParsingException;
+ import com.sun.xacml.ProcessingException;
import java.net.URI;
import java.text.ParseException;
import java.util.ArrayList;
***************
*** 108,125 ****
/**
- * Parser for dates with no time zones
- * <p>
- * This field is only initialized if needed (by initParsers()).
- * <p>
- * 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.
- */
- private static DateFormat simpleParser;
-
- /**
* Time zone value that indicates that the time zone was not
* specified.
--- 106,109 ----
***************
*** 194,199 ****
* offset to GMT, in minutes.
* @param 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.
*/
--- 178,182 ----
* offset to GMT, in minutes.
* @param defaultedTimeZone the time zone actually used for this
! * object, which must be specified.
* The offset to GMT, in minutes.
*/
***************
*** 202,205 ****
--- 185,194 ----
super(identifierURI);
+ // if the timezone is unspecified, it's illegal for the defaulted
+ // timezone to also be unspecified
+ if ((timeZone == TZ_UNSPECIFIED) &&
+ (defaultedTimeZone == TZ_UNSPECIFIED))
+ throw new ProcessingException("default timezone must be specified");
+
init(date, nanoseconds, timeZone, defaultedTimeZone);
}
***************
*** 246,250 ****
// Check that the date is normalized to 1/1/70
! if ((timeGMT > DateAttribute.MILLIS_PER_DAY) || (timeGMT < 0))
timeGMT = timeGMT % DateAttribute.MILLIS_PER_DAY;
}
--- 235,239 ----
// Check that the date is normalized to 1/1/70
! if ((timeGMT >= DateAttribute.MILLIS_PER_DAY) || (timeGMT < 0))
timeGMT = timeGMT % DateAttribute.MILLIS_PER_DAY;
}
***************
*** 306,330 ****
/**
- * Initialize the parser objects.
- */
- private static void initParsers() {
- // If simpleParser is already set, we're done.
- if (simpleParser != null)
- return;
-
- // Make sure that identifierURI is not null
- if (earlyException != null)
- throw earlyException;
-
- // Synchronize on identifierURI while initializing parsers
- // so we don't end up using a half-way initialized parser
- synchronized (identifierURI) {
- // This simple parser has no time zone
- simpleParser = new SimpleDateFormat("HH:mm:ss");
- simpleParser.setLenient(false);
- }
- }
-
- /**
* Gets the time represented by this object. The return
* value is a <code>Date</code> object representing the
--- 295,298 ----
***************
*** 450,454 ****
/**
* 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.
--- 418,422 ----
/**
* Encodes the value in a form suitable for including in XML data like
! * a request or an obligation. This returns a time value that could in
* turn be used by the factory to create a new instance with the same
* value.
***************
*** 460,497 ****
return encodedValue;
- if (timeZone == TZ_UNSPECIFIED) {
- // If no time zone was specified, format Date value in
- // local time with no time zone string.
- initParsers();
- synchronized (simpleParser) {
- encodedValue = simpleParser.format(new Date(timeGMT));
- }
- if (nanoseconds != 0) {
- encodedValue = encodedValue + "." +
- DateAttribute.zeroPadInt(nanoseconds, 9);
- }
- } else {
- // If a time zone was specified, don't use SimpleParser
- // because it can only format dates in the local (default)
- // time zone. And the offset between that time zone and the
- // time zone we need to display can vary in complicated ways.
-
- // Instead, do it ourselves using our formatDateWithTZ method.
- encodedValue = formatTimeWithTZ();
- }
- return encodedValue;
- }
-
- /**
- * Encodes the value of this object as an xsi:time.
- * Only for use when the time zone is specified.
- *
- * @return a <code>String</code> form of the value
- */
- private String formatTimeWithTZ() {
// "hh:mm:ss.sssssssss+hh:mm".length() = 27
StringBuffer buf = new StringBuffer(27);
int millis = (int)timeGMT;
int hour = millis / DateAttribute.MILLIS_PER_HOUR;
millis = millis % DateAttribute.MILLIS_PER_HOUR;
--- 428,448 ----
return encodedValue;
// "hh:mm:ss.sssssssss+hh:mm".length() = 27
StringBuffer buf = new StringBuffer(27);
+ // get the correct time for the timezone being used
int millis = (int)timeGMT;
+ if (timeZone == TZ_UNSPECIFIED)
+ millis += (defaultedTimeZone * DateAttribute.MILLIS_PER_MINUTE);
+ else
+ millis += (timeZone * DateAttribute.MILLIS_PER_MINUTE);
+
+ if (millis < 0) {
+ millis += DateAttribute.MILLIS_PER_DAY;
+ } else if (millis >= DateAttribute.MILLIS_PER_DAY) {
+ millis -= DateAttribute.MILLIS_PER_DAY;
+ }
+
+ // now generate the time string
int hour = millis / DateAttribute.MILLIS_PER_HOUR;
millis = millis % DateAttribute.MILLIS_PER_HOUR;
***************
*** 505,508 ****
--- 456,460 ----
buf.append(DateAttribute.zeroPadInt(second, 2));
+ // add any nanoseconds
if (nanoseconds != 0) {
buf.append('.');
***************
*** 510,526 ****
}
! int tzNoSign = timeZone;
! if (timeZone < 0) {
! tzNoSign = -tzNoSign;
! buf.append('-');
! } else
! buf.append('+');
! int tzHours = tzNoSign / 60;
! buf.append(DateAttribute.zeroPadInt(tzHours, 2));
! buf.append(':');
! int tzMinutes = tzNoSign % 60;
! buf.append(DateAttribute.zeroPadInt(tzMinutes, 2));
! return buf.toString();
}
}
--- 462,485 ----
}
! // if there is a specified timezone, then include that in the encoding
! if (timeZone != TZ_UNSPECIFIED) {
! int tzNoSign = timeZone;
! if (timeZone < 0) {
! tzNoSign = -tzNoSign;
! buf.append('-');
! } else
! buf.append('+');
! int tzHours = tzNoSign / 60;
! buf.append(DateAttribute.zeroPadInt(tzHours, 2));
! buf.append(':');
! int tzMinutes = tzNoSign % 60;
! buf.append(DateAttribute.zeroPadInt(tzMinutes, 2));
! }
! // remember the encoding for later
! encodedValue = buf.toString();
!
! return encodedValue;
}
+
}
|