Object[] functionParams = null;
long frequency = 0;
Date startTime = null;
Date endTime = null;
final Map<String, Object> resources = new HashMap<String, Object>();
final TaskDescription taskDescription = new TaskDescription();
final FunctionSchedulingManager functionSchedulingManager;
taskDescription.setGroup(FunctionSchedulingJob.MASHUP_GROUP);
taskDescription.setTaskClass(FunctionExecutionTask.class.getName());
OMElement propElem = FACTORY.createOMElement("property", TASK_OM_NAMESPACE);
OMNamespace nullNS = FACTORY.createOMNamespace("", "");
propElem.addAttribute("name", "axisService", nullNS);
propElem.addAttribute("value", axisService.getName(), nullNS);
taskDescription.addProperty(propElem);
resources.put(MashupConstants.AXIS2_CONFIGURATION_CONTEXT, configurationContext);
switch (argCount) {
case 2://A javascript function and its execution frequency were passed
//Extracting the javascript function from the arguments
if ((arguments[0] instanceof Function) || ((arguments[0] instanceof String))) {
jsFunction = arguments[0];
} else {
throw new CarbonException("Invalid parameter. The first parameter must be " +
"a JavaScript function.");
}
//Extracting the frequency from the arguments
if (arguments[1] != null && arguments[1] instanceof Number) {
frequency = ((Number) arguments[1]).longValue();
} else {
throw new CarbonException("Invalid parameter. The second parameter " +
"must be the execution frequency in milliseconds.");
}
//Storing the function meta-data to be used by the job at execution time
resources.put(FunctionSchedulingJob.JAVASCRIPT_FUNCTION, jsFunction);
resources.put(FunctionSchedulingJob.FUNCTION_PARAMETERS, functionParams);
resources.put(FunctionSchedulingJob.AXIS_SERVICE, axisService);
resources.put(FunctionSchedulingJob.TASK_NAME, taskName);
//Creating the trigger. There will be a one-to-one mapping between jobs and triggers in this implementation
taskDescription.setName(taskName);
taskDescription.setCount(SimpleTrigger.REPEAT_INDEFINITELY);
taskDescription.setInterval(frequency);
break;
case 3://A javascript function its execution frequency and parameters were passed
//Extracting the javascript function from the arguments=
if ((arguments[0] instanceof Function) || ((arguments[0] instanceof String))) {
jsFunction = arguments[0];
} else {
throw new CarbonException("Invalid parameter. The first parameter must " +
"be a JavaScript function.");
}
//Extracting the frequency from the arguments
if (arguments[1] != null && arguments[1] instanceof Number) {
frequency = ((Number) arguments[1]).longValue();
} else {
throw new CarbonException(
"Invalid parameter. The second parameter must be the " +
"execution frequency in milliseconds.");
}
//Extracting function parameters from the arguments
if (arguments[2] != null) {
if (arguments[2] instanceof NativeArray) {
NativeArray nativeArray = (NativeArray) arguments[2];
Object[] objects = nativeArray.getIds();
ArrayList tempParamHolder = new ArrayList();
for (int i = 0; i < objects.length; i++) {
Object currObject = objects[i];
if (currObject instanceof String) {
String property = (String) currObject;
if ("length".equals(property)) {
continue;
}
tempParamHolder.add(nativeArray.get(property, nativeArray));
} else {
Integer property = (Integer) currObject;
tempParamHolder
.add(nativeArray.get(property.intValue(), nativeArray));
}
}
//Convert the arraylist to an object array
functionParams = new Object[tempParamHolder.size()];
tempParamHolder.toArray(functionParams);
} else if (arguments[2] instanceof String) {
taskName = (String) arguments[2];
} else {
throw new CarbonException(
"Invalid parameter. The third parameter must be an Array " +
"of parameters to the argument, a string value for the task name or null.");
}
}
//Storing the function meta-data to be used by the job at execution time
resources.put(FunctionSchedulingJob.JAVASCRIPT_FUNCTION, jsFunction);
resources.put(FunctionSchedulingJob.FUNCTION_PARAMETERS, functionParams);
resources.put(FunctionSchedulingJob.AXIS_SERVICE, axisService);
resources.put(FunctionSchedulingJob.TASK_NAME, taskName);
//Creating the trigger. There will be a one-to-one mapping between jobs and triggers in this implementation
taskDescription.setName(taskName);
taskDescription.setCount(SimpleTrigger.REPEAT_INDEFINITELY);
taskDescription.setInterval(frequency);
break;
case 4:// A javascript function, its execution frequnecy, function parameters and a start time is passed.
//Extracting the javascript function from the arguments
if ((arguments[0] instanceof Function) || ((arguments[0] instanceof String))) {
jsFunction = arguments[0];
} else {
throw new CarbonException(
"Invalid parameter. The first parameter must be a JavaScript function.");
}
//Extracting the frequency from the arguments
if (arguments[1] != null && arguments[1] instanceof Number) {
frequency = ((Number) arguments[1]).longValue();
} else {
throw new CarbonException(
"Invalid parameter. The second parameter must be the execution " +
"frequency in milliseconds.");
}
//Extracting function parameters from the arguments
if (arguments[2] != null) {
if (arguments[2] instanceof NativeArray) {
NativeArray nativeArray = (NativeArray) arguments[2];
Object[] objects = nativeArray.getIds();
ArrayList tempParamHolder = new ArrayList();
for (int i = 0; i < objects.length; i++) {
Object currObject = objects[i];
if (currObject instanceof String) {
String property = (String) currObject;
if ("length".equals(property)) {
continue;
}
tempParamHolder.add(nativeArray.get(property, nativeArray));
} else {
Integer property = (Integer) currObject;
tempParamHolder
.add(nativeArray.get(property.intValue(), nativeArray));
}
}
//Convert the arraylist to an object array
functionParams = new Object[tempParamHolder.size()];
tempParamHolder.toArray(functionParams);
} else {
throw new CarbonException(
"Invalid parameter. The third parameter must be an Array of " +
"parameters to the argument or null.");
}
}
if (arguments[3] != null) {
if (arguments[3] instanceof String) {
taskName = (String) arguments[3];
} else {
try {
startTime = (Date) Context.jsToJava(arguments[3], Date.class);
} catch (EvaluatorException e) {
throw new CarbonException(
"Invalid parameter. The fourth parameter must be " +
"the start time in date format or a string value " +
"for the task name.", e);
}
}
}
//Storing the function meta-data to be used by the job at execution time
resources.put(FunctionSchedulingJob.JAVASCRIPT_FUNCTION, jsFunction);
resources.put(FunctionSchedulingJob.FUNCTION_PARAMETERS, functionParams);
resources.put(FunctionSchedulingJob.AXIS_SERVICE, axisService);
resources.put(FunctionSchedulingJob.TASK_NAME, taskName);
taskDescription.setName(taskName);
taskDescription.setCount(SimpleTrigger.REPEAT_INDEFINITELY);
taskDescription.setInterval(frequency);
taskDescription.setStartTime(startTime);
break;
case 5: // A javascript function, its execution frequnecy, function parameters, start time and an end time is passed.
//Extracting the javascript function from the arguments
if ((arguments[0] instanceof Function) || ((arguments[0] instanceof String))) {
jsFunction = arguments[0];
} else {
throw new CarbonException("Invalid parameter. The first parameter must be a " +
"JavaScript function.");
}
//Extracting the frequency from the arguments
if (arguments[1] != null && arguments[1] instanceof Number) {
frequency = ((Number) arguments[1]).longValue();
} else {
throw new CarbonException(
"Invalid parameter. The second parameter must be the execution " +
"frequency in milliseconds.");
}
//Extracting function parameters from the arguments
if (arguments[2] != null) {
if (arguments[2] instanceof NativeArray) {
NativeArray nativeArray = (NativeArray) arguments[2];
Object[] objects = nativeArray.getIds();
ArrayList tempParamHolder = new ArrayList();
for (int i = 0; i < objects.length; i++) {
Object currObject = objects[i];
if (currObject instanceof String) {
String property = (String) currObject;
if ("length".equals(property)) {
continue;
}
tempParamHolder.add(nativeArray.get(property, nativeArray));
} else {
Integer property = (Integer) currObject;
tempParamHolder
.add(nativeArray.get(property.intValue(), nativeArray));
}
}
//Convert the arraylist to an object array
functionParams = new Object[tempParamHolder.size()];
tempParamHolder.toArray(functionParams);
} else {
throw new CarbonException(
"Invalid parameter. The third parameter must be an Array of " +
"parameters to the argument or null.");
}
}
//Extracting the start time from the arguments
if (arguments[3] != null) {
if (arguments[3] instanceof String) {
taskName = (String) arguments[3];
} else {
try {
startTime = (Date) Context.jsToJava(arguments[3], Date.class);
} catch (EvaluatorException e) {
throw new CarbonException(
"Invalid parameter. The fourth parameter must be " +
"the start time in date format.", e);
}
}
}
//Extracting the end time from the arguments
if (arguments[4] != null) {
if (arguments[4] instanceof String) {
taskName = (String) arguments[4];
} else {
try {
endTime = (Date) Context.jsToJava(arguments[4], Date.class);
} catch (EvaluatorException e) {
throw new CarbonException(
"Invalid parameter. The fifth parameter must be " +
"the end time in date format or a string value " +
"for the task name.", e);
}
}
}
//Storing the function meta-data to be used by the job at execution time
resources.put(FunctionSchedulingJob.JAVASCRIPT_FUNCTION, jsFunction);
resources.put(FunctionSchedulingJob.FUNCTION_PARAMETERS, functionParams);
resources.put(FunctionSchedulingJob.AXIS_SERVICE, axisService);
resources.put(FunctionSchedulingJob.TASK_NAME, taskName);
taskDescription.setName(taskName);
taskDescription.setCount(SimpleTrigger.REPEAT_INDEFINITELY);
taskDescription.setInterval(frequency);
taskDescription.setStartTime(startTime);
taskDescription.setEndTime(endTime);
break;
case 6: // A javascript function, its execution frequnecy, function parameters, start time and an end time is passed.
//Extracting the javascript function from the arguments
if ((arguments[0] instanceof Function) || ((arguments[0] instanceof String))) {
jsFunction = arguments[0];
} else {
throw new CarbonException("Invalid parameter. The first parameter must be a " +
"JavaScript function.");
}
//Extracting the frequency from the arguments
if (arguments[1] != null && arguments[1] instanceof Number) {
frequency = ((Number) arguments[1]).longValue();
} else {
throw new CarbonException(
"Invalid parameter. The second parameter must be the execution " +
"frequency in milliseconds.");
}
//Extracting function parameters from the arguments
if (arguments[2] != null) {
if (arguments[2] instanceof NativeArray) {
NativeArray nativeArray = (NativeArray) arguments[2];
Object[] objects = nativeArray.getIds();
ArrayList tempParamHolder = new ArrayList();
for (int i = 0; i < objects.length; i++) {
Object currObject = objects[i];
if (currObject instanceof String) {
String property = (String) currObject;
if ("length".equals(property)) {
continue;
}
tempParamHolder.add(nativeArray.get(property, nativeArray));
} else {
Integer property = (Integer) currObject;
tempParamHolder
.add(nativeArray.get(property.intValue(), nativeArray));
}
}
//Convert the arraylist to an object array
functionParams = new Object[tempParamHolder.size()];
tempParamHolder.toArray(functionParams);
} else {
throw new CarbonException(
"Invalid parameter. The third parameter must be an Array of " +
"parameters to the argument or null.");
}
}
//Extracting the start time from the arguments
if (arguments[3] != null) {
try {
startTime = (Date) Context.jsToJava(arguments[3], Date.class);
} catch (EvaluatorException e) {
throw new CarbonException(
"Invalid parameter. The fourth parameter must be " +
"the start time in date format.", e);
}
}
if (arguments[4] != null) {
try {
endTime = (Date) Context.jsToJava(arguments[4], Date.class);
} catch (EvaluatorException e) {
throw new CarbonException(
"Invalid parameter. The fifth parameter must be " +
"the end time in date format.", e);
}
}
if (arguments[5] != null) {
if (arguments[5] instanceof String) {
taskName = (String) arguments[5];
} else {
throw new CarbonException(
"Invalid parameter. The sixth parameter must be a string value " +
"for the task name");
}
}
//Storing the function meta-data to be used by the job at execution time
resources.put(FunctionSchedulingJob.JAVASCRIPT_FUNCTION, jsFunction);
resources.put(FunctionSchedulingJob.FUNCTION_PARAMETERS, functionParams);
resources.put(FunctionSchedulingJob.AXIS_SERVICE, axisService);
resources.put(FunctionSchedulingJob.TASK_NAME, taskName);
taskDescription.setName(taskName);
taskDescription.setCount(SimpleTrigger.REPEAT_INDEFINITELY);
taskDescription.setInterval(frequency);
taskDescription.setStartTime(startTime);
taskDescription.setEndTime(endTime);
break;
default:
throw new CarbonException("Invalid number of parameters.");