View Javadoc
1   /*
2    * XmldbClientResourceSet.java
3    *
4    * Created on May 26, 2004, 3:19 PM
5    */
6   
7   package gov.noaa.gdsg.xmldbremote.xmldbClient;
8   
9   /***
10   * The client interface for the SOAP interface.
11   *
12   * @author  tns
13   * @version $Id: XmldbClientResourceSet.java,v 1.2 2004/11/03 23:52:39 mrxtravis Exp $
14   */
15  public class XmldbClientResourceSet implements org.xmldb.api.base.ResourceSet {
16      
17      private gov.noaa.gdsg.xmldbremote.ResourceSet resourceSet = null;
18      private gov.noaa.gdsg.xmldbremote.NmmrdbSoapBindingStub stub = null;
19      private gov.noaa.gdsg.xmldbremote.xmldbClient.XmldbClientCollection parentCollection = null;
20      
21      
22      /*** Creates a new instance of XmldbClientResourceSet
23       * @param resourceSet Represents the object on the remote server.
24       * @param stub used to make remote calls.
25       * @param parentCollection The collection this resource set is associated with.
26       */
27      public XmldbClientResourceSet(
28      gov.noaa.gdsg.xmldbremote.ResourceSet resourceSet,
29      gov.noaa.gdsg.xmldbremote.NmmrdbSoapBindingStub stub,
30      gov.noaa.gdsg.xmldbremote.xmldbClient.XmldbClientCollection parentCollection
31      ) {
32          if (resourceSet == null){
33              throw new NullPointerException("Parameter resourceSet can not be null in constructor");
34          }
35          if (stub == null){
36              throw new NullPointerException("Parameter stub can not be null in constructor");
37          }
38          if (parentCollection == null){
39              throw new NullPointerException("Parameter parentCollection can not be null in constructor");
40          }
41          this.resourceSet = resourceSet;
42          this.stub = stub;
43          this.parentCollection = parentCollection;
44      }
45      
46      /***Adds a resource to this resource set.
47       *@param resource The resource to add
48       *@throws org.xmldb.api.base.XMLDBException Everything is caught and rethrown as one.
49       */
50      public void addResource(org.xmldb.api.base.Resource resource) throws org.xmldb.api.base.XMLDBException {
51          if (resource instanceof XmldbClientResource){
52              try {
53                  XmldbClientResource clientResource = (XmldbClientResource) resource;
54                  stub.addResource(this.resourceSet,clientResource.getResourceTransport());
55              } catch (java.rmi.RemoteException e){
56                  throw new org.xmldb.api.base.XMLDBException(
57                  org.xmldb.api.base.ErrorCodes.VENDOR_ERROR, e.toString());
58              }
59          }
60          else {
61              throw new IllegalStateException("Can only add resources of type XmldbClientResource.");
62          }
63      }
64      
65      /***Clears this resrouce set of resource
66       *@throws org.xmldb.api.base.XMLDBException Everything is caught and rethrown as one.
67       */
68      public void clear() throws org.xmldb.api.base.XMLDBException {
69          try {
70              this.stub.clear(this.resourceSet);
71          } catch (java.rmi.RemoteException e){
72              throw new org.xmldb.api.base.XMLDBException(org.xmldb.api.base.ErrorCodes.VENDOR_ERROR, e);
73          }
74      }
75      
76      /*** Throws a NOT_IMPLEMENTED exception
77       *@throws org.xmldb.api.base.XMLDBException Everything is caught and rethrown as one.
78       *@return Nothing, ever.
79       */
80      public org.xmldb.api.base.ResourceIterator getIterator() throws org.xmldb.api.base.XMLDBException {
81          throw new org.xmldb.api.base.XMLDBException(
82          org.xmldb.api.base.ErrorCodes.NOT_IMPLEMENTED);
83      }
84      
85      
86      /*** Throws a NOT_IMPLEMENTED exception
87       *@throws org.xmldb.api.base.XMLDBException Everything is caught and rethrown as one.
88       *@return Nothing, ever.
89       */
90      public org.xmldb.api.base.Resource getMembersAsResource() throws org.xmldb.api.base.XMLDBException {
91          throw new org.xmldb.api.base.XMLDBException(
92          org.xmldb.api.base.ErrorCodes.NOT_IMPLEMENTED);
93      }
94      
95      /***
96       * Returns a requested resource.
97       * @param index The index, in this set, of the resource which one wishes to retrieve.
98       * @throws org.xmldb.api.base.XMLDBException All exceptions are rethrown as one.
99       * @return The request resource.
100      */
101     public org.xmldb.api.base.Resource getResource(long index) throws org.xmldb.api.base.XMLDBException {
102         try {
103             gov.noaa.gdsg.xmldbremote.Resource resourceTransport =
104             stub.getResource(this.resourceSet, index);
105             return new XmldbClientXMLResource(resourceTransport, this.stub, this.parentCollection);
106         } catch (java.rmi.RemoteException e){
107             throw new org.xmldb.api.base.XMLDBException(org.xmldb.api.base.ErrorCodes.VENDOR_ERROR, e);
108         }
109         
110     }
111     
112     /***Gets the the number of Resources in this set.
113      *@return The size
114      *@throws org.xmldb.api.base.XMLDBException All exceptions are rethrown as one.
115      */
116     public long getSize() throws org.xmldb.api.base.XMLDBException {
117         try {
118             return this.stub.getSize(this.resourceSet);
119         } catch (java.rmi.RemoteException e){
120             throw new org.xmldb.api.base.XMLDBException(org.xmldb.api.base.ErrorCodes.VENDOR_ERROR, e);
121         }
122     }
123     
124     /***Removes the resource from this resource set.
125      *@param index The index of the resource to remove.
126      *@throws org.xmldb.api.base.XMLDBException All exceptions are rethrown as one.
127      */
128     public void removeResource(long index) throws org.xmldb.api.base.XMLDBException {
129         try {
130             this.stub.removeResource(this.resourceSet, index);
131         } catch (java.rmi.RemoteException e){
132             throw new org.xmldb.api.base.XMLDBException(org.xmldb.api.base.ErrorCodes.VENDOR_ERROR, e);
133         }
134         
135     }
136     
137 }