KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thaiopensource > relaxng > impl > BuiltinDatatypeLibraryFactory


1 package com.thaiopensource.relaxng.impl;
2
3 import org.relaxng.datatype.DatatypeLibrary;
4 import org.relaxng.datatype.DatatypeLibraryFactory;
5
6 import java.util.Hashtable JavaDoc;
7
8 import com.thaiopensource.xml.util.WellKnownNamespaces;
9
10 class BuiltinDatatypeLibraryFactory implements DatatypeLibraryFactory {
11   private final Hashtable JavaDoc cache = new Hashtable JavaDoc();
12   private final DatatypeLibraryFactory factory;
13   private final DatatypeLibrary builtinDatatypeLibrary
14     = new BuiltinDatatypeLibrary();
15   private DatatypeLibrary lastDatatypeLibrary = null;
16   private String JavaDoc lastDatatypeLibraryUri = null;
17
18   BuiltinDatatypeLibraryFactory(DatatypeLibraryFactory factory) {
19     this.factory = factory;
20     cache.put(WellKnownNamespaces.RELAX_NG_COMPATIBILITY_DATATYPES,
21               new CompatibilityDatatypeLibrary(this));
22   }
23
24   public DatatypeLibrary createDatatypeLibrary(String JavaDoc uri) {
25     if (uri.equals(""))
26       return builtinDatatypeLibrary;
27     if (uri.equals(lastDatatypeLibraryUri))
28       return lastDatatypeLibrary;
29     DatatypeLibrary library = (DatatypeLibrary)cache.get(uri);
30     if (library == null) {
31       if (factory == null)
32     return null;
33       library = factory.createDatatypeLibrary(uri);
34       if (library == null)
35     return null;
36       cache.put(uri, library);
37     }
38     lastDatatypeLibraryUri = uri;
39     return lastDatatypeLibrary = library;
40   }
41 }
42
Popular Tags