1 | <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
---|
2 | <html>
|
---|
3 | <head>
|
---|
4 | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
---|
5 | <meta name="GENERATOR" content="Mozilla/4.76 [en] (X11; U; Linux 2.2.16-22 i686) [Netscape]">
|
---|
6 | <title>: Package org.nzdl.gsdl.service</title>
|
---|
7 | <!--NewPage-->
|
---|
8 | <!-- Generated by javadoc on Thu Mar 08 23:01:13 GMT+13:00 2001 -->
|
---|
9 | </head>
|
---|
10 | <body bgcolor="#FFFFFF">
|
---|
11 | Provides services for java client-side communication
|
---|
12 | to a Greenstone Digital Library via CORBA.
|
---|
13 | <br>
|
---|
14 | <h2>
|
---|
15 | Further Requirements</h2>
|
---|
16 |
|
---|
17 | <ul>
|
---|
18 | <li>
|
---|
19 | Sun Java 2 version 1.3 (or later)</li>
|
---|
20 |
|
---|
21 | <li>
|
---|
22 | Corbaserver, a server-side application for communicating to a Greenstone
|
---|
23 | Digital Library.</li>
|
---|
24 | </ul>
|
---|
25 |
|
---|
26 | <h2>
|
---|
27 | Java Interface Data Flows</h2>
|
---|
28 |
|
---|
29 | <center><img SRC="nzdl-service-package.png" ALT="NZDL Data Flow Diagram" height=280 width=637></center>
|
---|
30 |
|
---|
31 | <p><br>
|
---|
32 | <h2>
|
---|
33 | A Typical Query</h2>
|
---|
34 | From a users perspective, a typical query may work as follows:
|
---|
35 | <ul>
|
---|
36 | <li>
|
---|
37 | Create instances of the necessary NZDL Java-Client objects:</li>
|
---|
38 |
|
---|
39 | <ul>
|
---|
40 | <li>
|
---|
41 | a <b>NzdlQuery</b> object</li>
|
---|
42 |
|
---|
43 | <li>
|
---|
44 | a <b>NzdlRequest </b>object using your <b>NzdlQuery</b> object</li>
|
---|
45 |
|
---|
46 | <li>
|
---|
47 | a <b>NzdlResponse</b> object that will eventually hold response
|
---|
48 | data</li>
|
---|
49 |
|
---|
50 | <li>
|
---|
51 | a <b>NzdlService</b> object to service CORBA interface requests
|
---|
52 | to
|
---|
53 | a Greenstone collection</li>
|
---|
54 | </ul>
|
---|
55 |
|
---|
56 | <li>
|
---|
57 | Use the <b>NzdlService</b> object (with collection name and <b>NzdlRequest
|
---|
58 | </b>object)
|
---|
59 | to query the CORBA interface and place the reply into the <b>NzdlResponse</b>
|
---|
60 | object.</li>
|
---|
61 |
|
---|
62 | <li>
|
---|
63 | Create an instance of the <b>NzdlResultSet</b> object. Use <b>NzdlResponse.getResultSet()
|
---|
64 | </b>to
|
---|
65 | extract response data into the <b>NzdlResultSet</b> object.</li>
|
---|
66 |
|
---|
67 | <li>
|
---|
68 | Use the <b>NzdlResultSet</b> methods to view data such as document IDs</li>
|
---|
69 |
|
---|
70 | <br>Get documents using <b>NzdlService.getDocument()</b></ul>
|
---|
71 |
|
---|
72 | <h1>
|
---|
73 | Sample Code</h1>
|
---|
74 | Below is a trivial example of a client application. For a more elaborate
|
---|
75 | example, see <a href="../SimpleClient.html">SimpleClient</a>.
|
---|
76 | <p>In order to function, this app needs Corbaserver running on the same
|
---|
77 | machine.
|
---|
78 | <p><tt>/**</tt>
|
---|
79 | <br><tt>* TrivialDemo.java.</tt>
|
---|
80 | <br><tt>* A very simple client application that:</tt>
|
---|
81 | <br><tt>* - Creates a service object using an Interoperable</tt>
|
---|
82 | <br><tt>* Object Reference (IOR) from a file;</tt>
|
---|
83 | <br><tt>* - lists all available collections;</tt>
|
---|
84 | <br><tt>* - searches "demo" collection for "snail farming";</tt>
|
---|
85 | <br><tt>* - prints the number of hits;</tt>
|
---|
86 | <br><tt>* - lists first 10 titles found;</tt>
|
---|
87 | <br><tt>* - displays the unformatted text of first document found.</tt>
|
---|
88 | <br><tt>*/</tt>
|
---|
89 | <br><tt>import java.io.*;</tt>
|
---|
90 | <br><tt>import java.util.*;</tt>
|
---|
91 | <br><tt>import java.lang.*;</tt>
|
---|
92 | <br><tt>import org.nzdl.gsdl.service.*; //the java-client stuff</tt>
|
---|
93 | <br><tt>import org.nzdl.gsdl.util.NzdlIORs; //for obtaining the IOR</tt>
|
---|
94 | <p><tt>public class TrivialDemo {</tt>
|
---|
95 | <br><tt> public static void main( String [] args )</tt>
|
---|
96 | <br><tt> {</tt>
|
---|
97 | <br><tt> String myIorFile = "/tmp/localcorba.objid";</tt>
|
---|
98 | <br><tt> String myQueryString = "snail farming";</tt>
|
---|
99 | <br><tt> String myCollection = "demo";</tt>
|
---|
100 | <p><tt> // Create a Service Object</tt>
|
---|
101 | <br><tt> NzdlService myService = NzdlIORs.findIOR(null,
|
---|
102 | null,</tt>
|
---|
103 | <br><tt>
|
---|
104 | myIorFile, null);</tt>
|
---|
105 | <p><tt> // Use getCollectionSet to obtain List of Collections</tt>
|
---|
106 | <br><tt> Set myCollections = myService.getCollectionSet();</tt>
|
---|
107 | <p><tt> //Display List of Collections</tt>
|
---|
108 | <br><tt> System.out.println("\nThe available collections:");</tt>
|
---|
109 | <p><tt> for (Iterator i = myCollections.iterator(); i.hasNext();
|
---|
110 | )</tt>
|
---|
111 | <br><tt> {</tt>
|
---|
112 | <br><tt> String collName = (String)
|
---|
113 | i.next();</tt>
|
---|
114 | <br><tt> System.out.println("
|
---|
115 | "+ collName);</tt>
|
---|
116 | <br><tt> }</tt>
|
---|
117 | <p><tt> // Find The Number of documents in my collection</tt>
|
---|
118 | <br><tt> NzdlCollectionInfo myInfo = myService.getCollectionInfo(myCollection);</tt>
|
---|
119 | <br><tt> System.out.println("\nNum Of Collection docs
|
---|
120 | = "+myInfo.getNumOfDocs());</tt>
|
---|
121 | <p><tt> // Create query object</tt>
|
---|
122 | <br><tt> NzdlQuery query = new NzdlQuery( myQueryString
|
---|
123 | );</tt>
|
---|
124 | <p><tt> // Create request object</tt>
|
---|
125 | <br><tt> NzdlRequest request = new NzdlRequest( query
|
---|
126 | );</tt>
|
---|
127 | <p><tt> // create response object</tt>
|
---|
128 | <br><tt> NzdlResponse response = new NzdlResponse( );</tt>
|
---|
129 | <p><tt> // use service to get response from request to
|
---|
130 | myCollection</tt>
|
---|
131 | <br><tt> myService.service( myCollection, request, response
|
---|
132 | );</tt>
|
---|
133 | <p><tt> // use getResultSet to get results from response</tt>
|
---|
134 | <br><tt> NzdlResultSet results = response.getResultSet();</tt>
|
---|
135 | <p><tt> // getNumOfDocs</tt>
|
---|
136 | <br><tt> System.out.println("\nNumber of hits = "+results.getNumOfDocs());</tt>
|
---|
137 | <p><tt> // Use getDocumentIDs to build list of titles
|
---|
138 | (defaults: 1 - 10)</tt>
|
---|
139 | <br><tt> List docIDs = results.getDocumentIDs();</tt>
|
---|
140 | <br><tt> System.out.println("\nThe titles:");</tt>
|
---|
141 | <br><tt> for (ListIterator i = docIDs.listIterator();
|
---|
142 | i.hasNext(); )</tt>
|
---|
143 | <br><tt> {</tt>
|
---|
144 | <br><tt> Set metaData</tt>
|
---|
145 | <br><tt> = myService.getMetaData(
|
---|
146 | myCollection,(String)i.next(),"Title");</tt>
|
---|
147 | <br><tt> Iterator j = metaData.iterator();</tt>
|
---|
148 | <br><tt> System.out.println(j.next());
|
---|
149 | //print title metadata</tt>
|
---|
150 | <br><tt> }</tt>
|
---|
151 | <br><tt> System.out.println("\nThe first document returned
|
---|
152 | was:");</tt>
|
---|
153 | <p><tt> // Print first document returned</tt>
|
---|
154 | <br><tt> String myDoc</tt>
|
---|
155 | <br><tt> = myService.getDocument(myCollection,(String)docIDs.get(0));</tt>
|
---|
156 | <br><tt> System.out.println(myDoc);</tt>
|
---|
157 | <p><tt> } // end of main</tt>
|
---|
158 | <br><tt>} // end of demo class</tt>
|
---|
159 | <br>
|
---|
160 | </body>
|
---|
161 | </html>
|
---|