1
2
3
4
5
6
7 package gov.noaa.gdsg.xmldbremote.xmldbClient;
8
9 import org.xmldb.api.base.Database;
10
11 import java.net.URL;
12 import org.apache.axis.client.Service;
13 import org.apache.axis.AxisProperties;
14 import gov.noaa.gdsg.xmldbremote.NmmrdbSoapBindingStub;
15 import javax.xml.namespace.QName;
16
17
18 import gov.noaa.gdsg.xmldbremote.Collection;
19
20 /***
21 * This is an XML:DB Database API implementation which uses a SOAP stub
22 * to make remote calls.
23 *
24 * @author tns
25 * @version $Id: XmldbClientDatabase.java,v 1.3 2004/12/29 01:08:05 mrxtravis Exp $
26 */
27 public class XmldbClientDatabase implements Database {
28
29 private NmmrdbSoapBindingStub stub = null;
30
31 /*** Holds value of property endPointUrl. */
32 private String endPointUrl;
33
34 /*** Holds value of property service. */
35 private Service service;
36
37 /*** Holds value of property remoteDatabaseUri. */
38 private String remoteDatabaseUri;
39
40 public static Database newDefaultDatabase() throws org.xmldb.api.base.XMLDBException {
41
42 java.io.InputStream configuration = XmldbClientDatabase.class.getResourceAsStream("/databaseConfiguration.properties");
43 if (configuration == null){
44 throw new NullPointerException("Web service endpoint could not be determined.");
45 }
46 java.util.Properties prop = new java.util.Properties();
47 try {
48 prop.load(configuration);
49 } catch (java.io.IOException e){
50 throw new org.xmldb.api.base.XMLDBException( org.xmldb.api.base.ErrorCodes.VENDOR_ERROR,e.getMessage());
51 }
52 String endpointUrl = prop.getProperty("endPointUrl");
53 if (endpointUrl == null){
54 throw new NullPointerException("Property 'endPointUrl' not found in configuration file.");
55 }
56
57
58 java.util.Enumeration names = prop.propertyNames();
59 while (names.hasMoreElements()){
60 String name = (String) names.nextElement();
61 if (name.startsWith("axis.")){
62
63 AxisProperties.setProperty(name,prop.getProperty(name));
64 }
65 }
66
67 XmldbClientDatabase database = new XmldbClientDatabase();
68 database.setEndPointUrl(endpointUrl);
69 database.init();
70 return database;
71
72 }
73
74 public static Database newDatabase(String endpointUrl) throws org.xmldb.api.base.XMLDBException {
75 XmldbClientDatabase database = new XmldbClientDatabase();
76 database.setEndPointUrl(endpointUrl);
77 database.init();
78 return database;
79
80 }
81
82 /*** Creates a new instance of XmldbClientDatabase */
83 public XmldbClientDatabase() {
84 }
85
86 private void createService() throws org.xmldb.api.base.XMLDBException {
87 this.service = new Service();
88 this.service.setMaintainSession(true);
89 }
90
91 /***Initializes the datbase
92 * @throws org.xmldb.api.base.XMLDBException All exception are caught and rethrown as one.
93 */
94 public void init() throws org.xmldb.api.base.XMLDBException {
95 if (endPointUrl == null){
96 throw new IllegalStateException("Cannot initialize XmldbClientDatabase"
97 + " when the endPointUrl property has not been initialized");
98 }
99
100 try {
101
102 stub = new NmmrdbSoapBindingStub(new URL(endPointUrl), this.service);
103 stub.setMaintainSession(true);
104 } catch (org.apache.axis.AxisFault e){
105 throw new org.xmldb.api.base.XMLDBException(org.xmldb.api.base.ErrorCodes.VENDOR_ERROR, e);
106 } catch (java.net.MalformedURLException e){
107 throw new org.xmldb.api.base.XMLDBException(org.xmldb.api.base.ErrorCodes.VENDOR_ERROR, e);
108 }
109 }
110
111 /***
112 * Determines if this Database accepts the specified URI
113 * @param uri The URI to check.
114 * @throws org.xmldb.api.base.XMLDBException All exceptions are rethrown as one.
115 * @return true if accepted, false otherwise.
116 */
117 public boolean acceptsURI(String uri) throws org.xmldb.api.base.XMLDBException {
118 try {
119 return stub.acceptsURI(uri);
120 } catch (java.rmi.RemoteException e){
121 throw new org.xmldb.api.base.XMLDBException(org.xmldb.api.base.ErrorCodes.VENDOR_ERROR, e);
122 }
123 }
124
125 /***
126 * Returns the specified collection.
127 * @param uri The uri identifying the collection
128 * @param password The password associated with the user
129 * @param userName The user name
130 * @throws org.xmldb.api.base.XMLDBException All exceptions are rethrown as one.
131 * @return The specified collection.
132 */
133 public org.xmldb.api.base.Collection getCollection(String uri, String userName, String password) throws org.xmldb.api.base.XMLDBException {
134 try {
135 Collection collection = stub.getCollection(uri, userName, password);
136 return new XmldbClientCollection(collection, this.stub);
137 } catch (java.rmi.RemoteException e){
138 throw new org.xmldb.api.base.XMLDBException(org.xmldb.api.base.ErrorCodes.VENDOR_ERROR, e);
139 }
140 }
141
142 /*** Returns the conformance level of the remote database interface.
143 * @return The conformance level
144 *@throws org.xmldb.api.base.XMLDBException All exceptions are rethrown as one.
145 */
146 public String getConformanceLevel() throws org.xmldb.api.base.XMLDBException {
147 try {
148 return stub.getConformanceLevel();
149 } catch (java.rmi.RemoteException e){
150 throw new org.xmldb.api.base.XMLDBException(org.xmldb.api.base.ErrorCodes.VENDOR_ERROR, e);
151 }
152 }
153
154 /***Returns The name.
155 *@deprecated Use {@link #getNames}.
156 *@return A string
157 *@throws org.xmldb.api.base.XMLDBException All exceptions are rethrown as one.
158 */
159 public String getName() throws org.xmldb.api.base.XMLDBException {
160 try {
161 return stub.getName();
162 } catch (java.rmi.RemoteException e){
163 throw new org.xmldb.api.base.XMLDBException(org.xmldb.api.base.ErrorCodes.VENDOR_ERROR, e);
164 }
165 }
166
167 /*** Throws an exceptioin as ErrorCodes.NOT_IMPLEMENTED.
168 *@param str Ignored
169 *@return Nothing, ever.
170 *@throws org.xmldb.api.base.XMLDBException Always with ErrorCodes.NOT_IMPLEMENTED
171 */
172 public String getProperty(String str) throws org.xmldb.api.base.XMLDBException {
173 throw new org.xmldb.api.base.XMLDBException(
174 org.xmldb.api.base.ErrorCodes.NOT_IMPLEMENTED);
175 }
176
177 /*** Throws an exceptioin as ErrorCodes.NOT_IMPLEMENTED.
178 *@param str Ignored
179 *@param str1 Ignored
180 *@throws org.xmldb.api.base.XMLDBException Always with ErrorCodes.NOT_IMPLEMENTED
181 */
182 public void setProperty(String str, String str1) throws org.xmldb.api.base.XMLDBException {
183 throw new UnsupportedOperationException();
184 }
185
186 /*** Getter for property endPointUrl.
187 * @return Value of property endPointUrl.
188 *
189 */
190 public String getEndPointUrl() {
191 return this.endPointUrl;
192 }
193
194 /*** Setter for property endPointUrl.
195 * @param endPointUrl New value of property endPointUrl.
196 *
197 */
198 public void setEndPointUrl(String endPointUrl) {
199 this.endPointUrl = endPointUrl;
200 }
201
202 /*** Getter for property service.
203 * @return Value of property service.
204 *
205 */
206 public Service getService() {
207 return this.service;
208 }
209
210 /*** Setter for property service.
211 * @param service New value of property service.
212 *
213 */
214 public void setService(Service service) {
215 this.service = service;
216 }
217
218 /*** Getter for property databaseUri.
219 * @return Value of property databaseUri.
220 *
221 */
222 public String getRemoteDatabaseUri() {
223 return this.remoteDatabaseUri;
224 }
225
226 /***
227 * Setter for property databaseUri.
228 * @param remoteDatabaseUri New value of property databaseUri.
229 */
230 public void setRemoteDatabaseUri(String remoteDatabaseUri) {
231 this.remoteDatabaseUri = remoteDatabaseUri;
232 }
233 }