// If the Result is of type Workflow, create additional (child)
// PTasks.
if (r instanceof Workflow)
{
Workflow w = (Workflow) r;
Task[] tt = w.tasks();
Link[] ll = w.links();
Hashtable tkeyMap = new Hashtable();
// For each newly created PTask there is an associated key.
// These keys are used to connect Links later.
for (int i = 0; i < tt.length; i++)
{
String key = sqlImpl().creationFunctions().newTask(tt[i], r.context().task(), con);
tkeyMap.put(tt[i], key);
}
for (int j = 0; j < ll.length; j++)
{
sqlImpl().creationFunctions().newLink(ll[j], tkeyMap, con);
}
// Rewires the Links stated by the Context bindings
String in_link_1 = sqlImpl().queryFunctions().readInTask(kk, false, con);
String in_link_2 = sqlImpl().queryFunctions().readInTask(kk, true, con);
String out_link_1 = sqlImpl().queryFunctions().readOutTask(kk, false, con);
String out_link_2 = sqlImpl().queryFunctions().readOutTask(kk, true, con);
sqlImpl().updateFunctions().rewireInLink(kk, false, w.in_1_binding(), tkeyMap, con);
sqlImpl().updateFunctions().rewireInLink(kk, true, w.in_2_binding(), tkeyMap, con);
sqlImpl().updateFunctions().rewireOutLink(kk, false, w.out_1_binding(), tkeyMap, con);
sqlImpl().updateFunctions().rewireOutLink(kk, true, w.out_2_binding(), tkeyMap, con);
// For each new PTask, check if it is done.
for (int k = 0; k < tt.length; k++)
{
String kkey = (String) tkeyMap.get(tt[k]);