public void startProviding() throws Exception {
try {
NodeList lSchedules = mSchedules.getElementsByTagName( "schedule" );
for( int i = 0; i < lSchedules.getLength(); i++ ) {
Node lSchedule = lSchedules.item( i );
NodeList lAttributes = lSchedule.getChildNodes();
Text lItem = getNode( lAttributes, "target-mbean-name" );
if( lItem == null ) {
log.error( "No 'target-mbean-name' is specified therefore this Schedule is ignored" );
continue;
}
log.info( "Got 'target-mbean-name' element: " + lItem + ", node value: " + lItem.getData() + lItem.getChildNodes() );
String lTarget = lItem.getData();
lItem = getNode( lAttributes, "target-method-name" );
if( lItem == null ) {
log.error( "No 'target-method-name' is specified therefore this Schedule is ignored" );
continue;
}
String lMethodName = lItem.getData();
lItem = getNode( lAttributes, "target-method-signature" );
if( lItem == null ) {
log.error( "No 'target-method-signature' is specified therefore this Schedule is ignored" );
continue;
}
String lMethodSignature = lItem.getData();
lItem = getNode( lAttributes, "date-format" );
String dateFormat = null;
if (lItem != null)
{
dateFormat = lItem.getData();
if (dateFormat != null && dateFormat.trim().length() != 0)
try
{
new SimpleDateFormat(dateFormat);
}
catch (Exception e)
{
log.error( "Invalid date format therefore this Schedule is ignored", e);
continue;
}
}
lItem = getNode( lAttributes, "start-date" );
if( lItem == null ) {
log.error( "No 'start-date' is specified therefore this Schedule is ignored" );
continue;
}
String lStartDate = lItem.getData();
lItem = getNode( lAttributes, "period" );
if( lItem == null ) {
log.error( "No 'period' is specified therefore this Schedule is ignored" );
continue;
}
String lPeriod = lItem.getData();
lItem = getNode( lAttributes, "repetitions" );
if( lItem == null ) {
log.error( "No 'repetitions' is specified therefore this Schedule is ignored" );
continue;
}
String lRepeptions = lItem.getData();
try {
// Add Schedule
int lID = addSchedule(
new ObjectName( lTarget ),
lMethodName,
getSignature( lMethodSignature ),
getStartDate( lStartDate, dateFormat ),
new Long( lPeriod ).longValue(),
new Integer( lRepeptions ).intValue()
);
mIDList.add( new Integer( lID ) );
}
catch( NumberFormatException nfe ) {
log.error( "Could not convert a number", nfe );
}
}
} catch( Exception e ) {
e.printStackTrace();
throw e;
}
}
Add the Schedule to the Schedule Manager |