You are viewing a plain text version of this content. The canonical link for it is here.
Posted to imperius-commits@incubator.apache.org by ke...@apache.org on 2008/01/11 18:57:14 UTC
svn commit: r611261 [16/43] - in /incubator/imperius/trunk: ./
imperius-javaspl/ imperius-javaspl/src/main/java/org/apache/imperius/javaspl/
imperius-splcore/
imperius-splcore/src/main/antlr/org/apache/imperius/spl/parser/compiler/
imperius-splcore/src...
Modified: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/DateTime.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/DateTime.java?rev=611261&r1=611260&r2=611261&view=diff
==============================================================================
--- incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/DateTime.java (original)
+++ incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/DateTime.java Fri Jan 11 10:56:30 2008
@@ -1,864 +1,864 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-//
-
-/**
- * @author Prashant Baliga <pr...@in.ibm.com>
- *
- */
-package org.apache.imperius.spl.parser.expressions.impl;
-
-import java.util.Calendar;
-import java.util.NoSuchElementException;
-import java.util.StringTokenizer;
-import java.util.TimeZone;
-import java.util.logging.Logger;
-
-import org.apache.imperius.spl.external.Expression;
-import org.apache.imperius.spl.external.TypeConstants;
-import org.apache.imperius.spl.parser.exceptions.SPLException;
-import org.apache.imperius.spl.parser.util.TypeInfo;
-import org.apache.imperius.util.SPLLogger;
-
-
-/**
- * This class implements a for xsd:dateTime.
- * <p>
- *
- * It
- * <ul>
- * <li>supports http://www.w3.org/TR/1998/NOTE-datetime-19980827
- * <li>supports version without - and : in date/time (see for example)
- * http://www.cl.cam.ac.uk/~mgk25/iso-time.html
- * <li> does not support week modifiers etc.
- * </ul>
- *
- *
- * @author Policy Toolkit Team
- */
-public class DateTime implements Expression
-{
-
-
- private int _timeZoneMinuteOffset = 0;
-
- private int _timeZoneMillisOffset = 0;
-
- private String _timeZoneString = "GMT";
-
- private int _millis = -1;
-
- private int _second = -1;
-
- private int _minute = -1;
-
- private int _hour = -1;
-
- private int _day = -1;
-
- private int _month = -1;
-
- private int _year = -1;
-
- private boolean eraAD = true;
-
- public boolean isArray = false;
-
- private TypeInfo _dataType = null;
-
- private static int UTC_MULTIPLIER = 60000;
-
- private static Logger logger = SPLLogger.getSPLLogger().getLogger();
- private static final String sourceClass="DateTime";
-
-
-
- public boolean isArray()
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "isArray");
-
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "isArray");
-
-
- return isArray;
- }
-
- public DateTime(String splDateTime) throws SPLException
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "DateTime");
-
-
- //System.out.println(" date string :" + dateStringGeneric);
- // Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(GMT));
-
- // CIM date format yyyymmddHHMMSS.mmmmmmsUUU
- String dateString = splDateTime.replace('*', '0');
-
- String YEAR = dateString.substring(0, 4);
- String MONTH = dateString.substring(4, 6);
- String DAY_OF_MONTH = dateString.substring(6, 8);
- String HOUR_OF_DAY = dateString.substring(8, 10);
- String MINUTE = dateString.substring(10, 12);
- String SECOND = dateString.substring(12, 14);// leaving out '.'
- String MILLISECOND = dateString.substring(15, 18);// leaving out the
- // last 3 digits as
- // microsecond is
- // not supported,
- // restricting to
- // millisecond
- String sign = dateString.substring(21, 22);// can be '+' or '-'
- String utcOffset = dateString.substring(22, 25);// needs to converted to
- // GMT
-
-
- _year = Integer.parseInt(YEAR);
- _month = Integer.parseInt(MONTH);
- _day = Integer.parseInt(DAY_OF_MONTH);
- _hour = Integer.parseInt(HOUR_OF_DAY);
- //System.out.println("MINUTE "+MINUTE);
- _minute = Integer.parseInt(MINUTE);
- //System.out.println("_minute "+_minute);
-
- _second = Integer.parseInt(SECOND);
- _millis = Integer.parseInt(MILLISECOND);
-
- int timeZoneMinuteOffset = Integer.parseInt(utcOffset);
- int hrs = timeZoneMinuteOffset / 60;
- _timeZoneString = _timeZoneString + sign + hrs;
-
- int zoneOffsetMilliseconds = timeZoneMinuteOffset * UTC_MULTIPLIER;
-
- if (sign.equalsIgnoreCase("-"))
- {
- zoneOffsetMilliseconds = 0 - zoneOffsetMilliseconds;
- timeZoneMinuteOffset = 0 - timeZoneMinuteOffset;
- }
- _timeZoneMinuteOffset = timeZoneMinuteOffset;
- _timeZoneMillisOffset = zoneOffsetMilliseconds;
- //System.out.println("created calendar");
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "DateTime");
-
-
- }
-
- public String getTimeZoneString()
- {
- return _timeZoneString;
- }
-
- public static boolean isDateTimeString(String dateStringGeneric)
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "isDateTimeString");
-
-
- //System.out.println("*****Checking to see if string is datetime"+dateStringGeneric);
- String dateStr=dateStringGeneric.substring(1, dateStringGeneric.length()-1);
- //System.out.println("*****Checking to see if string is dateStr"+dateStr);
-
- dateStr = dateStr.replace('*', '0');
- //System.out.println("*****Checking to see if string is dateStr"+dateStr+dateStr.length());
-
- if(dateStr.length()!=25)
- {
- return false;
- }
- String YEAR = dateStr.substring(0, 4);
- String MONTH = dateStr.substring(4, 6);
- String DAY_OF_MONTH = dateStr.substring(6, 8);
- String HOUR_OF_DAY = dateStr.substring(8, 10);
- String MINUTE = dateStr.substring(10, 12);
- String SECOND = dateStr.substring(12, 14);// leaving out '.'
- String MILLISECOND = dateStr.substring(15, 18);// leaving out the
- // last 3 digits as
- // microsecond is
- // not supported,
- // restricting to
- // millisecond
- String sign = dateStr.substring(21, 22);// can be '+' or '-'
- String utcOffset = dateStr.substring(22, 25);// needs to converted to
-
- //System.out.println("*****YEAR"+Integer.parseInt(YEAR));
- try
- {
- if(Integer.parseInt(YEAR) >=0 && Integer.parseInt(YEAR) <=9999)
- {//System.out.println("*****MONTH"+Integer.parseInt(MONTH));
- if(Integer.parseInt(MONTH) >0 && Integer.parseInt(MONTH) <=12)
- {//System.out.println("*****DAY_OF_MONTH"+Integer.parseInt(DAY_OF_MONTH));
- if(Integer.parseInt(DAY_OF_MONTH) >0 && Integer.parseInt(DAY_OF_MONTH) <=31)
- {//System.out.println("*****HOUR_OF_DAY"+Integer.parseInt(HOUR_OF_DAY));
- if(Integer.parseInt(HOUR_OF_DAY) >=0 && Integer.parseInt(HOUR_OF_DAY) <24)
- {//System.out.println("*****MINUTE"+Integer.parseInt(MINUTE));
- if(Integer.parseInt(MINUTE) >=0 && Integer.parseInt(MINUTE) <60)
- {//System.out.println("*****SECOND"+Integer.parseInt(SECOND));
- if(Integer.parseInt(SECOND) >=0 && Integer.parseInt(SECOND) <60)
- {//System.out.println("*****MILLISECOND"+Integer.parseInt(MILLISECOND));
- if(Integer.parseInt(MILLISECOND) >=0 && Integer.parseInt(MILLISECOND) <=999)
- {//System.out.println("*****+"+sign);
- if(sign.equalsIgnoreCase("+") || sign.equalsIgnoreCase("-"))
- {//System.out.println("*****utcOffset"+Integer.parseInt(utcOffset));
- if(Integer.parseInt(utcOffset) >=0 && Integer.parseInt(MILLISECOND) <=999)
- {
- //System.out.println(dateStringGeneric+" is a DATETIME string");
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "isDateTimeString");
- return true;
-
-
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- catch(NumberFormatException e)
- {
-// System.out.println(" string is not a datetime string "+e.getMessage());
- return false;
- }
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "isDateTimeString");
- //System.out.println(dateStringGeneric+" is not a DATETIME string");
-
- return false;
- }
-
- /**
- * for xsd:dateTime TimePeriod format Supports all of:
- * http://www.w3.org/TR/1998/NOTE-datetime-19980827 Plus version without -
- * and : in date/time (see for example)
- * http://www.cl.cam.ac.uk/~mgk25/iso-time.html
- *
- * @param isUTC
- * @param isodate
- * @throws ExpressionException
- *//*
- public DateTime(String isodate) throws SPLException
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "DateTime");
-
- _dataType = new TypeInfo(TypeConstants.dateTime);
-
- // -YYYY-MM-DDThh:mm:ss.sTZD
- // or
- // -YYYYMMDDThhmmss.sTZD
- // or
- // -YYYYMMDDThhmmss
- // or combination of both
-
- // does not support week specifiers, etc.
- // null argument check
-
- if (isodate == null)
- return;
-
- if (isodate.startsWith("-"))
- {
- this.eraAD = false;
- }
-
- StringTokenizer datetime = new StringTokenizer(isodate.trim(), "T",
- true);
-
- String datepart = null;
- String timeTZpart = null;
- boolean inTime = false;
- while (datetime.hasMoreTokens())
- {
- String token = datetime.nextToken();
- if (token.equalsIgnoreCase("T"))
- {
- if (inTime)
- {
- logger.severe(
- "invalid expression: invalid date.");
- throw new SPLException(
- "invalid expression: invalid date.");
- }
- else
- {
- inTime = true;
- continue;
- }
- }
- else if (inTime)
- {
- timeTZpart = token;
- }
- else
- {
- datepart = token;
- }
- }
-
- try
- {
- // datepart
-
- if (datepart != null)
- {
-
- String overflow = null;
- StringTokenizer dateToken = new StringTokenizer(datepart, "-",
- false);
-
- // Year
- if (dateToken.hasMoreElements())
- {
- String yearStr = (String) dateToken.nextElement();
- if (yearStr.length() > 4)
- {
- overflow = yearStr.substring(4, yearStr.length());
- yearStr = yearStr.substring(0, 4);
- }
- int yearVal = Integer.parseInt(yearStr);
- this.year = yearVal;
- }
- else
- {
-
- return;
- }
-
- // Month
- if (overflow != null || dateToken.hasMoreElements())
- {
- String monthStr = "";
- if (overflow != null)
- {
- monthStr = overflow;
- overflow = null;
- }
- else if (dateToken.hasMoreElements())
- {
- monthStr = (String) dateToken.nextElement();
- }
-
- if (monthStr.length() > 2)
- {
- overflow = monthStr.substring(2, monthStr.length());
- monthStr = monthStr.substring(0, 2);
- }
- this.month = Integer.parseInt(monthStr) - 1;
- }
- else
- {
- return;
- }
-
- // Day
- if (overflow != null || dateToken.hasMoreElements())
- {
- String dayStr = "";
- if (overflow != null)
- {
- dayStr = overflow;
- overflow = null;
- }
- else if (dateToken.hasMoreElements())
- {
- dayStr = (String) dateToken.nextElement();
- }
-
- if (dayStr.length() > 2)
- {
- overflow = dayStr.substring(2, dayStr.length());
- dayStr = dayStr.substring(0, 2);
- }
- this.day = Integer.parseInt(dayStr);
- }
- else
- {
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "DateTime");
-
- return;
- }
-
- }
-
- // Timepart
-
- if (timeTZpart != null)
- {
- }
-
- StringTokenizer timezoneToken = new StringTokenizer(timeTZpart,
- "Z+-", true);
-
- // Get just the time (not timezone)
- String timepart = "";
-
- if (timezoneToken.hasMoreElements())
- {
- timepart = timezoneToken.nextToken();
- }
-
- String overflow = null;
- StringTokenizer timeToken = new StringTokenizer(timepart, ":", true);
-
- // hour
- if (timeToken.hasMoreElements())
- {
- String hourStr = (String) timeToken.nextElement();
- if (hourStr.length() > 2)
- {
- overflow = hourStr.substring(2, hourStr.length());
- hourStr = hourStr.substring(0, 2);
- }
- this.hour = Integer.parseInt(hourStr);
- }
- else
- {
- this.hour = 0;
- }
-
- // minute
- if (overflow != null
- || (hasToken(timeToken, ":") && timeToken.hasMoreElements()))
- {
- String minuteStr = "";
- if (overflow != null)
- {
- minuteStr = overflow;
- overflow = null;
- }
- else if (timeToken.hasMoreElements())
- {
- minuteStr = (String) timeToken.nextElement();
- }
-
- if (minuteStr.length() > 2)
- {
- overflow = minuteStr.substring(2, minuteStr.length());
- minuteStr = minuteStr.substring(0, 2);
- }
- this.minute = Integer.parseInt(minuteStr);
- }
- else
- {
- this.minute = 0;
- }
-
- // second complete whole and part
- String secondStr = "";
-// String wholeSecond = "";
- String fractionSecond = "";
-
- if (overflow != null
- || (hasToken(timeToken, ":") && timeToken.hasMoreElements()))
- {
-
- if (overflow != null)
- {
- secondStr = overflow;
- overflow = null;
- }
- else if (timeToken.hasMoreElements())
- {
- secondStr = (String) timeToken.nextElement();
- }
-
- // We are at the end -- if there are more tokens at this point
- // then it is an error
- if (timeToken.hasMoreElements())
- {
- logger.severe(
- "invalid expression: "
- + "RFC3060 TimePeriodCondition requires the time part be of the form HH:MM:SS.SSSS, but the given time does not meet this requirement: "
- + isodate + ".");
- throw new SPLException(
- "invalid expression: "
- + "RFC3060 TimePeriodCondition requires the time part be of the form HH:MM:SS.SSSS, but the given time does not meet this requirement: "
- + isodate + ".");
- }
-
- // now we need to tease out the fractional seconds part
-
- StringTokenizer secondToken = new StringTokenizer(secondStr,
- ".", false);
-
- if (secondToken.hasMoreElements())
- {
-// wholeSecond = secondToken.nextToken();
- }
- if (secondToken.hasMoreElements())
- {
- fractionSecond = secondToken.nextToken();
- }
- if (secondToken.hasMoreElements())
- {
- logger.severe(
- "invalid expression: "
- + "RFC3060 TimePeriodCondition requires the time part be of the form HH:MM:SS.SSSS, but the given time does not meet this requirement: "
- + isodate + ".");
-
- throw new SPLException(
- "invalid expression: "
- + "RFC3060 TimePeriodCondition requires the time part be of the form HH:MM:SS.SSSS, but the given time does not meet this requirement: "
- + isodate + ".");
- }
-
- }
-
- // whole second
-
- if (secondStr.length() > 2)
- {
- overflow = secondStr.substring(2, secondStr.length());
- secondStr = secondStr.substring(0, 2);
- }
- if (secondStr.length() > 0)
- {
-
- this.second = Integer.parseInt(secondStr);
- }
- else
- {
- this.second = 0;
- }
-
- // fraction second / millisecond
-
- if (fractionSecond.length() > 0)
- {
- while (fractionSecond.length() < 3)
- {
- fractionSecond += "0";
- }
-
- for (int i = 0; i < fractionSecond.length(); i++)
- {
- if (!Character.isDigit(fractionSecond.charAt(i)))
- {
- logger.severe(
- "invalid expression: "
- + "Format of fractional seconds in RFC 3060 time is invalid: "
- + isodate);
- throw new SPLException(
- "invalid expression: "
- + "Format of fractional seconds in RFC 3060 time is invalid: "
- + isodate);
- }
- }
- fractionSecond = fractionSecond.substring(0, 3);
- // Cut trailing chars..
-
- this.millis = Integer.parseInt(fractionSecond);
- }
- else
- {
- this.millis = 0;
- }
-
- // get TIMEZONE
-
- if (timezoneToken.hasMoreElements())
- {
- String oper = timezoneToken.nextToken();
- if (!oper.equals("Z"))
- { // UTC case
- if (!(oper.equals("+") || oper.equals("-")))
- {
- logger.severe(
- "invalid expression: "
- + "Z, +. - required to specify a TZ in a RFC3060 TimePeriodCondition.");
-
-
- throw new SPLException(
- "invalid expression: "
- + "Z, +. - required to specify a TZ in a RFC3060 TimePeriodCondition.");
- }
- int factor = (oper.equals("-") ? -1 : 1);
-
- overflow = null;
-
- if (!timezoneToken.hasMoreElements())
- {
- logger.severe(
- "invalid expression: "
- + "TZ without hour specified in a RFC3060 TimePeriodCondition.");
-
- throw new SPLException(
- "invalid expression: "
- + "TZ without hour specified in a RFC3060 TimePeriodCondition.");
- }
-
- String timezonediff = timezoneToken.nextToken();
-
- StringTokenizer tzdToken = new StringTokenizer(
- timezonediff, ":", true);
-
- // hour
- if (tzdToken.hasMoreElements())
- {
- String hourStr = (String) tzdToken.nextElement();
- if (hourStr.length() > 2)
- {
- overflow = hourStr.substring(2, hourStr.length());
- hourStr = hourStr.substring(0, 2);
- }
- int hourValue = Integer.parseInt(hourStr);
- this.timeZoneHourOffset = factor * hourValue;
- }
- else
- {logger.severe(
- "invalid expression: "
- + "TZ without hour specified in a RFC3060 TimePeriodCondition.");
-
- throw new SPLException(
- "invalid expression: "
- + "TZ without hour specified in a RFC3060 TimePeriodCondition.");
- }
-
- // minute
- if (overflow != null
- || (hasToken(tzdToken, ":") && tzdToken
- .hasMoreElements()))
- {
- String minuteStr = "";
- if (overflow != null)
- {
- minuteStr = overflow;
- overflow = null;
- }
- else if (tzdToken.hasMoreElements())
- {
- minuteStr = (String) tzdToken.nextElement();
- }
-
- if (minuteStr.length() > 2)
- {
- overflow = minuteStr.substring(2, minuteStr
- .length());
- minuteStr = minuteStr.substring(0, 2);
- }
- int minuteValue = Integer.parseInt(minuteStr);
- this.timeZoneMinuteOffset = factor * minuteValue;
- }
-
- }
-
- }
-
- }
- catch (Exception ex)
- {
- logger.severe(Thread.currentThread().getName()+" "+"invalid expression: "
- + "Error converting to a Number.");
-
- throw new SPLException("invalid expression: "
- + "Error converting to a Number.");
- }
-
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "DateTime");
-
- }
-
- private static boolean hasToken(StringTokenizer st, String token)
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "hasToken");
-
- try
- {
- if (st.hasMoreElements() && st.nextToken().equals(token))
- {
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "hasToken");
-
- return true;
- }
- else
- {
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "hasToken");
-
- return false;
- }
- }
- catch (NoSuchElementException ex)
- {
- ex.getMessage();
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "hasToken");
-
- return false;
- }
- }
- */
- /**
- * Returns the day number for this dateTime, or -1 if it is unspecified
- *
- * @return
- */
- public int getDay()
- {
-
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getDay");
-
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getDay");
- return _day;
- }
-
- /**
- * Returns the hour number for this dateTime, or -1 if it is unspecified
- *
- * @return
- */
- public int getHour()
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getHour");
-
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getHour");
-
- return _hour;
- }
-
- /**
- * Returns the milliseconds number for this dateTime, or -1 if it is
- * unspecified
- *
- * @return
- */
- public int getMillis()
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getMillis");
-
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getMillis");
-
- return _millis;
- }
-
- /**
- * Returns the minute number for this dateTime, or -1 if it is unspecified
- *
- * @return
- */
- public int getMinute()
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getMinute");
-
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getMinute");
-
- return _minute;
- }
-
- /**
- * Returns the month number for this dateTime, or -1 if it is unspecified
- *
- * @return
- */
- public int getMonth()
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getMonth");
-
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getMonth");
-
- return _month;
- }
-
- /**
- * Returns the second number for this dateTime, or -1 if it is unspecified
- *
- * @return
- */
- public int getSecond()
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getSecond");
-
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getSecond");
-
- return _second;
- }
-
-
-
-
- /**
- * Returns the year number for this dateTime, or -1 if it is unspecified
- *
- * @return
- */
- public int getYear()
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getYear");
-
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getYear");
-
- return _year;
- }
-
- /**
- * Returns true if this is an AD date, or false if this is a BC date.
- *
- * @return
- */
- public boolean isEraAD()
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "isEraAD");
-
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "isEraAD");
-
- return eraAD;
- }
-
- public Object evaluate() throws SPLException
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
-
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
-
- // TODO Auto-generated method stub
- return null;
- }
-
- public TypeInfo getType()
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getType");
-
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getType");
-
- // TODO Auto-generated method stub
- return _dataType;
- }
-
- public boolean validate() throws SPLException
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "validate");
-
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate");
-
- // TODO Auto-generated method stub
- return false;
- }
-
- public String toString()
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "toString");
-
- String str=Integer.toString(this._year)+"/"+Integer.toString(this._month)+"/"+Integer.toString(this._day)+" "+Integer.toString(this._hour)+":"+Integer.toString(this._minute)+":"+Integer.toString(this._second)+":"+Integer.toString(this._millis)+" MinuteOffset:"+Integer.toString(this.getTimeZoneMinuteOffset())+" eraAD:"+Boolean.toString(this.eraAD);
-
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "toString");
-
- return str;
- }
-
- public int getTimeZoneMinuteOffset() {
- // TODO Auto-generated method stub
- return _timeZoneMinuteOffset;
- }
-
- public String getReferenceTypeName() throws SPLException {
- // TODO Auto-generated method stub
- return null;
- }
-
-}
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+//
+
+/**
+ * @author Prashant Baliga <pr...@in.ibm.com>
+ *
+ */
+package org.apache.imperius.spl.parser.expressions.impl;
+
+import java.util.Calendar;
+import java.util.NoSuchElementException;
+import java.util.StringTokenizer;
+import java.util.TimeZone;
+import java.util.logging.Logger;
+
+import org.apache.imperius.spl.external.Expression;
+import org.apache.imperius.spl.external.TypeConstants;
+import org.apache.imperius.spl.parser.exceptions.SPLException;
+import org.apache.imperius.spl.parser.util.TypeInfo;
+import org.apache.imperius.util.SPLLogger;
+
+
+/**
+ * This class implements a for xsd:dateTime.
+ * <p>
+ *
+ * It
+ * <ul>
+ * <li>supports http://www.w3.org/TR/1998/NOTE-datetime-19980827
+ * <li>supports version without - and : in date/time (see for example)
+ * http://www.cl.cam.ac.uk/~mgk25/iso-time.html
+ * <li> does not support week modifiers etc.
+ * </ul>
+ *
+ *
+ * @author Policy Toolkit Team
+ */
+public class DateTime implements Expression
+{
+
+
+ private int _timeZoneMinuteOffset = 0;
+
+ private int _timeZoneMillisOffset = 0;
+
+ private String _timeZoneString = "GMT";
+
+ private int _millis = -1;
+
+ private int _second = -1;
+
+ private int _minute = -1;
+
+ private int _hour = -1;
+
+ private int _day = -1;
+
+ private int _month = -1;
+
+ private int _year = -1;
+
+ private boolean eraAD = true;
+
+ public boolean isArray = false;
+
+ private TypeInfo _dataType = null;
+
+ private static int UTC_MULTIPLIER = 60000;
+
+ private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+ private static final String sourceClass="DateTime";
+
+
+
+ public boolean isArray()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "isArray");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "isArray");
+
+
+ return isArray;
+ }
+
+ public DateTime(String splDateTime) throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "DateTime");
+
+
+ //System.out.println(" date string :" + dateStringGeneric);
+ // Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(GMT));
+
+ // CIM date format yyyymmddHHMMSS.mmmmmmsUUU
+ String dateString = splDateTime.replace('*', '0');
+
+ String YEAR = dateString.substring(0, 4);
+ String MONTH = dateString.substring(4, 6);
+ String DAY_OF_MONTH = dateString.substring(6, 8);
+ String HOUR_OF_DAY = dateString.substring(8, 10);
+ String MINUTE = dateString.substring(10, 12);
+ String SECOND = dateString.substring(12, 14);// leaving out '.'
+ String MILLISECOND = dateString.substring(15, 18);// leaving out the
+ // last 3 digits as
+ // microsecond is
+ // not supported,
+ // restricting to
+ // millisecond
+ String sign = dateString.substring(21, 22);// can be '+' or '-'
+ String utcOffset = dateString.substring(22, 25);// needs to converted to
+ // GMT
+
+
+ _year = Integer.parseInt(YEAR);
+ _month = Integer.parseInt(MONTH);
+ _day = Integer.parseInt(DAY_OF_MONTH);
+ _hour = Integer.parseInt(HOUR_OF_DAY);
+ //System.out.println("MINUTE "+MINUTE);
+ _minute = Integer.parseInt(MINUTE);
+ //System.out.println("_minute "+_minute);
+
+ _second = Integer.parseInt(SECOND);
+ _millis = Integer.parseInt(MILLISECOND);
+
+ int timeZoneMinuteOffset = Integer.parseInt(utcOffset);
+ int hrs = timeZoneMinuteOffset / 60;
+ _timeZoneString = _timeZoneString + sign + hrs;
+
+ int zoneOffsetMilliseconds = timeZoneMinuteOffset * UTC_MULTIPLIER;
+
+ if (sign.equalsIgnoreCase("-"))
+ {
+ zoneOffsetMilliseconds = 0 - zoneOffsetMilliseconds;
+ timeZoneMinuteOffset = 0 - timeZoneMinuteOffset;
+ }
+ _timeZoneMinuteOffset = timeZoneMinuteOffset;
+ _timeZoneMillisOffset = zoneOffsetMilliseconds;
+ //System.out.println("created calendar");
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "DateTime");
+
+
+ }
+
+ public String getTimeZoneString()
+ {
+ return _timeZoneString;
+ }
+
+ public static boolean isDateTimeString(String dateStringGeneric)
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "isDateTimeString");
+
+
+ //System.out.println("*****Checking to see if string is datetime"+dateStringGeneric);
+ String dateStr=dateStringGeneric.substring(1, dateStringGeneric.length()-1);
+ //System.out.println("*****Checking to see if string is dateStr"+dateStr);
+
+ dateStr = dateStr.replace('*', '0');
+ //System.out.println("*****Checking to see if string is dateStr"+dateStr+dateStr.length());
+
+ if(dateStr.length()!=25)
+ {
+ return false;
+ }
+ String YEAR = dateStr.substring(0, 4);
+ String MONTH = dateStr.substring(4, 6);
+ String DAY_OF_MONTH = dateStr.substring(6, 8);
+ String HOUR_OF_DAY = dateStr.substring(8, 10);
+ String MINUTE = dateStr.substring(10, 12);
+ String SECOND = dateStr.substring(12, 14);// leaving out '.'
+ String MILLISECOND = dateStr.substring(15, 18);// leaving out the
+ // last 3 digits as
+ // microsecond is
+ // not supported,
+ // restricting to
+ // millisecond
+ String sign = dateStr.substring(21, 22);// can be '+' or '-'
+ String utcOffset = dateStr.substring(22, 25);// needs to converted to
+
+ //System.out.println("*****YEAR"+Integer.parseInt(YEAR));
+ try
+ {
+ if(Integer.parseInt(YEAR) >=0 && Integer.parseInt(YEAR) <=9999)
+ {//System.out.println("*****MONTH"+Integer.parseInt(MONTH));
+ if(Integer.parseInt(MONTH) >0 && Integer.parseInt(MONTH) <=12)
+ {//System.out.println("*****DAY_OF_MONTH"+Integer.parseInt(DAY_OF_MONTH));
+ if(Integer.parseInt(DAY_OF_MONTH) >0 && Integer.parseInt(DAY_OF_MONTH) <=31)
+ {//System.out.println("*****HOUR_OF_DAY"+Integer.parseInt(HOUR_OF_DAY));
+ if(Integer.parseInt(HOUR_OF_DAY) >=0 && Integer.parseInt(HOUR_OF_DAY) <24)
+ {//System.out.println("*****MINUTE"+Integer.parseInt(MINUTE));
+ if(Integer.parseInt(MINUTE) >=0 && Integer.parseInt(MINUTE) <60)
+ {//System.out.println("*****SECOND"+Integer.parseInt(SECOND));
+ if(Integer.parseInt(SECOND) >=0 && Integer.parseInt(SECOND) <60)
+ {//System.out.println("*****MILLISECOND"+Integer.parseInt(MILLISECOND));
+ if(Integer.parseInt(MILLISECOND) >=0 && Integer.parseInt(MILLISECOND) <=999)
+ {//System.out.println("*****+"+sign);
+ if(sign.equalsIgnoreCase("+") || sign.equalsIgnoreCase("-"))
+ {//System.out.println("*****utcOffset"+Integer.parseInt(utcOffset));
+ if(Integer.parseInt(utcOffset) >=0 && Integer.parseInt(MILLISECOND) <=999)
+ {
+ //System.out.println(dateStringGeneric+" is a DATETIME string");
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "isDateTimeString");
+ return true;
+
+
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ catch(NumberFormatException e)
+ {
+// System.out.println(" string is not a datetime string "+e.getMessage());
+ return false;
+ }
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "isDateTimeString");
+ //System.out.println(dateStringGeneric+" is not a DATETIME string");
+
+ return false;
+ }
+
+ /**
+ * for xsd:dateTime TimePeriod format Supports all of:
+ * http://www.w3.org/TR/1998/NOTE-datetime-19980827 Plus version without -
+ * and : in date/time (see for example)
+ * http://www.cl.cam.ac.uk/~mgk25/iso-time.html
+ *
+ * @param isUTC
+ * @param isodate
+ * @throws ExpressionException
+ *//*
+ public DateTime(String isodate) throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "DateTime");
+
+ _dataType = new TypeInfo(TypeConstants.dateTime);
+
+ // -YYYY-MM-DDThh:mm:ss.sTZD
+ // or
+ // -YYYYMMDDThhmmss.sTZD
+ // or
+ // -YYYYMMDDThhmmss
+ // or combination of both
+
+ // does not support week specifiers, etc.
+ // null argument check
+
+ if (isodate == null)
+ return;
+
+ if (isodate.startsWith("-"))
+ {
+ this.eraAD = false;
+ }
+
+ StringTokenizer datetime = new StringTokenizer(isodate.trim(), "T",
+ true);
+
+ String datepart = null;
+ String timeTZpart = null;
+ boolean inTime = false;
+ while (datetime.hasMoreTokens())
+ {
+ String token = datetime.nextToken();
+ if (token.equalsIgnoreCase("T"))
+ {
+ if (inTime)
+ {
+ logger.severe(
+ "invalid expression: invalid date.");
+ throw new SPLException(
+ "invalid expression: invalid date.");
+ }
+ else
+ {
+ inTime = true;
+ continue;
+ }
+ }
+ else if (inTime)
+ {
+ timeTZpart = token;
+ }
+ else
+ {
+ datepart = token;
+ }
+ }
+
+ try
+ {
+ // datepart
+
+ if (datepart != null)
+ {
+
+ String overflow = null;
+ StringTokenizer dateToken = new StringTokenizer(datepart, "-",
+ false);
+
+ // Year
+ if (dateToken.hasMoreElements())
+ {
+ String yearStr = (String) dateToken.nextElement();
+ if (yearStr.length() > 4)
+ {
+ overflow = yearStr.substring(4, yearStr.length());
+ yearStr = yearStr.substring(0, 4);
+ }
+ int yearVal = Integer.parseInt(yearStr);
+ this.year = yearVal;
+ }
+ else
+ {
+
+ return;
+ }
+
+ // Month
+ if (overflow != null || dateToken.hasMoreElements())
+ {
+ String monthStr = "";
+ if (overflow != null)
+ {
+ monthStr = overflow;
+ overflow = null;
+ }
+ else if (dateToken.hasMoreElements())
+ {
+ monthStr = (String) dateToken.nextElement();
+ }
+
+ if (monthStr.length() > 2)
+ {
+ overflow = monthStr.substring(2, monthStr.length());
+ monthStr = monthStr.substring(0, 2);
+ }
+ this.month = Integer.parseInt(monthStr) - 1;
+ }
+ else
+ {
+ return;
+ }
+
+ // Day
+ if (overflow != null || dateToken.hasMoreElements())
+ {
+ String dayStr = "";
+ if (overflow != null)
+ {
+ dayStr = overflow;
+ overflow = null;
+ }
+ else if (dateToken.hasMoreElements())
+ {
+ dayStr = (String) dateToken.nextElement();
+ }
+
+ if (dayStr.length() > 2)
+ {
+ overflow = dayStr.substring(2, dayStr.length());
+ dayStr = dayStr.substring(0, 2);
+ }
+ this.day = Integer.parseInt(dayStr);
+ }
+ else
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "DateTime");
+
+ return;
+ }
+
+ }
+
+ // Timepart
+
+ if (timeTZpart != null)
+ {
+ }
+
+ StringTokenizer timezoneToken = new StringTokenizer(timeTZpart,
+ "Z+-", true);
+
+ // Get just the time (not timezone)
+ String timepart = "";
+
+ if (timezoneToken.hasMoreElements())
+ {
+ timepart = timezoneToken.nextToken();
+ }
+
+ String overflow = null;
+ StringTokenizer timeToken = new StringTokenizer(timepart, ":", true);
+
+ // hour
+ if (timeToken.hasMoreElements())
+ {
+ String hourStr = (String) timeToken.nextElement();
+ if (hourStr.length() > 2)
+ {
+ overflow = hourStr.substring(2, hourStr.length());
+ hourStr = hourStr.substring(0, 2);
+ }
+ this.hour = Integer.parseInt(hourStr);
+ }
+ else
+ {
+ this.hour = 0;
+ }
+
+ // minute
+ if (overflow != null
+ || (hasToken(timeToken, ":") && timeToken.hasMoreElements()))
+ {
+ String minuteStr = "";
+ if (overflow != null)
+ {
+ minuteStr = overflow;
+ overflow = null;
+ }
+ else if (timeToken.hasMoreElements())
+ {
+ minuteStr = (String) timeToken.nextElement();
+ }
+
+ if (minuteStr.length() > 2)
+ {
+ overflow = minuteStr.substring(2, minuteStr.length());
+ minuteStr = minuteStr.substring(0, 2);
+ }
+ this.minute = Integer.parseInt(minuteStr);
+ }
+ else
+ {
+ this.minute = 0;
+ }
+
+ // second complete whole and part
+ String secondStr = "";
+// String wholeSecond = "";
+ String fractionSecond = "";
+
+ if (overflow != null
+ || (hasToken(timeToken, ":") && timeToken.hasMoreElements()))
+ {
+
+ if (overflow != null)
+ {
+ secondStr = overflow;
+ overflow = null;
+ }
+ else if (timeToken.hasMoreElements())
+ {
+ secondStr = (String) timeToken.nextElement();
+ }
+
+ // We are at the end -- if there are more tokens at this point
+ // then it is an error
+ if (timeToken.hasMoreElements())
+ {
+ logger.severe(
+ "invalid expression: "
+ + "RFC3060 TimePeriodCondition requires the time part be of the form HH:MM:SS.SSSS, but the given time does not meet this requirement: "
+ + isodate + ".");
+ throw new SPLException(
+ "invalid expression: "
+ + "RFC3060 TimePeriodCondition requires the time part be of the form HH:MM:SS.SSSS, but the given time does not meet this requirement: "
+ + isodate + ".");
+ }
+
+ // now we need to tease out the fractional seconds part
+
+ StringTokenizer secondToken = new StringTokenizer(secondStr,
+ ".", false);
+
+ if (secondToken.hasMoreElements())
+ {
+// wholeSecond = secondToken.nextToken();
+ }
+ if (secondToken.hasMoreElements())
+ {
+ fractionSecond = secondToken.nextToken();
+ }
+ if (secondToken.hasMoreElements())
+ {
+ logger.severe(
+ "invalid expression: "
+ + "RFC3060 TimePeriodCondition requires the time part be of the form HH:MM:SS.SSSS, but the given time does not meet this requirement: "
+ + isodate + ".");
+
+ throw new SPLException(
+ "invalid expression: "
+ + "RFC3060 TimePeriodCondition requires the time part be of the form HH:MM:SS.SSSS, but the given time does not meet this requirement: "
+ + isodate + ".");
+ }
+
+ }
+
+ // whole second
+
+ if (secondStr.length() > 2)
+ {
+ overflow = secondStr.substring(2, secondStr.length());
+ secondStr = secondStr.substring(0, 2);
+ }
+ if (secondStr.length() > 0)
+ {
+
+ this.second = Integer.parseInt(secondStr);
+ }
+ else
+ {
+ this.second = 0;
+ }
+
+ // fraction second / millisecond
+
+ if (fractionSecond.length() > 0)
+ {
+ while (fractionSecond.length() < 3)
+ {
+ fractionSecond += "0";
+ }
+
+ for (int i = 0; i < fractionSecond.length(); i++)
+ {
+ if (!Character.isDigit(fractionSecond.charAt(i)))
+ {
+ logger.severe(
+ "invalid expression: "
+ + "Format of fractional seconds in RFC 3060 time is invalid: "
+ + isodate);
+ throw new SPLException(
+ "invalid expression: "
+ + "Format of fractional seconds in RFC 3060 time is invalid: "
+ + isodate);
+ }
+ }
+ fractionSecond = fractionSecond.substring(0, 3);
+ // Cut trailing chars..
+
+ this.millis = Integer.parseInt(fractionSecond);
+ }
+ else
+ {
+ this.millis = 0;
+ }
+
+ // get TIMEZONE
+
+ if (timezoneToken.hasMoreElements())
+ {
+ String oper = timezoneToken.nextToken();
+ if (!oper.equals("Z"))
+ { // UTC case
+ if (!(oper.equals("+") || oper.equals("-")))
+ {
+ logger.severe(
+ "invalid expression: "
+ + "Z, +. - required to specify a TZ in a RFC3060 TimePeriodCondition.");
+
+
+ throw new SPLException(
+ "invalid expression: "
+ + "Z, +. - required to specify a TZ in a RFC3060 TimePeriodCondition.");
+ }
+ int factor = (oper.equals("-") ? -1 : 1);
+
+ overflow = null;
+
+ if (!timezoneToken.hasMoreElements())
+ {
+ logger.severe(
+ "invalid expression: "
+ + "TZ without hour specified in a RFC3060 TimePeriodCondition.");
+
+ throw new SPLException(
+ "invalid expression: "
+ + "TZ without hour specified in a RFC3060 TimePeriodCondition.");
+ }
+
+ String timezonediff = timezoneToken.nextToken();
+
+ StringTokenizer tzdToken = new StringTokenizer(
+ timezonediff, ":", true);
+
+ // hour
+ if (tzdToken.hasMoreElements())
+ {
+ String hourStr = (String) tzdToken.nextElement();
+ if (hourStr.length() > 2)
+ {
+ overflow = hourStr.substring(2, hourStr.length());
+ hourStr = hourStr.substring(0, 2);
+ }
+ int hourValue = Integer.parseInt(hourStr);
+ this.timeZoneHourOffset = factor * hourValue;
+ }
+ else
+ {logger.severe(
+ "invalid expression: "
+ + "TZ without hour specified in a RFC3060 TimePeriodCondition.");
+
+ throw new SPLException(
+ "invalid expression: "
+ + "TZ without hour specified in a RFC3060 TimePeriodCondition.");
+ }
+
+ // minute
+ if (overflow != null
+ || (hasToken(tzdToken, ":") && tzdToken
+ .hasMoreElements()))
+ {
+ String minuteStr = "";
+ if (overflow != null)
+ {
+ minuteStr = overflow;
+ overflow = null;
+ }
+ else if (tzdToken.hasMoreElements())
+ {
+ minuteStr = (String) tzdToken.nextElement();
+ }
+
+ if (minuteStr.length() > 2)
+ {
+ overflow = minuteStr.substring(2, minuteStr
+ .length());
+ minuteStr = minuteStr.substring(0, 2);
+ }
+ int minuteValue = Integer.parseInt(minuteStr);
+ this.timeZoneMinuteOffset = factor * minuteValue;
+ }
+
+ }
+
+ }
+
+ }
+ catch (Exception ex)
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"invalid expression: "
+ + "Error converting to a Number.");
+
+ throw new SPLException("invalid expression: "
+ + "Error converting to a Number.");
+ }
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "DateTime");
+
+ }
+
+ private static boolean hasToken(StringTokenizer st, String token)
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "hasToken");
+
+ try
+ {
+ if (st.hasMoreElements() && st.nextToken().equals(token))
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "hasToken");
+
+ return true;
+ }
+ else
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "hasToken");
+
+ return false;
+ }
+ }
+ catch (NoSuchElementException ex)
+ {
+ ex.getMessage();
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "hasToken");
+
+ return false;
+ }
+ }
+ */
+ /**
+ * Returns the day number for this dateTime, or -1 if it is unspecified
+ *
+ * @return
+ */
+ public int getDay()
+ {
+
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getDay");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getDay");
+ return _day;
+ }
+
+ /**
+ * Returns the hour number for this dateTime, or -1 if it is unspecified
+ *
+ * @return
+ */
+ public int getHour()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getHour");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getHour");
+
+ return _hour;
+ }
+
+ /**
+ * Returns the milliseconds number for this dateTime, or -1 if it is
+ * unspecified
+ *
+ * @return
+ */
+ public int getMillis()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getMillis");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getMillis");
+
+ return _millis;
+ }
+
+ /**
+ * Returns the minute number for this dateTime, or -1 if it is unspecified
+ *
+ * @return
+ */
+ public int getMinute()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getMinute");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getMinute");
+
+ return _minute;
+ }
+
+ /**
+ * Returns the month number for this dateTime, or -1 if it is unspecified
+ *
+ * @return
+ */
+ public int getMonth()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getMonth");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getMonth");
+
+ return _month;
+ }
+
+ /**
+ * Returns the second number for this dateTime, or -1 if it is unspecified
+ *
+ * @return
+ */
+ public int getSecond()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getSecond");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getSecond");
+
+ return _second;
+ }
+
+
+
+
+ /**
+ * Returns the year number for this dateTime, or -1 if it is unspecified
+ *
+ * @return
+ */
+ public int getYear()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getYear");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getYear");
+
+ return _year;
+ }
+
+ /**
+ * Returns true if this is an AD date, or false if this is a BC date.
+ *
+ * @return
+ */
+ public boolean isEraAD()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "isEraAD");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "isEraAD");
+
+ return eraAD;
+ }
+
+ public Object evaluate() throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public TypeInfo getType()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getType");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getType");
+
+ // TODO Auto-generated method stub
+ return _dataType;
+ }
+
+ public boolean validate() throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "validate");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate");
+
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public String toString()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "toString");
+
+ String str=Integer.toString(this._year)+"/"+Integer.toString(this._month)+"/"+Integer.toString(this._day)+" "+Integer.toString(this._hour)+":"+Integer.toString(this._minute)+":"+Integer.toString(this._second)+":"+Integer.toString(this._millis)+" MinuteOffset:"+Integer.toString(this.getTimeZoneMinuteOffset())+" eraAD:"+Boolean.toString(this.eraAD);
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "toString");
+
+ return str;
+ }
+
+ public int getTimeZoneMinuteOffset() {
+ // TODO Auto-generated method stub
+ return _timeZoneMinuteOffset;
+ }
+
+ public String getReferenceTypeName() throws SPLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Propchange: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/DateTime.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/DateTimeConstant.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/DateTimeConstant.java?rev=611261&r1=611260&r2=611261&view=diff
==============================================================================
--- incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/DateTimeConstant.java (original)
+++ incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/DateTimeConstant.java Fri Jan 11 10:56:30 2008
@@ -1,174 +1,174 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-//
-
-/**
- * @author Prashant Baliga <pr...@in.ibm.com>
- *
- */
-package org.apache.imperius.spl.parser.expressions.impl;
-
-import java.util.Calendar;
-import java.util.Date;
-import java.util.logging.Logger;
-
-import org.apache.imperius.spl.external.TypeConstants;
-import org.apache.imperius.spl.parser.exceptions.SPLException;
-import org.apache.imperius.spl.parser.expressions.CalendarExpression;
-import org.apache.imperius.spl.parser.expressions.ConstantExpression;
-import org.apache.imperius.spl.parser.expressions.TimeZoneExpression;
-import org.apache.imperius.spl.parser.util.ExpressionUtility;
-import org.apache.imperius.spl.parser.util.TypeInfo;
-import org.apache.imperius.util.SPLLogger;
-
-
-public class DateTimeConstant extends ConstantExpression implements
- CalendarExpression
-{
-
- /*
- * value of this constant
- */
- Calendar _calendarValue;
-
- DateTime _dateTime;
-
- boolean preferStandardTime;
-
- boolean isLenient;
-
-
-
-
-
-
- private TypeInfo _dataType=new TypeInfo();
-
- private static Logger logger = SPLLogger.getSPLLogger().getLogger();
- private static final String sourceClass="DateTimeConstant";
-
-
-
- public boolean isArray()
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "isArray");
-
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "isArray");
-
-
- return _dataType.getIsArray();
- }
-
-
-
-
- public DateTimeConstant(String dateStr) throws SPLException
- {
-
- _dateTime = new DateTime(dateStr);
- _dataType.setType(TypeConstants.dateTime);
- }
-
- public DateTimeConstant(Calendar val) throws SPLException
- {
- _dataType.setType(TypeConstants.dateTime);
- _calendarValue = val;
- }
-
- /**
- * Evaluates and returns the value of this expression using the specified
- * <code>SensorLookup</code> to obtain the values of indeterminates
- * (quantities whose magnitude cannot be determined at the time of authoring
- * the expression) occuring in this expression. Since this
- * <code>Expression</code> has a constant value, the specified
- * <code>SensorLookup</code>is not used.
- * <p>
- *
- * @param s
- * the specified <code>SensorLookup</code>
- * @return the value of this expression
- * @throws com.ibm.autonomic.policy.expression.EvaluationException
- */
- public Object evaluate() throws SPLException
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
-
- try
- {
- if (_calendarValue == null)
- {
- _calendarValue = ExpressionUtility.computeCalendarValue(this.isLenient,
- this.preferStandardTime, this._dateTime);
- // Need to construct the constant
-
- }
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate" + _calendarValue);
-
- return _calendarValue;
-
- }
- catch (Exception e)
- {
- logger.severe(Thread.currentThread().getName()+" "+"evaluation error: " + e.toString());
-
- throw new SPLException("evaluation error: " + e.toString());
- }
-
- }
-
- public TypeInfo getType()
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getType");
-
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getType");
-
- return _dataType;
- }
-
- public String toString()
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "toString");
- String str="";
- if(this._calendarValue ==null){
- try{
- this.evaluate();
- }
- catch(SPLException e){
- e.printStackTrace();
- logger.severe(e.getMessage());
- }
- }
- if(this._calendarValue !=null){
-
-
- Calendar cal=this._calendarValue;
- Date dt=cal.getTime();
- //dt.
- //str=Integer.toString(dt.getYear())+"/"+Integer.toString(dt.getMonth())+"/"+Integer.toString(dt.getDay())+" "+Integer.toString(dt.getHours())+":"+Integer.toString(dt.getMinutes())+":"+Integer.toString(dt.getSeconds())+":"+Integer.toString(0)+" MinuteOffset:"+Integer.toString(dt.getTimezoneOffset())+" eraAD:"+Boolean.toString(true);
- str=Integer.toString(cal.get(Calendar.DAY_OF_MONTH))+"/"+Integer.toString(cal.get(Calendar.MONTH))+
- "/"+Integer.toString(cal.get(Calendar.DAY_OF_WEEK))+" "+Integer.toString(cal.get(Calendar.HOUR_OF_DAY))+":"+
- Integer.toString(cal.get(Calendar.MINUTE))+":"+Integer.toString(cal.get(Calendar.SECOND))+":"+Integer.toString(0)+" MinuteOffset:"+
- Integer.toString((cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET))/60 * 1000)+" eraAD:"+Boolean.toString(true);
- }
- else{
- str="DateTimeConstant";
- }
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "toString");
-
- return str;
- }
-
-
-
-}
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+//
+
+/**
+ * @author Prashant Baliga <pr...@in.ibm.com>
+ *
+ */
+package org.apache.imperius.spl.parser.expressions.impl;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.logging.Logger;
+
+import org.apache.imperius.spl.external.TypeConstants;
+import org.apache.imperius.spl.parser.exceptions.SPLException;
+import org.apache.imperius.spl.parser.expressions.CalendarExpression;
+import org.apache.imperius.spl.parser.expressions.ConstantExpression;
+import org.apache.imperius.spl.parser.expressions.TimeZoneExpression;
+import org.apache.imperius.spl.parser.util.ExpressionUtility;
+import org.apache.imperius.spl.parser.util.TypeInfo;
+import org.apache.imperius.util.SPLLogger;
+
+
+public class DateTimeConstant extends ConstantExpression implements
+ CalendarExpression
+{
+
+ /*
+ * value of this constant
+ */
+ Calendar _calendarValue;
+
+ DateTime _dateTime;
+
+ boolean preferStandardTime;
+
+ boolean isLenient;
+
+
+
+
+
+
+ private TypeInfo _dataType=new TypeInfo();
+
+ private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+ private static final String sourceClass="DateTimeConstant";
+
+
+
+ public boolean isArray()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "isArray");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "isArray");
+
+
+ return _dataType.getIsArray();
+ }
+
+
+
+
+ public DateTimeConstant(String dateStr) throws SPLException
+ {
+
+ _dateTime = new DateTime(dateStr);
+ _dataType.setType(TypeConstants.dateTime);
+ }
+
+ public DateTimeConstant(Calendar val) throws SPLException
+ {
+ _dataType.setType(TypeConstants.dateTime);
+ _calendarValue = val;
+ }
+
+ /**
+ * Evaluates and returns the value of this expression using the specified
+ * <code>SensorLookup</code> to obtain the values of indeterminates
+ * (quantities whose magnitude cannot be determined at the time of authoring
+ * the expression) occuring in this expression. Since this
+ * <code>Expression</code> has a constant value, the specified
+ * <code>SensorLookup</code>is not used.
+ * <p>
+ *
+ * @param s
+ * the specified <code>SensorLookup</code>
+ * @return the value of this expression
+ * @throws com.ibm.autonomic.policy.expression.EvaluationException
+ */
+ public Object evaluate() throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+
+ try
+ {
+ if (_calendarValue == null)
+ {
+ _calendarValue = ExpressionUtility.computeCalendarValue(this.isLenient,
+ this.preferStandardTime, this._dateTime);
+ // Need to construct the constant
+
+ }
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate" + _calendarValue);
+
+ return _calendarValue;
+
+ }
+ catch (Exception e)
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"evaluation error: " + e.toString());
+
+ throw new SPLException("evaluation error: " + e.toString());
+ }
+
+ }
+
+ public TypeInfo getType()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getType");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getType");
+
+ return _dataType;
+ }
+
+ public String toString()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "toString");
+ String str="";
+ if(this._calendarValue ==null){
+ try{
+ this.evaluate();
+ }
+ catch(SPLException e){
+ e.printStackTrace();
+ logger.severe(e.getMessage());
+ }
+ }
+ if(this._calendarValue !=null){
+
+
+ Calendar cal=this._calendarValue;
+ Date dt=cal.getTime();
+ //dt.
+ //str=Integer.toString(dt.getYear())+"/"+Integer.toString(dt.getMonth())+"/"+Integer.toString(dt.getDay())+" "+Integer.toString(dt.getHours())+":"+Integer.toString(dt.getMinutes())+":"+Integer.toString(dt.getSeconds())+":"+Integer.toString(0)+" MinuteOffset:"+Integer.toString(dt.getTimezoneOffset())+" eraAD:"+Boolean.toString(true);
+ str=Integer.toString(cal.get(Calendar.DAY_OF_MONTH))+"/"+Integer.toString(cal.get(Calendar.MONTH))+
+ "/"+Integer.toString(cal.get(Calendar.DAY_OF_WEEK))+" "+Integer.toString(cal.get(Calendar.HOUR_OF_DAY))+":"+
+ Integer.toString(cal.get(Calendar.MINUTE))+":"+Integer.toString(cal.get(Calendar.SECOND))+":"+Integer.toString(0)+" MinuteOffset:"+
+ Integer.toString((cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET))/60 * 1000)+" eraAD:"+Boolean.toString(true);
+ }
+ else{
+ str="DateTimeConstant";
+ }
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "toString");
+
+ return str;
+ }
+
+
+
+}
Propchange: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/expressions/impl/DateTimeConstant.java
------------------------------------------------------------------------------
svn:eol-style = native