Update of /cvsroot/sunxacml/sunxacml/com/sun/xacml/attr
In directory sc8-pr-cvs1:/tmp/cvs-serv21844/com/sun/xacml/attr
Modified Files:
AttributeFactory.java AttributeSelector.java
TimeAttribute.java
Log Message:
TimeAttribute fix for DST and new Time & current env features plus some small
fixes and cleanups
Index: AttributeFactory.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/attr/AttributeFactory.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** AttributeFactory.java 13 Feb 2003 22:19:10 -0000 1.1.1.1
--- AttributeFactory.java 11 Aug 2003 20:48:44 -0000 1.2
***************
*** 266,271 ****
* @return a new <code>AttributeValue</code>
*
! * @throws UnknownIdentifierException if the type in the node isn't
! * known to the factory
* @throws ParsingException if the node is invalid or can't be parsed
* by the appropriate proxy
--- 266,271 ----
* @return a new <code>AttributeValue</code>
*
! * @throws UnknownIdentifierException if the data type isn't known to
! * the factory
* @throws ParsingException if the node is invalid or can't be parsed
* by the appropriate proxy
***************
*** 285,290 ****
* @return a new <code>AttributeValue</code>
*
! * @throws UnknownIdentifierException if the type in the node isn't
! * known to the factory
* @throws ParsingException if the node is invalid or can't be parsed
* by the appropriate proxy
--- 285,290 ----
* @return a new <code>AttributeValue</code>
*
! * @throws UnknownIdentifierException if the type isn't known to
! * the factory
* @throws ParsingException if the node is invalid or can't be parsed
* by the appropriate proxy
***************
*** 319,324 ****
* @return a new <code>AttributeValue</code>
*
! * @throws UnknownIdentifierException if the type in the node isn't
! * known to the factory
* @throws ParsingException if the text is invalid or can't be parsed
* by the appropriate proxy
--- 319,324 ----
* @return a new <code>AttributeValue</code>
*
! * @throws UnknownIdentifierException if the data type isn't known to
! * the factory
* @throws ParsingException if the text is invalid or can't be parsed
* by the appropriate proxy
Index: AttributeSelector.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/attr/AttributeSelector.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** AttributeSelector.java 29 Jul 2003 22:01:47 -0000 1.2
--- AttributeSelector.java 11 Aug 2003 20:48:45 -0000 1.3
***************
*** 93,97 ****
* of the XML type.
*
! * @param node the root of the DOM tree for the XML AttributeSelectorType
* XML type
*
--- 93,97 ----
* of the XML type.
*
! * @param root the root of the DOM tree for the XML AttributeSelectorType
* XML type
*
Index: TimeAttribute.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/attr/TimeAttribute.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** TimeAttribute.java 13 Feb 2003 22:19:10 -0000 1.1.1.1
--- TimeAttribute.java 11 Aug 2003 20:48:45 -0000 1.2
***************
*** 50,53 ****
--- 50,54 ----
import java.util.Iterator;
import java.util.List;
+ import java.util.TimeZone;
import org.w3c.dom.Node;
***************
*** 127,143 ****
/**
! * The actual time that this object represents, in GMT, with the
! * date set to January 1, 1970. If no time zone was specified, the local
! * time zone is used to convert to seconds relative to GMT.
! * <p>
! * 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.
*/
! private Date value;
/**
! * 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.
--- 128,140 ----
/**
! * The time that this object represents in second resolution, in
! * milliseconds GMT, with zero being midnight. If no time zone was
! * specified, the local time zone is used to convert to milliseconds
! * relative to GMT.
*/
! private long timeGMT;
/**
! * The number of nanoseconds beyond the time given by the timeGMT
* field. The XML Query document says that fractional seconds
* must be supported down to at least 100 nanosecond resolution.
***************
*** 147,150 ****
--- 144,151 ----
private int nanoseconds;
+ // NOTE: now that we're not using a Date object, the above two variables
+ // could be condensed, and the interface could be changed so we don't
+ // need to worry about tracking the time values separately
+
/**
* The time zone specified for this object (or TZ_UNSPECIFIED if
***************
*** 167,171 ****
/**
* Creates a new <code>TimeAttribute</code> that represents
! * the current time in the default time zone.
*/
public TimeAttribute() {
--- 168,172 ----
/**
* Creates a new <code>TimeAttribute</code> that represents
! * the current time in the current time zone.
*/
public TimeAttribute() {
***************
*** 224,228 ****
*/
private void init(Date date, int nanoseconds, int timeZone,
! int defaultedTimeZone) {
// Shouldn't happen, but just in case...
--- 225,229 ----
*/
private void init(Date date, int nanoseconds, int timeZone,
! int defaultedTimeZone) {
// Shouldn't happen, but just in case...
***************
*** 230,247 ****
throw earlyException;
! // Make a new Date object
! this.value = (Date) date.clone();
// Combine the nanoseconds so they are between 0 and 999,999,999
this.nanoseconds =
! DateTimeAttribute.combineNanos(this.value, nanoseconds);
this.timeZone = timeZone;
this.defaultedTimeZone = defaultedTimeZone;
! // Check that the date is normalized to 1/1/70, and adjust as needed
! long millis = value.getTime();
! if ((millis > DateAttribute.MILLIS_PER_DAY) || (millis < 0)) {
! millis = millis % DateAttribute.MILLIS_PER_DAY;
! value.setTime(millis);
! }
}
--- 231,251 ----
throw earlyException;
! // get a temporary copy of the date
! Date tmpDate = (Date)(date.clone());
!
// Combine the nanoseconds so they are between 0 and 999,999,999
this.nanoseconds =
! DateTimeAttribute.combineNanos(tmpDate, nanoseconds);
!
! // now that the date has been (potentially) updated, store the time
! this.timeGMT = tmpDate.getTime();
!
! // keep track of the timezone values
this.timeZone = timeZone;
this.defaultedTimeZone = defaultedTimeZone;
! // Check that the date is normalized to 1/1/70
! if ((timeGMT > DateAttribute.MILLIS_PER_DAY) || (timeGMT < 0))
! timeGMT = timeGMT % DateAttribute.MILLIS_PER_DAY;
}
***************
*** 279,286 ****
DateTimeAttribute dateTime = DateTimeAttribute.getInstance(value);
! return new TimeAttribute(dateTime.getValue(),
dateTime.getNanoseconds(),
dateTime.getTimeZone(),
! dateTime.getDefaultedTimeZone());
}
--- 283,306 ----
DateTimeAttribute dateTime = DateTimeAttribute.getInstance(value);
! // if there was no explicit TZ provided, then we want to make sure
! // the that the defaulting is done correctly, especially since 1/1/70
! // is always out of daylight savings time
!
! Date dateValue = dateTime.getValue();
! int defaultedTimeZone = dateTime.getDefaultedTimeZone();
! if (dateTime.getTimeZone() == TZ_UNSPECIFIED) {
! TimeZone localTZ = TimeZone.getDefault();
! int newDefTimeZone =
! DateTimeAttribute.getDefaultTZOffset(new Date());
! dateValue = new Date(dateValue.getTime() -
! (newDefTimeZone - defaultedTimeZone) *
! DateAttribute.MILLIS_PER_MINUTE);
! defaultedTimeZone = newDefTimeZone;
! }
!
! return new TimeAttribute(dateValue,
dateTime.getNanoseconds(),
dateTime.getTimeZone(),
! defaultedTimeZone);
}
***************
*** 312,318 ****
* of January 1, 1970. Subsecond values are handled by the
* {@link #getNanoseconds getNanoseconds} method.
- * <p>
- * <b>NOTE:</b> The <code>Date</code> object is cloned before it
- * is returned to avoid unauthorized changes.
*
* @return a <code>Date</code> object representing the
--- 332,335 ----
***************
*** 320,324 ****
*/
public Date getValue() {
! return (Date) value.clone();
}
--- 337,353 ----
*/
public Date getValue() {
! return new Date(timeGMT);
! }
!
! /**
! * Gets the number of milliseconds since midnight GMT that this attribute
! * value represents. This is the same time returned by
! * <code>getValue</code>, and likewise the milliseconds are provided
! * with second resolution.
! *
! * @return milliseconds since midnight GMT
! */
! public long getMilliseconds() {
! return timeGMT;
}
***************
*** 366,370 ****
TimeAttribute other = (TimeAttribute)o;
! return (value.equals(other.value) &&
(nanoseconds == other.nanoseconds));
}
--- 395,399 ----
TimeAttribute other = (TimeAttribute)o;
! return (timeGMT == other.timeGMT &&
(nanoseconds == other.nanoseconds));
}
***************
*** 378,386 ****
*/
public int hashCode() {
! // Both the value field and the nanoseconds field are considered
// by the equals method, so it's best if the hashCode is derived
// from both of those fields.
! int hashCode = value.hashCode();
! hashCode = 31*hashCode + nanoseconds;
return hashCode;
}
--- 407,418 ----
*/
public int hashCode() {
! // the standard Date hashcode is used here...
! int hashCode = (int)(timeGMT ^ (timeGMT >>> 32));
!
! // ...but both the timeGMT and the nanoseconds fields are considered
// by the equals method, so it's best if the hashCode is derived
// from both of those fields.
! hashCode = (31 * hashCode) + nanoseconds;
!
return hashCode;
}
***************
*** 392,404 ****
*/
public String toString() {
! StringBuffer sb = new StringBuffer();
! sb.append("TimeAttribute: [\n");
! sb.append(" Date: " + value + " local time");
sb.append(" Nanoseconds: " + nanoseconds);
sb.append(" TimeZone: " + timeZone);
sb.append(" Defaulted TimeZone: " + defaultedTimeZone);
! sb.append("]");
! return sb.toString();
}
--- 424,449 ----
*/
public String toString() {
! StringBuffer sb = new StringBuffer();
! sb.append("TimeAttribute: [\n");
!
! // calculate the GMT value of this time
! long secsGMT = timeGMT / 1000;
! long minsGMT = secsGMT / 60;
! secsGMT = secsGMT % 60;
! long hoursGMT = minsGMT / 60;
! minsGMT = minsGMT % 60;
! // put the right number of zeros in place
! String hoursStr = (hoursGMT < 10) ? "0" + hoursGMT : "" + hoursGMT;
! String minsStr = (minsGMT < 10) ? "0" + minsGMT : "" + minsGMT;
! String secsStr = (secsGMT < 10) ? "0" + secsGMT : "" + secsGMT;
!
! sb.append(" Time GMT: " + hoursStr + ":" + minsStr + ":" + secsStr);
sb.append(" Nanoseconds: " + nanoseconds);
sb.append(" TimeZone: " + timeZone);
sb.append(" Defaulted TimeZone: " + defaultedTimeZone);
! sb.append("]");
!
! return sb.toString();
}
***************
*** 420,424 ****
initParsers();
synchronized (simpleParser) {
! encodedValue = simpleParser.format(value);
}
if (nanoseconds != 0) {
--- 465,469 ----
initParsers();
synchronized (simpleParser) {
! encodedValue = simpleParser.format(new Date(timeGMT));
}
if (nanoseconds != 0) {
***************
*** 448,452 ****
StringBuffer buf = new StringBuffer(27);
! int millis = (int) value.getTime();
int hour = millis / DateAttribute.MILLIS_PER_HOUR;
millis = millis % DateAttribute.MILLIS_PER_HOUR;
--- 493,497 ----
StringBuffer buf = new StringBuffer(27);
! int millis = (int)timeGMT;
int hour = millis / DateAttribute.MILLIS_PER_HOUR;
millis = millis % DateAttribute.MILLIS_PER_HOUR;
|