1
2
3
4
5
6
7 package gov.noaa.gdsg.xmldbremote.xmldbClient;
8
9 import org.xmldb.api.base.Collection;
10
11
12 /***
13 * This class wraps the SOAP calls into the XML:DB Database API.
14 *
15 * @author tns
16 * @version $Id: XmldbClientCollection.java,v 1.2 2004/11/03 23:52:39 mrxtravis Exp $
17 */
18 public class XmldbClientCollection implements Collection {
19
20 private gov.noaa.gdsg.xmldbremote.Collection collectionTransport = null;
21 private gov.noaa.gdsg.xmldbremote.NmmrdbSoapBindingStub stub = null;
22
23 /***
24 * Creates a new instance of Collection
25 * @param collectionTransport The transport object used to identify the remote object.
26 * @param stub The stub used to call the remote method.
27 */
28 public XmldbClientCollection(gov.noaa.gdsg.xmldbremote.Collection collectionTransport,
29 gov.noaa.gdsg.xmldbremote.NmmrdbSoapBindingStub stub) {
30 if (collectionTransport == null){
31 throw new NullPointerException("Parameter collectionTransport cannot be null when instantiating XmldbClientCollection");
32 }
33 if (stub == null){
34 throw new NullPointerException("Parameter stub can not be null when instantiating XmldbClientCollection");
35 }
36 this.collectionTransport = collectionTransport;
37 this.stub = stub;
38 }
39
40 /***Closes the this collection and releases the resources.
41 * @throws org.xmldb.api.base.XMLDBException All exception are caught and rethrown as one.
42 */
43 public void close() throws org.xmldb.api.base.XMLDBException {
44 try {
45 this.stub.close(this.collectionTransport);
46 } catch (java.rmi.RemoteException e){
47 throw new org.xmldb.api.base.XMLDBException(org.xmldb.api.base.ErrorCodes.VENDOR_ERROR, e);
48 }
49 }
50
51 /***Creates a new ID which is used to create a resource.
52 * @return The created ID.
53 * @throws org.xmldb.api.base.XMLDBException All exception are caught and rethrown as one.
54 *
55 */
56 public String createId() throws org.xmldb.api.base.XMLDBException {
57 try {
58 return this.stub.createId(this.collectionTransport);
59 } catch (java.rmi.RemoteException e){
60 throw new org.xmldb.api.base.XMLDBException(org.xmldb.api.base.ErrorCodes.VENDOR_ERROR, e);
61 }
62
63 }
64
65 /***
66 * Creates a new empty resource with the given id
67 * @param id The id of the new resource
68 * @param type The type of resource to create
69 * @throws org.xmldb.api.base.XMLDBException All exception are caught and rethrown as one.
70 * @return A fresh new resource.
71 */
72 public org.xmldb.api.base.Resource createResource(String id, String type) throws org.xmldb.api.base.XMLDBException {
73 try {
74 gov.noaa.gdsg.xmldbremote.Resource resourceTransport =
75 this.stub.createResource(this.collectionTransport, id, type);
76
77 if (type.equals("XMLResource")){
78 return new XmldbClientXMLResource(resourceTransport, stub, this);
79 }
80 else {
81 throw new org.xmldb.api.base.XMLDBException( org.xmldb.api.base.ErrorCodes.NOT_IMPLEMENTED,"BinaryResource not implemented");
82 }
83 } catch (java.rmi.RemoteException e){
84 throw new org.xmldb.api.base.XMLDBException(org.xmldb.api.base.ErrorCodes.VENDOR_ERROR, e);
85 }
86
87 }
88
89 /***
90 * Return the child collection by name
91 * @param name The name of the child collection
92 * @throws org.xmldb.api.base.XMLDBException All exception are caught and rethrown as one.
93 * @return The specified child collection.
94 */
95 public org.xmldb.api.base.Collection getChildCollection(String name) throws org.xmldb.api.base.XMLDBException {
96 try {
97 gov.noaa.gdsg.xmldbremote.Collection collectionTransport =
98 this.stub.getChildCollection(this.collectionTransport, name);
99 return new XmldbClientCollection(collectionTransport, stub);
100 } catch (java.rmi.RemoteException e){
101 throw new org.xmldb.api.base.XMLDBException(org.xmldb.api.base.ErrorCodes.VENDOR_ERROR, e);
102 }
103
104 }
105
106 /*** Returns the number of child collections.
107 * @return The number of child collections.
108 * @throws org.xmldb.api.base.XMLDBException All exception are caught and rethrown as one.
109 */
110 public int getChildCollectionCount() throws org.xmldb.api.base.XMLDBException {
111 try {
112 return this.stub.getChildCollectionCount(this.collectionTransport);
113 } catch (java.rmi.RemoteException e){
114 throw new org.xmldb.api.base.XMLDBException(org.xmldb.api.base.ErrorCodes.VENDOR_ERROR, e);
115 }
116
117 }
118
119 /***Returns the name of this collection
120 * @return The name.
121 * @throws org.xmldb.api.base.XMLDBException All exception are caught and rethrown as one.
122 */
123 public String getName() throws org.xmldb.api.base.XMLDBException {
124 return this.collectionTransport.getName();
125 }
126
127 /***Returns the parent collection associated with this collection
128 * @return The parent Collection.
129 * @throws org.xmldb.api.base.XMLDBException All exception are caught and rethrown as one.
130 */
131 public org.xmldb.api.base.Collection getParentCollection() throws org.xmldb.api.base.XMLDBException {
132 try {
133 gov.noaa.gdsg.xmldbremote.Collection collectionTransport = this.stub.getParentCollection(this.collectionTransport);
134 return new XmldbClientCollection(collectionTransport,stub);
135 } catch (java.rmi.RemoteException e){
136 throw new org.xmldb.api.base.XMLDBException(org.xmldb.api.base.ErrorCodes.VENDOR_ERROR, e);
137 }
138 }
139
140 /***
141 * Throws a NOT_IMPLEMETED exception.
142 * @param str Ignored.
143 * @throws org.xmldb.api.base.XMLDBException with {@link ErrorCodes.NOT_IMPLEMENTED}.
144 * @return Nothing, ever.
145 */
146 public String getProperty(String str) throws org.xmldb.api.base.XMLDBException {
147 throw new org.xmldb.api.base.XMLDBException(
148 org.xmldb.api.base.ErrorCodes.NOT_IMPLEMENTED,"getProperty Not " +
149 "implemented in the gov.noaa.gdsg.xmldbremote.xmldbClient.XmldbClientCollection class.");
150 }
151
152 /***
153 * Returns the resource Idenitifed by the specified string.
154 * @return The requested Resource.
155 * @param id The id of the resource to find.
156 * @throws org.xmldb.api.base.XMLDBException All exception are caught and rethrown as one.
157 */
158 public org.xmldb.api.base.Resource getResource(String id) throws org.xmldb.api.base.XMLDBException {
159 try {
160 gov.noaa.gdsg.xmldbremote.Resource resourceTransport =
161 this.stub.getResource(this.collectionTransport, id);
162 return new XmldbClientXMLResource(resourceTransport, this.stub, this);
163 } catch (java.rmi.RemoteException e){
164 throw new org.xmldb.api.base.XMLDBException(org.xmldb.api.base.ErrorCodes.VENDOR_ERROR, e);
165 }
166
167 }
168
169 /***Returns the number of resource in this record set
170 * @return int
171 * @throws org.xmldb.api.base.XMLDBException All exception are caught and rethrown as one.
172 */
173 public int getResourceCount() throws org.xmldb.api.base.XMLDBException {
174 try {
175 return this.stub.getResourceCount(this.collectionTransport);
176 } catch (java.rmi.RemoteException e){
177 throw new org.xmldb.api.base.XMLDBException(org.xmldb.api.base.ErrorCodes.VENDOR_ERROR, e);
178 }
179
180 }
181
182 /***Returns the specified service.
183 * @throws org.xmldb.api.base.XMLDBException All exception are caught and rethrown as one.
184 * @return The specified Service.
185 * @param name The name of the Service
186 * @param version The Service version
187 */
188 public org.xmldb.api.base.Service getService(String name, String version) throws org.xmldb.api.base.XMLDBException {
189 try {
190 gov.noaa.gdsg.xmldbremote.Service service =
191 this.stub.getService(this.collectionTransport,name, version);
192 if (service.getName().equals("XPathQueryService")){
193 return new XmldbClientXPathQueryService(service, stub,this);
194 }
195 else {
196 throw new org.xmldb.api.base.XMLDBException(org.xmldb.api.base.ErrorCodes.NO_SUCH_SERVICE,
197 "XMLDB Remote classes have not implemented this type of class");
198 }
199 } catch (java.rmi.RemoteException e){
200 throw new org.xmldb.api.base.XMLDBException(org.xmldb.api.base.ErrorCodes.VENDOR_ERROR, e);
201 }
202
203
204 }
205
206 /***Returns all know services associated with this collection.
207 *@return All known services
208 * @throws org.xmldb.api.base.XMLDBException All exception are caught and rethrown as one.
209 */
210 public org.xmldb.api.base.Service[] getServices() throws org.xmldb.api.base.XMLDBException {
211 try {
212 gov.noaa.gdsg.xmldbremote.Service[] services =
213 this.stub.getServices(this.collectionTransport);
214
215 XmldbClientService[] clientServices = new XmldbClientService[services.length];
216 for (int i = 0; i < services.length; i++){
217 if (services[i].getName().equals("XPathQueryService")){
218 clientServices[i] = new XmldbClientXPathQueryService(services[i], this.stub, this);
219 }
220 }
221 return clientServices;
222 } catch (java.rmi.RemoteException e){
223 throw new org.xmldb.api.base.XMLDBException(org.xmldb.api.base.ErrorCodes.VENDOR_ERROR, e);
224 }
225
226 }
227
228 /***Determines if this collection is open.
229 *@return true if the collection connection is open, false otherwise.
230 * @throws org.xmldb.api.base.XMLDBException All exception are caught and rethrown as one.
231 *
232 */
233 public boolean isOpen() throws org.xmldb.api.base.XMLDBException {
234 try {
235 return this.stub.isOpen(this.collectionTransport);
236 } catch (java.rmi.RemoteException e){
237 throw new org.xmldb.api.base.XMLDBException(org.xmldb.api.base.ErrorCodes.VENDOR_ERROR, e);
238 }
239
240 }
241
242 /***Returns a list of child collections
243 * @return The list of child collections
244 * @throws org.xmldb.api.base.XMLDBException All exception are caught and rethrown as one.
245 *
246 */
247 public String[] listChildCollections() throws org.xmldb.api.base.XMLDBException {
248 try {
249 return this.stub.listChildCollections(this.collectionTransport);
250 } catch (java.rmi.RemoteException e){
251 throw new org.xmldb.api.base.XMLDBException(org.xmldb.api.base.ErrorCodes.VENDOR_ERROR, e);
252 }
253
254 }
255
256 /***
257 * Lists all resources associated with this collection.
258 * @throws org.xmldb.api.base.XMLDBException All exception are caught and rethrown as one.
259 * @return A list of resources ids.
260 */
261 public String[] listResources() throws org.xmldb.api.base.XMLDBException {
262 try {
263 return this.stub.listResources(this.collectionTransport);
264 } catch (java.rmi.RemoteException e){
265 throw new org.xmldb.api.base.XMLDBException(org.xmldb.api.base.ErrorCodes.VENDOR_ERROR, e);
266 }
267
268 }
269
270 /***Removes the specified resource from this collection.
271 * @throws org.xmldb.api.base.XMLDBException All exception are caught and rethrown as one.
272 * @param resource The resource to remove.
273 */
274 public void removeResource(org.xmldb.api.base.Resource resource) throws org.xmldb.api.base.XMLDBException {
275 if (! (resource instanceof XmldbClientResource)){
276 throw new IllegalStateException("Resouce must be of type gov.noaa.gdsg.xmldbremote.xmldbClient.XmldbClientResource");
277 }
278
279 if (resource instanceof XmldbClientXMLResource){
280 try {
281 XmldbClientXMLResource clientResource = (XmldbClientXMLResource) resource;
282 gov.noaa.gdsg.xmldbremote.Resource resourceTransport = clientResource.getResourceTransport();
283 stub.removeResource(this.collectionTransport,resourceTransport);
284 } catch (java.rmi.RemoteException e){
285 throw new org.xmldb.api.base.XMLDBException(org.xmldb.api.base.ErrorCodes.VENDOR_ERROR, e.toString());
286 }
287 }
288 else {
289 throw new UnsupportedOperationException();
290 }
291 }
292
293 /***Throws a NOT_IMPLEMENTED exception.
294 * @throws org.xmldb.api.base.XMLDBException as ErrorCodes.NOT_IMPLEMENTED
295 * @param str Ignored
296 * @param str1 Ignored.
297 */
298 public void setProperty(String str, String str1) throws org.xmldb.api.base.XMLDBException {
299 throw new org.xmldb.api.base.XMLDBException(
300 org.xmldb.api.base.ErrorCodes.NOT_IMPLEMENTED);
301 }
302
303 /***Stores the specified resource in this collection.
304 * @throws org.xmldb.api.base.XMLDBException All exception are caught and rethrown as one.
305 * @param resource The resource to store.
306 */
307 public void storeResource(org.xmldb.api.base.Resource resource) throws org.xmldb.api.base.XMLDBException {
308 if (! (resource instanceof XmldbClientResource)){
309 throw new org.xmldb.api.base.XMLDBException(org.xmldb.api.base.ErrorCodes.UNKNOWN_RESOURCE_TYPE,
310 "Resouce must be of type XmldbClientResource");
311 }
312
313 XmldbClientResource clientResource = (XmldbClientResource) resource;
314
315 if (clientResource instanceof XmldbClientXMLResource){
316 XmldbClientXMLResource xResource = (XmldbClientXMLResource) clientResource;
317 xResource.syncDomWithService();
318 }
319
320 try {
321 gov.noaa.gdsg.xmldbremote.Resource resourceTransport = clientResource.getResourceTransport();
322
323 this.stub.storeResource(this.collectionTransport,resourceTransport);
324 } catch (java.rmi.RemoteException e){
325 throw new org.xmldb.api.base.XMLDBException(org.xmldb.api.base.ErrorCodes.VENDOR_ERROR, e);
326 }
327 }
328
329 /***Returns the collection transport object associated with this Collection
330 *@return The collection transport object
331 */
332 public gov.noaa.gdsg.xmldbremote.Collection getCollectionTransport(){
333 return this.collectionTransport;
334 }
335
336 }