int [] dayofweek;
int [] year = null;
String timeZoneStr = null;
// Creates a new AlarmManager
AlarmManager mgr = new AlarmManager(Console.getTestFlag(0));
// Generate alarms for absolute or relative case
NodeList alarmNodeList = alarmsNode.getChildNodes();
String identityNodeName = alarmNodeList.item(0).getNodeName();
//if (identityNodeName.equals("JcronAlarm")) { // Absolute case
if (identityNodeName.equals(XmultraConfig.JCRON_ALARM)) { // Absolute case
//NodeList alarmNodeList = alarmsNode.getChildNodes();
for (int i = 0; i < alarmNodeList.getLength(); i++) {
Node alarmNode = alarmNodeList.item(i);
String [] myTokens;
int [] myFields = new int[MAXFIELDS];
// Get minute, hour, .....
String startString = null;
String endString = null;
myTokens = new String[1];
// For second
myTokens[0] = ((startString = getSecondStart(alarmNode)) == null) ?
"-1" : ((endString = getSecondEnd(alarmNode)) == null) ?
startString : startString + "-" + endString;
if (startString != null && ((parseInts(startString)[0] < 0)
|| (parseInts(startString)[0] > 59))) {
logInitWarningMessage(
"Second element, Start attribute has value: " +
startString + ". Must be between 0 and 59.");
return false;
}
if (endString != null && ((parseInts(endString)[0] < 0)
|| (parseInts(endString)[0] > 59))) {
logInitWarningMessage(
"Second element, End attribute has value: " +
endString + ". Must be between 0 and 59.");
return false;
}
if (myTokens[0] == "-1") {
second = new int[1];
second[0] = -1;
} else {
myFields = getFields(myTokens);
secondSize = myFields.length;
second = new int[secondSize];
second = myFields;
}
// For minute
myTokens[0] = ((startString = getMinuteStart(alarmNode)) == null) ?
"-1" : ((endString = getMinuteEnd(alarmNode)) == null) ?
startString : startString + "-" + endString;
if (startString != null && ((parseInts(startString)[0] < 0)
|| (parseInts(startString)[0] > 59))) {
logInitWarningMessage(
"Minute element, Start attribute has value: " +
startString + ". Must be between 0 and 59.");
return false;
}
if (endString != null && ((parseInts(endString)[0] < 0)
|| (parseInts(endString)[0] > 59))) {
logInitWarningMessage(
"Minute element, End attribute has value: " +
endString + ". Must be between 0 and 59.");
return false;
}
if (myTokens[0] == "-1") {
minute = new int[1];
minute[0] = -1;
} else {
myFields = getFields(myTokens);
minuteSize = myFields.length;
minute = new int[minuteSize];
minute = myFields;
}
// For hour
myTokens[0] = ((startString = (getHourStart(alarmNode))) == null) ?
"-1" : ((endString = getHourEnd(alarmNode)) == null) ?
startString : startString + "-" + endString;
if (myTokens[0] == "-1") {
hour = new int[1];
hour[0] = -1;
} else {
myFields = getFields(myTokens);
hourSize = myFields.length;
hour = new int[hourSize];
hour = myFields;
}
// For day of month
myTokens[0] = ((startString = (getDayofmonthStart(alarmNode)))
== null) ?
"-1" : ((endString = getDayofmonthEnd(alarmNode)) == null) ?
startString : startString + "-" + endString;
if (myTokens[0] == "-1") {
dayofmonth = new int[1];
dayofmonth[0] = -1;
} else {
myFields = getFields(myTokens);
dayofmonthSize = myFields.length;
dayofmonth = new int[dayofmonthSize];
dayofmonth = myFields;
}
// For month
myTokens[0] = ((startString =
(getMonthStart(alarmNode))) == null) ?
"-1" : ((endString = getMonthEnd(alarmNode)) == null) ?
startString : startString + "-" + endString;
if (myTokens[0] == "-1") {
month = new int[1];
month[0] = -1;
} else {
myFields = getFields(myTokens);
monthSize = myFields.length;
month = new int[monthSize];
month = myFields;
}
// For day of week
myTokens[0] = ((startString = (getDayofweekStart(alarmNode)))
== null) ?
"-1" : ((endString = getDayofweekEnd(alarmNode))
== null) ? startString : startString + "-" + endString;
if (myTokens[0] == "-1") {
dayofweek = new int[1];
dayofweek[0] = -1;
} else {
myFields = getFields(myTokens);
dayofweekSize = myFields.length;
dayofweek = new int[dayofweekSize];
dayofweek = myFields;
}
// For year
startString = null;
endString = null;
myTokens[0] = ((startString = (getYearStart(alarmNode))) == null) ?
"-1" : ((endString = getYearEnd(alarmNode))
== null) ? startString : startString + "-" + endString;
if (startString != null && ((parseInts(startString)[0] < 2000)
|| (parseInts(startString)[0] > 3000))) {
logInitWarningMessage(
"Year element, Start attribute has value: " +
startString + ". Must be between 2000 and 3000.");
return false;
}
if (endString != null && ((parseInts(endString)[0] < 2000)
|| (parseInts(endString)[0] > 3000))) {
logInitWarningMessage(
"Year element, End attribute has value: " +
endString + ". Must be between 2000 and 3000.");
return false;
}
if (myTokens[0] == "-1") {
year = new int[1];
year[0] = -1;
} else {
myFields = getFields(myTokens);
yearSize = myFields.length;
year = new int[yearSize];
year = myFields;
}
// For timezone
timeZoneStr = getTimeZone(alarmNode);
// If a timezone was entered and it is not null or empty, check to see if it
// is valid. If not, log error.
if (timeZoneStr != null && !validTimeZonesSet.contains(timeZoneStr)) {
StringBuffer logMsg = new StringBuffer();
Iterator tzIter = validTimeZonesSet.iterator();
logMsg.append("'" + timeZoneStr + "' is not a valid TimeZone.\n");
logMsg.append("TimeZone must be one of the following:\n");
while(tzIter.hasNext()){
String okTimeZone = (String)tzIter.next();
okTimeZone = strings.substitute("/",".", okTimeZone);
logMsg.append(okTimeZone).append("\n");
}
logInitWarningMessage(logMsg.toString());
return false;
}
// Look up cross references in case this JDK is less than ver 1.4.
timeZoneStr = dateUtils.getTimeZoneCrossReference(timeZoneStr);
// End timezone
int totalSize = secondSize * minuteSize * hourSize * dayofmonthSize *
monthSize * dayofweekSize * yearSize;
AlarmEntry [] alarmEntryArray = new AlarmEntry[totalSize];
// Register alarms
int totali = 0;
for (int yeari = 0; yeari < yearSize; yeari++)
for (int dayofweeki = 0; dayofweeki < dayofweekSize; dayofweeki++)
for (int monthi = 0; monthi < monthSize; monthi++)
for (int dayofmonthi = 0; dayofmonthi < dayofmonthSize;
dayofmonthi++)
for (int houri = 0; houri < hourSize; houri++)
for (int minutei = 0; minutei < minuteSize; minutei++) {
for (int secondi = 0; secondi < secondSize; secondi++) {
try {
alarmEntryArray[totali] = new AlarmEntry(second[secondi],
minute[minutei], hour[houri], dayofmonth[dayofmonthi],
month[monthi], dayofweek[dayofweeki], year[yeari],timeZoneStr,
myAlarmListener);
mgr.addAlarm(alarmEntryArray[totali]);
}
catch (PastDateException e) {
// Make log entry.
msgEntry.setAppContext(
"JcronWatchManager -- set up alarm").setDocInfo(null);
msgEntry.setMessageText("PastDateException");
msgEntry.setError("PastDateException - ignore on startup of Xmultra");
logger.logWarning(msgEntry);
}
catch (InvalidTimeZoneException e) {
// Make log entry.
msgEntry.setAppContext(
"JcronWatchManager -- set up alarm").setDocInfo(null);
msgEntry.setMessageText("Invalid TimeZone.");
msgEntry.setError(e.getMessage());
logger.logWarning(msgEntry);
return false;
}
totali++;
}
} // end of for
} // end of each cronAlarm
} else if (identityNodeName.equals(XmultraConfig.RELATIVE_JCRON_ALARM)) { // Relative case
int delaySeconds = 0;
String intervalValueString = null;
String isRepetitiveString = null;
isRepetitiveString = xmlParseUtils.getAttributeValueFromNode(
alarmNodeList.item(0), XmultraConfig.REPETITIVE_ATTRIBUTE);
// Get the list of interval nodes
NodeList intervalNodeList = alarmNodeList.item(0).getChildNodes();
// Tranverse the node list
for (int i = 0; i < intervalNodeList.getLength(); i++) {
Node intervalNode = intervalNodeList.item(i);
// Get attributes for the interval node
intervalValueString = xmlParseUtils.getAttributeValueFromNode(
intervalNode, XmultraConfig.VALUE_ATTRIBUTE);
// Get the hour interval
if (intervalNode.getNodeName().equals(XmultraConfig.HOUR_INTERVAL)) {
try {
delaySeconds += Integer.parseInt(intervalValueString) *
XmultraConfig.SECONDS_PER_HOUR;
} catch (NumberFormatException e) {
logInitWarningMessage(
"HourInterval element, Value attribute has value: " +
intervalValueString + ". Must be integer.");
return false;
}
// Get the day interval
} else if (intervalNode.getNodeName().equals(XmultraConfig.DAY_INTERVAL)) {
try {
delaySeconds += Integer.parseInt(intervalValueString) *
XmultraConfig.SECONDS_PER_DAY;
} catch (NumberFormatException e) {
logInitWarningMessage(
"DayInterval element, Value attribute has value: " +
intervalValueString + ". Must be integer.");
return false;
}
// Get the minute interval
} else if (intervalNode.getNodeName().equals(XmultraConfig.MINUTE_INTERVAL)) {
try {
delaySeconds += Integer.parseInt(intervalValueString) *
XmultraConfig.SECONDS_PER_MINUTE;
} catch (NumberFormatException e) {
logInitWarningMessage(
"MinuteInterval element, Value attribute has value: " +
intervalValueString + ". Must be integer.");
return false;
}
// Get the second interval
} else {
try {
delaySeconds += Integer.parseInt(intervalValueString);
} catch (NumberFormatException e) {
logInitWarningMessage(
"SecondInterval element, Value attribute has value: " +
intervalValueString + ". Must be integer.");
return false;
}
}
}
// Set the alarm for the second interval
if (isRepetitiveString == null || isRepetitiveString.equalsIgnoreCase("yes")) {
isRepetitiveString = "true";
} else {
isRepetitiveString = "false";
}
try {
AlarmEntry cronAlarmEntry = new AlarmEntry(
delaySeconds, Boolean.valueOf(isRepetitiveString).booleanValue(),
myAlarmListener);
mgr.addAlarm(cronAlarmEntry);
} catch (PastDateException e) {
// Make log entry.
msgEntry.setAppContext(
"JcronWatchManager -- set up alarm").setDocInfo(null);
msgEntry.setMessageText("PastDateException");