This example creates a runtime task that uses complex types in
its interface. The complex types are already defined, that is, the local file
system on the client has XSD files that contain the description of the complex
types.
Why and when to perform this task
The example runs only inside the context of the calling enterprise
application, for which the resources are loaded.
Steps for this task
- Access the ClientTaskFactory and create a resource set to contain
the definitions of the new task model.
ClientTaskFactory factory = ClientTaskFactory.newInstance();
ResourceSet resourceSet = factory.createResourceSet();
- Add the XSD definitions of your complex types to the resource set
so that they are available when you define your operations.
The
files are located relative to the location where the code is executed.
factory.loadXSDSchema( resourceSet, "InputBO.xsd" );
factory.loadXSDSchema( resourceSet, "OutputBO.xsd" );
- Create the WSDL definition and add the descriptions of your operations.
// create the WSDL interface
Definition definition = factory.createWSDLDefinition
( resourceSet, new QName( "http://www.ibm.com/task/test/", "test" ) );
// create a port type
PortType portType = factory.createPortType( definition, "doItPT" );
// create an operation; the input message is an InputBO and
// the output message an OutputBO;
// a fault message is not specified
Operation operation = factory.createOperation
( definition, portType, "doIt",
new QName( "http://Input", "InputBO" ),
new QName( "http://Output", "OutputBO" ),
null );
- Create the EMF model of your new human task.
If you
are creating a task instance, a valid-from date (UTCDate) is not required.
TTask humanTask = factory.createTTask( resourceSet,
TTaskKinds.HTASK_LITERAL,
"TestTask",
new UTCDate( "2005-01-01T00:00:00" ),
"http://www.ibm.com/task/test/",
portType,
operation );
This
step initializes the properties of the task model with default values.
- Modify the properties of your human task model.
// use the methods from the com.ibm.wbit.tel package, for example,
humanTask.setBusinessRelevance( TBoolean, YES_LITERAL );
// retrieve the task factory to create or modify composite task elements
TaskFactory taskFactory = factory.getTaskFactory();
// specify escalation settings
TVerb verb = taskFactory.createTVerb();
verb.setName("John");
// create escalationReceiver and add verb
TEscalationReceiver escalationReceiver =
taskFactory.createTEscalationReceiver();
escalationReceiver.setVerb(verb);
// create escalation and add escalation receiver
TEscalation escalation = taskFactory.createTEscalation();
escalation.setEscalationReceiver(escalationReceiver);
- Create the task model that contains all the resource definitions.
TaskModel taskModel = ClientTaskFactory.createTaskModel( resourceSet );
- Validate the task model and correct any validation problems that
are found.
ValidationProblem[] validationProblems = taskModel.validate();
- Create the runtime task instance or template.
Use
the HumanTaskManagerService interface to create the task instance or the task
template. You must provide an application name that contains the data type
definitions so that they can be accessed. The application must also contain
a dummy task or process so that the application is loaded by Business Process
Choreographer.
- The following snippet creates a task instance:
task.createTask( taskModel, "BOapplication", "HTM" );
- The following snippet creates a task template:
task.createTaskTemplate( taskModel, "BOapplication" );
Result
If a runtime task instance is created, it can now be started. If
a runtime task template is created, you can now create task instances from
the template.