Monday 15 April 2013

java - State Pattern using Spring DI -


Since I am new to spring, I face problem in changing the state of my state using plain Java Have to do Actually, I used to do a project using the state system, but I acknowledged this approach that each state does not consistently know it as a reference class.

There is an area in the reference class "current location", IState is the type, and its method is setstate (ISTAT state)

One method in ISAT is the GEEXtext (context reference).

And I have kept some time (keep) in the reference class. It is true now and in order to stop the processing, it has gone wrong in the ExtStState, I call currentState.goNext () in this loop.

Each state calls some database transactions and webservice and depending on its result, this theme sets the next state using thesetset (new statesfor ()) - for example

code sample:

  public interface istat {public zero is known ( 

context context);} public class StateOne IState {public void goNext (context Context) {// do some logic if (user.getTitle.equals ("manager") {context.setState (new StateThree ());} else if (User.getTitle.equals ("teamLead") {context.setState ( New StateTwo ());} Other { Context.setState (New ExitState ())}}}}}} Reference to public category {Private Boolean Keep = True; Private Istate Current State, Public Zero SetState (ISTAT State) {currentState = state; Now that I have Spring D Annotation- Based, I'm facing the problem, that the context is with "current state management" @ etooyer, but I need a spring container if I am in a state and "if statement Successful of " If three states are injected, then "state" inject two and otherwise inject the extestate.

If I use @quilifiers (value = "state on") it will only specify the first state that implements the interface, but the second condition that I set based on the condition is not me Know how to specify it in the spring.

Besides this, we need to specify org.springframework.core.Order to specify the order of beans, but I do not know the values ​​received in advance from the database or webservice, it is specified at runtime should be done.

Is it possible to change this plain Java with Spring D and how?

Sorry for any help and thanks to advance in advance.

You should use ApplicationContext . Example given below:

  // Inject context into your bean - @Autowired ApplicationContext applicationContext; // Get the Bean from Reference (@Atovair equivalent) applicationContext.getBean (Statute class);    

No comments:

Post a Comment