1 | /*
|
---|
2 | * MGGDBMService.java
|
---|
3 | * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
|
---|
4 | *
|
---|
5 | * This program is free software; you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published by
|
---|
7 | * the Free Software Foundation; either version 2 of the License, or
|
---|
8 | * (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This program is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | * GNU General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU General Public License
|
---|
16 | * along with this program; if not, write to the Free Software
|
---|
17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
18 | */
|
---|
19 | package org.greenstone.gsdl3.service;
|
---|
20 |
|
---|
21 | import org.w3c.dom.Document;
|
---|
22 | import org.w3c.dom.Node;
|
---|
23 | import org.w3c.dom.Text;
|
---|
24 | import org.w3c.dom.Element;
|
---|
25 | import org.w3c.dom.NodeList;
|
---|
26 | /**
|
---|
27 | *
|
---|
28 | * @author <a href="mailto:[email protected]">Katherine Don</a>
|
---|
29 | * @version $Revision: 3235 $
|
---|
30 | */
|
---|
31 |
|
---|
32 | public class MGGDBMService
|
---|
33 | extends ServiceModule {
|
---|
34 |
|
---|
35 | /** passes the request Element to the appropriate service function*/
|
---|
36 | protected Element processService(String name, Element request) {
|
---|
37 |
|
---|
38 | // dont need to check that the service name is supported for this particular object, because that has been checked by ServiceModule
|
---|
39 | if (name.equals("TextQuery")) {
|
---|
40 | return processTextQuery(request);
|
---|
41 | } else if (name.equals("DocRetrieve")) {
|
---|
42 | return processDocRetrieve(request);
|
---|
43 | } else if (name.equals("MetadataRetrieve")) {
|
---|
44 | return processMetadataRetrieve(request);
|
---|
45 | }
|
---|
46 |
|
---|
47 | System.err.println("MGGDBMService:should never get here. service type wrong:"+name);
|
---|
48 | return null;
|
---|
49 | }
|
---|
50 | /** configure this service */
|
---|
51 | public boolean configure(Element info) {
|
---|
52 |
|
---|
53 | System.out.println("configuring MGGDBMService");
|
---|
54 |
|
---|
55 | Element e = null;
|
---|
56 | // these entries should reflect the build config file - some services may not be available depending on how the colleciton was built.
|
---|
57 | // set up short_service_info_ - for now just has name and type
|
---|
58 | e = doc_.createElement("service");
|
---|
59 | e.setAttribute("type", "query");
|
---|
60 | e.setAttribute("name", "TextQuery");
|
---|
61 | short_service_info_.appendChild(e);
|
---|
62 |
|
---|
63 | e = doc_.createElement("service");
|
---|
64 | e.setAttribute("type", "query");
|
---|
65 | e.setAttribute("name", "DocRetrieve");
|
---|
66 | short_service_info_.appendChild(e);
|
---|
67 |
|
---|
68 | e = doc_.createElement("service");
|
---|
69 | e.setAttribute("type", "query");
|
---|
70 | e.setAttribute("name", "MetadataRetrieve");
|
---|
71 | short_service_info_.appendChild(e);
|
---|
72 |
|
---|
73 |
|
---|
74 | // set up service_info_map_ - for now, just has the same elements as above
|
---|
75 | // should have full details about each service incl params lists etc.
|
---|
76 | e = doc_.createElement("service");
|
---|
77 | e.setAttribute("type", "query");
|
---|
78 | e.setAttribute("name", "TextQuery");
|
---|
79 | service_info_map_.put("TextQuery", e);
|
---|
80 |
|
---|
81 | e = doc_.createElement("service");
|
---|
82 | e.setAttribute("type", "query");
|
---|
83 | e.setAttribute("name", "DocRetrieve");
|
---|
84 | service_info_map_.put("DocRetrieve", e);
|
---|
85 |
|
---|
86 | e = doc_.createElement("service");
|
---|
87 | e.setAttribute("type", "query");
|
---|
88 | e.setAttribute("name", "MetadataRetrieve");
|
---|
89 | service_info_map_.put("MetadataRetrieve", e);
|
---|
90 |
|
---|
91 | return true;
|
---|
92 | }
|
---|
93 | /** process a text query */
|
---|
94 | protected Element processTextQuery(Element request) {
|
---|
95 | Element result = doc_.createElement("response");
|
---|
96 | result.setAttribute("name", "TextQuery");
|
---|
97 |
|
---|
98 | // dummy result
|
---|
99 | Text t = null;
|
---|
100 | t = doc_.createTextNode("Textquery result... ");
|
---|
101 | result.appendChild(t);
|
---|
102 | return result;
|
---|
103 | }
|
---|
104 |
|
---|
105 | /** retrieve a document */
|
---|
106 | protected Element processDocRetrieve(Element request) {
|
---|
107 | Element result = doc_.createElement("response");
|
---|
108 | result.setAttribute("name", "DocRetrieve");
|
---|
109 |
|
---|
110 | // dummy result
|
---|
111 | Text t = null;
|
---|
112 | t = doc_.createTextNode("DocRetrieve result... ");
|
---|
113 | result.appendChild(t);
|
---|
114 | return result;
|
---|
115 | }
|
---|
116 |
|
---|
117 | /** retrieve metadata */
|
---|
118 | protected Element processMetadataRetrieve(Element request) {
|
---|
119 | Element result = doc_.createElement("response");
|
---|
120 | result.setAttribute("name", "MetadataRetrieve");
|
---|
121 |
|
---|
122 | // dummy result
|
---|
123 | Text t = null;
|
---|
124 | t = doc_.createTextNode("MetadataRetrieve result... ");
|
---|
125 | result.appendChild(t);
|
---|
126 | return result;
|
---|
127 | }
|
---|
128 |
|
---|
129 | }
|
---|