View Javadoc

1   /**
2   The contents of this file are subject to the Mozilla Public License Version 1.1 
3   (the "License"); you may not use this file except in compliance with the License. 
4   You may obtain a copy of the License at http://www.mozilla.org/MPL/ 
5   Software distributed under the License is distributed on an "AS IS" basis, 
6   WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the 
7   specific language governing rights and limitations under the License. 
8   
9   The Original Code is "IDGenerator.java".  Description: 
10  "Interface providing methods for generating message IDs" 
11  
12  The Initial Developer of the Original Code is University Health Network. Copyright (C) 
13  2001.  All Rights Reserved. 
14  
15  Contributor(s): ______________________________________. 
16  
17  Alternatively, the contents of this file may be used under the terms of the 
18  GNU General Public License (the  "GPL"), in which case the provisions of the GPL are 
19  applicable instead of those above.  If you wish to allow use of your version of this 
20  file only under the terms of the GPL and not to allow others to use your version 
21  of this file under the MPL, indicate your decision by deleting  the provisions above 
22  and replace  them with the notice and other provisions required by the GPL License.  
23  If you do not delete the provisions above, a recipient may use your version of 
24  this file under either the MPL or the GPL. 
25   */
26  package ca.uhn.hl7v2.util.idgenerator;
27  
28  import java.io.IOException;
29  
30  /**
31   * MessageID generator interface. This is a replacement for the legacy
32   * MessageIDGenerator class, which should not be used anymore.
33   * <p>
34   * An instance implementing this interface can be configured by setting the
35   * property in the {@link ca.uhn.hl7v2.parser.ParserConfiguration} class and
36   * will then be used to generate IDs for all messages created by HAPI. The
37   * default implementation is {@link FileBasedHiLoGenerator}.
38   * <p>
39   * HAPI does not provide ID generators that depend on external resources (except
40   * for files). Implementors are encouraged to add their own classes
41   * (implementing {@link IDGenerator.Ordered}, e.g. based on database tables
42   * or sequences, and use it as delegate in {@link DelegatingHiLoGenerator}.
43   * 
44   * @see DelegatingHiLoGenerator
45   * @see FileBasedHiLoGenerator
46   * 
47   * @author Christian Ohr
48   */
49  public interface IDGenerator {
50  
51  	/**
52  	 * Generates and returns a new ID. Note: This method must be implemented to
53  	 * be thread-safe.
54  	 * 
55  	 * @return a new ID.
56  	 * 
57  	 * @throws IOException
58  	 */
59  	String getID() throws IOException;
60  
61  	/**
62  	 * Extension for continuous ID sequences
63  	 */
64  	public interface Ordered extends IDGenerator {
65  
66  		void reset();
67  		int getIncrement();
68  
69  	}
70  
71  	/**
72  	 * Ordered ID sequences with a configurable increment
73  	 */
74  	public abstract class OrderedSupport implements Ordered {
75  
76  		private int increment = 1;
77  
78  		OrderedSupport(int increment) {
79  			super();
80  			this.increment = increment;
81  		}
82  
83  		public OrderedSupport() {
84  			this(1);
85  		}
86  
87  		public void reset() {
88  		}
89  
90  		public int getIncrement() {
91  			return increment;
92  		}
93  
94  	}
95  
96  }