1 | package org.greenstone.gsdl3.util;
|
---|
2 |
|
---|
3 | import org.greenstone.gsdl3.core.ModuleInterface;
|
---|
4 | import org.w3c.dom.Document;
|
---|
5 | import org.w3c.dom.Element;
|
---|
6 | public class Request {
|
---|
7 |
|
---|
8 | private Document document = null;
|
---|
9 | private UserContext userContext = null;
|
---|
10 | private ModuleInterface operator = null;
|
---|
11 | private String type = null;
|
---|
12 | private String to = "";
|
---|
13 | /**
|
---|
14 | *
|
---|
15 | * @param userContext
|
---|
16 | * @param router
|
---|
17 | * @param requestType
|
---|
18 | * @param doc Document for request
|
---|
19 | */
|
---|
20 | public Request(Document doc, UserContext userContext, ModuleInterface router, String requestType) {
|
---|
21 | assert(router != null);
|
---|
22 | assert(requestType != null);
|
---|
23 | assert(doc != null);
|
---|
24 | this.document = doc;
|
---|
25 | this.userContext = userContext;
|
---|
26 | this.operator = router;
|
---|
27 | this.type = requestType;
|
---|
28 | }
|
---|
29 | /**
|
---|
30 | *
|
---|
31 | * @param docList requested document list
|
---|
32 | * @param paramList request parameters
|
---|
33 | * @return
|
---|
34 | */
|
---|
35 | public Element send(Element docList, Element paramList) {
|
---|
36 | Element message = document.createElement(GSXML.MESSAGE_ELEM);
|
---|
37 | Element request = GSXML.createBasicRequest(document, type, to, userContext);
|
---|
38 | message.appendChild(request);
|
---|
39 | request.appendChild(paramList);
|
---|
40 | request.appendChild(docList);
|
---|
41 | Element response = (Element) operator.process(message);
|
---|
42 | return response;
|
---|
43 | }
|
---|
44 | public Element send() {
|
---|
45 | Element message = document.createElement(GSXML.MESSAGE_ELEM);
|
---|
46 | Element request = GSXML.createBasicRequest(document, type, to, userContext);
|
---|
47 | message.appendChild(request);
|
---|
48 | Element response = (Element) operator.process(message);
|
---|
49 | return response;
|
---|
50 | }
|
---|
51 | /**
|
---|
52 | *
|
---|
53 | * @param collection target collection
|
---|
54 | * @param service target service
|
---|
55 | */
|
---|
56 | public void setToCollectionService(String collection, String service) {
|
---|
57 | this.to = GSPath.appendLink(collection, service);
|
---|
58 | }
|
---|
59 | }
|
---|