notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
svn commit: r1548 - in development/laboratory/planet/components/transitionmachine: . api/src/main/net/dpml/transitionmachine basic/src/main/net/dpml/transitionmachine/basic
- From: niclas AT netcompartner.com
- To: notify-dpml AT lists.ibiblio.org
- Subject: svn commit: r1548 - in development/laboratory/planet/components/transitionmachine: . api/src/main/net/dpml/transitionmachine basic/src/main/net/dpml/transitionmachine/basic
- Date: Fri, 21 Jan 2005 12:07:58 +0100
Author: niclas
Date: Fri Jan 21 12:07:58 2005
New Revision: 1548
Added:
development/laboratory/planet/components/transitionmachine/basic/src/main/net/dpml/transitionmachine/basic/CommandRuleComponent.java
(contents, props changed)
development/laboratory/planet/components/transitionmachine/basic/src/main/net/dpml/transitionmachine/basic/CommandRuleImpl.java
(contents, props changed)
development/laboratory/planet/components/transitionmachine/basic/src/main/net/dpml/transitionmachine/basic/StateComponent.java
(contents, props changed)
Removed:
development/laboratory/planet/components/transitionmachine/basic/src/main/net/dpml/transitionmachine/basic/CommandRule.java
Modified:
development/laboratory/planet/components/transitionmachine/api/src/main/net/dpml/transitionmachine/TransitionListener.java
development/laboratory/planet/components/transitionmachine/basic/src/main/net/dpml/transitionmachine/basic/StateImpl.java
development/laboratory/planet/components/transitionmachine/basic/src/main/net/dpml/transitionmachine/basic/TransitionComponent.java
development/laboratory/planet/components/transitionmachine/basic/src/main/net/dpml/transitionmachine/basic/TransitionImpl.java
development/laboratory/planet/components/transitionmachine/index.xml
Log:
Tightening up the TM contract, since we soon need this to graduate.
Modified:
development/laboratory/planet/components/transitionmachine/api/src/main/net/dpml/transitionmachine/TransitionListener.java
==============================================================================
---
development/laboratory/planet/components/transitionmachine/api/src/main/net/dpml/transitionmachine/TransitionListener.java
(original)
+++
development/laboratory/planet/components/transitionmachine/api/src/main/net/dpml/transitionmachine/TransitionListener.java
Fri Jan 21 12:07:58 2005
@@ -29,5 +29,9 @@
*/
public interface TransitionListener
{
+ /** Event fired when a transition occur from one state to another.
+ * It is intended that the functionality tied to the transition machine
+ * is implemented thorugh this interface.
+ */
void transition( TransitionEvent event );
}
Added:
development/laboratory/planet/components/transitionmachine/basic/src/main/net/dpml/transitionmachine/basic/CommandRuleComponent.java
==============================================================================
--- (empty file)
+++
development/laboratory/planet/components/transitionmachine/basic/src/main/net/dpml/transitionmachine/basic/CommandRuleComponent.java
Fri Jan 21 12:07:58 2005
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2004 Niclas Hedhman.
+ * Created: Dec 20, 2004
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.transitionmachine.basic;
+
+import net.dpml.transitionmachine.TransitionRule;
+import net.dpml.parameters.Parameters;
+import net.dpml.parameters.ParameterException;
+
+/**
+ * The CommandRule is a plain rule, that checks if the Command string is of
a particular and
+ * exact value.
+ * <p/>
+ * The generic CommandRule should be enough for most situations, unless
dynamically user
+ * re-programmable statemachines are needed.
+ *
+ * @metro.component name="CommandRule" lifestyle="singleton"
collection="hard"
+ * @metro.service type="net.dpml.transitionmachine.TransitionRule"
+ */
+public class CommandRuleComponent extends CommandRuleImpl
+ implements TransitionRule
+{
+ private String m_command;
+ private int m_priority;
+ private boolean m_ignoreCase;
+
+ public CommandRuleComponent( Parameters params )
+ throws ParameterException
+ {
+ super(
+ params.getParameter( "command" ),
+ params.getParameterAsInteger( "priority", 100 ),
+ params.getParameterAsBoolean( "ignore-case", false )
+ );
+ }
+}
Added:
development/laboratory/planet/components/transitionmachine/basic/src/main/net/dpml/transitionmachine/basic/CommandRuleImpl.java
==============================================================================
--- (empty file)
+++
development/laboratory/planet/components/transitionmachine/basic/src/main/net/dpml/transitionmachine/basic/CommandRuleImpl.java
Fri Jan 21 12:07:58 2005
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2004 Niclas Hedhman.
+ * Created: Dec 20, 2004
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.transitionmachine.basic;
+
+import net.dpml.lang.NullArgumentException;
+import net.dpml.parameters.Parameters;
+import net.dpml.parameters.ParameterException;
+import net.dpml.transitionmachine.TransitionRule;
+
+/**
+ * The CommandRule is a plain rule, that checks if the Command string is of
a particular and
+ * exact value.
+ * <p/>
+ * The generic CommandRule should be enough for most situations, unless
dynamically user
+ * re-programmable statemachines are needed.
+ */
+public class CommandRuleImpl
+ implements TransitionRule
+{
+ private String m_command;
+ private int m_priority;
+ private boolean m_ignoreCase;
+
+ public CommandRuleImpl( String command, int priority, boolean ignoreCase
)
+ throws ParameterException, NullArgumentException
+ {
+ if( command == null )
+ {
+ throw new NullArgumentException( "command" );
+ }
+ m_command = command;
+ m_priority = priority;
+ m_ignoreCase = ignoreCase;
+ }
+
+ /**
+ * Returns whether the command string corresponds to this transition
rule.
+ *
+ * @param commandString An command string passed to the
TransitionMachine.
+ *
+ * @return true if the Transition defined by this TransitionRule should
be performed, false
+ * otherwise.
+ */
+ public boolean isTransition( String commandString )
+ {
+ if( m_ignoreCase )
+ {
+ return m_command.equalsIgnoreCase( commandString );
+ }
+ return m_command.equals( commandString );
+ }
+
+ public int getPriority()
+ {
+ return m_priority;
+ }
+
+ /**
+ * Compares this object with the specified object for order. Returns a
negative integer, zero,
+ * or a positive integer as this object is less than, equal to, or
greater than the specified
+ * object.<p>
+ * <p/>
+ * In the foregoing description, the notation
<tt>sgn(</tt><i>expression</i><tt>)</tt>
+ * designates the mathematical <i>signum</i> function, which is defined
to return one of
+ * <tt>-1</tt>, <tt>0</tt>, or <tt>1</tt> according to whether the value
of <i>expression</i> is
+ * negative, zero or positive.
+ * <p/>
+ * The implementor must ensure <tt>sgn(x.compareTo(y)) ==
-sgn(y.compareTo(x))</tt> for all
+ * <tt>x</tt> and <tt>y</tt>. (This implies that
<tt>x.compareTo(y)</tt> must throw an
+ * exception iff <tt>y.compareTo(x)</tt> throws an exception.)<p>
+ * <p/>
+ * The implementor must also ensure that the relation is transitive:
<tt>(x.compareTo(y)>0
+ * && y.compareTo(z)>0)</tt> implies
<tt>x.compareTo(z)>0</tt>.<p>
+ * <p/>
+ * Finally, the implementer must ensure that <tt>x.compareTo(y)==0</tt>
implies that
+ * <tt>sgn(x.compareTo(z)) == sgn(y.compareTo(z))</tt>, for all
<tt>z</tt>.<p>
+ * <p/>
+ * It is strongly recommended, but <i>not</i> strictly required that
<tt>(x.compareTo(y)==0) ==
+ * (x.equals(y))</tt>. Generally speaking, any class that implements
the <tt>Comparable</tt>
+ * interface and violates this condition should clearly indicate this
fact. The recommended
+ * language is "Note: this class has a natural ordering that is
inconsistent with equals."
+ *
+ * @param o the Object to be compared.
+ *
+ * @return a negative integer, zero, or a positive integer as this
object is less than, equal
+ * to, or greater than the specified object.
+ *
+ * @throws ClassCastException if the specified object's type prevents it
from being compared to
+ * this Object.
+ */
+ public int compareTo( Object o )
+ {
+ if( o instanceof TransitionRule )
+ {
+ TransitionRule rule = (TransitionRule) o;
+ int p = rule.getPriority();
+ if( p == m_priority )
+ return 0;
+ if( p > m_priority )
+ return -1;
+ else
+ return 1;
+ }
+ return -1;
+ }
+}
Added:
development/laboratory/planet/components/transitionmachine/basic/src/main/net/dpml/transitionmachine/basic/StateComponent.java
==============================================================================
--- (empty file)
+++
development/laboratory/planet/components/transitionmachine/basic/src/main/net/dpml/transitionmachine/basic/StateComponent.java
Fri Jan 21 12:07:58 2005
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2004 Niclas Hedhman.
+ * Created: Dec 20, 2004
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.transitionmachine.basic;
+
+import java.util.Locale;
+import java.util.ResourceBundle;
+import net.dpml.parameters.ParameterException;
+import net.dpml.parameters.Parameters;
+import net.dpml.transitionmachine.State;
+import net.dpml.transitionmachine.TransitionMachine;
+
+/**
+ * This class represents each State internal in the TransitionMachine.
+ * <p/>
+ * Each State is defined as a Metro component, and has an Identity (machine
readable), a Name
+ * and a Description, which are both human-readable in the caller's Locale.
</p>
+ * <p/>
+ * The Name and Description is read from the java.util.ResourceBundle named
+ * "net.dpml.transitionmachine.Resources", and can be either a properties
file, or a
+ * net.dpml.i18n.BundleHandler. </p>
+ * <p/>
+ * For each "identity", i.e. each StateComponent, you need to have two
resource strings, with the same
+ * name as the identity, prepended with ".name" and ".description"
respectively. Example; </p>
+ * <code><pre>
+ * normal.name=Normal
+ * normal.description=This is the Normal state, where it is waiting for a
command.
+ * print.name=Printing
+ * print.description=In this state, the printing rendering is in progress.
It will leave \
+ * this state when all data has been delivered to the output buffers.
+ * error.name=Failure
+ * error.description=Something has gone wrong and it is set into an error
state. Reset command
+ * required.
+ * </pre></code>
+ *
+ * @metro.component name="state" lifestyle="singleton"
+ * @metro.service type="net.dpml.transitionmachine.State"
+ */
+public class StateComponent extends StateImpl
+ implements State
+{
+ public StateComponent( Parameters params )
+ throws ParameterException
+ {
+ super( params.getParameter( "identity" ) );
+ }
+}
+
Modified:
development/laboratory/planet/components/transitionmachine/basic/src/main/net/dpml/transitionmachine/basic/StateImpl.java
==============================================================================
---
development/laboratory/planet/components/transitionmachine/basic/src/main/net/dpml/transitionmachine/basic/StateImpl.java
(original)
+++
development/laboratory/planet/components/transitionmachine/basic/src/main/net/dpml/transitionmachine/basic/StateImpl.java
Fri Jan 21 12:07:58 2005
@@ -21,16 +21,17 @@
import java.util.Locale;
import java.util.ResourceBundle;
+import net.dpml.lang.NullArgumentException;
import net.dpml.parameters.ParameterException;
import net.dpml.parameters.Parameters;
import net.dpml.transitionmachine.State;
import net.dpml.transitionmachine.TransitionMachine;
/**
- * This class represents each StateImpl internal in the TransitionMachine.
+ * This class represents each State internal in the TransitionMachine.
* <p/>
* <p/>
- * Each StateImpl is defined as a Metro component, and has an Identity
(machine readable), a Name
+ * Each StateImpl has an Identity (machine readable), a Name
* and a Description, which are both human-readable in the caller's Locale.
</p>
* <p/>
* The Name and Description is read from the java.util.ResourceBundle named
@@ -49,19 +50,21 @@
* error.description=Something has gone wrong and it is set into an error
state. Reset command
* required.
* </pre></code>
- *
- * @metro.component name="state" lifestyle="singleton"
- * @metro.service type="net.dpml.transitionmachine.State"
*/
-public class StateImpl
+public class StateImpl
implements State
{
private String m_identity;
- public StateImpl( Parameters params )
- throws ParameterException
+ public StateImpl( String identity )
+ throws ParameterException, NullArgumentException
{
- m_identity = params.getParameter( "identity" );
+ if( identity == null )
+ {
+ throw new NullArgumentException( "identity" );
+ }
+
+ m_identity = identity;
}
public String getIdentity()
Modified:
development/laboratory/planet/components/transitionmachine/basic/src/main/net/dpml/transitionmachine/basic/TransitionComponent.java
==============================================================================
---
development/laboratory/planet/components/transitionmachine/basic/src/main/net/dpml/transitionmachine/basic/TransitionComponent.java
(original)
+++
development/laboratory/planet/components/transitionmachine/basic/src/main/net/dpml/transitionmachine/basic/TransitionComponent.java
Fri Jan 21 12:07:58 2005
@@ -16,9 +16,10 @@
/**
* @metro.component name="transition" lifestyle="transient" collection="hard"
- * @metro.service type="net.dpml.transitionmachine.Transition"
+ * @metro.service type="net.dpml.transitionmachine.Transition"
*/
-public class TransitionComponent implements Transition
+public class TransitionComponent
+ implements Transition
{
private State m_beginState;
private State m_endState;
@@ -142,7 +143,7 @@
result = ( result >>> 17 ) + m_identity.hashCode();
return result;
}
-
+
public String toString()
{
return "transition[" + m_identity +"]";
Modified:
development/laboratory/planet/components/transitionmachine/basic/src/main/net/dpml/transitionmachine/basic/TransitionImpl.java
==============================================================================
---
development/laboratory/planet/components/transitionmachine/basic/src/main/net/dpml/transitionmachine/basic/TransitionImpl.java
(original)
+++
development/laboratory/planet/components/transitionmachine/basic/src/main/net/dpml/transitionmachine/basic/TransitionImpl.java
Fri Jan 21 12:07:58 2005
@@ -5,7 +5,7 @@
import java.util.ResourceBundle;
import java.util.ArrayList;
-import net.dpml.exception.NullArgumentException;
+import net.dpml.lang.NullArgumentException;
import net.dpml.transitionmachine.Transition;
import net.dpml.transitionmachine.State;
@@ -13,13 +13,13 @@
import net.dpml.transitionmachine.TransitionRule;
import net.dpml.transitionmachine.TransitionListener;
-public class TransitionImpl
+public class TransitionImpl
implements Transition
{
private State m_beginState;
private State m_endState;
private String m_identity;
- private TransitionRule m_Rule;
+ private TransitionRule m_rule;
private ArrayList m_listeners;
/*
@@ -28,8 +28,10 @@
* @param beginState The StateImpl from which this Transition starts at.
* @param endState The StateImpl to where this Transition leads to.
* @param identity The Identity of this Transition.
+ * @param rule The TransitionRule for this transition to activate.
*/
- public TransitionImpl( State beginState, State endState, String identity
)
+ public TransitionImpl( State beginState, State endState, String identity,
+ TransitionRule rule )
{
if( beginState == null )
{
@@ -46,11 +48,12 @@
m_beginState = beginState;
m_endState = endState;
m_identity = identity;
+ m_rule = rule;
}
public TransitionRule getTransitionRule()
{
- return m_Rule;
+ return m_rule;
}
public State getBeginState()
Modified: development/laboratory/planet/components/transitionmachine/index.xml
==============================================================================
--- development/laboratory/planet/components/transitionmachine/index.xml
(original)
+++ development/laboratory/planet/components/transitionmachine/index.xml
Fri Jan 21 12:07:58 2005
@@ -1,19 +1,19 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
+<!--
Copyright 2004 Stephen J McConnell
Copyright 2004 Niclas Hedhman
-
+
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
+ You may obtain a copy of the License at
+
http://www.apache.org/licenses/LICENSE-2.0
-
+
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
-
+
See the License for the specific language governing permissions and
limitations under the License.
-->
@@ -21,6 +21,7 @@
<index>
<import uri="artifact:module:dpml/metro/dpml-metro#SNAPSHOT"/>
<import uri="artifact:module:dpml/magic/dpml-magic#SNAPSHOT"/>
+ <import uri="artifact:module:dpml/transit/dpml-transit#SNAPSHOT"/>
<project file="module.xml">
<info>
@@ -35,7 +36,7 @@
</plugins>
<dependencies>
<include key="dpml-transit"/>
- <include key="dpml-util"/>
+ <include key="dpml-util" />
</dependencies>
</project>
@@ -44,7 +45,7 @@
<group>dpml/transitionmachine</group>
<name>dpml-transitionmachine-api</name>
<version>1.0.0</version>
- <status>SNAPSHOT</status>
+ <status>SNAPSHOT</status>
</info>
<dependencies>
</dependencies>
@@ -58,7 +59,7 @@
<group>dpml/transitionmachine</group>
<name>dpml-transitionmachine-basic</name>
<version>1.0.0</version>
- <status>SNAPSHOT</status>
+ <status>SNAPSHOT</status>
</info>
<dependencies>
<include key="dpml-activity-api" />
@@ -66,7 +67,7 @@
<include key="dpml-parameters-api" />
<include key="dpml-service-api" />
<include key="dpml-transitionmachine-api" />
- <include key="dpml-util-exception" />
+ <include key="dpml-transit" />
</dependencies>
<plugins>
<include key="dpml-meta-tools"/>
@@ -78,7 +79,7 @@
<group>dpml/transitionmachine/demo</group>
<name>dpml-trafficlight</name>
<version>1.0.0</version>
- <status>SNAPSHOT</status>
+ <status>SNAPSHOT</status>
</info>
<dependencies>
<include key="dpml-transitionmachine-basic" />
- svn commit: r1548 - in development/laboratory/planet/components/transitionmachine: . api/src/main/net/dpml/transitionmachine basic/src/main/net/dpml/transitionmachine/basic, niclas, 01/21/2005
Archive powered by MHonArc 2.6.24.