1 | /*
|
---|
2 | * Server.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.hli;
|
---|
22 |
|
---|
23 | import org.nzdl.gsdl.service.*;
|
---|
24 | import org.nzdl.gsdl.corba.gsdlInterface.*;
|
---|
25 | import org.nzdl.gsdl.util.*;
|
---|
26 |
|
---|
27 |
|
---|
28 | // java standard library classes used
|
---|
29 | import java.io.IOException;
|
---|
30 | import java.io.Serializable;
|
---|
31 | import java.lang.Cloneable;
|
---|
32 | import java.util.Vector;
|
---|
33 | import java.util.Set;
|
---|
34 | import java.util.Iterator;
|
---|
35 | import java.util.Enumeration;
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * A high level view of a digital library server.
|
---|
39 | *
|
---|
40 | *
|
---|
41 | * @author stuart yeates ([email protected])
|
---|
42 | * @version $Revision: 2220 $
|
---|
43 | * @see Collection
|
---|
44 | * @see Document
|
---|
45 | * @see
|
---|
46 | */
|
---|
47 |
|
---|
48 | public class Server implements Cloneable, Serializable
|
---|
49 | {
|
---|
50 | /** The host running the server. Currently broken. */
|
---|
51 | String host = "";
|
---|
52 | /** The host running the server. Currently broken. */
|
---|
53 | public String getHost() { return host; };
|
---|
54 | /** The host running the server. Currently broken. */
|
---|
55 | public void setHost(String str) { host = str; };
|
---|
56 |
|
---|
57 | /** The Independant Object Reference for this Server */
|
---|
58 | String IOR = "";
|
---|
59 | /** The Independant Object Reference for this Server */
|
---|
60 | public String getIOR() { return IOR; };
|
---|
61 | /** The Independant Object Reference for this Server */
|
---|
62 | public void setIOR(String str) { IOR = str; };
|
---|
63 |
|
---|
64 | /** The collections offered by this server */
|
---|
65 | Vector collections = null;
|
---|
66 | /** The collections offered by this server */
|
---|
67 | public Vector getCollections() {
|
---|
68 | return new Vector(collections);
|
---|
69 | }
|
---|
70 | /** The underlying interface */
|
---|
71 | NzdlService nzdl = null;
|
---|
72 |
|
---|
73 | /** Initialise (or re-initialise) the Server */
|
---|
74 | public void update() {
|
---|
75 | //construct a new interface
|
---|
76 | if (IOR != null && IOR != "")
|
---|
77 | nzdl = NzdlServiceFactory.createNzdlService(IOR);
|
---|
78 | if (nzdl == null)
|
---|
79 | throw new Error("Null NzdlService");
|
---|
80 |
|
---|
81 | // clear the collection set
|
---|
82 | if (collections != null)
|
---|
83 | collections.clear();
|
---|
84 | collections = new Vector();
|
---|
85 |
|
---|
86 | // restock the collection set
|
---|
87 | Set set = nzdl.getCollectionSet();
|
---|
88 | if (set == null)
|
---|
89 | throw new Error("getCollectionSet() returned null");
|
---|
90 | Iterator iter = set.iterator() ;
|
---|
91 | if (iter == null)
|
---|
92 | throw new Error("iterator() returned null");
|
---|
93 | while(iter.hasNext()) {
|
---|
94 | String name = (String) iter.next();
|
---|
95 | NzdlCollectionInfo info = nzdl.getCollectionInfo(name);
|
---|
96 | Collection collection = new Collection(this,name,info);
|
---|
97 | collections.add(collection);
|
---|
98 | }
|
---|
99 | }
|
---|
100 |
|
---|
101 | /** Find a collection based on it's name */
|
---|
102 | public Collection collectionForName(String name) {
|
---|
103 | Enumeration e = collections.elements();
|
---|
104 | while(e.hasMoreElements()) {
|
---|
105 | Collection collection = (Collection) e.nextElement();
|
---|
106 | if (collection!= null && collection.getName().equals(name)) {
|
---|
107 | return collection;
|
---|
108 | }
|
---|
109 | }
|
---|
110 | return null;
|
---|
111 | }
|
---|
112 | /** Build a new Server */
|
---|
113 | public Server(NzdlService nzdl) {
|
---|
114 | this.nzdl = nzdl;
|
---|
115 | update();
|
---|
116 | }
|
---|
117 |
|
---|
118 | /** Build a new Server */
|
---|
119 | public Server(String IOR) {
|
---|
120 | this.IOR = IOR;
|
---|
121 | update();
|
---|
122 | }
|
---|
123 |
|
---|
124 | public static void main(String args[]) throws IOException
|
---|
125 | {
|
---|
126 | NzdlService nzdl= NzdlServiceFactory.findIOR(args,null,null,null,null);
|
---|
127 | Server server = new Server(nzdl);
|
---|
128 | }
|
---|
129 |
|
---|
130 | }
|
---|
131 |
|
---|
132 |
|
---|
133 |
|
---|
134 |
|
---|
135 |
|
---|
136 |
|
---|
137 |
|
---|
138 |
|
---|
139 |
|
---|
140 |
|
---|
141 |
|
---|