01: package org.databene.benerator.wrapper;
02:
03: import org.databene.benerator.Generator;
04: import org.databene.id.IdProvider;
05:
06: public class IdGenerator<E> implements Generator<E> {
07:
08: private IdProvider<E> source;
09:
10: public IdGenerator(IdProvider<E> source) {
11: this .source = source;
12: }
13:
14: // properties ------------------------------------------------------------------------------------------------------
15:
16: /**
17: * @return the source
18: */
19: public IdProvider<E> getSource() {
20: return source;
21: }
22:
23: /**
24: * @param source the source to set
25: */
26: public void setSource(IdProvider<E> source) {
27: this .source = source;
28: }
29:
30: // Generator interface ---------------------------------------------------------------------------------------------
31:
32: public Class<E> getGeneratedType() {
33: return source.getType();
34: }
35:
36: public void validate() {
37: if (source == null)
38: throw new IllegalArgumentException("source is null");
39: }
40:
41: public boolean available() {
42: return source.hasNext();
43: }
44:
45: public void close() {
46: source.close();
47: }
48:
49: public E generate() {
50: return source.next();
51: }
52:
53: public void reset() {
54: // ignored
55: }
56:
57: }
|