View Javadoc

1   /*
2    * ServiceHandler.java
3    *
4    * Created on April 16, 2004, 1:25 PM
5    */
6   
7   package gov.noaa.gdsg.xmldbremote.service;
8   
9   import org.xmldb.api.base.Service;
10  import org.xmldb.api.base.ResourceSet;
11  import org.xmldb.api.base.Collection;
12  import org.xmldb.api.modules.XPathQueryService;
13  import org.xmldb.api.base.XMLDBException;
14  
15  import gov.noaa.gdsg.xmldbremote.service.transport.BaseTransport;
16  import gov.noaa.gdsg.xmldbremote.service.transport.ServiceTransport;
17  
18  /***
19   * Wrapps {@see Service} objects and creates a lightweight transport object to
20   * represent the actual object.
21   * @author tns
22   * @version $Id: ServiceHandler.java,v 1.1 2004/10/29 18:06:13 mrxtravis Exp $
23   */
24  public class ServiceHandler extends BaseHandler{
25      
26      /*** Creates a new instance of ServiceHandler */
27      public ServiceHandler() {
28      }
29      
30      /***
31       * Creates a ServiceTransport object.
32       * @param object The actual object to create a transport object from.
33       * @throws org.xmldb.api.base.XMLDBException If something goes wrong.
34       * @return The newly created transport object.
35       */
36      public BaseTransport createTransportObject(Object object) throws XMLDBException {
37          Service service = (Service) object;
38          ServiceTransport transport = new ServiceTransport();
39          transport.setName(service.getName());
40          transport.setVersion(service.getVersion());
41          return transport;
42      }
43      
44      /***
45       * Wrapper for the {@see Service#clearNamespace} method.
46       * @param transport The transport object which represents the actual object.
47       * @throws org.xmldb.api.base.XMLDBException If the wrapped method thows one.
48       */
49      public void clearNamespaces(ServiceTransport transport) throws XMLDBException {
50          XPathQueryService service = (XPathQueryService) this.getObjectFromSession(transport);
51          service.clearNamespaces();
52      }
53      
54      /***
55       * Wrapper for {@see Service#getNamespace} method.
56       * @param transport The rep of the actual object.
57       * @param prefix Passed to the wrapped method.
58       * @throws org.xmldb.api.base.XMLDBException If the wrapped method throws one.
59       * @return Whatever the wrapped method throws.
60       */
61      public String getNamespace(ServiceTransport transport, String prefix) throws XMLDBException {
62          XPathQueryService service = (XPathQueryService) this.getObjectFromSession(transport);
63          return service.getNamespace(prefix);
64      }
65      
66      /***
67       * Wrapper for {@see XPathQueryService#query} method.
68       * @return Whatever the wrapped method throws.
69       * @param transport The transport object which represents the actual object.
70       * @param query The query to pass to the wrapped method
71       * @throws org.xmldb.api.base.XMLDBException If the wrapped method throws one.
72       */
73      public ResourceSet query(ServiceTransport transport, String query) throws XMLDBException {
74          XPathQueryService service = (XPathQueryService) this.getObjectFromSession(transport);
75          return service.query(query);
76      }
77      
78      /***
79       * Rapper for {@see XPathQueryService#queryResource} method.
80       * @return Whatever the wrapped method throws.
81       * @param id Passed to the Wrapped method.
82       * @param query Passed to the Wrapped method.
83       * @param transport The transport object which represents the actual object.
84       * @throws org.xmldb.api.base.XMLDBException If the wrapped method throws one.
85       */
86      public ResourceSet queryResource(ServiceTransport transport, String id, String query) throws XMLDBException {
87          XPathQueryService service = (XPathQueryService) this.getObjectFromSession(transport);
88          return service.queryResource(id,query);
89      }
90      
91      /***
92       * Wrapper for the {@see Service#removeNamespace} method.
93       * @param prefix Passed to the Wrapped method.
94       * @param transport The transport object which represents the actual object.
95       * @throws org.xmldb.api.base.XMLDBException If the wrapped method throws one.
96       */
97      public void removeNamespace(ServiceTransport transport, String prefix) throws XMLDBException {
98          XPathQueryService service = (XPathQueryService) this.getObjectFromSession(transport);
99          service.removeNamespace(prefix);
100     }
101     
102     /***
103      * Wrapper for the {@Service#setNamespace} method.
104      * @param prefix Passed to the Wrapped method.
105      * @param uri Passed to the Wrapped method.
106      * @param transport The transport object which represents the actual object.
107      * @throws org.xmldb.api.base.XMLDBException If the wrapped method throws one.
108      */
109     public void setNamespace(ServiceTransport transport, String prefix, String uri) throws XMLDBException {
110         XPathQueryService service = (XPathQueryService) this.getObjectFromSession(transport);
111         service.setNamespace(prefix,uri);
112     }
113     
114     //getName is taken care of in the transport object
115     //getVersion is too
116     
117     /***
118      * Wrapper for the {Service#setCollection} method.
119      * @param collection Passed to the Wrapped method.
120      * @param transport The transport object which represents the actual object.
121      * @throws org.xmldb.api.base.XMLDBException If the wrapped method throws one.
122      */
123     public void setCollection(ServiceTransport transport, Collection collection) throws XMLDBException {
124         Service service = (Service) this.getObjectFromSession(transport);
125         service.setCollection(collection);
126     }
127     
128     
129     
130 }