View Javadoc

1   /*******************************************************************************
2    * Copyright (c) 2011 Michael Mimo Moratti.
3    *
4    * Michael Mimo Moratti licenses this file to you under the Apache License, version 2.0
5    * (the "License"); you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at:
7    *     http://www.apache.org/licenses/LICENSE-2.0
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
11   * License for the specific language governing permissions and limitations
12   * under the License.
13   *******************************************************************************/
14  package ch.mimo.netty.handler.codec.icap;
15  
16  import org.jboss.netty.buffer.ChannelBuffer;
17  
18  /**
19   * Abstract state implementation for all Decoder states.
20   * 
21   * @author Michael Mimo Moratti (mimo@mimo.ch)
22   *
23   * @param <T>
24   * 
25   * @see IcapMessageDecoder
26   * @see StateEnum
27   */
28  public abstract class State<T extends Object> {
29  	
30  	private String name;
31  	
32  	public State(String name) {
33  		this.name = name;
34  	}
35  	
36  	/**
37  	 * Preparation method
38  	 */
39  	public abstract void onEntry(ChannelBuffer buffer, IcapMessageDecoder icapMessageDecoder) throws DecodingException;
40  	
41  	/**
42  	 * execution method
43  	 * @return @see {@link StateReturnValue} that contains, dependent on the relevance a return value.
44  	 */
45  	public abstract StateReturnValue execute(ChannelBuffer buffer, IcapMessageDecoder icapMessageDecoder) throws DecodingException;
46  	
47  	/**
48  	 * Flow decision method
49  	 * @return has to return a valid next state. Can be itself.
50  	 */
51  	public abstract StateEnum onExit(ChannelBuffer buffer, IcapMessageDecoder icapMessageDecoder, T decisionInformation) throws DecodingException;
52  
53  	public String toString() {
54  		return name;
55  	}
56  }