in modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionFactory.java [46:176]
public static TaskDescription createTaskDescription(OMElement el, OMNamespace tagetNamespace) {
if (log.isDebugEnabled()) {
log.debug("Creating SimpleQuartz Task");
}
QName task = createQName(TASK, tagetNamespace);
if (task.equals(el.getQName())) {
TaskDescription taskDescription = new TaskDescription();
String name = el.getAttributeValue(
new QName(NULL_NAMESPACE, "name"));
if (name != null) {
taskDescription.setName(name);
} else {
handleException("Name for a task is required, missing name in the task");
}
String group = el.getAttributeValue(
new QName(NULL_NAMESPACE, "group"));
if (group != null) {
taskDescription.setGroup(group);
}
// set the task class
OMAttribute classAttr = el.getAttribute(new QName("class"));
if (classAttr != null && classAttr.getAttributeValue() != null) {
String classname = classAttr.getAttributeValue();
try {
Class.forName(classname).newInstance();
} catch (Exception e) {
handleException("Failed to load task class " + classname, e);
}
taskDescription.setTaskClass(classname);
} else {
log.warn("TaskClass cannot be found." +
"Task implementation may need a task class if there is no default one");
}
OMElement descElem = el.getFirstChildWithName(createQName(DESCRIPTION, tagetNamespace));
if (descElem != null) {
taskDescription.setDescription(descElem.getText());
}
// set pinned server list
OMAttribute pinnedServers = el.getAttribute(new QName(NULL_NAMESPACE, "pinnedServers"));
if (pinnedServers != null) {
String pinnedServersValue = pinnedServers.getAttributeValue();
if (pinnedServersValue == null) {
// default to all servers
} else {
StringTokenizer st = new StringTokenizer(pinnedServersValue, " ,");
List<String> pinnedServersList = new ArrayList<String>();
while (st.hasMoreTokens()) {
String token = st.nextToken();
if (token.length() != 0) {
pinnedServersList.add(token);
}
}
taskDescription.setPinnedServers(pinnedServersList);
}
}
// next sort out the property children
Iterator it = el.getChildrenWithName(createQName(PROPERTY, tagetNamespace));
while (it.hasNext()) {
OMElement prop = (OMElement) it.next();
if (PropertyHelper.isStaticProperty(prop)) {
taskDescription.addProperty(prop);
} else {
handleException("Tasks does not support dynamic properties");
}
}
// setting the trigger to the task
OMElement trigger = el.getFirstChildWithName(createQName(TRIGGER, tagetNamespace));
if (trigger != null) {
OMAttribute count = trigger.getAttribute(new QName("count"));
if (count != null) {
try {
taskDescription.setCount(Integer.parseInt(count.getAttributeValue()));
} catch (Exception e) {
handleException("Failed to parse trigger count as an integer", e);
}
}
OMAttribute once = trigger.getAttribute(new QName("once"));
if (once != null && Boolean.TRUE.toString().equals(once.getAttributeValue())) {
taskDescription.setCount(1);
taskDescription.setInterval(1);
}
OMAttribute repeatInterval = trigger.getAttribute(new QName("interval"));
if (repeatInterval == null && taskDescription.getCount() > 1) {
handleException("Trigger seems to be " +
"a simple trigger, but no interval specified");
} else if (repeatInterval != null && repeatInterval.getAttributeValue() != null) {
try {
long repeatIntervalInSeconds = Long.parseLong(
repeatInterval.getAttributeValue());
long repeatIntervalInMillis = repeatIntervalInSeconds * 1000;
taskDescription.setInterval(repeatIntervalInMillis);
} catch (Exception e) {
handleException("Failed to parse trigger interval as a long value", e);
}
}
OMAttribute expr = trigger.getAttribute(new QName("cron"));
if (expr == null && taskDescription.getInterval() == 0) {
taskDescription.setCount(1);
taskDescription.setInterval(1);
} else if (expr != null && taskDescription.getInterval() > 0) {
handleException("Trigger syntax error : " +
"both cron and simple trigger attributes are present");
} else if (expr != null && expr.getAttributeValue() != null) {
taskDescription.setCron(expr.getAttributeValue());
}
} else {
taskDescription.setCount(1);
taskDescription.setInterval(1);
}
return taskDescription;
} else {
handleException("Syntax error in the task : wrong QName for the task");
return null;
}
}