1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.archive.uid;
24
25 import java.net.URI;
26 import java.net.URISyntaxException;
27 import java.util.Map;
28
29 /***
30 * Factory that generates uids.
31 * Singleton. Default implementation is {@link UUIDGenerator}. To
32 * change, specify alternate implementation of {@link Generator} with
33 * {@link #SYSTEM_PROPERTY_GENERATOR_KEY} system property.
34 * @author stack
35 * @version $Revision: 4417 $ $Date: 2006-08-02 01:12:00 +0000 (Wed, 02 Aug 2006) $
36 */
37 public class GeneratorFactory implements Generator {
38 public final String SYSTEM_PROPERTY_GENERATOR_KEY =
39 this.getClass().toString() + ".generator";
40 private static final String DEFAULT_GENERATOR =
41 "org.archive.uid.UUIDGenerator";
42 private static final GeneratorFactory factory = new GeneratorFactory();
43 private final Generator generator;
44
45 private GeneratorFactory() {
46 super();
47 String className = System.getProperty(SYSTEM_PROPERTY_GENERATOR_KEY,
48 DEFAULT_GENERATOR);
49 Generator ridg = null;
50 try {
51 Class c = Class.forName(className);
52 ridg = (Generator) c.newInstance();
53 } catch (Exception e) {
54 e.printStackTrace();
55 }
56 this.generator = ridg;
57 }
58
59 public URI getRecordID() throws URISyntaxException {
60 return this.generator.getRecordID();
61 }
62
63 public URI getQualifiedRecordID(Map<String, String> qualifiers)
64 throws URISyntaxException {
65 return this.generator.getQualifiedRecordID(qualifiers);
66 }
67
68 public URI getQualifiedRecordID(String key, String value)
69 throws URISyntaxException {
70 return this.generator.getQualifiedRecordID(key, value);
71 }
72
73 public URI qualifyRecordID(final URI uri,
74 final Map<String, String> qualifiers)
75 throws URISyntaxException {
76 return this.generator.qualifyRecordID(uri, qualifiers);
77 }
78
79 public static GeneratorFactory getFactory() {
80 return factory;
81 }
82 }