commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject svn commit: r234141 [2/4] - in /jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml: ./ env/ model/
Date Sun, 21 Aug 2005 03:24:37 GMT
Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/SCXMLHelper.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/SCXMLHelper.java?rev=234141&r1=234140&r2=234141&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/SCXMLHelper.java (original)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/SCXMLHelper.java Sat Aug 20 20:24:20 2005
@@ -1,6 +1,6 @@
 /*
- *    
- *   Copyright 2004 The Apache Software Foundation.
+ *
+ *   Copyright 2005 The Apache Software Foundation.
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -33,50 +33,54 @@
  * Helper class, all methods static final.
  *
  */
-public class SCXMLHelper {
+public final class SCXMLHelper {
 
     /**
-     * Return true if the string is empty
-     * 
+     * Return true if the string is empty.
+     *
      * @param attr The String to test
      * @return Is string empty
      */
-    public static final boolean isStringEmpty(String attr) {
-        return (attr == null || attr.trim().length() == 0) ? true : false;
+    public static boolean isStringEmpty(final String attr) {
+        if (attr == null || attr.trim().length() == 0) {
+            return true;
+        }
+        return false;
     }
 
     /**
-     * Checks whether a transition target tt (State or Parallel) is a descendant
-     * of the transition target ctx.
-     * 
+     * Checks whether a transition target tt (State or Parallel) is a
+     * descendant of the transition target context.
+     *
      * @param tt
      *            TransitionTarget to check - a potential descendant
      * @param ctx
      *            TransitionTarget context - a potential ancestor
      * @return true iff tt is a descendant of ctx, false otherwise
      */
-    public static final boolean isDescendant(TransitionTarget tt,
-            TransitionTarget ctx) {
-        while ((tt = tt.getParent()) != null) {
-            if (tt == ctx) {
+    public static boolean isDescendant(final TransitionTarget tt,
+            final TransitionTarget ctx) {
+        TransitionTarget parent = tt.getParent();
+        while (parent != null) {
+            if (parent == ctx) {
                 return true;
             }
+            parent = parent.getParent();
         }
         return false;
     }
 
     /**
      * Creates a set which contains given states and all their ancestors
-     * recursively up to the upper bound. Null upperBound means root 
+     * recursively up to the upper bound. Null upperBound means root
      * of the state machine.
-     *   
-     * @param upperBounds 
-     * @param transTargets
-     *            [in]
-     * 
+     *
+     * @param states The Set of States
+     * @param upperBounds The Set of upper bound States
      * @return transitive closure of a given state set
      */
-    public static final Set getAncestorClosure(Set states, Set upperBounds) {
+    public static Set getAncestorClosure(final Set states,
+            final Set upperBounds) {
         Set closure = new HashSet((int) (states.size() * 2));
         for (Iterator i = states.iterator(); i.hasNext();) {
             TransitionTarget tt = (TransitionTarget) i.next();
@@ -98,21 +102,22 @@
      * Checks whether a given set of states is a legal Harel State Table
      * configuration (with the respect to the definition of the OR and AND
      * states).
-     * 
+     *
      * @param states
      *            a set of states
      * @param errRep
      *            ErrorReporter to report detailed error info if needed
      * @return true if a given state configuration is legal, false otherwise
      */
-    public static final boolean isLegalConfig(Set states, ErrorReporter errRep) {
+    public static boolean isLegalConfig(final Set states,
+            final ErrorReporter errRep) {
         /*
          * For every active state we add 1 to the count of its parent. Each
          * Parallel should reach count equal to the number of its children and
          * contribute by 1 to its parent. Each State should reach count exactly
          * 1. SCXML elemnt (top) should reach count exactly 1. We essentially
-         * summarize up the hierarchy tree starting with a given set of states =
-         * active configuration.
+         * summarize up the hierarchy tree starting with a given set of
+         * states = active configuration.
          */
         boolean legalConfig = true; // let's be optimists
         Map counts = new IdentityHashMap();
@@ -166,15 +171,15 @@
     }
 
     /**
-     * finds the least common ancestor of transition targets tt1 and tt2 if one
-     * exists.
-     * 
-     * @param tt1
-     * @param tt2
+     * Finds the least common ancestor of transition targets tt1 and tt2 if
+     * one exists.
+     *
+     * @param tt1 First TransitionTarget
+     * @param tt2 Second TransitionTarget
      * @return closest common ancestor of tt1 and tt2 or null
      */
-    public static final TransitionTarget getLCA(TransitionTarget tt1,
-            TransitionTarget tt2) {
+    public static TransitionTarget getLCA(final TransitionTarget tt1,
+            final TransitionTarget tt2) {
         if (tt1 == tt2) {
             return tt1; //self-transition
         } else if (isDescendant(tt1, tt2)) {
@@ -203,11 +208,12 @@
     }
 
     /**
-     * Returns the set of all states (and parallels) which are exited if a given transition t is
-     * going to be taken. Current states are necessary to be taken into account
-     * due to orthogonal states and cross-region transitions - see UML specs.
-     * for more details.
-     * 
+     * Returns the set of all states (and parallels) which are exited if a
+     * given transition t is going to be taken.
+     * Current states are necessary to be taken into account
+     * due to orthogonal states and cross-region transitions -
+     * see UML specs for more details.
+     *
      * @param t
      *            transition to be taken
      * @param currentStates
@@ -215,21 +221,23 @@
      * @return a set of all states (including composite) which are exited if a
      *         given transition is taken
      */
-    public static final Set getStatesExited(Transition t, Set currentStates) {
+    public static Set getStatesExited(final Transition t,
+            final Set currentStates) {
         Set allStates = new HashSet();
         Path p = t.getPath();
         //the easy part
         allStates.addAll(p.getUpwardSegment());
         if (p.isCrossRegion()) {
-            for (Iterator regions = p.getRegionsExited().iterator(); 
-                    regions.hasNext(); ) {
-                Parallel par = ((Parallel) ((State) regions.next()).getParent());
-                //let's find affected states in sibling regions            
-                for (Iterator siblings = par.getStates().iterator(); 
-                        siblings.hasNext(); ) {
+            for (Iterator regions = p.getRegionsExited().iterator();
+                    regions.hasNext();) {
+                Parallel par = ((Parallel) ((State) regions.next()).
+                    getParent());
+                //let's find affected states in sibling regions
+                for (Iterator siblings = par.getStates().iterator();
+                        siblings.hasNext();) {
                     State s = (State) siblings.next();
-                    for (Iterator act = currentStates.iterator(); 
-                            act.hasNext(); ) {
+                    for (Iterator act = currentStates.iterator();
+                            act.hasNext();) {
                         TransitionTarget a = (TransitionTarget) act.next();
                         if (isDescendant(a, s)) {
                             //a is affected
@@ -250,18 +258,30 @@
     /**
      * According to the UML definition, two transitions
      * are conflicting if the sets of states they exit overlap.
-     * 
+     *
      * @param t1 a transition to check against t2
      * @param t2 a transition to check against t1
      * @param currentStates the set of current states (simple states only)
      * @return true if the t1 and t2 are conflicting transitions
      * @see #getStatesExited(Transition, Set)
      */
-    public static final boolean inConflict(Transition t1, Transition t2,
-            Set currentStates) {
+    public static boolean inConflict(final Transition t1,
+            final Transition t2, final Set currentStates) {
         Set ts1 = getStatesExited(t1, currentStates);
         Set ts2 = getStatesExited(t2, currentStates);
         ts1.retainAll(ts2);
-        return (ts1.isEmpty()) ? false : true;
+        if (ts1.isEmpty()) {
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * Discourage instantiation since this is a utility class.
+     */
+    private SCXMLHelper() {
+        super();
     }
+
 }
+

Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/SCXMLListener.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/SCXMLListener.java?rev=234141&r1=234140&r2=234141&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/SCXMLListener.java (original)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/SCXMLListener.java Sat Aug 20 20:24:20 2005
@@ -1,6 +1,6 @@
 /*
- *    
- *   Copyright 2004 The Apache Software Foundation.
+ *
+ *   Copyright 2005 The Apache Software Foundation.
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -22,32 +22,33 @@
 
 /**
  * Listener interface for Observable entities in the SCXML model.
- * 
+ *
  */
 public interface SCXMLListener {
-    
+
     /**
-     * Handle the entry into a TransitionTarget
-     * 
+     * Handle the entry into a TransitionTarget.
+     *
      * @param state The TransitionTarget entered
      */
-    public void onEntry(TransitionTarget state);
+    void onEntry(TransitionTarget state);
 
     /**
-     * Handle the exit out of a TransitionTarget
-     * 
+     * Handle the exit out of a TransitionTarget.
+     *
      * @param state The TransitionTarget exited
      */
-    public void onExit(TransitionTarget state);
+    void onExit(TransitionTarget state);
 
     /**
-     * Handle the transition
-     * 
+     * Handle the transition.
+     *
      * @param from The source TransitionTarget
      * @param to The destination TransitionTarget
      * @param transition The Transition taken
      */
-    public void onTransition(TransitionTarget from, TransitionTarget to,
+    void onTransition(TransitionTarget from, TransitionTarget to,
             Transition transition);
 
 }
+

Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/SCXMLSemantics.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/SCXMLSemantics.java?rev=234141&r1=234140&r2=234141&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/SCXMLSemantics.java (original)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/SCXMLSemantics.java Sat Aug 20 20:24:20 2005
@@ -1,6 +1,6 @@
 /*
- *    
- *   Copyright 2004 The Apache Software Foundation.
+ *
+ *   Copyright 2005 The Apache Software Foundation.
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -68,19 +68,23 @@
  * the SCXMLExecutor and make it therefore pluggable. Semantics agnostic utility
  * functions and common operators as defined in UML can be found in the
  * SCXMLHelper or attached directly to the SCXML model elements.
- * 
+ *
  * Specific semantics can be created by subclassing SCXMLSemantics, the current
  * implementation aligns mostly with W3C SCXML July 5 public draft (that is,
  * UML 1.5) however, certain aspects are taken from STATEMATE.
- * 
- * 
- *  
+ *
  */
 public class SCXMLSemantics {
 
+    /**
+     * SCXML Logger for the application.
+     */
     protected static org.apache.commons.logging.Log appLog = LogFactory
             .getLog("scxml.app.log");
 
+    /**
+     * The TransitionTarget comparator.
+     */
     protected TransitionTargetComparator ttc = new TransitionTargetComparator();
 
     /**
@@ -90,7 +94,8 @@
      * @param errRep
      *            ErrorReporter callback
      */
-    public SCXML normalizeStateMachine(SCXML input, ErrorReporter errRep) {
+    public SCXML normalizeStateMachine(final SCXML input,
+            final ErrorReporter errRep) {
         //it is a no-op for now
         return input;
     }
@@ -107,8 +112,9 @@
      * @throws ModelException
      *             in case there is a fatal SCXML object model problem.
      */
-    public void determineInitialStates(SCXML input, Set states, List entryList,
-            ErrorReporter errRep) throws ModelException {
+    public void determineInitialStates(final SCXML input, final Set states,
+            final List entryList, final ErrorReporter errRep)
+            throws ModelException {
         State tmp = input.getInitialState();
         if (tmp == null) {
             errRep.onError(ErrorReporter.NO_INITIAL,
@@ -119,7 +125,7 @@
             //set of ALL entered states (even if initialState is a jump-over)
             Set onEntry = SCXMLHelper.getAncestorClosure(states, null);
             // sort onEntry according state hierarchy
-            Object oen[] = onEntry.toArray();
+            Object[] oen = onEntry.toArray();
             onEntry.clear();
             Arrays.sort(oen, getTTComparator());
             // we need to impose reverse order for the onEntry list
@@ -137,23 +143,28 @@
      *            collection of internal events generated by the actions [out]
      * @param exec
      *            execution environment [inout]
+     * @param errRep
+     *            ErrorReporter callback [inout]
      * @throws ModelException
-     *             in case there is a fatal SCXML object model problem.
+     *             in case there is a fatal SCXML object model problem
      * @throws SCXMLExpressionException
+     *             in case there is an problem evaluating an expression
+     *             within the SCXML document
      * @see ErrorReporter
      * @see NotificationRegistry
      * @see EventDispatcher
      * @see Context
      * @see Evaluator
      */
-    public void executeActionList(List actions, Collection derivedEvents,
-            SCXMLExecutor exec, ErrorReporter errRep) throws ModelException,
-            SCXMLExpressionException {
+    public void executeActionList(final List actions,
+            final Collection derivedEvents, final SCXMLExecutor exec,
+            final ErrorReporter errRep)
+            throws ModelException, SCXMLExpressionException {
         // NOTE: "if" statement is a container - we may need to call this method
         // recursively and pass a sub-list of actions embedded in a particular
         // "if"
         Evaluator eval = exec.getEvaluator();
-        for (Iterator i = actions.iterator(); i.hasNext(); ) {
+        for (Iterator i = actions.iterator(); i.hasNext();) {
             Action a = (Action) i.next();
             State parentState = a.getParentState();
             Context ctx = parentState.getContext();
@@ -176,10 +187,12 @@
                 Cancel cncl = (Cancel) a;
                 exec.getEventdispatcher().cancel(cncl.getSendId());
             } else if (a instanceof Exit) {
-                // Ignore; Exit instance holds other information that might 
-                // be needed, and is not transformed at parse time. 
-                //throw new ModelException("The <exit/> tag must be transformed"
-                //        + " to an anonymous final state at the parse time!");
+                // Ignore; Exit instance holds other information that might
+                // be needed, and is not transformed at parse time.
+                //throw new ModelException("The <exit/> tag must be "
+                //    + "transformed to an anonymous final state at "
+                //    + "the parse time!");
+                continue; //for checkstyle
             } else if (a instanceof If) {
                 //determine elseif/else separators evaluate conditions
                 //extract a sub-list of If's actions and invoke
@@ -188,9 +201,10 @@
                 If ifo = (If) a;
                 List subAct = ifo.getActions();
                 boolean cnd = eval.evalCond(ctx, ifo.getCond()).booleanValue();
-                for (Iterator ifiter = subAct.iterator(); ifiter.hasNext(); ) {
+                for (Iterator ifiter = subAct.iterator(); ifiter.hasNext();) {
                     Action aa = (Action) ifiter.next();
-                    if (cnd && !(aa instanceof ElseIf) && !(aa instanceof Else)) {
+                    if (cnd && !(aa instanceof ElseIf)
+                            && !(aa instanceof Else)) {
                         todoList.add(aa);
                     } else if (cnd
                             && (aa instanceof ElseIf || aa instanceof Else)) {
@@ -202,6 +216,7 @@
                         cnd = true;
                     } else {
                         //skip
+                        continue; //for checkstyle
                     }
                 }
                 if (!todoList.isEmpty()) {
@@ -220,7 +235,8 @@
                 }
                 Map params = null;
                 if (!SCXMLHelper.isStringEmpty(snd.getNamelist())) {
-                    StringTokenizer tkn = new StringTokenizer(snd.getNamelist());
+                    StringTokenizer tkn = new StringTokenizer(snd.
+                        getNamelist());
                     params = new HashMap(tkn.countTokens());
                     while (tkn.hasMoreTokens()) {
                         String varName = tkn.nextToken();
@@ -253,10 +269,10 @@
 
     /**
      * Exectutes all OnExit/Transition/OnEntry transitional actions.
-     * 
+     *
      * @param step
-     *            [inout] provides EntryList, TransitList, ExitList gets updated
-     *            its AfterStatus/Events
+     *            [inout] provides EntryList, TransitList, ExitList gets
+     *            updated its AfterStatus/Events
      * @param exec
      *            [inout] execution environment - SCXMLExecutor instance
      * @param errRep
@@ -264,17 +280,18 @@
      * @throws ModelException
      *             in case there is a fatal SCXML object model problem.
      */
-    public void executeActions(Step step, SCXMLExecutor exec,
-            ErrorReporter errRep) throws ModelException {
+    public void executeActions(final Step step, final SCXMLExecutor exec,
+            final ErrorReporter errRep) throws ModelException {
         SCXML sm = exec.getStateMachine();
         NotificationRegistry nr = sm.getNotificationRegistry();
         Collection internalEvents = step.getAfterStatus().getEvents();
         // ExecutePhaseActions / OnExit
-        for (Iterator i = step.getExitList().iterator(); i.hasNext(); ) {
+        for (Iterator i = step.getExitList().iterator(); i.hasNext();) {
             TransitionTarget tt = (TransitionTarget) i.next();
             OnExit oe = tt.getOnExit();
             try {
-                executeActionList(oe.getActions(), internalEvents, exec, errRep);
+                executeActionList(oe.getActions(), internalEvents, exec,
+                    errRep);
             } catch (SCXMLExpressionException e) {
                 errRep.onError(ErrorReporter.EXPRESSION_ERROR, e.getMessage(),
                         oe);
@@ -286,10 +303,11 @@
             internalEvents.add(te);
         }
         // ExecutePhaseActions / Transitions
-        for (Iterator i = step.getTransitList().iterator(); i.hasNext(); ) {
+        for (Iterator i = step.getTransitList().iterator(); i.hasNext();) {
             Transition t = (Transition) i.next();
             try {
-                executeActionList(t.getActions(), internalEvents, exec, errRep);
+                executeActionList(t.getActions(), internalEvents, exec,
+                    errRep);
             } catch (SCXMLExpressionException e) {
                 errRep.onError(ErrorReporter.EXPRESSION_ERROR, e.getMessage(),
                         t);
@@ -298,11 +316,12 @@
             nr.fireOnTransition(sm, t.getParent(), t.getRuntimeTarget(), t);
         }
         // ExecutePhaseActions / OnEntry
-        for (Iterator i = step.getEntryList().iterator(); i.hasNext(); ) {
+        for (Iterator i = step.getEntryList().iterator(); i.hasNext();) {
             TransitionTarget tt = (TransitionTarget) i.next();
             OnEntry oe = tt.getOnEntry();
             try {
-                executeActionList(oe.getActions(), internalEvents, exec, errRep);
+                executeActionList(oe.getActions(), internalEvents, exec,
+                    errRep);
             } catch (SCXMLExpressionException e) {
                 errRep.onError(ErrorReporter.EXPRESSION_ERROR, e.getMessage(),
                         oe);
@@ -314,10 +333,13 @@
             internalEvents.add(te);
             //3.2.1 and 3.4 (.done events)
             if (tt instanceof State) {
-                State ts = (State)tt;
+                State ts = (State) tt;
                 if (ts.getIsFinal()) {
-                    State parent = (State)ts.getParent();
-                    String prefix = (parent == null) ? "" : parent.getId();
+                    State parent = (State) ts.getParent();
+                    String prefix = "";
+                    if (parent != null) {
+                        prefix = parent.getId();
+                    }
                     te = new TriggerEvent(prefix + ".done",
                             TriggerEvent.CHANGE_EVENT);
                     internalEvents.add(te);
@@ -327,22 +349,22 @@
                     if (parent != null && parent.isRegion()) {
                         //3.4 we got a region, which is finalized
                         //let's check its siblings too
-                        Parallel p = (Parallel)parent.getParent();
+                        Parallel p = (Parallel) parent.getParent();
                         int finCount = 0;
                         int pCount = p.getStates().size();
-                        Iterator regions = p.getStates().iterator();
-                        while(regions.hasNext()) {
-                            State reg = (State)regions.next();
-                            if(reg.isDone()) {
+                        for (Iterator regions = p.getStates().iterator();
+                                regions.hasNext();) {
+                            State reg = (State) regions.next();
+                            if (reg.isDone()) {
                                 finCount++;
                             }
                         }
-                        if(finCount == pCount) {
+                        if (finCount == pCount) {
                             te = new TriggerEvent(p.getId() + ".done",
                                         TriggerEvent.CHANGE_EVENT);
                             internalEvents.add(te);
-                            te = new TriggerEvent(p.getParent().getId() + ".done",
-                                    TriggerEvent.CHANGE_EVENT);
+                            te = new TriggerEvent(p.getParent().getId()
+                                + ".done", TriggerEvent.CHANGE_EVENT);
                             internalEvents.add(te);
                             //this is not in the specs, but is makes sense
                             p.getParentState().setDone(true);
@@ -362,8 +384,8 @@
      * @param errRep
      *            ErrorReporter callback [inout]
      */
-    public void enumerateReachableTransitions(SCXML stateMachine, Step step,
-            ErrorReporter errRep) {
+    public void enumerateReachableTransitions(final SCXML stateMachine,
+            final Step step, final ErrorReporter errRep) {
         // prevents adding the same transition multiple times
         Set transSet = new HashSet();
         // prevents visiting the same state multiple times
@@ -372,7 +394,8 @@
         LinkedList todoList = new LinkedList(stateSet);
         while (!todoList.isEmpty()) {
             State st = (State) todoList.removeFirst();
-            for (Iterator i = st.getTransitionsList().iterator(); i.hasNext(); ) {
+            for (Iterator i = st.getTransitionsList().iterator();
+                    i.hasNext();) {
                 Transition t = (Transition) i.next();
                 if (!transSet.contains(t)) {
                     transSet.add(t);
@@ -398,31 +421,34 @@
      * @param errRep
      *            ErrorReporter callback [inout]
      */
-    public void filterTransitionsSet(Step step, Evaluator evaluator,
-            ErrorReporter errRep) {
+    public void filterTransitionsSet(final Step step,
+            final Evaluator evaluator, final ErrorReporter errRep) {
         /*
-         * - filter transition set by applying events (step/beforeStatus/events +
-         * step/externalEvents) (local check) - evaluating guard conditions for
-         * each transition (local check) - transition precedence (bottom-up) as
-         * defined by SCXML specs
+         * - filter transition set by applying events
+         * (step/beforeStatus/events + step/externalEvents) (local check)
+         * - evaluating guard conditions for
+         * each transition (local check) - transition precedence (bottom-up)
+         * as defined by SCXML specs
          */
         Set allEvents = new HashSet(step.getBeforeStatus().getEvents()
                 .size()
                 + step.getExternalEvents().size());
         //for now, we only match against event names
         for (Iterator ei = step.getBeforeStatus().getEvents().iterator();
-                ei.hasNext(); ) {
+                ei.hasNext();) {
             TriggerEvent te = (TriggerEvent) ei.next();
             allEvents.add(te.getName());
         }
-        for (Iterator ei = step.getExternalEvents().iterator(); ei.hasNext(); ) {
+        for (Iterator ei = step.getExternalEvents().iterator();
+                ei.hasNext();) {
             TriggerEvent te = (TriggerEvent) ei.next();
             allEvents.add(te.getName());
         }
         //remove list (filtered-out list)
         List removeList = new LinkedList();
         //iterate over non-filtered transition set
-        for (Iterator iter = step.getTransitList().iterator(); iter.hasNext();) {
+        for (Iterator iter = step.getTransitList().iterator();
+                iter.hasNext();) {
             Transition t = (Transition) iter.next();
             // event check
             String event = t.getEvent();
@@ -446,7 +472,7 @@
                             .getMessage(), t);
                 }
             }
-            if (rslt.booleanValue() == false) {
+            if (!rslt.booleanValue()) {
                 // guard condition has not passed
                 removeList.add(t);
             }
@@ -460,7 +486,7 @@
         // only if there are multiple enabled transitions
         if (step.getTransitList().size() > 1) {
             // global transition precedence check
-            Object trans[] = step.getTransitList().toArray();
+            Object[] trans = step.getTransitList().toArray();
             Set currentStates = step.getBeforeStatus().getStates();
             // non-determinism candidates
             Set nonDeterm = new HashSet();
@@ -493,7 +519,7 @@
             nonDeterm.removeAll(removeList);
             if (nonDeterm.size() > 0) {
                 errRep.onError(ErrorReporter.NON_DETERMINISTIC,
-                        "Multiple conflicting transitions enabled.", nonDeterm);
+                    "Multiple conflicting transitions enabled.", nonDeterm);
             }
             // apply global transition filter
             step.getTransitList().removeAll(removeList);
@@ -508,20 +534,21 @@
      * @param errRep
      *            ErrorReporter callback [inout]
      */
-    public void seedTargetSet(Step step, ErrorReporter errRep) {
+    public void seedTargetSet(final Step step, final ErrorReporter errRep) {
         Set sources = step.getBeforeStatus().getStates();
         Set targets = step.getAfterStatus().getStates();
         List transitions = step.getTransitList();
         /* populate the target set by taking targets of selected transitions */
-        for (Iterator i = transitions.iterator(); i.hasNext(); ) {
+        for (Iterator i = transitions.iterator(); i.hasNext();) {
             Transition t = (Transition) i.next();
             targets.add(t.getRuntimeTarget());
         }
-        /* retain the source states, which are not affected by the transitions */
-        for (Iterator i = sources.iterator(); i.hasNext(); ) {
+        /* retain the source states, which are not affected by the
+           transitions */
+        for (Iterator i = sources.iterator(); i.hasNext();) {
             State s = (State) i.next();
             boolean retain = true;
-            for (Iterator j = transitions.iterator(); j.hasNext(); ) {
+            for (Iterator j = transitions.iterator(); j.hasNext();) {
                 Transition t = (Transition) j.next();
                 State ts = (State) t.getParent();
                 if (s == ts || SCXMLHelper.isDescendant(s, ts)) {
@@ -540,10 +567,11 @@
      *            a set seeded in previous step [inout]
      * @param errRep
      *            ErrorReporter callback [inout]
+     * @throws ModelException On illegal configuration
      * @see #seedTargetSet(Step, ErrorReporter)
      */
-    public void determineTargetStates(Set states, ErrorReporter errRep)
-            throws ModelException {
+    public void determineTargetStates(final Set states,
+            final ErrorReporter errRep) throws ModelException {
         LinkedList wrkSet = new LinkedList(states);
         // clear the seed-set - will be populated by leaf states
         states.clear();
@@ -569,7 +597,8 @@
                     // or History
                     TransitionTarget init = ini.getTransition().getTarget();
                     if (init == null
-                        || !(init instanceof State || init instanceof History)) {
+                        ||
+                        !(init instanceof State || init instanceof History)) {
                         errRep.onError(ErrorReporter.ILLEGAL_INITIAL,
                             "Initial does not point to a State or a History!",
                             st);
@@ -607,7 +636,8 @@
      * @param errRep
      *            ErrorReporter callback [inout]
      */
-    public void buildOnExitOnEntryLists(Step step, ErrorReporter errRep) {
+    public void buildOnExitOnEntryLists(final Step step,
+            final ErrorReporter errRep) {
         //set of exited states
         Set onExit = SCXMLHelper.getAncestorClosure(step.getBeforeStatus()
                 .getStates(), null);
@@ -619,7 +649,7 @@
         onExit.removeAll(onEntry);
         onEntry.removeAll(onExit2);
         //explicitly add self-transitions
-        for (Iterator i = step.getTransitList().iterator(); i.hasNext(); ) {
+        for (Iterator i = step.getTransitList().iterator(); i.hasNext();) {
             Transition t = (Transition) i.next();
             if (t.getParent() == t.getTarget()) {
                 onExit.add(t.getParent());
@@ -627,9 +657,9 @@
             }
         }
         // sort onEntry and onExit according state hierarchy
-        Object oex[] = onExit.toArray();
+        Object[] oex = onExit.toArray();
         onExit.clear();
-        Object oen[] = onEntry.toArray();
+        Object[] oen = onEntry.toArray();
         onEntry.clear();
         Arrays.sort(oex, getTTComparator());
         Arrays.sort(oen, getTTComparator());
@@ -639,25 +669,26 @@
         Collections.reverse(entering);
         step.getEntryList().addAll(entering);
         // reset 'done' flag
-        for (Iterator reset = entering.iterator(); reset.hasNext(); ) {
+        for (Iterator reset = entering.iterator(); reset.hasNext();) {
             Object o = reset.next();
-            if(o instanceof State) {
-                ((State)o).setDone(false);
+            if (o instanceof State) {
+                ((State) o).setDone(false);
             }
         }
     }
 
     /**
      * Go over the exit list and update history information for relevant states.
-     * 
+     *
      * @param step
      *            [inout]
      * @param errRep
      *            ErrorReporter callback [inout]
      */
-    public void updateHistoryStates(Step step, ErrorReporter errRep) {
+    public void updateHistoryStates(final Step step,
+            final ErrorReporter errRep) {
         Set oldState = step.getBeforeStatus().getStates();
-        for (Iterator i = step.getExitList().iterator(); i.hasNext(); ) {
+        for (Iterator i = step.getExitList().iterator(); i.hasNext();) {
             Object o = i.next();
             if (o instanceof State) {
                 State s = (State) o;
@@ -700,17 +731,18 @@
     }
 
     /**
-     * Implements prefix match, that is, if, for example, 
+     * Implements prefix match, that is, if, for example,
      * &quot;mouse.click&quot; is a member of eventOccurrences and a
      * transition is triggered by &quot;mouse&quot;, the method returns true.
-     * 
+     *
      * @param transEvent
      *            a trigger event of a transition
      * @param eventOccurrences
      *            current events
      * @return true/false
      */
-    public boolean eventMatch(String transEvent, Set eventOccurrences) {
+    public boolean eventMatch(final String transEvent,
+            final Set eventOccurrences) {
         if (SCXMLHelper.isStringEmpty(transEvent)) {
             return true;
         } else {
@@ -726,12 +758,14 @@
             return false;
         }
     }
-    
+
     /**
-     *  TransitionTargetComparator factory method 
+     * TransitionTargetComparator factory method.
+     * @return Comparator The TransitionTarget comparator
      */
     final Comparator getTTComparator() {
         return ttc;
     }
 
 }
+

Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/Status.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/Status.java?rev=234141&r1=234140&r2=234141&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/Status.java (original)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/Status.java Sat Aug 20 20:24:20 2005
@@ -1,6 +1,6 @@
 /*
- *    
- *   Copyright 2004 The Apache Software Foundation.
+ *
+ *   Copyright 2005 The Apache Software Foundation.
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -27,10 +27,10 @@
 
 /**
  * The encapsulation of the current state of a state machine.
- * 
+ *
  */
 public class Status {
-    
+
     /**
      * The states that are currently active.
      */
@@ -43,22 +43,22 @@
 
     /**
      * Have we reached a final configuration for this state machine.
-     * 
-     * True - if all the states are final and there are not events 
+     *
+     * True - if all the states are final and there are not events
      * pending from the last step. False - otherwise.
-     * 
+     *
      * @return Whether a final configuration has been reached.
      */
     public boolean isFinal() {
         boolean rslt = true;
-        for (Iterator i = states.iterator(); i.hasNext(); ) {
-            State s = (State)i.next();
+        for (Iterator i = states.iterator(); i.hasNext();) {
+            State s = (State) i.next();
             if (!s.getIsFinal()) {
                 rslt = false;
                 break;
             }
             //the status is final only iff these are top-level states
-            if(s.getParent() != null) {
+            if (s.getParent() != null) {
                 rslt = false;
                 break;
             }
@@ -70,7 +70,7 @@
     }
 
     /**
-     * Constructor
+     * Constructor.
      */
     public Status() {
         states = new HashSet();
@@ -79,7 +79,7 @@
 
     /**
      * Get the states configuration (leaf only).
-     * 
+     *
      * @return Returns the states configuration - simple (leaf) states only.
      */
     public Set getStates() {
@@ -88,7 +88,7 @@
 
     /**
      * Get the events that are currently queued.
-     * 
+     *
      * @return The events that are currently queued.
      */
     public Collection getEvents() {
@@ -96,13 +96,14 @@
     }
 
     /**
-     * Get the complete states configuration
-     * 
+     * Get the complete states configuration.
+     *
      * @return complete states configuration including simple states and their
      *         complex ancestors up to the root.
      */
     public Set getAllStates() {
         return SCXMLHelper.getAncestorClosure(states, null);
     }
-    
+
 }
+

Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/Step.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/Step.java?rev=234141&r1=234140&r2=234141&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/Step.java (original)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/Step.java Sat Aug 20 20:24:20 2005
@@ -1,6 +1,6 @@
 /*
- *    
- *   Copyright 2004 The Apache Software Foundation.
+ *
+ *   Copyright 2005 The Apache Software Foundation.
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -23,12 +23,12 @@
 
 /**
  * A logical unit of progression in the execution of a SCXML model.
- * 
+ *
  */
 class Step {
-    
+
     /**
-     * Constructor
+     * Constructor.
       */
     public Step() {
         this.externalEvents = new ArrayList();
@@ -38,19 +38,19 @@
         this.entryList = new ArrayList();
         this.transitList = new ArrayList();
     }
-    
+
     /**
-     * @param externalEvents The external events received in this 
+     * @param externalEvents The external events received in this
      *     unit of progression
      * @param beforeStatus The before status
      */
-    public Step(Collection externalEvents, Status beforeStatus) {
-        if(externalEvents != null) {
+    public Step(final Collection externalEvents, final Status beforeStatus) {
+        if (externalEvents != null) {
             this.externalEvents = externalEvents;
         } else {
             this.externalEvents = new ArrayList();
         }
-        if(beforeStatus != null) {
+        if (beforeStatus != null) {
             this.beforeStatus = beforeStatus;
         } else {
             this.beforeStatus = new Status();
@@ -60,91 +60,92 @@
         this.entryList = new ArrayList();
         this.transitList = new ArrayList();
     }
-    
+
     /**
-     * The external events in this step
+     * The external events in this step.
      */
     private Collection externalEvents;
 
     /**
-     * The status before this step
+     * The status before this step.
      */
     private Status beforeStatus;
 
     /**
-     * The status after this step
+     * The status after this step.
      */
     private Status afterStatus;
 
     /**
-     * The list of TransitionTargets that were exited during this step
+     * The list of TransitionTargets that were exited during this step.
      */
     private List exitList;
 
     /**
-     * The list of TransitionTargets that were entered during this step
+     * The list of TransitionTargets that were entered during this step.
      */
     private List entryList;
 
     /**
-     * The list of Transitions taken during this step
+     * The list of Transitions taken during this step.
      */
     private List transitList;
-    
+
     /**
      * @return Returns the afterStatus.
      */
     public Status getAfterStatus() {
         return afterStatus;
     }
-    
+
     /**
      * @param afterStatus The afterStatus to set.
      */
-    public void setAfterStatus(Status afterStatus) {
+    public void setAfterStatus(final Status afterStatus) {
         this.afterStatus = afterStatus;
     }
-    
+
     /**
      * @return Returns the beforeStatus.
      */
     public Status getBeforeStatus() {
         return beforeStatus;
     }
-    
+
     /**
      * @param beforeStatus The beforeStatus to set.
      */
-    public void setBeforeStatus(Status beforeStatus) {
+    public void setBeforeStatus(final Status beforeStatus) {
         this.beforeStatus = beforeStatus;
     }
-    
+
     /**
      * @return Returns the entryList.
      */
     public List getEntryList() {
         return entryList;
     }
-    
+
     /**
      * @return Returns the exitList.
      */
     public List getExitList() {
         return exitList;
     }
-    
+
     /**
      * @return Returns the externalEvents.
      */
     public Collection getExternalEvents() {
         return externalEvents;
     }
-    
+
     /**
      * @return Returns the transitList.
      */
     public List getTransitList() {
         return transitList;
-    }    
+    }
 
 }
+

Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/TransitionTargetComparator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/TransitionTargetComparator.java?rev=234141&r1=234140&r2=234141&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/TransitionTargetComparator.java (original)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/TransitionTargetComparator.java Sat Aug 20 20:24:20 2005
@@ -1,6 +1,6 @@
 /*
- *    
- *   Copyright 2004 The Apache Software Foundation.
+ *
+ *   Copyright 2005 The Apache Software Foundation.
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -23,37 +23,40 @@
 
 
 /**
- * A comparator for TransitionTarget instances
- * 
+ * A comparator for TransitionTarget instances.
+ *
  */
-class TransitionTargetComparator implements Comparator {
+final class TransitionTargetComparator implements Comparator {
 
     /**
-     * Constructor
+     * Constructor.
      */
     TransitionTargetComparator() {
         super();
     }
 
     /**
-     * Compares two instances of TransitionTarget in terms of the SCXML tree hierarchy.
-     * <p>Important Remarks:</p> does not fullfill the Comparator contract, since
-     * it returns 0 if o1 == o2 and also if they are not related to each other
-     * and at the same time the chain-to-parent length for o1 is the same length 
-     * as for o2 (that is, they are equally deeply nested)
+     * Compares two instances of TransitionTarget in terms of the
+     * SCXML tree hierarchy.
+     * <p>Important Remarks:</p> does not fullfill the Comparator contract,
+     * since it returns 0 if o1 == o2 and also if they are not related to each
+     * other and at the same time the chain-to-parent length for o1 is the
+     * same length as for o2 (that is, they are equally deeply nested)
+     *
+     * @param o1 The first TransitionTarget object
+     * @param o2 The second TransitionTarget object
+     * @return int The comparation result
      * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
-     * @throws ClassCastException 
-     *             if any of the parameters is not a TransitionTarget intance.
      * @see TransitionTarget
      */
-    public final int compare(Object o1, Object o2) {
-        TransitionTarget tt1 = (TransitionTarget)o1;
-        TransitionTarget tt2 = (TransitionTarget)o2;
-        if(tt1 == tt2) {
+    public int compare(final Object o1, final Object o2) {
+        TransitionTarget tt1 = (TransitionTarget) o1;
+        TransitionTarget tt2 = (TransitionTarget) o2;
+        if (tt1 == tt2) {
             return 0;
-        } else if(SCXMLHelper.isDescendant(tt1, tt2)) {
+        } else if (SCXMLHelper.isDescendant(tt1, tt2)) {
             return -1;
-        } else if(SCXMLHelper.isDescendant(tt2, tt1)) {
+        } else if (SCXMLHelper.isDescendant(tt2, tt1)) {
             return 1;
         } else {
             //the tt1 and tt2 are parallel, now we have to count chain sizes
@@ -63,12 +66,22 @@
             return tc2 - tc1;
         }
     }
-    
-    private final int countChainLength(TransitionTarget tt) {
+
+    /**
+     * The &quot;depth&quot; at which this TransitionTarget exists in the
+     * SCXML object model.
+     *
+     * @param tt The TransitionTarget
+     * @return int The &quot;depth&quot;
+     */
+    private int countChainLength(final TransitionTarget tt) {
         int count = 0;
-        while((tt = tt.getParent()) != null) {
+        TransitionTarget parent = tt.getParent();
+        while (parent != null) {
             count++;
+            parent = parent.getParent();
         }
         return count;
     }
-}
\ No newline at end of file
+}
+

Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/TriggerEvent.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/TriggerEvent.java?rev=234141&r1=234140&r2=234141&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/TriggerEvent.java (original)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/TriggerEvent.java Sat Aug 20 20:24:20 2005
@@ -1,6 +1,6 @@
 /*
- *    
- *   Copyright 2004 The Apache Software Foundation.
+ *
+ *   Copyright 2005 The Apache Software Foundation.
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -20,18 +20,19 @@
 /**
  * A class representing an event. Specific event types have been
  * defined in reference to SCXML.
- * 
+ *
  */
 public class TriggerEvent {
-    
+
     /**
-     * Constructor
-     * 
+     * Constructor.
+     *
      * @param name The event name
      * @param type The event type
      * @param payload The event payload
      */
-    public TriggerEvent(String name, int type, Object payload) {
+    public TriggerEvent(final String name, final int type,
+            final Object payload) {
         super();
         this.name = name;
         this.type = type;
@@ -39,53 +40,53 @@
     }
 
     /**
-     * Constructor
-     * 
+     * Constructor.
+     *
      * @param name The event name
      * @param type The event type
      */
-    public TriggerEvent(String name, int type) {
+    public TriggerEvent(final String name, final int type) {
         this(name, type, null);
     }
 
     /**
-     * <code>CALL_EVENT</code>
+     * <code>CALL_EVENT</code>.
      */
     public static final int CALL_EVENT = 1;
 
     /**
-     * <code>CHANGE_EVENT</code>
-     * 
+     * <code>CHANGE_EVENT</code>.
+     *
      */
     public static final int CHANGE_EVENT = 2;
 
     /**
-     * <code>SIGNAL_EVENT</code>
-     * 
+     * <code>SIGNAL_EVENT</code>.
+     *
      */
     public static final int SIGNAL_EVENT = 3;
 
     /**
-     * <code>TIME_EVENT</code>
-     * 
+     * <code>TIME_EVENT</code>.
+     *
      */
     public static final int TIME_EVENT = 4;
 
     /**
-     * The event name
-     * 
+     * The event name.
+     *
      */
     private String name;
 
     /**
-     * The event type
-     * 
+     * The event type.
+     *
      */
     private int type;
 
     /**
-     * The event payload
-     * 
+     * The event payload.
+     *
      */
     private Object payload;
 
@@ -111,23 +112,22 @@
     }
 
     /**
-     * Define an equals operator for TriggerEvent
-     * 
+     * Define an equals operator for TriggerEvent.
+     *
      * @see java.lang.Object#equals(java.lang.Object)
      */
-    public boolean equals(Object obj) {
+    public boolean equals(final Object obj) {
         if (obj instanceof TriggerEvent) {
             TriggerEvent te2 = (TriggerEvent) obj;
             if (type == te2.type && name.equals(te2.name)
-                && ((payload == null && te2.payload == null) 
+                && ((payload == null && te2.payload == null)
                      || (payload != null && payload.equals(te2.payload)))) {
                 return true;
-            } else {
-                return false;
             }
-        } else {
             return false;
         }
+        return false;
     }
-    
+
 }
+

Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/ELContext.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/ELContext.java?rev=234141&r1=234140&r2=234141&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/ELContext.java (original)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/ELContext.java Sat Aug 20 20:24:20 2005
@@ -1,6 +1,6 @@
 /*
- *    
- *   Copyright 2004 The Apache Software Foundation.
+ *
+ *   Copyright 2005 The Apache Software Foundation.
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
 
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Map;
 
 import javax.servlet.jsp.el.ELException;
 import javax.servlet.jsp.el.VariableResolver;
@@ -27,20 +28,21 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.commons.scxml.Context;
 
-/** 
+/**
  * EL Context for SCXML interpreter.
- * 
+ *
  */
 public class ELContext implements Context , VariableResolver {
-    
-    //let's make the log category implementation independent
+
+    /** Implementation independent log category. */
     protected static Log log = LogFactory.getLog(Context.class);
-    
+    /** The parent Context to this Context. */
     protected Context parent = null;
-    protected HashMap vars = new HashMap();
-    
+    /** The Map of variables and their values in this Context. */
+    protected Map vars = new HashMap();
+
     /**
-     * Constructor
+     * Constructor.
      *
      */
     public ELContext() {
@@ -48,23 +50,27 @@
     }
 
     /**
-     * @param parent a parent ELContext, can be null 
+     * Constructor.
+     *
+     * @param parent a parent ELContext, can be null
      */
-    public ELContext(Context parent) {
+    public ELContext(final Context parent) {
         this.parent = parent;
     }
 
     /**
      * Assigns a new value to an existing variable or creates a new one.
-     * The method searches the chain of parent Contexts for variable 
+     * The method searches the chain of parent Contexts for variable
      * existence.
-     * 
-     * @see org.apache.commons.scxml.Context#set(java.lang.String, java.lang.Object)
+     *
+     * @param name The variable name
+     * @param value The variable value
+     * @see org.apache.commons.scxml.Context#set(String, Object)
      */
-    public void set(String name, Object value) {
-        if(vars.containsKey(name)) { //first try to override local
+    public void set(final String name, final Object value) {
+        if (vars.containsKey(name)) { //first try to override local
             setLocal(name, value);
-        } else if(parent != null && parent.has(name)) { //then check for global
+        } else if (parent != null && parent.has(name)) { //then check for global
             parent.set(name, value);
         } else { //otherwise create a new local variable
             setLocal(name, value);
@@ -72,14 +78,16 @@
     }
 
     /**
-     * Get the value of this variable; delegating to parent
-     * 
+     * Get the value of this variable; delegating to parent.
+     *
+     * @param name The variable name
+     * @return Object The variable value
      * @see org.apache.commons.scxml.Context#get(java.lang.String)
      */
-    public Object get(String name) {
-        if(vars.containsKey(name)) {
+    public Object get(final String name) {
+        if (vars.containsKey(name)) {
             return vars.get(name);
-        } else if(parent != null) {
+        } else if (parent != null) {
             return parent.get(name);
         } else {
             return null;
@@ -87,23 +95,25 @@
     }
 
     /**
-     * Check if this variable exists, delegating to parent
-     * 
+     * Check if this variable exists, delegating to parent.
+     *
+     * @param name The variable name
+     * @return boolean true if this variable exists
      * @see org.apache.commons.scxml.Context#has(java.lang.String)
      */
-    public boolean has(String name) {
-        if(vars.containsKey(name)) {
+    public boolean has(final String name) {
+        if (vars.containsKey(name)) {
             return true;
-        } else if(parent != null && parent.has(name)) {
+        } else if (parent != null && parent.has(name)) {
             return true;
-        } else {
-            return false;
         }
+        return false;
     }
 
     /**
-     * Get an Iterator over all variables in this Context
-     * 
+     * Get an Iterator over all variables in this Context.
+     *
+     * @return Iterator The Iterator over all variables in this Context
      * @see org.apache.commons.scxml.Context#iterator()
      */
     public Iterator iterator() {
@@ -111,8 +121,8 @@
     }
 
     /**
-     * Clear this Context
-     * 
+     * Clear this Context.
+     *
      * @see org.apache.commons.scxml.Context#reset()
      */
     public void reset() {
@@ -120,8 +130,9 @@
     }
 
     /**
-     * Get the parent Context, may be null
-     * 
+     * Get the parent Context, may be null.
+     *
+     * @return Context The parent Context
      * @see org.apache.commons.scxml.Context#getParent()
      */
     public Context getParent() {
@@ -130,26 +141,33 @@
 
     /**
      * Assigns a new value to an existing variable or creates a new one.
-     * The method allows to shaddow a variable of the same name up the 
+     * The method allows to shaddow a variable of the same name up the
      * Context chain.
-     * 
-     * @see org.apache.commons.scxml.Context#setLocal(java.lang.String, java.lang.Object)
+     *
+     * @param name The variable name
+     * @param value The variable value
+     * @see org.apache.commons.scxml.Context#setLocal(String, Object)
      */
-    public void setLocal(String name, Object value) {
+    public void setLocal(final String name, final Object value) {
         vars.put(name, value);
-        if(log.isDebugEnabled() && !name.equals("_ALL_STATES")) {
+        if (log.isDebugEnabled() && !name.equals("_ALL_STATES")) {
             log.debug(name + " = " + String.valueOf(value));
         }
     }
 
     /**
-     * Resolves the specified variable. Returns null if the variable is 
-     * not found. 
-     * 
-     * @see javax.servlet.jsp.el.VariableResolver#resolveVariable(java.lang.String)
+     * Resolves the specified variable. Returns null if the variable is
+     * not found.
+     *
+     * @param pName The variable to resolve
+     * @return Object The value of the variable, or null, if it does not
+     *                exist
+     * @throws ELException While resolving the variable
+     * @see javax.servlet.jsp.el.VariableResolver#resolveVariable(String)
      */
-    public Object resolveVariable(String pName) throws ELException {
+    public Object resolveVariable(final String pName) throws ELException {
         return get(pName);
     }
 
 }
+

Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/ELEvaluator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/ELEvaluator.java?rev=234141&r1=234140&r2=234141&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/ELEvaluator.java (original)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/ELEvaluator.java Sat Aug 20 20:24:20 2005
@@ -1,6 +1,6 @@
 /*
- *    
- *   Copyright 2004 The Apache Software Foundation.
+ *
+ *   Copyright 2005 The Apache Software Foundation.
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -37,64 +37,68 @@
 
 /**
  * EL engine interface for SCXML Interpreter.
- * 
+ *
  */
 public class ELEvaluator implements Evaluator {
 
-    //let's make the log category implementation independent
+    /** Implementation independent log category. */
     private static Log log = LogFactory.getLog(Evaluator.class);
+    /** Function Mapper for SCXML expressions. */
     private FunctionMapper fm = new FunctWrapper();
+    /** Pattern for recognizing the SCXML In() special predicate. */
     private static Pattern inFct = Pattern.compile("In\\(");
 
-    ExpressionEvaluator ee = null;
+    /** The expression evaluator implementation for the JSP/EL environment. */
+    private ExpressionEvaluator ee = null;
 
     /**
-     * Constructor
+     * Constructor.
      */
     public ELEvaluator() {
         ee = new ExpressionEvaluatorImpl();
     }
 
     /**
-     * Evaluate an expression
-     * 
+     * Evaluate an expression.
+     *
      * @param ctx variable context
      * @param expr expression
      * @return a result of the evaluation
-     * @throws SCXMLExpressionException
-     * @see org.apache.commons.scxml.Evaluator#eval(org.apache.commons.scxml.Context, java.lang.String)
+     * @throws SCXMLExpressionException For a malformed expression
+     * @see Evaluator#eval(Context, String)
      */
-    public Object eval(Context ctx, String expr) 
+    public Object eval(final Context ctx, final String expr)
     throws SCXMLExpressionException {
         VariableResolver vr = null;
-        if(ctx instanceof VariableResolver) {
-            vr = (VariableResolver)ctx;
+        if (ctx instanceof VariableResolver) {
+            vr = (VariableResolver) ctx;
         } else {
             vr = new CtxWrapper(ctx);
         }
         try {
-            expr = inFct.matcher(expr).replaceAll("In(_ALL_STATES, ");
-            Object rslt = ee.evaluate(expr, Object.class, vr, fm);
-            if(log.isTraceEnabled()) {
-                log.trace(expr + " = " + String.valueOf(rslt));                
+            String evalExpr = inFct.matcher(expr).
+                replaceAll("In(_ALL_STATES, ");
+            Object rslt = ee.evaluate(evalExpr, Object.class, vr, fm);
+            if (log.isTraceEnabled()) {
+                log.trace(expr + " = " + String.valueOf(rslt));
             }
-            return rslt; 
+            return rslt;
         } catch (ELException e) {
             throw new SCXMLExpressionException(e);
-        } 
+        }
     }
 
     /**
      * Create a new child context.
-     * 
+     *
      * @param parent parent context
      * @return new child context
-     * @see org.apache.commons.scxml.Evaluator#newContext(org.apache.commons.scxml.Context)
+     * @see Evaluator#newContext(Context)
      */
-    public Context newContext(Context parent) {
+    public Context newContext(final Context parent) {
         //for now, we do not support nested variable contexts
         //world is flat ;)
-        if(parent != null) {
+        if (parent != null) {
             return parent;
         } else {
             return new ELContext(null);
@@ -102,39 +106,47 @@
     }
 
     /**
-     * @see org.apache.commons.scxml.Evaluator#evalCond(org.apache.commons.scxml.Context, java.lang.String)
+     * @see Evaluator#evalCond(Context, String)
      */
-    public Boolean evalCond(Context ctx, String expr) 
+    public Boolean evalCond(final Context ctx, final String expr)
     throws SCXMLExpressionException {
         VariableResolver vr = null;
-        if(ctx instanceof VariableResolver) {
-            vr = (VariableResolver)ctx;
+        if (ctx instanceof VariableResolver) {
+            vr = (VariableResolver) ctx;
         } else {
             vr = new CtxWrapper(ctx);
         }
         try {
-            expr = inFct.matcher(expr).replaceAll("In(_ALL_STATES, ");
-            Boolean rslt = (Boolean) ee.evaluate(expr, Boolean.class, vr, fm);
-            if(log.isDebugEnabled()) {
-                log.debug(expr + " = " + String.valueOf(rslt));                
+            String evalExpr = inFct.matcher(expr).
+                replaceAll("In(_ALL_STATES, ");
+            Boolean rslt = (Boolean) ee.evaluate(evalExpr, Boolean.class,
+                vr, fm);
+            if (log.isDebugEnabled()) {
+                log.debug(expr + " = " + String.valueOf(rslt));
             }
             return rslt;
         } catch (ELException e) {
             throw new SCXMLExpressionException(e);
-        } 
+        }
     }
-    
+
     /**
-     * A Context wrapper that implements VariableResolver
+     * A Context wrapper that implements VariableResolver.
      */
     class CtxWrapper implements VariableResolver {
-        Context ctx = null;
-        CtxWrapper(Context ctx) {
+        /** Context to be wrapped. */
+        private Context ctx = null;
+        /**
+         * Constructor.
+         * @param ctx The Context to be wrapped.
+         */
+        CtxWrapper(final Context ctx) {
             this.ctx = ctx;
         }
-        public Object resolveVariable(String pName) throws ELException {
+        /** @see VariableResolver#resolveVariable(String) */
+        public Object resolveVariable(final String pName) throws ELException {
             Object rslt = ctx.get(pName);
-            if(rslt == null) {
+            if (rslt == null) {
                 throw new ELException("Variable " + pName + "does not exist!");
             }
             return rslt;
@@ -142,18 +154,17 @@
     }
 
     /**
-     * A simple function mapper for SCXML defined functions
+     * A simple function mapper for SCXML defined functions.
      */
     class FunctWrapper implements FunctionMapper {
 
         /**
-         * @see javax.servlet.jsp.el.FunctionMapper#resolveFunction(java.lang.String, java.lang.String)
+         * @see FunctionMapper#resolveFunction(String, String)
          */
-        public Method resolveFunction(String prefix, String localName) {
-            if(localName.equals("In")) {
-                Class attrs[] = new Class[2];
-                attrs[0] = Set.class;
-                attrs[1] = String.class;
+        public Method resolveFunction(final String prefix,
+                final String localName) {
+            if (localName.equals("In")) {
+                Class[] attrs = new Class[] {Set.class, String.class};
                 try {
                     return ELEvaluator.class.getMethod("isMember", attrs);
                 } catch (SecurityException e) {
@@ -161,7 +172,7 @@
                 } catch (NoSuchMethodException e) {
                     log.error("resolving isMember(Set, String)", e);
                 }
-            } 
+            }
             return null;
         }
     }
@@ -169,16 +180,16 @@
     /**
      * Does this state belong to the Set of these States.
      * Simple ID based comparator
-     * 
+     *
      * @param allStates The Set of State objects to look in
      * @param state The State to compare with
      * @return Whether this State belongs to this Set
      */
-    public static final boolean isMember(Set allStates, String state) {
-        Iterator i = allStates.iterator();
-        while(i.hasNext()) {
-            TransitionTarget tt = (TransitionTarget)i.next();
-            if(state.equals(tt.getId())) {
+    public static final boolean isMember(final Set allStates,
+            final String state) {
+        for (Iterator i = allStates.iterator(); i.hasNext();) {
+            TransitionTarget tt = (TransitionTarget) i.next();
+            if (state.equals(tt.getId())) {
                 return true;
             }
         }
@@ -186,3 +197,4 @@
     }
 
 }
+

Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/RootContext.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/RootContext.java?rev=234141&r1=234140&r2=234141&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/RootContext.java (original)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/RootContext.java Sat Aug 20 20:24:20 2005
@@ -1,6 +1,6 @@
 /*
- *    
- *   Copyright 2004 The Apache Software Foundation.
+ *
+ *   Copyright 2005 The Apache Software Foundation.
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -26,17 +26,18 @@
 /**
  * EL Context for root SCXML element. Wrapper around the host JSP context.
  * Must treat variables in the host JSP environments as read-only.
- * 
+ *
  */
 public final class RootContext extends ELContext {
-    
+
+    /** Host JSP's VariableResolver. */
     private VariableResolver vr;
     /**
-     * Constructor
-     *  
-     * @param ctx the host JspContext 
+     * Constructor.
+     *
+     * @param ctx the host JspContext
      */
-    public RootContext(JspContext ctx) {
+    public RootContext(final JspContext ctx) {
         super();
         if (ctx == null) {
             log.error("Host JSP Context cannot be null");
@@ -45,13 +46,14 @@
         this.vr = ctx.getVariableResolver();
     }
 
-    /** 
-     * Get the value of the given variable in this Context
-     * 
+    /**
+     * Get the value of the given variable in this Context.
+     *
+     * @param name The name of the variable
      * @return The value (or null)
      * @see org.apache.commons.scxml.Context#get(java.lang.String)
      */
-    public Object get(String name) {
+    public Object get(final String name) {
         Object value = super.get(name);
         if (value == null) {
             try {
@@ -63,9 +65,9 @@
         return value;
     }
 
-    /** 
-     * Get the Iterator
-     * 
+    /**
+     * Get the Iterator.
+     *
      * @see org.apache.commons.scxml.Context#iterator()
      */
     public Iterator iterator() {
@@ -75,3 +77,4 @@
     }
 
 }
+

Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/ServletContextResolver.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/ServletContextResolver.java?rev=234141&r1=234140&r2=234141&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/ServletContextResolver.java (original)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/ServletContextResolver.java Sat Aug 20 20:24:20 2005
@@ -1,6 +1,6 @@
 /*
- *    
- *   Copyright 2004 The Apache Software Foundation.
+ *
+ *   Copyright 2005 The Apache Software Foundation.
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -22,41 +22,45 @@
 import org.apache.commons.scxml.PathResolver;
 
 /**
- * A wrapper around ServletContext that implements PathResolver
- * 
+ * A wrapper around ServletContext that implements PathResolver.
+ *
  * @see org.apache.commons.scxml.PathResolver
  */
 public class ServletContextResolver implements PathResolver {
-    
-    ServletContext ctx = null;
+
+    /** The SevletContext we will use to resolve paths. */
+    private ServletContext ctx = null;
 
     /**
-     * @param ctx The ServletContext instance for this RDC runtime.
+     * Constructor.
+     *
+     * @param ctx The ServletContext instance for this web application.
      */
-    public ServletContextResolver(ServletContext ctx) {
+    public ServletContextResolver(final ServletContext ctx) {
         this.ctx = ctx;
     }
-    
+
     /**
-     * Delegates to the underlying ServletContext.getRealPath(String)
-     * 
+     * Delegates to the underlying ServletContext's getRealPath(String).
+     *
      * @param ctxPath context sensitive path, can be a relative URL
      * @return resolved path (an absolute URL) or <code>null</code>
      * @see org.apache.commons.scxml.PathResolver#resolvePath(java.lang.String)
      */
-    public String resolvePath(String ctxPath) {
+    public String resolvePath(final String ctxPath) {
         return ctx.getRealPath(ctxPath);
     }
 
     /**
      * Retrieve the PathResolver rooted at the given path.
-     * 
+     *
      * @param ctxPath context sensitive path, can be a relative URL
      * @return returns a new resolver rooted at ctxPath
      * @see org.apache.commons.scxml.PathResolver#getResolver(java.lang.String)
      */
-    public PathResolver getResolver(String ctxPath) {
+    public PathResolver getResolver(final String ctxPath) {
         return this;
     }
 
 }
+

Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleDispatcher.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleDispatcher.java?rev=234141&r1=234140&r2=234141&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleDispatcher.java (original)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleDispatcher.java Sat Aug 20 20:24:20 2005
@@ -1,6 +1,6 @@
 /*
- *    
- *   Copyright 2004 The Apache Software Foundation.
+ *
+ *   Copyright 2005 The Apache Software Foundation.
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -24,35 +24,39 @@
 import org.apache.commons.scxml.EventDispatcher;
 
 /**
- * Trivial EventDispatcher implementation. No remote eventing.
- * 
+ * Trivial EventDispatcher implementation.
+ * No remote eventing.
+ *
  */
-public class SimpleDispatcher implements EventDispatcher {
-    
+public final class SimpleDispatcher implements EventDispatcher {
+
+     /** Implementation independent log category. */
      private static Log log = LogFactory.getLog(EventDispatcher.class);
 
     /**
-     *  Constructor
+     *  Constructor.
      */
     public SimpleDispatcher() {
+        super();
     }
 
     /**
-     * @see org.apache.commons.scxml.EventDispatcher#cancel(java.lang.String)
+     * @see EventDispatcher#cancel(String)
      */
-    public void cancel(String sendId) {
-        if(log.isInfoEnabled()) {
+    public void cancel(final String sendId) {
+        if (log.isInfoEnabled()) {
             log.info("cancel( sendId: " + sendId + ")");
         }
     }
 
     /**
-     * @see org.apache.commons.scxml.EventDispatcher#send(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.util.Map, java.lang.Object, long)
+     * @see EventDispatcher#send(String,String,String,String,Map,Object,long)
      */
-    public void send(String sendId, String target, String targetType,
-            String event, Map params, Object hints, long delay) {
-        if(log.isInfoEnabled()) {
-            StringBuffer buf = new StringBuffer(32);
+    public void send(final String sendId, final String target,
+            final String targetType, final String event, final Map params,
+            final Object hints, final long delay) {
+        if (log.isInfoEnabled()) {
+            StringBuffer buf = new StringBuffer();
             buf.append("send ( sendId: ").append(sendId);
             buf.append(", target: ").append(target);
             buf.append(", targetType: ").append(targetType);
@@ -67,3 +71,4 @@
     }
 
 }
+

Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/Standalone.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/Standalone.java?rev=234141&r1=234140&r2=234141&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/Standalone.java (original)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/Standalone.java Sat Aug 20 20:24:20 2005
@@ -1,6 +1,6 @@
 /*
- *    
- *   Copyright 2004 The Apache Software Foundation.
+ *
+ *   Copyright 2005 The Apache Software Foundation.
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -36,14 +36,16 @@
 /**
  * Standalone SCXML Interpreter.
  * Useful for command-line testing and debugging.
- * 
+ *
  */
-public class Standalone {
+public final class Standalone {
 
     /**
-     * Launcher
+     * Launcher.
+     * @param args The arguments, one expected, the URI or filename of the
+     *             SCXML document
      */
-    public static void main(String[] args) {
+    public static void main(final String[] args) {
         if (args.length != 1) {
             System.out.println("USAGE: java " + Standalone.class.getName()
                     + "<url|filename>");
@@ -55,8 +57,9 @@
             Context rootCtx = engine.newContext(null);
             EventDispatcher ed = new SimpleDispatcher();
             Tracer trc = new Tracer();
-            SCXML doc = SCXMLDigester.digest(new URL(uri), trc, rootCtx, engine);
-            if(doc == null) {
+            SCXML doc = SCXMLDigester.digest(new URL(uri), trc, rootCtx,
+                engine);
+            if (doc == null) {
                 System.err.println("The SCXML document " + uri
                         + " can not be parsed!");
                 System.exit(-1);
@@ -66,55 +69,65 @@
             doc.addListener(trc);
             exec.setSuperStep(true);
             exec.setStateMachine(doc);
-            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
+            BufferedReader br = new BufferedReader(new
+                InputStreamReader(System.in));
             String event = null;
-            while((event = br.readLine()) != null) {
+            while ((event = br.readLine()) != null) {
                 event = event.trim();
-                if(event.equals("help") || event.equals("?")) {
-                    System.out.println("enter a space-separated list of events");
+                if (event.equalsIgnoreCase("help") || event.equals("?")) {
+                    System.out.println("enter a space-separated list of "
+                        + "events");
                     System.out.println("to quit, enter \"quit\"");
-                    System.out.println("to reset state machine, enter \"reset\"");
-                } else if(event.equals("quit")) {
+                    System.out.println("to reset state machine, enter "
+                        + "\"reset\"");
+                } else if (event.equalsIgnoreCase("quit")) {
                     break;
-                } else if(event.equals("reset")) {
+                } else if (event.equalsIgnoreCase("reset")) {
                     exec.reset();
                 } else {
                     StringTokenizer st = new StringTokenizer(event);
                     int tkns = st.countTokens();
-                    TriggerEvent evts[] = new TriggerEvent[tkns];
-                    for(int i=0; i<tkns; i++) {
+                    TriggerEvent[] evts = new TriggerEvent[tkns];
+                    for (int i = 0; i < tkns; i++) {
                         evts[i] = new TriggerEvent(st.nextToken(),
                                 TriggerEvent.SIGNAL_EVENT, null);
                     }
                     exec.triggerEvents(evts);
-                    if(exec.getCurrentStatus().isFinal()) {
+                    if (exec.getCurrentStatus().isFinal()) {
                         System.out.println("A final configuration reached.");
                     }
                 }
             }
         } catch (IOException e) {
             e.printStackTrace();
-        } catch (ModelException e){
+        } catch (ModelException e) {
             e.printStackTrace();
         }
-        
+
     }
-    
-      /**
-       * @param uri an absolute or relative URL
-       * @return java.lang.String canonical URL (absolute)
-       * @throws java.io.IOException if a relative URL can not be resolved
-       * to a local file
-       * @author Lubos Ures
-       */
-      private static String getCanonicalURI(String uri) throws IOException {
+
+    /**
+     * @param uri an absolute or relative URL
+     * @return java.lang.String canonical URL (absolute)
+     * @throws java.io.IOException if a relative URL can not be resolved
+     *         to a local file
+     */
+    private static String getCanonicalURI(final String uri)
+    throws IOException {
         if (uri.toLowerCase().startsWith("http://")
-                || uri.toLowerCase().startsWith("file://")) {
-        } else {
-            File in = new File(uri);
-            uri = "file:///" + in.getCanonicalPath();
+            || uri.toLowerCase().startsWith("file://")) {
+                return uri;
         }
-        return uri;
+        File in = new File(uri);
+        return "file:///" + in.getCanonicalPath();
     }
-        
+
+    /**
+     * Discourage instantiation since this is a utility class.
+     */
+    private Standalone() {
+        super();
+    }
+
 }
+

Modified: jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/Tracer.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/Tracer.java?rev=234141&r1=234140&r2=234141&view=diff
==============================================================================
--- jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/Tracer.java (original)
+++ jakarta/commons/sandbox/scxml/trunk/src/main/java/org/apache/commons/scxml/env/Tracer.java Sat Aug 20 20:24:20 2005
@@ -1,6 +1,6 @@
 /*
- *    
- *   Copyright 2004 The Apache Software Foundation.
+ *
+ *   Copyright 2005 The Apache Software Foundation.
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -36,25 +37,28 @@
 
 /**
  * A simple logger connected to Jakarta Commons Logging.
- * 
+ *
  */
 public class Tracer implements ErrorReporter, SCXMLListener, ErrorHandler {
 
+    /** A Logger for the Tracer. */
     private static Log log = LogFactory.getLog(Tracer.class);
-    
+
     /**
-     * Constructor
+     * Constructor.
      */
     public Tracer() {
+        super();
     }
 
     /**
-     * @see org.apache.commons.scxml.ErrorReporter#onError(java.lang.String, java.lang.String, java.lang.Object)
+     * @see ErrorReporter#onError(String, String, Object)
      */
-    public void onError(String errCode, String errDetail, Object errCtx) {
+    public void onError(final String errorCode, final String errDetail,
+            final Object errCtx) {
         //Note: the if-then-else below is based on the actual usage
         // (codebase search), it has to be kept up-to-date as the code changes
-        errCode = errCode.intern();
+        String errCode = errorCode.intern();
         StringBuffer msg = new StringBuffer();
         msg.append(errCode).append(" (");
         msg.append(errDetail).append("): ");
@@ -65,7 +69,7 @@
             } else if (errCtx instanceof State) {
                 //determineInitialStates
                 //determineTargetStates
-                msg.append("State " + Tracer.getTTPath((State)errCtx));
+                msg.append("State " + Tracer.getTTPath((State) errCtx));
             }
         } else if (errCode == ErrorReporter.UNKNOWN_ACTION) {
             //executeActionList
@@ -73,12 +77,11 @@
         } else if (errCode == ErrorReporter.NON_DETERMINISTIC) {
             //filterTransitionSet
             msg.append(" [");
-            if(errCtx instanceof HashSet) {
-                Iterator i = ((HashSet)errCtx).iterator();
-                while(i.hasNext()) {
-                    Transition t = (Transition)i.next();
+            if (errCtx instanceof HashSet) {
+                for (Iterator i = ((Set) errCtx).iterator(); i.hasNext();) {
+                    Transition t = (Transition) i.next();
                     msg.append(transToString(t.getParent(), t.getTarget(), t));
-                    if(i.hasNext()) {
+                    if (i.hasNext()) {
                         msg.append(", ");
                     }
                 }
@@ -87,26 +90,25 @@
         } else if (errCode == ErrorReporter.ILLEGAL_CONFIG) {
             //isLegalConfig
             if (errCtx instanceof Map.Entry) {
-                TransitionTarget tt = (TransitionTarget)(((Map.Entry)errCtx).getKey());
-                HashSet vals = (HashSet)(((Map.Entry)errCtx).getValue());
+                TransitionTarget tt = (TransitionTarget)
+                    (((Map.Entry) errCtx).getKey());
+                Set vals = (Set) (((Map.Entry) errCtx).getValue());
                 msg.append(Tracer.getTTPath(tt) + " : [");
-                Iterator i = vals.iterator();
-                while(i.hasNext()) {
-                    TransitionTarget tx = (TransitionTarget)i.next();
+                for (Iterator i = vals.iterator(); i.hasNext();) {
+                    TransitionTarget tx = (TransitionTarget) i.next();
                     msg.append(Tracer.getTTPath(tx));
-                    if(i.hasNext()) {
+                    if (i.hasNext()) {
                         msg.append(", ");
                     }
                 }
                 msg.append(']');
-            } else if (errCtx instanceof HashSet) {
-                HashSet vals = (HashSet)(errCtx);
+            } else if (errCtx instanceof Set) {
+                Set vals = (Set) errCtx;
                 msg.append("<SCXML> : [");
-                Iterator i = vals.iterator();
-                while(i.hasNext()) {
-                    TransitionTarget tx = (TransitionTarget)i.next();
+                for (Iterator i = vals.iterator(); i.hasNext();) {
+                    TransitionTarget tx = (TransitionTarget) i.next();
                     msg.append(Tracer.getTTPath(tx));
-                    if(i.hasNext()) {
+                    if (i.hasNext()) {
                         msg.append(", ");
                     }
                 }
@@ -117,29 +119,37 @@
     }
 
     /**
-     * @see org.apache.commons.scxml.SCXMLListener#onEntry(org.apache.commons.scxml.model.TransitionTarget)
+     * @see SCXMLListener#onEntry(TransitionTarget)
      */
-    public void onEntry(TransitionTarget state) {
+    public void onEntry(final TransitionTarget state) {
         log.info(Tracer.getTTPath(state));
     }
 
     /**
-     * @see org.apache.commons.scxml.SCXMLListener#onExit(org.apache.commons.scxml.model.TransitionTarget)
+     * @see SCXMLListener#onExit(TransitionTarget)
      */
-    public void onExit(TransitionTarget state) {
+    public void onExit(final TransitionTarget state) {
         log.info(Tracer.getTTPath(state));
     }
 
     /**
-     * @see org.apache.commons.scxml.SCXMLListener#onTransition(org.apache.commons.scxml.model.TransitionTarget, org.apache.commons.scxml.model.TransitionTarget, org.apache.commons.scxml.model.Transition)
+* @see SCXMLListener#onTransition(TransitionTarget,TransitionTarget,Transition)
      */
-    public void onTransition(TransitionTarget from, TransitionTarget to,
-            Transition transition) {
+    public void onTransition(final TransitionTarget from,
+            final TransitionTarget to, final Transition transition) {
         log.info(transToString(from, to, transition));
     }
-    
-    private static final String transToString(TransitionTarget from,
-            TransitionTarget to, Transition transition) {
+
+    /**
+     * Create a human readable log view of this transition.
+     *
+     * @param from The source TransitionTarget
+     * @param to The destination TransitionTarget
+     * @param transition The Transition that is taken
+     * @return String The human readable log entry
+     */
+    private static String transToString(final TransitionTarget from,
+            final TransitionTarget to, final Transition transition) {
         StringBuffer buf = new StringBuffer("transition (");
         buf.append("event = ").append(transition.getEvent());
         buf.append(", cond = ").append(transition.getCond());
@@ -152,37 +162,47 @@
     /**
      * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
      */
-    public void warning(SAXParseException exception) throws SAXException {
+    public void warning(final SAXParseException exception)
+    throws SAXException {
         log.warn(exception.getMessage(), exception);
     }
 
     /**
      * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
      */
-    public void error(SAXParseException exception) throws SAXException {
+    public void error(final SAXParseException exception)
+    throws SAXException {
         log.error(exception.getMessage(), exception);
     }
 
     /**
      * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
      */
-    public void fatalError(SAXParseException exception) throws SAXException {
+    public void fatalError(final SAXParseException exception)
+    throws SAXException {
         log.fatal(exception.getMessage(), exception);
     }
 
-    private static final String getTTPath(TransitionTarget tt) {
-        if(tt.getParent() == null) {
+    /**
+     * Write out this TransitionTarget location in a XPath style format.
+     *
+     * @param tt The TransitionTarget whose &quot;path&quot; is to needed
+     * @return String The XPath style location of the TransitionTarget within
+     *                the SCXML document
+     */
+    private static String getTTPath(final TransitionTarget tt) {
+        TransitionTarget parent = tt.getParent();
+        if (parent == null) {
             return "/" + tt.getId();
         } else {
             LinkedList ll = new LinkedList();
-            while(tt != null) {
-                ll.addFirst(tt);
-                tt = tt.getParent();
+            while (parent != null) {
+                ll.addFirst(parent);
+                parent = parent.getParent();
             }
-            Iterator i = ll.iterator();
             StringBuffer names = new StringBuffer();
-            while(i.hasNext()) {
-                TransitionTarget tmp = (TransitionTarget)i.next();
+            for (Iterator i = ll.iterator(); i.hasNext();) {
+                TransitionTarget tmp = (TransitionTarget) i.next();
                 names.append('/').append(tmp.getId());
             }
             return names.toString();
@@ -190,3 +210,4 @@
     }
 
 }
+



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message