KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > archive > uid > GeneratorFactory


1 /* $Id: GeneratorFactory.java,v 1.1 2006/08/02 01:12:00 stack-sf Exp $
2  *
3  * Created on July 27th, 2006
4  *
5  * Copyright (C) 2006 Internet Archive.
6  *
7  * This file is part of the Heritrix web crawler (crawler.archive.org).
8  *
9  * Heritrix is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU Lesser Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * any later version.
13  *
14  * Heritrix is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Lesser Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser Public License
20  * along with Heritrix; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */

23 package org.archive.uid;
24
25 import java.net.URI JavaDoc;
26 import java.net.URISyntaxException JavaDoc;
27 import java.util.Map JavaDoc;
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: 1.1 $ $Date: 2006/08/02 01:12:00 $
36  */

37 public class GeneratorFactory implements Generator {
38     public final String JavaDoc SYSTEM_PROPERTY_GENERATOR_KEY =
39         this.getClass().toString() + ".generator";
40     private static final String JavaDoc 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 JavaDoc className = System.getProperty(SYSTEM_PROPERTY_GENERATOR_KEY,
48             DEFAULT_GENERATOR);
49         Generator ridg = null;
50         try {
51             Class JavaDoc c = Class.forName(className);
52             ridg = (Generator) c.newInstance();
53         } catch (Exception JavaDoc e) {
54             e.printStackTrace();
55         }
56         this.generator = ridg;
57     }
58     
59     public URI JavaDoc getRecordID() throws URISyntaxException JavaDoc {
60         return this.generator.getRecordID();
61     }
62     
63     public URI JavaDoc getQualifiedRecordID(Map JavaDoc<String JavaDoc, String JavaDoc> qualifiers)
64     throws URISyntaxException JavaDoc {
65         return this.generator.getQualifiedRecordID(qualifiers);
66     }
67     
68     public URI JavaDoc getQualifiedRecordID(String JavaDoc key, String JavaDoc value)
69     throws URISyntaxException JavaDoc {
70         return this.generator.getQualifiedRecordID(key, value);
71     }
72     
73     public URI JavaDoc qualifyRecordID(final URI JavaDoc uri,
74             final Map JavaDoc<String JavaDoc, String JavaDoc> qualifiers)
75     throws URISyntaxException JavaDoc {
76         return this.generator.qualifyRecordID(uri, qualifiers);
77     }
78
79     public static GeneratorFactory getFactory() {
80         return factory;
81     }
82 }
83
Popular Tags