public GraphActivity convertToBlock(ComplexActivity resultingBlock, GraphActivity starter){
//System.out.println("----- convertToBlk : "+ name);
if (outgoing.size()==1 && incoming.size()<=1) {
//System.out.println("in seq");
ComplexActivity sequenceBlock;
if (isSequenceBlock(resultingBlock)) {
sequenceBlock = resultingBlock;
} else {
sequenceBlock = new ComplexActivity();
resultingBlock.addChildActivity(sequenceBlock);
}
sequenceBlock.addChildActivity(createBlockActivity());
GraphActivity next = (GraphActivity)outgoing.elementAt(0);
//System.out.println("in seq: next:" + next.outgoing.size());
// if(!next.isEnd())
next = next.convertToBlock(sequenceBlock, starter);
return next;
} else if(outgoing.size() > 1) {
//starter = this;
GraphActivity next = null;
ComplexActivity innerBlock = null;
ComplexActivity firstBlock = resultingBlock;
Vector insertedActivities = new Vector(); //for undo
if (isXOR()) { //Switch block
innerBlock = new SwitchActivity();
} else { //All block
//System.out.println("in all");
innerBlock = new AllActivity();
if (!isSequenceBlock(resultingBlock)) {
ComplexActivity sequenceBlock = new ComplexActivity();
resultingBlock.addChildActivity(sequenceBlock);
resultingBlock = sequenceBlock;
}
Activity thisAct = createBlockActivity();
resultingBlock.addChildActivity(thisAct);
insertedActivities.add(resultingBlock);
insertedActivities.add(thisAct);
}
setAsStarterOf(innerBlock);
resultingBlock.addChildActivity(innerBlock);
insertedActivities.add(innerBlock);
for (int i=0; i<outgoing.size(); i++) {
next = (GraphActivity)outgoing.elementAt(i);
next = next.convertToBlock(innerBlock, this);
if(next == null) break;
}
if (next != null) {
//System.out.println("next is " + next.name);
if(!next.isOnceVisited() && !next.isEnd()){
next.flagVisited(); //flow only once
GraphActivity findingStarter = starter;
ComplexActivity findingBlock = resultingBlock;
while (findingStarter!=null && findingStarter.isBlockWith(next)) {
//System.out.println("in going up the level of block, the starter is " + starter.name);
starter = findingStarter;
resultingBlock = findingBlock;
findingBlock = getParentBlockOf(resultingBlock);
if(findingBlock==null)
findingStarter = null;
else
findingStarter = getStarterOf(findingBlock);
}
//���� ��'�� seq�� �ƴϸ� seq�� ����� �� ��, �ڽ�; �ű �߰��ؾ���
if (!(innerBlock instanceof SwitchActivity))
resultingBlock.addChildActivity(next.createBlockActivity());
((GraphActivity)next.outgoing.elementAt(0)).convertToBlock(resultingBlock, starter);
}
return next;
} else {
//firstBlock.remove();
//System.out.println("*********rebuild the block");
//recode: '���� all���; ��� '�� seq�� �� �ٷ� ���� ���� seq�� ����־�� ��
for(int i=0; i<insertedActivities.size(); i++)
firstBlock.removeChildActivity((Activity)insertedActivities.elementAt(i));
if(!isInAllBlock(innerBlock)){
//System.out.println(" -- is not in all-block. the starter is " + starter.name);
return convertToBlock(firstBlock, starter); //trace again if the first try has failed. the first try would make a little change good for retracing
}else {
//System.out.println(" -- is in all-block");
return null;
}
}
}else if(incoming.size()>1){ //Join node
//System.out.println("in join: ");
//if(resultingBlock)// testing this join is corresponding to this block
// System.out.println("in join:act.getParentActivity()" + resultingBlock.getParentActivity());
// System.out.println("in join:act name = " + name + " and the resultingBlock is " + resultingBlock +" isInAllBlock is " + isInAllBlock(resultingBlock));
// System.out.println("in join:the starter is " + starter.name);
if (isInAllBlock(resultingBlock) && isXOR()) {
// System.out.println(" case 1");
GraphActivity next = ((GraphActivity)outgoing.elementAt(0)).convertToBlock(resultingBlock, starter); //skip this XOR act and continue tracing
return next;
}else if(!isInAllBlock(resultingBlock) && isXOR() && !starter.isBlockWith(this)){
// System.out.println(" case 2: XOR split "+ starter.name );
GraphActivity next = ((GraphActivity)outgoing.elementAt(0)).convertToBlock(resultingBlock, starter); //skip this XOR act and continue tracing
return next;
}else
/* if(!isInAllBlock(resultingBlock) && !isXOR()){
System.out.println(" case 3");
resultingBlock.addChildActivity(createBlockActivity()); //don't skip and continue tracing
GraphActivity next = ((GraphActivity)outgoing.elementAt(0)).convertToBlock(resultingBlock, starter); //skip this XOR act and continue tracing
return next;
}else */
{
//case 4: ���� ������� ���; ��� link�� ����� ��'�� all-block�� ���Խ�Ŵ
ComplexActivity superBlock = getMinimumBlockOf(resultingBlock);
// System.out.println(" case 4: resultingBlock is " + resultingBlock);
// System.out.println(" : isBlockWith " + starter.name + " = " + starter.isBlockWith(this));
// System.out.println(" : superBlock1 is " + superBlock);
if(!isXOR() && !starter.isBlockWith(this) && /*isInAllBlock(resultingBlock) && */superBlock!=null && isAllBlock(superBlock)){