View Javadoc
1   /*
2    * ListDatabase.java
3    *
4    * Created on December 20, 2004, 3:35 PM
5    */
6   
7   package gov.noaa.eds.xapi.generic;
8   
9   import java.util.Hashtable;
10  import org.xmldb.api.base.Collection;
11  import org.xmldb.api.base.Database;
12  import org.xmldb.api.base.ErrorCodes;
13  import org.xmldb.api.base.XMLDBException;
14  
15  /***
16   * An implementation of an XAPI Database, when the database is just
17   * a collection of XAPI Collection objects.
18   * @author tns
19   * @version $Id: GenericDatabase.java,v 1.2 2004/12/23 22:26:01 mrxtravis Exp $
20   */
21  public class GenericDatabase extends GenericConfigurable implements Database {
22      
23      private Hashtable collections = new Hashtable();
24      
25      private String conformanceLevel = "Core Level 1";
26      
27      /*** Creates a new instance of ListDatabase */
28      public GenericDatabase() {
29      }
30      
31      /***Add a Collection to the list of collections.  If a collection is added
32       * that has the same name as another collection, the old one is replaced.
33       *@param collection A collection to add.
34       */
35      public void addCollection(Collection collection) throws XMLDBException {
36          String name = collection.getName();
37          if (name == null){
38              throw new NullPointerException("Collection's name property must be set.");
39          }
40          this.collections.put(collection.getName(),collection);
41      }
42  
43      /***Checks the list of collections and determines if one of
44       *them is named with the specified uri.
45       *@param uri The uri to check if a collection exists
46       */
47      public boolean acceptsURI(String uri) {
48          return collections.containsKey(uri);
49      }
50  
51      /***Returns null, use getNames
52       *@depricate
53       */
54      public String getName() {
55          return null;
56      }
57      
58      /***Returns the known collections
59       *@return The known collection names
60       */
61      public String[] getNames(){
62          return (String[]) collections.keySet().toArray(new String[0]);
63      }
64  
65      /*** Returns the conformance level.  The default is "Core Level 1.0".
66       *@return The conformance level
67       */
68      public String getConformanceLevel() {
69          return this.conformanceLevel;
70      }
71      
72      /***Sets the conformance level as specified at {@link http://xmldb-org.sourceforge.net/xapi/" target="alexandria_uri">http://xmldb-org.sourceforge.net/xapi/}.
73       *The default is set to Core Level 0.
74       *
75       *@param conformanceLevel
76       */
77      public void setConformanceLevel(String conformanceLevel){
78          this.conformanceLevel = conformanceLevel;
79      }
80  
81      /***Returns a collection with the specified uri
82       *@param uri The uri of the collection
83       *@param userName The user name to use for permissions
84       *@param password The user name to use for permissions
85       */
86      public Collection getCollection(String uri, String userName, String password) throws XMLDBException {
87          Collection col = (Collection) collections.get(uri);
88          if (col == null){
89              throw new XMLDBException (ErrorCodes.INVALID_COLLECTION);
90          }
91          return col;
92      }
93      
94  }