KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > betwixt > io > id > AbstractIDGenerator


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.betwixt.io.id;
17
18 import org.apache.commons.betwixt.io.IDGenerator;
19
20 /** <p>Abstract superclass for {@link IDGenerator} implementations.</p>
21   *
22   * <p>It implements the entire <code>IDGenerator</code> interface.
23   * When <code>nextId</code> is called,
24   * this class sets the <code>LastId</code> property (as well
25   * as returning the value).
26   * Subclasses should override {@link #nextIdImpl}.</p>
27   *
28   * @author <a HREF="mailto:rdonkin@apache.org">Robert Burrell Donkin</a>
29   * @version $Revision: 1.7 $
30   */

31 public abstract class AbstractIDGenerator implements IDGenerator {
32     
33     /** Last <code>ID</code> returned */
34     private String JavaDoc lastId = "0";
35     
36     /**
37      * Gets last <code>ID</code> returned.
38      *
39      * @return the last id created by the generated
40      */

41     public final String JavaDoc getLastId() {
42         return lastId;
43     }
44     
45     /**
46       * <p>Generate next <code>ID</code>.</p>
47       *
48       * <p>This method obtains the next <code>ID</code> from subclass
49       * and then uses this to set the <code>LastId</code> property.</p>
50       *
51       * @return the next id generated
52       */

53     public final String JavaDoc nextId() {
54         lastId = nextIdImpl();
55         return lastId;
56     }
57     
58     /**
59       * Subclasses should <strong>provide an implementation</strong> for this method.
60       * This implementation needs only provide the next <code>ID</code>
61       * value (according to it's algorithm).
62       * Setting the <code>LastId</code> property can be left to this class.
63       *
64       * @return the next id generated
65       */

66     protected abstract String JavaDoc nextIdImpl();
67 }
68
Popular Tags