1 | /*
|
---|
2 | * SimpleServer.java
|
---|
3 | * Copyright (C) 2000 Stuart Yeates
|
---|
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 |
|
---|
20 | // the package we're in
|
---|
21 | package org.nzdl.gsdl;
|
---|
22 |
|
---|
23 | // java standard library classes used
|
---|
24 | import java.io.*;
|
---|
25 | //import java.util.*;
|
---|
26 |
|
---|
27 | import org.omg.CosNaming.*;
|
---|
28 | import org.omg.CORBA.ORB;
|
---|
29 |
|
---|
30 | // local libraries
|
---|
31 | import org.nzdl.gsdl.corba.gsdlInterface.*;
|
---|
32 | import org.nzdl.gsdl.service.NzdlCollectionInfo;
|
---|
33 | import org.nzdl.gsdl.service.NzdlQuery;
|
---|
34 | import org.nzdl.gsdl.service.NzdlRequest;
|
---|
35 | import org.nzdl.gsdl.service.NzdlResponse;
|
---|
36 | import org.nzdl.gsdl.service.NzdlResultSet;
|
---|
37 | import org.nzdl.gsdl.service.NzdlService;
|
---|
38 | import org.nzdl.gsdl.service.NzdlServiceServer;
|
---|
39 | import org.nzdl.gsdl.service.NzdlServiceClient;
|
---|
40 | import org.nzdl.gsdl.util.NzdlCorbaFactory;
|
---|
41 | import org.nzdl.gsdl.util.NzdlServiceFactory;
|
---|
42 |
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * SimpleServer A very basic Greenstone server (not yet complete).
|
---|
46 | *
|
---|
47 | * @author stuart yeates ([email protected])
|
---|
48 | * @version $Revision: 2179 $
|
---|
49 | * @see org.nzdl.gsdl.SimpleClient
|
---|
50 | * @see org.nzdl.gsdl.service.NzdlServiceServer
|
---|
51 | * @see org.omg.CORBA.ORB
|
---|
52 | * @see <a href="http://www.nzdl.org/">The New Zealand Digital Library Project</a>
|
---|
53 | * @see <a href="http://www.nzdl.org/fast-cgi-bin/library?&a=p&p=gsdl">Greenstone Digital Library Software</a>
|
---|
54 | */
|
---|
55 |
|
---|
56 |
|
---|
57 | public class SimpleServer implements Serializable, Cloneable
|
---|
58 | {
|
---|
59 | static String IORFileName = "/tmp/localcorba.proxy.objid";
|
---|
60 |
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Starts up a trivial server.
|
---|
64 | *
|
---|
65 | * @param args the arguments passed through to the orb initialisation code...
|
---|
66 | */
|
---|
67 | public static void main(String args[])
|
---|
68 | {
|
---|
69 | corbaComErrorHolder error = NzdlCorbaFactory.createComErrorHolder();
|
---|
70 | try{
|
---|
71 | NzdlServiceFactory.caching = true;
|
---|
72 | NzdlServiceFactory.doMultiple = true;
|
---|
73 | NzdlServiceFactory.saveDocs = true;
|
---|
74 |
|
---|
75 | NzdlServiceClient client = NzdlServiceFactory.createNzdlService();
|
---|
76 |
|
---|
77 | ORB orb = ORB.init(args, null);
|
---|
78 |
|
---|
79 | // Create the servant and register it with the ORB
|
---|
80 | NzdlServiceServer simpleRef = new NzdlServiceServer(client.nzdl);
|
---|
81 |
|
---|
82 | simpleRef.initialise(error);
|
---|
83 | if (error.value.value() != corbaComError._corbaNoError) {
|
---|
84 | System.err.println("CORBA error after initialisation:" + error.value.value());
|
---|
85 | }
|
---|
86 |
|
---|
87 | orb.connect(simpleRef);
|
---|
88 | System.err.println(orb.object_to_string(simpleRef));
|
---|
89 |
|
---|
90 | NzdlServiceFactory.registerIOR(orb.object_to_string(simpleRef));
|
---|
91 |
|
---|
92 | try {
|
---|
93 | BufferedWriter output
|
---|
94 | = new BufferedWriter(new FileWriter(IORFileName));
|
---|
95 | output.write(orb.object_to_string(simpleRef));
|
---|
96 | output.flush();
|
---|
97 | } catch (java.io.IOException e) {
|
---|
98 | System.err.println("Error reading IOR file:\n" + e);
|
---|
99 | }
|
---|
100 |
|
---|
101 |
|
---|
102 |
|
---|
103 | // Wait for invocations from clients
|
---|
104 | java.lang.Object sync = new java.lang.Object();
|
---|
105 | synchronized(sync){
|
---|
106 | sync.wait();
|
---|
107 | }
|
---|
108 |
|
---|
109 | } catch(Exception e) {
|
---|
110 | System.err.println("CORBA error:" + error.value.value());
|
---|
111 | System.err.println("ERROR: " + e);
|
---|
112 | e.printStackTrace(System.out);
|
---|
113 | }
|
---|
114 |
|
---|
115 | }
|
---|
116 | }
|
---|
117 |
|
---|
118 |
|
---|
119 |
|
---|
120 |
|
---|
121 |
|
---|
122 |
|
---|