1 23 package org.archive.uid; 24 25 import java.net.URI ; 26 import java.net.URISyntaxException ; 27 import java.util.Map ; 28 29 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 } 83 | Popular Tags |