mt5225 / scxmlgui

Automatically exported from code.google.com/p/scxmlgui
0 stars 0 forks source link

Validate no transition between parallel siblings #29

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a parallel state ps1
2. Create two children for ps1, ch1 and ch2
3. Create a transition between ps1 and ps2

What is the expected output? What do you see instead?
Is expected a validation error.

What version of the product are you using? On what operating system?
Windows 7, last version.

Please provide any additional information below.

scxml reference:
http://www.w3.org/TR/scxml/#parallel

A conformant SCXML document must not contain any transitions between parallel 
siblings. 

Original issue reported on code.google.com by cver...@gmail.com on 29 Nov 2011 at 10:28

GoogleCodeExporter commented 9 years ago
i'll take a few days to test this bug report and possibly commit a bug fix.
feel free to send a patch if you fix the problem before me.
thanks

Original comment by fmorbini on 3 Dec 2011 at 9:32

GoogleCodeExporter commented 9 years ago
Hi,

I'm implementing SCXML, not the GUI, but I can give you my code where I do
this validation so you can use it on yours.

For each state in parallel states check the LCA from transitions and, if
the LCA is the parallel state itself then... validation error...
private void validateNoTransitionBetweenParallelSiblings(ParallelState
parallelState)throws ParallelSiblingTransactionException {

List<State> stateList=stateToList(parallelState);
for(State state:stateList){
for(Transition transition:state.getTransitions()){
if(searchLCA(transition).equals(parallelState)){
throw new ParallelSiblingTransactionException();
}
}
}
 }

To calculate the LCA I calculate first the breadcrumb of each state and
compare until one state is different... the last common state in the
breadcrumb is the LCA.
In my case null is the scxml itself (it depends on how you calculate the
breadcrumb).

protected State searchLCA(Transition transition) {
State[] states = new State[] { transition.getSourceState(),
transition.getTargetState() };
return searchLCA(states);
}

protected State searchLCA(State[] states) {
State LCA= ROOT_STATE;
Iterator<State>[] breadcrumbs = new Iterator[states.length];

// get all the breadcrumbs
for (int i = 0; i < states.length; i++) {
breadcrumbs[i] = states[i].getBreadCrumb().iterator();
i++;
}

 State candidate;
State other;
boolean foundLCA = false;

while (!foundLCA) {
//take the first state from breadcrumbs
candidate=breadcrumbs[0].hasNext()?breadcrumbs[0].next():null;
if(candidate!=null){
//and compare with all the other states
for (int i = 1; i < states.length&&!foundLCA; i++) {
other=breadcrumbs[i].hasNext()?breadcrumbs[0].next():null;
if(other==null||other.equals(candidate)){
foundLCA=true;
 }
}
//if no other states is different from candidate
if(!foundLCA){
//put candidate to LCA
LCA=candidate;
}
 }else{
//there is no candidate so... LCA has been found
foundLCA=true;
}
}
 return LCA;
}

And last, to calculate the breadcrumb (this could be cached to improve
performance):
@Override
public List<State> getBreadCrumb() {
List<State> breadcrumb = new ArrayList<State>();
calculateBreadCrumb(breadcrumb);

return breadcrumb;
}
protected void calculateBreadCrumb(List<State> breadcrumb) {
BasicState aux = (BasicState) parent;
if (aux != null) {
aux.calculateBreadCrumb(breadcrumb);
breadcrumb.add(aux);
}

}

I hope this code could help you!!

Regards.

Original comment by cver...@gmail.com on 5 Dec 2011 at 10:47

GoogleCodeExporter commented 9 years ago
Have you found this useful?

Original comment by cver...@gmail.com on 9 Dec 2011 at 10:14

GoogleCodeExporter commented 9 years ago
sorry, haven't looked at this yet. I may take an additional couple of weeks 
before i'll be able to check this out.

Original comment by fmorbini on 10 Dec 2011 at 2:17

GoogleCodeExporter commented 9 years ago
fixed in revision 140.

Original comment by fmorbini on 3 Jan 2012 at 6:34

GoogleCodeExporter commented 9 years ago
Thanks!

Original comment by cver...@gmail.com on 25 Jan 2012 at 3:42