Index: lutingenerator/src/java/org/codelutin/generator/models/state/xml/StateModelStateImpl.java diff -u /dev/null lutingenerator/src/java/org/codelutin/generator/models/state/xml/StateModelStateImpl.java:1.1 --- /dev/null Fri May 25 16:20:14 2007 +++ lutingenerator/src/java/org/codelutin/generator/models/state/xml/StateModelStateImpl.java Fri May 25 16:20:08 2007 @@ -0,0 +1,115 @@ +/* *##% + * Copyright (C) 2007 Code Lutin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +package org.codelutin.generator.models.state.xml; + +import java.util.ArrayList; +import java.util.List; + +import org.codelutin.generator.models.state.StateModelState; +import org.codelutin.generator.models.state.StateModelTransition; + +/** + * StateModelStateImpl.java + * + * @author chatellier + * @version $Revision: 1.1 $ + * + * Last update : $Date: 2007/05/25 16:20:08 $ + * By : $Author: chatellier $ + */ +/** + * StateModelStateImpl.java + * + * @author chatellier + * @version $Revision: 1.1 $ + * + * Last update : $Date: 2007/05/25 16:20:08 $ + * By : $Author: chatellier $ + */ +public class StateModelStateImpl implements StateModelState { + + /** + * State name + */ + protected String name; + + /** + * Transition list + */ + protected List listTransitions; + + /** + * Constructor + */ + public StateModelStateImpl() { + super(); + listTransitions = new ArrayList(); + } + + /* (non-Javadoc) + * @see org.codelutin.generator.models.state.StateModelState#getName() + */ + public String getName() { + return name; + } + + /** + * Set state name + * @param name the name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Add transition + * @param transition a transition + */ + public void addTransition(StateModelTransition transition) { + listTransitions.add(transition); + } + + /* (non-Javadoc) + * @see org.codelutin.generator.models.state.StateModelState#getTransitions() + */ + public List getTransitions() { + return listTransitions; + } + + /* (non-Javadoc) + * @see org.codelutin.generator.models.state.StateModelState#isComplexe() + */ + public boolean isComplex() { + return false; + } + + /* (non-Javadoc) + * @see org.codelutin.generator.models.state.StateModelState#isFinal() + */ + public boolean isFinal() { + return false; + } + + /* (non-Javadoc) + * @see org.codelutin.generator.models.state.StateModelState#isInitial() + */ + public boolean isInitial() { + return false; + } +} Index: lutingenerator/src/java/org/codelutin/generator/models/state/xml/StateModelImpl.java diff -u /dev/null lutingenerator/src/java/org/codelutin/generator/models/state/xml/StateModelImpl.java:1.1 --- /dev/null Fri May 25 16:20:14 2007 +++ lutingenerator/src/java/org/codelutin/generator/models/state/xml/StateModelImpl.java Fri May 25 16:20:08 2007 @@ -0,0 +1,99 @@ +/* *##% + * Copyright (C) 2007 Code Lutin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +package org.codelutin.generator.models.state.xml; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.codelutin.generator.models.state.StateModel; +import org.codelutin.generator.models.state.StateModelStateChart; + +/** + * StateModelImpl.java + * + * @author chatellier + * @version $Revision: 1.1 $ + * + * Last update : $Date: 2007/05/25 16:20:08 $ + * By : $Author: chatellier $ + */ +public class StateModelImpl implements StateModel { + + /** + * List of charts composing this model + */ + protected List listStateCharts; + + /** + * Name of this model + */ + protected String name = null; + + /** + * Construteur + */ + public StateModelImpl() { + super(); + listStateCharts = new ArrayList(); + } + + /* (non-Javadoc) + * @see org.codelutin.generator.models.state.StateModel#getName() + */ + public String getName() { + return null; + } + + /** + * Set model name + * @param name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Add chart + * @param chart + */ + public void addStateChart(StateModelStateChart chart) { + + // appele apres construction du StateModelStateChartImpl + // corrige les liens entre les nom d'etat, et les instances d'état + ((StateModelStateChartImpl)chart).correctTransitionNameToInstance(null); + + listStateCharts.add(chart); + } + + /* (non-Javadoc) + * @see org.codelutin.generator.models.state.StateModel#getStateCharts() + */ + public List getStateCharts() { + return listStateCharts; + } + + /** + * Add a list of stateCharts into current model + * @param charts list + */ + public void addAllStateCharts(Collection charts) { + listStateCharts.addAll(charts); + } +} Index: lutingenerator/src/java/org/codelutin/generator/models/state/xml/StateModelTransitionImpl.java diff -u /dev/null lutingenerator/src/java/org/codelutin/generator/models/state/xml/StateModelTransitionImpl.java:1.1 --- /dev/null Fri May 25 16:20:14 2007 +++ lutingenerator/src/java/org/codelutin/generator/models/state/xml/StateModelTransitionImpl.java Fri May 25 16:20:08 2007 @@ -0,0 +1,105 @@ +/* *##% + * Copyright (C) 2007 Code Lutin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +package org.codelutin.generator.models.state.xml; + +import org.codelutin.generator.models.state.StateModelState; +import org.codelutin.generator.models.state.StateModelTransition; + +/** + * StateModelTransitionImpl + * + * @author chatellier + * @version $Revision: 1.1 $ + * + * Last update : $Date: 2007/05/25 16:20:08 $ + * By : $Author: chatellier $ + */ +public class StateModelTransitionImpl implements StateModelTransition { + + /** + * Destination state name + */ + protected String stateName = null; + + /** + * Event + */ + protected String event; + + /** + * Destination state reference + */ + protected StateModelState state = null; + + /** + * Constructor + */ + public StateModelTransitionImpl() { + super(); + } + + /** + * ToState name + * @param stateName name + */ + public void setToState(String stateName) { + this.stateName = stateName; + } + + /** + * Get toState name + * @return the stateName + */ + public String getStateName() { + return stateName; + } + + /** + * Permet de positionner un lien sur l'instance de l'état. + * + * On ne peut pas le faire directement car le fichier xml n'est + * potentielement par ordonne, et par concequent, les etat n'ont pas encore + * ete traite. + */ + public void setState(StateModelState state) { + this.state = state; + } + + /* (non-Javadoc) + * @see org.codelutin.generator.models.state.StateModelTransition#getDestinationState() + */ + public StateModelState getDestinationState() { + return state; + } + + /* (non-Javadoc) + * @see org.codelutin.generator.models.state.StateModelTransition#getEvent() + */ + public String getEvent() { + return event; + } + + /** + * Set transition event + * @param event event name + */ + public void setEvent(String event) { + this.event = event; + } +} Index: lutingenerator/src/java/org/codelutin/generator/models/state/xml/StateModelSimpleStateImpl.java diff -u /dev/null lutingenerator/src/java/org/codelutin/generator/models/state/xml/StateModelSimpleStateImpl.java:1.1 --- /dev/null Fri May 25 16:20:14 2007 +++ lutingenerator/src/java/org/codelutin/generator/models/state/xml/StateModelSimpleStateImpl.java Fri May 25 16:20:08 2007 @@ -0,0 +1,76 @@ +/* *##% + * Copyright (C) 2007 Code Lutin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +package org.codelutin.generator.models.state.xml; + +import org.codelutin.generator.models.state.StateModelSimpleState; + +/** + * StateModelSimpleStateImpl.java + * + * @author chatellier + * @version $Revision: 1.1 $ + * + * Last update : $Date: 2007/05/25 16:20:08 $ + * By : $Author: chatellier $ + */ +public class StateModelSimpleStateImpl extends StateModelStateImpl implements StateModelSimpleState { + + /** init state ? */ + protected boolean initialState; + + /** final state ? */ + protected boolean finalState; + + /** + * Constructeur + */ + public StateModelSimpleStateImpl() { + initialState = finalState = false; + } + + /** + * @return the finalState + */ + public boolean isFinal() { + return finalState; + } + + /** + * @param finalState the finalState to set + */ + public void setFinal(boolean finalState) { + this.finalState = finalState; + } + + /** + * @return the initialState + */ + public boolean isInitial() { + return initialState; + } + + /** + * @param initialState the initialState to set + */ + public void setInitial(boolean initialState) { + this.initialState = initialState; + } + + +} Index: lutingenerator/src/java/org/codelutin/generator/models/state/xml/StateModelStateChartImpl.java diff -u /dev/null lutingenerator/src/java/org/codelutin/generator/models/state/xml/StateModelStateChartImpl.java:1.1 --- /dev/null Fri May 25 16:20:14 2007 +++ lutingenerator/src/java/org/codelutin/generator/models/state/xml/StateModelStateChartImpl.java Fri May 25 16:20:08 2007 @@ -0,0 +1,54 @@ +/* *##% + * Copyright (C) 2007 Code Lutin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +package org.codelutin.generator.models.state.xml; + +import org.codelutin.generator.models.state.StateModelStateChart; + +/** + * StateModelStateChartImpl.java + * + * @author chatellier + * @version $Revision: 1.1 $ + * + * Last update : $Date: 2007/05/25 16:20:08 $ + * By : $Author: chatellier $ + */ +public class StateModelStateChartImpl extends StateModelComplexeStateImpl implements StateModelStateChart { + + /** + * Package name + */ + protected String packageName; + + + /* (non-Javadoc) + * @see org.codelutin.generator.models.state.StateModelStateChart#getPackageName() + */ + public String getPackageName() { + return packageName; + } + + /** + * Set package name + * @param packageName + */ + public void setPackage(String packageName) { + this.packageName = packageName; + } +} Index: lutingenerator/src/java/org/codelutin/generator/models/state/xml/StateModelComplexeStateImpl.java diff -u /dev/null lutingenerator/src/java/org/codelutin/generator/models/state/xml/StateModelComplexeStateImpl.java:1.1 --- /dev/null Fri May 25 16:20:17 2007 +++ lutingenerator/src/java/org/codelutin/generator/models/state/xml/StateModelComplexeStateImpl.java Fri May 25 16:20:08 2007 @@ -0,0 +1,150 @@ +/* *##% + * Copyright (C) 2007 Code Lutin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +package org.codelutin.generator.models.state.xml; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.codelutin.generator.models.state.StateModelComplexState; +import org.codelutin.generator.models.state.StateModelSimpleState; +import org.codelutin.generator.models.state.StateModelState; +import org.codelutin.generator.models.state.StateModelTransition; + +/** + * StateModelComplexeStateImpl.java + * + * @author chatellier + * @version $Revision: 1.1 $ + * + * Last update : $Date: 2007/05/25 16:20:08 $ + * By : $Author: chatellier $ + */ +public class StateModelComplexeStateImpl extends StateModelStateImpl implements StateModelComplexState { + + /** + * States'set of this state + */ + protected Map mapState; + + /** + * Constructor + */ + public StateModelComplexeStateImpl() { + super(); + mapState = new HashMap(); + } + + /** + * Add a state + * @param state the state + */ + public void addState(StateModelState state) { + mapState.put(state.getName(),state); + } + + /* (non-Javadoc) + * @see org.codelutin.generator.models.state.StateModelComplexeState#getStates() + */ + public Collection getStates() { + return mapState.values(); + } + + /** + * Correct association, because, the xml file migth be non ordonated + */ + void correctTransitionNameToInstance(StateModelComplexeStateImpl parent) { + + // iterator + Iterator it = mapState.values().iterator(); + + while(it.hasNext()) { + StateModelState state = it.next(); + + // reboucle si l'etat est complexe + if(state instanceof StateModelComplexeStateImpl) { + ((StateModelComplexeStateImpl)state).correctTransitionNameToInstance(this); + } + else { + for(StateModelTransition tr : state.getTransitions()) { + StateModelTransitionImpl tri = (StateModelTransitionImpl)tr; + String name = tri.getStateName(); + + // l'etat apartient au cas complexe courant + if(this.getState(name) != null) { + tri.setState(this.getState(name)); + } + else { + // l'etat apartient au cas complexe parent + if(parent != null && parent.getState(name)!= null) { + tri.setState(parent.getState(name)); + } + // sinon il reste a null, tant pis + } + } + } + } + } + + /** + * Return a state ref by his name + * @param stateName a state or null if state doesnt exists + */ + StateModelState getState(String stateName) { + return mapState.get(stateName); + } + + /* (non-Javadoc) + * @see org.codelutin.generator.models.state.xml.StateModelStateImpl#isComplexe() + */ + @Override + public boolean isComplex() { + // TODO Auto-generated method stub + return true; + } + + /* (non-Javadoc) + * @see org.codelutin.generator.models.state.StateModelComplexeState#getInitialState() + */ + public StateModelState getInitialState() { + + StateModelState response = null; + + // iterator + Iterator it = mapState.values().iterator(); + + while(it.hasNext()) { + StateModelState state = it.next(); + + // if state is simple + if(!state.isComplex()) { + StateModelSimpleState simpleState = (StateModelSimpleState)state; + + if(simpleState.isInitial()) { + // get(0), normalement il n'y a qu'une transition sur un etat initial + response = simpleState.getTransitions().get(0).getDestinationState(); + } + } + } + + return response; + } + +} Index: lutingenerator/src/java/org/codelutin/generator/models/state/xml/DigesterStateModelRuleSet.java diff -u /dev/null lutingenerator/src/java/org/codelutin/generator/models/state/xml/DigesterStateModelRuleSet.java:1.1 --- /dev/null Fri May 25 16:20:17 2007 +++ lutingenerator/src/java/org/codelutin/generator/models/state/xml/DigesterStateModelRuleSet.java Fri May 25 16:20:08 2007 @@ -0,0 +1,85 @@ +/* *##% + * Copyright (C) 2007 Code Lutin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +package org.codelutin.generator.models.state.xml; + +import org.apache.commons.digester.Digester; +import org.apache.commons.digester.RuleSetBase; + +/** + * StateModelDigesterRuleSet + * + * Definit principalement : + * - la classe d'implementation a utiliser pour chaque noeud + * - la methode a appeler apres chaque noeud + * + * Ce jeu de regle ne cree pas l'element racine. + * Il doit etre cree et ajoute a la pile digester avant l'appel a + * Digester.parse(File). + * + * Exemple: + * + * StateModel monModel = new StateModelImpl() + * Digester d = new Digester(); + * d.push(monModel); + * d.parse(file); + * + * + * @author chatellier + * @version $Revision: 1.1 $ + * + * Last update : $Date: 2007/05/25 16:20:08 $ By : $Author: chatellier $ + */ +public class DigesterStateModelRuleSet extends RuleSetBase { + + protected String prefix = null; + + public DigesterStateModelRuleSet() { + this(""); + } + + public DigesterStateModelRuleSet(String prefix) { + super(); + this.prefix = prefix; + this.namespaceURI = "http://www.codelutin.org/lutingenerator/stateModel"; + } + + public void addRuleInstances(Digester digester) { + + //digester.addObjectCreate("stateModel", StateModelImpl.class); + //digester.addFactoryCreate("stateModel", DigesterStateModelFactory.class); + // root element must be present on stask + digester.addSetProperties("stateModel"); + + digester.addObjectCreate("stateModel/stateChart", StateModelStateChartImpl.class); + digester.addSetProperties("stateModel/stateChart"); + digester.addSetNext("stateModel/stateChart", "addStateChart"); + + digester.addObjectCreate("*/state", StateModelSimpleStateImpl.class); + digester.addSetProperties("*/state"); + digester.addSetNext("*/state", "addState"); + + digester.addObjectCreate("*/complexeState", StateModelComplexeStateImpl.class); + digester.addSetProperties("*/complexeState"); + digester.addSetNext("*/complexeState", "addState"); + + digester.addObjectCreate("*/transition", StateModelTransitionImpl.class); + digester.addSetProperties("*/transition"); + digester.addSetNext("*/transition", "addTransition"); + } +}