Page 2 of 2 FirstFirst 12
Results 11 to 18 of 18

Thread: Somethings to think about

  1. #11
    Join Date
    Aug 2004
    Posts
    229

    Default

    Wow, your project sounds exactly (exactly!) like another one I worked on a few years ago. It was POS with both a monitor (Swing UI) and 2 line display (made by a certain large company that is... blue...). This was before Spring or Spring-rich, of course, but we ended up designing an IoC XML configuration mechanism before the term IoC was in use (or even existed?) and a state machine with which to drive the UI (and inputs into the state machine could be from anything - keyboard, external device, network, etc). I didn't work on the GUI directly - my area was the XML configuration and the state machine - but your message just brought back all sorts of deja vu.

  2. #12
    Join Date
    Jun 2005
    Location
    Yorkshire, England
    Posts
    9

    Default

    There is a downside to the state machine UI independance. You cannot use pop ups during commands for warnings, errors and choices without spoiling it.

    Of course if it comes to a choice between Swing and SWT, or another local UI, then a factory can be provided for popups. However, if we are trying to reuse these operations in a web framework then you have to introduce a new state to communicate with the user.

    This may not be a bad thing. Other developers are introducing pop ups into my commands all the time, because they can't be bothered to set up new states. So there are times that pressing a button can trigger a whole series of pop ups when the user should really be presented with another screen with all these choices on them.

    Perhaps the points in the workflow where pop ups appear should always be configured as a 'wait for input' state. This would allow some UIs to handle them as pop ups, while a Web UI could display a whole new page.

    Finally freeing the commands from user interaction would also mean we could introduce transactions around them, or even execute them on a server.

  3. #13
    Join Date
    Jan 2005
    Location
    Ottawa Canada
    Posts
    14

    Default

    There is a downside to the state machine UI independence. You cannot use pop ups during commands for warnings, errors and choices without spoiling it.
    I think the above is an example of the code telling us that something is wrong. In an earlier post to this thread I said
    We sometimes accidentally merge concepts because they are typically used together…
    I think that this happens a lot with command objects, probably because most applications only have one presentation tier and the application code accidentally gets mixed into the command objects.

    We should keep a very clear separation between the presentation code and the application code (application service objects) – they are different. I hit this all the time because our system sometimes implements identical functionality (identical screens and operations) in both a Swing based rich client application and Struts based web application. SpringRC should live exclusively in the presentation tier of the system as should Struts.

    Taking this view, any behavior that could be common to either the SpringRC or Struts presentation tier should be implemented in an application service object that lives at the application tier. The Struts action simply calls the application service object to do the work, and of course the SpringRC command object also simply calls the same application service object. The only thing that is left in the Spring command or Struts action is the stuff that is truly part of the presentation tier, which is surprisingly little.

    This really doesn’t help with the original problem you mentioned about pop ups from a command spoiling the state machine. I am convinced that it can be done, but I need to try some code to explore the details of how. (please post the results if someone beats me to trying this)

    Jim

  4. #14
    Join Date
    Jun 2005
    Location
    Yorkshire, England
    Posts
    9

    Default More on the state machine

    This is my first stab at how a state machine might be used. I still not clear on how I would like to define views, so I'm going to leave that out.

    Please don't look for any sort of logical consistency in these examples, they are just random ideas to illustrate what I got in mind. Also bear in mind that I'm a spring novice who is still working through the book.

    BTW, I've started to refer to commands/actions as operations because those terms are being used elsewhere. This should help add to the confusion :-)

    Code:
    <beans>
    	<!--
    		In an MDI application the singleton attribute would need to
    		be set to false
    	-->
    
    	<bean id="bookingStateMachine" class="org....StateMachineEngine"
    							 singleton="false">
    
    		<!-- An operation to take the machine to the first state -->
    		<property name="start">
    			<ref bean="bootOperation"/>
    		</property>
    
    		<!-- Watch for this in the context passed to operations -->
    		<property name="document">
    			<bean class="MyDataModel" singleton="false"/>
    		</property>
    	</bean>
    
    	<!--
    		Wiring up an operation.  The result returned by the execute
    		method on an operation is mapped on to the id of the next state.
    
    		There may be no results map, there does not have to be a
    		change in state.
    
    		Somewhere in here I want to be able to push the current
    		state onto a stack for a later pop, or even pop it off.
    		Any ideas?
    	 -->
    
    	<bean id="bookSeat" class="org....OperationMapper">
    		<property name="operation">
    			<bean class="example.BookSeatOperation"/>
    		</property>
    		<property name="results">
    			<map>
    				<entry key="next">
    					<ref bean="myNextState/>
    				</entry>
    				<entry key="badData">
    					<ref bean="displayErrorState/>
    				</entry>
    			</map>
    		</property>
    	</bean>
    
    	<!--
    		Different states can share sets or subsets of operations.
    	 -->
    
    	<bean id="operationSet1" class="org.....OperationSet">
    		<property name="operations">
    			<set>
    				<ref bean="bookSeat"/>
    				<ref bean="viewAvailability"/>
    			</set>
    		</property>
    		<property name="include">
    			<set>
    				<ref bean="operationSubSet1"/>
    				<ref bean="operationSubSet2"/>
    			</set>
    		</property>
    	</bean>
    
    	<bean id="displayingWizardPage4State" class="org.....State">
    		<property name="operationSet">
    			<ref bean="operationSet1"/>
    		</property>
    	</bean>
    
    	.....
    Code:
    /**
     * The interface implemented by the programmer to provide workflow logic.
     *
     * There may be more than one instance of a document requiring the same set of
     * states and operations in an application &#40;e.g. an MDI application&#41;.
     * So Operation and State beans should not hold references to the current
     * document.  They should take it from the passed context.
     */
    public interface Operation &#123;
    	/**
    	 * Do some workflow logic and indicate the outcome.
    	 * @return a string indicating the result.
    	 */
    	public String execute&#40;Context context&#41;;
    	/**
    	 * Is this operation currently possible?  Not called unless in a state
    	 * that allows the action.
    	 */
    	public boolean isEnabled&#40;Context context&#41;;
    &#125;
    Code:
    /**
     * Provided by the state machine to operations.
     */
    public interface Context &#123;
    
    	public State getState&#40;&#41;;
    	/**
     	 * The object provided by the programmer to the state machine.
    	 * It is a means by which operations and GUI views communicate.
     	 */
    	public Object getDocument&#40;&#41;;
    	/**
    	 * If this is called by the operation then the state machine gives any
    	 * registered GUI the chance to display the progress.
    	 * <P>
    	 * Swing must not drive the state machine using the event dispatch
    	 * thread for this to happen.
    	 */
    	public void showProgress&#40;int min, int max&#41;;
    	/**
    	 * Set the amount of progress to display.
    	 */
    	public void setProgress&#40;int progress, String messageKey&#41;;
    &#125;
    How we might add a Listener to the state machine....

    Code:
    <beans>
    
    	<bean id="myStateMachine" class="org....StateMachine"
    							 singleton="false">
    		.....
    		<property name="listeners">
    			<list>
    				<ref bean="myGuiStateManager"/>
    			</list>
    		</property>
    	</bean>
    
    	<!--
    		So that in an MDI application we get a new set of views for
    		each document, but we re-use them when working within that
    		document, We give each it's own view factory.  Also nice
    		to read these definitions from another file.
    	
    		- Does this work?
    	-->
    	<bean id="myGuiStateManager" class="org....GuiManager"
    							 singleton="false">
    		<property name="viewFactory">
    			<bean "org....XmlViewFactory">
    				<constructor-arg>
    					myswingviews.xml
    				</constructor-arg>
    				<constructor-arg>
    					myStateViewMap
    				</constructor-arg>
    			</bean>
    		</property>
    	</bean>
    
    	....
    And that's as far as I've got.

    I do have ideas about views, but they keep changing. I want to treat views as containers with different panels that are attached depending on state. This has worked in my current app, but I don't think it will suit everyone.

    Reg.

  5. #15
    Join Date
    Aug 2004
    Posts
    229

    Default

    I just skimmed an article written about webflow, and from the little I now know, I'm becoming even more convinced that Spring webflow could work with Spring-rich. Take a look at http://www.javalobby.org/articles/spring-webflow/
    My question is, why not utilize the efforts of the webflow guys? All we would have to do is get them to drop that silly "web" from their name - and then, of course, write integration code.

    - Andy

  6. #16
    Join Date
    Jun 2005
    Location
    Yorkshire, England
    Posts
    9

    Default

    I think you are right Andy. My starting point was Struts, so I guess it was always going to look like any Web FrontController type framework.

    I've had a quick look at the article you linked and http://www.theserverside.com/article...=SpringWebFlow , and aside from the http/web focus it is very much what I am thinking off. It has some nice features I've not seen before; such as the definition of the complete flows from page to page. The syntax beats mine hands down.

    (I do find their concept of an action as a state a bit alien - Ho Hum)

    In a GUI app there could be some differences. The ability to have several frames/flows open at the same time (it may handle this - I'm not sure). The form controls that deliver something other than strings and are already validated before submission. I don't know if Spring-RCP forms are being designed with all this in mind.

    So, I'm going to do some research, a bit more thinking, and may be wait for the Spring-RCP state machine.

    Reg

  7. #17
    Join Date
    Jan 2005
    Location
    Ottawa Canada
    Posts
    14

    Default

    I also think that there is an opportunity to use Spring WebFlow (or at least these concepts) for the navigation portion of a rich client application. This makes sense, especially if we carefully separate the presentation tier from the application service tier (the guts of the application that is completely independent of what it looks like and the presentation technology being used).

    It is easy to think about an ‘application’ that is built using either a web based interface or a rich client interface that does exactly the same thing. If a navigation (state transition) engine like Spring WebFlow is useful for a web based presentation tier, then it should be also useful for a rich client based presentation tier. What has happened by doing this is that we have removed the navigation from the presentation tier and put it into the application service tier where it probably belongs.

    I do find their concept of an action as a state a bit alien
    It does seem a bit strange, but if it works so well with web applications I suspect it is right.

    I’m wondering though if the ‘command’ object would need to change a bit for this to work. It seems to me that the command object should be just an event generator, not the holder of code that does the actual work. I see the command object as one of the presentation tier objects, and by definition they shouldn’t really do much. They should simply be bound to a presentation independent service object that lives in the application service tier to do the work. Is it this service object that generates the state transitions that are managed by ‘webFlow’?

    Jim

  8. #18
    Join Date
    Jun 2005
    Location
    Yorkshire, England
    Posts
    9

    Default

    It seems to me that the command object should be just an event generator, not the holder of code that does the actual work.
    That's right. In my current application I have a single class (SwingAction) that implements java.swing.Action. The actionPerformed method on this class feeds a request to my front controller to execute the named business logic (WorkflowAction). Which is does between setting a busy cursor and displaying the correct views for the new state. It is instances of SwingAction that gets attached to buttons or used in the java.swing.ActionMap attached to a frame when a state is entered.

    Hence my utter indecision over what to call these objects (actions, commands, operations or workflow).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •