List<Attribute> attrList = entry.getAttribute(attrType);
if ((attrList == null) || attrList.isEmpty())
{
Message message = ERR_TASKSCHED_NO_CLASS_ATTRIBUTE.get(ATTR_TASK_ID);
throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message);
}
if (attrList.size() > 1)
{
Message message = ERR_TASKSCHED_MULTIPLE_CLASS_TYPES.get(ATTR_TASK_ID);
throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message);
}
Attribute attr = attrList.get(0);
if (attr.isEmpty())
{
Message message = ERR_TASKSCHED_NO_CLASS_VALUES.get(ATTR_TASK_ID);
throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message);
}
Iterator<AttributeValue> iterator = attr.iterator();
AttributeValue value = iterator.next();
if (iterator.hasNext())
{
Message message = ERR_TASKSCHED_MULTIPLE_CLASS_VALUES.get(ATTR_TASK_ID);
throw new DirectoryException(ResultCode.OBJECTCLASS_VIOLATION, message);
}
// Try to load the specified class.
String taskClassName = value.getValue().toString();
Class<?> taskClass;
try
{
taskClass = DirectoryServer.loadClass(taskClassName);
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
Message message = ERR_TASKSCHED_CANNOT_LOAD_CLASS.
get(String.valueOf(taskClassName), ATTR_TASK_CLASS,
stackTraceToSingleLineString(e));
throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
message);
}
// Instantiate the class as a task.
Task task;
try
{
task = (Task) taskClass.newInstance();
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
Message message = ERR_TASKSCHED_CANNOT_INSTANTIATE_CLASS_AS_TASK.get(
String.valueOf(taskClassName), Task.class.getName());
throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
message);
}
// Perform the necessary internal and external initialization for the task.
try
{
task.initializeTaskInternal(this, entry);
}
catch (InitializationException ie)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, ie);
}
Message message = ERR_TASKSCHED_CANNOT_INITIALIZE_INTERNAL.get(
String.valueOf(taskClassName), ie.getMessage());
throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
message);
}
catch (Exception e)
{
Message message = ERR_TASKSCHED_CANNOT_INITIALIZE_INTERNAL.get(
String.valueOf(taskClassName), stackTraceToSingleLineString(e));
throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
message);
}
if (!TaskState.isDone(task.getTaskState()) &&
!DirectoryServer.getAllowedTasks().contains(taskClassName))
{
Message message = ERR_TASKSCHED_NOT_ALLOWED_TASK.get(taskClassName);
throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message);
}
task.setOperation(operation);
// Avoid task specific initialization for completed tasks.