/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
/**
* A runtime representation of the user-defined calendar-based
* timeout expression for an enterprise bean timer.
*/
private boolean automatic_ = false;
private boolean configured = false;
private boolean isValid = true;
private boolean lastDayOfMonth = false;
private static final Pattern orderedDayPattern = Pattern.compile("(1st|2nd|3rd|[45]th|last)\\s+[a-z][a-z][a-z]");
static {
}
/** Construct TimerSchedule instance with all defaults.
*/
public TimerSchedule() {}
/** Construct TimerSchedule instance from a given ScheduleExpression.
* Need to copy all values because ScheduleExpression is mutable
* and can be modified by the user.
*/
// Create local copies
configure();
}
/** Construct TimerSchedule instance from a given Schedule annotation.
*/
automatic_ = true;
configure();
}
/** Reconstruct TimerSchedule instance from a given String.
*/
throw new EJBException("Cannot construct TimerSchedule from " + s);
}
}
configure();
}
assertNotEmpty(s, SECOND);
return this;
}
return second_;
}
assertNotEmpty(m, MINUTE);
return this;
}
return minute_;
}
assertNotEmpty(h, HOUR);
return this;
}
return hour_;
}
dayOfMonth_ = d.trim();
return this;
}
return dayOfMonth_;
}
assertNotEmpty(m, MONTH);
return this;
}
return month_;
}
dayOfWeek_ = d.trim();
return this;
}
return dayOfWeek_;
}
assertNotEmpty(y, YEAR);
return this;
}
return year_;
}
return this;
}
return timezone_;
}
return tz_;
}
// Create a copy of the user's value
return this;
}
// Return a copy of the internal value
}
// Create a copy of the user's value
return this;
}
// Return a copy of the internal value
}
automatic_ = b;
return this;
}
public boolean isAutomatic() {
return automatic_;
}
return methodName_;
}
public int getMethodParamCount() {
return paramCount_;
}
StringBuffer s = new StringBuffer()
.append(" # ")
if (automatic_) {
}
return s.toString();
}
return new ScheduleExpression().
}
public int hashCode() {
return getScheduleAsString().hashCode();
}
if (o == this)
return true;
if (o == null || !(o instanceof TimerSchedule))
return false;
TimerSchedule t = (TimerSchedule)o;
}
/**
* Returns true if this Schedule can calculate its next timeout
* without errors.
*/
ts.getNextTimeout();
return true;
}
/**
* Returns true if this date can be used for the next timeout of
* the schedule represented by this instance.
*/
return false;
}
return isValid;
}
}
continue;
}
return true;
}
}
return false;
}
/**
* Returns the Date of the next possible timeout.
*/
return getNextTimeout(new GregorianCalendar());
}
/**
* Returns the Date of the next possible timeout after the specific date.
*/
return getNextTimeout(next);
}
/**
* Returns the Date of the next possible timeout after the specific Calendar date
*/
if (!configured) {
configure();
}
}
} else {
}
//System.out.println("... starting with ... " + next.getTime() );
}
//System.out.println("... testing year ... " + year);
continue;
}
// set to the beginning of the year
}
break;
}
}
//System.out.println("... returning ... " + next.getTime() + " <> " + next.getTimeInMillis());
return next;
}
/**
* Returns the Date of the next possible timeout for a specific
* year value and starting date. If year is 0, any year will be correct.
*/
int i = 0;
break;
}
if (++i > MAX_YEAR_TRY) {
// Can't find the date - it's most probably invalid
isValid = false;
break;
}
continue;
}
// Either dayOfMonth_ is specified, and we'll use it or
// neither is specified and any one can be used.
//System.out.println("==> Processing DAY_OF_MONTH ...");
continue;
}
// dayOfWeek_ is specified and dayOfMonth_ is not
//System.out.println("==> Processing DAY_OF_WEEK ...");
continue;
}
} else {
// Both are specified - pick the closest date:
boolean changed = false;
//System.out.println("==> Processing 1 DAY_OF_MONTH ...");
}
//System.out.println("==> Processing 2 DAY_OF_WEEK ...");
}
continue;
}
}
continue;
}
continue;
}
continue;
}
break;
}
return next;
}
/**
* Populate all internale structures to be used for the next timeout
* calculations
*/
private void configure() {
// XXX Can it ever be called by different threads?
parseYears();
}
configured = true;
}
/**
* Populate the BitSet where true bits represent set values.
* Input data can be either a number or a case insensitive abbreviated name.
*/
// All
if (s.equals("*")) {
if (!isDayOfWeek(field)) {
} else {
}
}
return;
}
// List
} else {
}
}
return;
}
// Range
return;
}
// Increments
int begin = 0;
}
i = i + incr;
}
return;
}
// Single value
}
/**
* Process a range of values for that represents values other than days of the month.
*/
//System.out.println("==> IN RANGE: " + s);
if (begin < 0) {
}
boolean b = isDayOfWeek(field);
// Special case for dayOfWeek="0-7" translates to "*"
//System.out.println("== 0-7 RANGE from: " + arr[0] + " to " + arr[1]);
}
} else {
//System.out.println("== RANGE from: " + begin + " to " + end);
if (b) {
// DaysOfWeek start with 1 in java.util.Calendar, and there are 7 of them
} else {
}
}
}
/**
* Preprocess data that represents days of the month.
* Input data can be one or more of a positive or a negative number, an order,
* or a case insensitive abbreviated name.
*/
private void parseDaysOfMonth() {
// All
return;
}
// List
} else {
}
}
return;
}
// Range
return;
}
// Single value
}
/**
* Process a range of values for that represents days of the month.
*/
// If these are positive numbers or a range from a positive
// number to the last day of the month - process them now
int end = 31;
}
throw new IllegalArgumentException("Invalid dayOfMonth range: " + s);
}
} else {
// Otherwise just remember - we'll process it later
}
}
/**
* Preprocess data that represents years.
* Input data can be one or more positive number, or a range of them.
*/
private void parseYears() {
// All
return;
}
// List
} else {
}
}
return;
}
// Range
return;
}
}
/**
* Adds a List of values that correspond to the specified range
*/
}
}
}
boolean changed = false;
}
//System.out.println("==> Incrementing ...");
// Recalculate bits for the next month
}
}
if (nextvalue == -1)
throw new IllegalArgumentException("Should not happen - no value found");
//System.out.println(".... seting " + field + " ... to ... " + nextvalue);
changed = true;
}
return changed;
}
/**
* Split a String that represents a list of values.
*/
return s.split("\\s*,\\s*");
}
/**
* Split a String that represents a range of values.
*/
}
/**
* Convert a String to a number. If the String represents a
* number, return its int value. If the String represents a
* (case insensitive) name of the day of the week or a month,
* return the corresponding numeric value from the conversionTable.
* If field represents DAY_OF_WEEK, return the value from the conversionTable
* that represents Calendar's value of the result.
*/
int i;
}
} else {
}
if (isDayOfWeek(field)) {
}
return result;
}
/**
* Process a single value that represents a day of the month.
* Input data can be a positive or a negative number, an order,
* or a case insensitive abbreviated name.
*/
if (i < 1 || i > 31) {
}
daysOfMonth.set(i);
lastDayOfMonth = true;
} else {
// Just remember - we'll process it later
}
}
/**
* Use preprocessed values to create a BitSet that represents set
* days of this month.
*/
return daysOfMonth;
}
if (lastDayOfMonth) {
}
if (dayBeforeEndOfMonth > 0) {
}
for (int i = 0; i < size; i++) {
}
return bits;
}
/**
* Return day of the month that represents the specific occurance of
* this day of the week, like "2nd Mon" or "Last Wed" or part of a range
* which in turn can be any valid option for dayOfMonth.
*/
return parseInt(s, DAY_OF_MONTH);
}
if (s.equals("last")) {
return lastday;
int num = -1;
}
// Convert name of the day to a number, then number to the
// Calendar's value for that day.
}
throw new IllegalArgumentException("Invalid dayOfMonth value: " + s);
}
/**
* Return day of the month that represents the specific occurance of
* this day of the week, like "2nd Mon" or "Last Wed".
*/
if (num == -1) {
}
int result = 1;
result = i;
break;
}
}
return result;
}
/**
* Return day of the month that represents the last occurance of this day of the week
*/
for (int i = lastday; i >= 1; i--) {
result = i;
break;
}
}
return result;
}
// Check if it's a range
} else {
//System.out.println("++++++++ getDayForDayOfMonth(" + date.getTime() + " - " + s + " ) " + getDayForDayOfMonth(date, s));
}
}
/**
* Set bits on for all values between begin and end (inclusive).
* This method doesn't use conversion table because all values had been
* already processed before reaching this point.
*/
//System.out.println("== SETTING from: " + begin + " up to " + (end + 1));
// "Dec-Dec" is "Dec", not "*"
} else {
//System.out.println("== SETTING from: " + begin + " up to " + size);
//System.out.println("== AND from: " + start + " up to " + (end + 1));
}
}
/**
* Convert a String to an int. Throws IllegalArgumentException instead of
* the NumberFormatException.
*/
try {
} catch (NumberFormatException e) {
}
}
/**
* A valid year value is 4 digits after 1969
*/
private int assertValidYear(int y) {
return y;
}
/** Checks that a value is between the valid range
*/
}
}
/** Checks that a value is not null
*/
if (s == null) {
}
}
/** Checks that a value is not null and not an empty String.
*/
assertNotNull(s, field);
if (s.length() == 0) {
}
}
/** Checks that a conversion of a String to the internal representation was successful.
*/
if (v == null) {
}
}
/** Returns true if field represents DAY_OF_WEEK.
* Will be used to get the value from the conversionTable
* that represents Calendar's value of the result instead of the face value.
*/
}
}