View Javadoc

1   /*
2    * Copyright 2001-2005 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.sf.nxqd.xmldb;
17  
18  import java.io.File;
19  import java.io.StringReader;
20  import java.util.Iterator;
21  import java.util.List;
22  import java.util.Properties;
23  import java.util.Enumeration;
24  import java.util.logging.Level;
25  import java.util.logging.Logger;
26  
27  import org.xmldb.api.base.Collection;
28  import org.xmldb.api.base.Service;
29  import org.xmldb.api.base.Configurable;
30  import org.xmldb.api.base.XMLDBException;
31  
32  /**
33   * The class <code>NxqdService</code> is an abstract class from which all
34   * Xml:DB services are derived.
35   *
36   * @author <a href="mailto:webhiker@sourceforge.net">webhiker</a>
37   * @version 1.0
38   */
39  public class NxqdService implements Configurable, Service {
40      private static Logger logger        = Logger.getLogger(NxqdService.class.getName());
41      public static final String NAME    = "nxqd.service.name";
42      public static final String VERSION = "nxqd.service.version";
43      private Collection col;
44      private Properties properties;
45  
46      /**
47       *  
48       */
49      public NxqdService(String name, String version) {
50  	properties = new Properties();
51  	setProperty(NAME, name);
52  	setProperty(VERSION, version);
53      }
54  
55      /**
56       * @see org.xmldb.api.base.Service#getName()
57       */
58      public final String getName() {
59  	return getProperty(NAME);
60      }
61  
62      /**
63       * @see org.xmldb.api.base.Service#getVersion()
64       */
65      public final String getVersion() {
66  	return getProperty(VERSION);
67      }
68  
69  
70      /**
71       * @see org.xmldb.api.base.Service#setCollection(org.xmldb.api.base.Collection)
72       */
73      public void setCollection(Collection col) throws XMLDBException {
74          this.col = col;
75      }
76  
77      /**
78       * The <code>getCollection</code> method returns the <code>Collection</code>
79       * associated with this service.
80       *
81       * @return a <code>Collection</code> value
82       * @exception XMLDBException if an error occurs
83       */
84      protected Collection getCollection() throws XMLDBException {
85          return this.col;
86      }
87  
88  
89      /**
90       * @see org.xmldb.api.base.Configurable#getProperty(java.lang.String)
91       */
92      public synchronized String getProperty(String name) {
93          return properties.getProperty(name);
94      }
95  
96      /**
97       * @see org.xmldb.api.base.Configurable#setProperty(java.lang.String,
98       *      java.lang.String)
99       */
100     public synchronized void setProperty(String name, String value) {
101 	properties.setProperty(name, value);
102     }
103 
104     /**
105      * @see java.util.Map#remove(java.lang.Object)
106      *
107      * @param name a <code>String</code> value
108      */
109     public synchronized void removeProperty(String name) {
110 	properties.remove(name);
111     }
112 
113 
114     /**
115      * @see java.util.Hashtable#keys()
116      *
117      */
118     public synchronized Enumeration keys() {
119 	return properties.keys();
120     }
121 
122 }