Closed GoogleCodeExporter closed 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
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
Have you found this useful?
Original comment by cver...@gmail.com
on 9 Dec 2011 at 10:14
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
fixed in revision 140.
Original comment by fmorbini
on 3 Jan 2012 at 6:34
Thanks!
Original comment by cver...@gmail.com
on 25 Jan 2012 at 3:42
Original issue reported on code.google.com by
cver...@gmail.com
on 29 Nov 2011 at 10:28