source: trunk/java-client/org/nzdl/gsdl/SimpleServer.java@ 2077

Last change on this file since 2077 was 2077, checked in by say1, 23 years ago

started work on the Java server. still many hacks.

  • Property svn:keywords set to Author Date Id Revision
File size: 7.1 KB
Line 
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
21package org.nzdl;
22
23// java standard library classes used
24import java.io.IOException;
25import java.io.Serializable;
26import java.lang.Cloneable;
27import java.util.*;
28
29// HelloServer will use the naming service.
30import org.omg.CosNaming.*;
31// The package containing special exceptions thrown by the name service.
32//import org.omg.CosNaming.NamingContextPackage.*;
33// All CORBA applications need these classes.
34import org.omg.CORBA.ORB;
35
36// local libraries
37import org.nzdl.corba.gsdlInterface.*;
38import org.nzdl.service.NzdlCollectionInfo;
39import org.nzdl.service.NzdlQuery;
40import org.nzdl.service.NzdlRequest;
41import org.nzdl.service.NzdlResponse;
42import org.nzdl.service.NzdlResultSet;
43import org.nzdl.service.NzdlService;
44import org.nzdl.util.NzdlCorbaFactory;
45
46
47/**
48 * SimpleServer
49 *
50 * Based on algorithms in ...
51 *
52 * @author stuart yeates ([email protected])
53 * @version $Revision: 2077 $
54 * @see
55 * @see
56 * @see
57 *
58 */
59
60
61public class SimpleServer
62{
63 /**
64 * Tests...
65 *
66 *
67 * @exception java.io.IOException when ...
68 * @param args the arguments ...
69 */
70 public static void main(String args[])
71 {
72 try{
73
74 ORB orb = ORB.init(args, null);
75
76 // Create the servant and register it with the ORB
77 NzdlServer simpleRef = new NzdlServer();
78 orb.connect(simpleRef);
79
80 // Get the root naming context
81 org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
82 NamingContext ncRef = NamingContextHelper.narrow(objRef);
83
84 // Bind the object reference in naming
85 NameComponent nc = new NameComponent("Hello", "");
86 NameComponent path[] = {nc};
87 ncRef.rebind(path, simpleRef);
88
89 // Wait for invocations from clients
90 java.lang.Object sync = new java.lang.Object();
91 synchronized(sync){
92 sync.wait();
93 }
94
95 } catch(Exception e) {
96 System.err.println("ERROR: " + e);
97 e.printStackTrace(System.out);
98 }
99 }
100}
101
102 /**
103 * Tests...
104 *
105 *
106 * @exception java.io.IOException when ...
107 * @param args the arguments ...
108 */
109
110
111class NzdlServer extends _corbaifaceImplBase {
112
113 NzdlService nzdl = null;
114
115 NzdlServer(NzdlService service) {
116 nzdl = service;
117 }
118
119 NzdlServer() {
120 nzdl = null;
121 }
122
123 public boolean initialise () {
124 // TODO should map the anything in NzdlService?
125 return true;
126 }
127 public void configure (corbatext_t key,
128 corbatext_t[] cfgline) {
129// m_nzdlServer.configure( NzdlCorbaFactory.toCorbaText( _key ),
130// NzdlCorbaFactory.toCorbaTextArray( _values ));
131
132 nzdl.configure( NzdlCorbaFactory.toString(key),
133 NzdlCorbaFactory.toSet(cfgline));
134 }
135
136 public void collectionList (corbatext_tarrayHolder collist) {
137 //corbatext_tarrayHolder c_collSet = NzdlCorbaFactory.createCorbaTextArrayHolder();
138 //m_nzdlServer.collectionList(c_collSet);
139 //Set collSet = new HashSet();
140 //for (int i=0; i<c_collSet.value.length; i++) {
141 // collSet.add( NzdlCorbaFactory.toString( c_collSet.value[i] ) );
142 //}
143 //return collSet ;
144 Set set = nzdl.getCollectionSet();
145
146 Iterator itr = set.iterator();
147 int i = 0;
148 while (itr.hasNext()) {
149 String s = (String) itr.next();
150 collist.value[i++] = NzdlCorbaFactory.toCorbaText(s);
151 }
152
153 return;
154 }
155 public void hasCollection (corbatext_t corbaCollection,
156 org.omg.CORBA.BooleanHolder has,
157 corbaComErrorHolder error) {
158// corbaComErrorHolder c_err = NzdlCorbaFactory.createComErrorHolder();
159// org.omg.CORBA.BooleanHolder c_has = new org.omg.CORBA.BooleanHolder();
160// m_nzdlServer.hasCollection( NzdlCorbaFactory.toCorbaText(_name), c_has, c_err );
161// if (c_err.value.value() != 0)
162// System.err.println("hasCollection error " + c_err.value.value());
163// return c_has.value;
164 String name = NzdlCorbaFactory.toString(corbaCollection);
165 has.value = nzdl.hasCollection(name);
166 return;
167 }
168 public boolean ping (corbatext_t collection,
169 corbaComErrorHolder error) {
170 String name = NzdlCorbaFactory.toString(collection);
171 return nzdl.hasCollection(name);
172 }
173 public void getDocument (corbatext_t collection,
174 corbaDocRequestHolder request,
175 corbaDocResponseHolder response,
176 corbaComErrorHolder error) {
177// corbatext_t c_name = NzdlCorbaFactory.toCorbaText( _name );
178// corbaDocRequestHolder c_request = NzdlCorbaFactory.createDocRequestHolder( _docID );
179// corbaDocResponseHolder c_response = NzdlCorbaFactory.createDocResponseHolder( );
180// corbaComErrorHolder c_err = NzdlCorbaFactory.createComErrorHolder();
181// m_nzdlServer.getDocument( c_name, c_request, c_response, c_err );
182// if (c_err.value.value() != 0)
183// System.err.println("getDocument() error " + c_err.value.value());
184// return NzdlCorbaFactory.toString( c_response.value.doc );
185 String collectionName = NzdlCorbaFactory.toString(collection);
186 String documentID = NzdlCorbaFactory.toString(request.value.OID);
187 String doc = nzdl.getDocument( collectionName, documentID );
188 response.value.doc = NzdlCorbaFactory.toCorbaText(doc);
189 return;
190 }
191 public void getCollectInfo (corbatext_t collection,
192 corbaColInfoResponseHolder response,
193 corbaComErrorHolder error) {
194// corbaComErrorHolder c_err = NzdlCorbaFactory.createComErrorHolder();
195// corbaColInfoResponseHolder c_info = NzdlCorbaFactory.createColInfoResponseHolder();
196// m_nzdlServer.getCollectInfo( NzdlCorbaFactory.toCorbaText(_name), c_info, c_err );
197// if (c_err.value.value() != 0)
198// System.err.println("getCollectionInfo() error " + c_err.value.value());
199// return new NzdlCollectionInfo( c_info.value );
200 String collectionName = NzdlCorbaFactory.toString(collection);
201 NzdlCollectionInfo info = nzdl.getCollectionInfo( collectionName );
202 response.value = info.getInfo();
203 return;
204 }
205 public void getFilterInfo (corbatext_t collection,
206 corbatext_tarrayHolder filterNames,
207 corbaComErrorHolder error) {
208
209 return;
210 }
211 public void getFilterOptions (corbatext_t collection,
212 corbatext_t option,
213 corbaFilterOptionsResponseHolder response,
214 corbaComErrorHolder error) {
215 return;
216 }
217 public void filter (corbatext_t collection,
218 corbaFilterRequest request,
219 corbaFilterResponseHolder response,
220 corbaComErrorHolder error) {
221 return;
222 }
223}
224
225
Note: See TracBrowser for help on using the repository browser.