1
2
3
4
5
6
7
8
9
10
11 package org.astrogrid.store.adapter.aladin;
12
13 import org.astrogrid.community.common.security.data.SecurityToken;
14 import org.astrogrid.store.Ivorn;
15 import org.astrogrid.store.delegate.StoreClient;
16 import org.astrogrid.store.tree.Container;
17 import org.astrogrid.store.tree.File;
18 import org.astrogrid.store.tree.IterationSixTreeClient;
19 import org.astrogrid.store.tree.Node;
20 import org.astrogrid.store.tree.TreeClientDuplicateException;
21 import org.astrogrid.store.tree.TreeClientLoginException;
22 import org.astrogrid.store.tree.TreeClientSecurityException;
23 import org.astrogrid.store.tree.TreeClientServiceException;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.io.OutputStream;
31 import java.net.URL;
32 import java.util.ArrayList;
33 import java.util.Collection;
34 import java.util.Collections;
35 import java.util.Iterator;
36
37 /*** Wrapper around a {@link org.astrogrid.store.tree.TreeClient} to support the deprecated interface in this package
38 * @deprecated use {@link org.astrogrid.store.tree} instead
39 * @author Noel Winstanley nw@jb.man.ac.uk 05-Nov-2004
40 */
41 public class IterationSixAladinAdapter implements AladinAdapter {
42 /***
43 * Commons Logger for this class
44 */
45 private static final Log logger = LogFactory
46 .getLog(IterationSixAladinAdapter.class);
47
48 /*** Construct a new IterationSixAladinAdapter
49 *
50 */
51 public IterationSixAladinAdapter() {
52 this.treeclient = new IterationSixTreeClient();
53
54 }
55 protected final IterationSixTreeClient treeclient;
56
57
58 /***
59 * @see org.astrogrid.store.adapter.aladin.AladinAdapter#login(org.astrogrid.store.Ivorn, java.lang.String)
60 */
61 public void login(Ivorn communityIvorn, String password)
62 throws AladinAdapterLoginException, AladinAdapterServiceException {
63 try {
64 treeclient.login(communityIvorn,password);
65 } catch (TreeClientLoginException e) {
66 throw new AladinAdapterLoginException(e.getMessage(),e);
67 } catch (TreeClientServiceException e) {
68 throw new AladinAdapterServiceException(e.getMessage(),e);
69 }
70 }
71
72 public StoreClient getStoreClient() {
73 return treeclient.getStoreClient();
74 }
75
76 /***
77 * @see org.astrogrid.store.adapter.aladin.AladinAdapter#logout()
78 */
79 public void logout() throws AladinAdapterServiceException {
80 try {
81 treeclient.logout();
82 } catch (TreeClientServiceException e) {
83 throw new AladinAdapterServiceException(e.getMessage(),e);
84 }
85
86 }
87
88 /***
89 * @see org.astrogrid.store.adapter.aladin.AladinAdapter#getToken()
90 */
91 public SecurityToken getToken() {
92 return treeclient.getToken();
93 }
94
95 /*** queries server, rebuilds tree.
96 * @see org.astrogrid.store.adapter.aladin.AladinAdapter#getRoot()
97 */
98 public AladinAdapterContainer getRoot()
99 throws AladinAdapterSecurityException,
100 AladinAdapterServiceException {
101
102 Container root;
103 try {
104 root = treeclient.getRoot();
105 } catch (TreeClientSecurityException e) {
106 throw new AladinAdapterSecurityException(e.getMessage(),e);
107 } catch (TreeClientServiceException e) {
108 throw new AladinAdapterServiceException(e.getMessage(),e);
109 }
110 return wrapRoot(root);
111 }
112
113 private final AladinAdapterContainer wrapRoot(Container c) {
114 return new IterationSixContainer(c);
115 }
116
117 /***
118 * Iteration-6 version of an aladin adapter node.
119 * @author Noel Winstanley nw@jb.man.ac.uk 05-Nov-2004
120 *
121 */
122 protected class IterationSixNode implements AladinAdapterNode {
123
124 public IterationSixNode(Node n) {
125 this.node = n;
126 }
127
128 protected final Node node;
129 /***
130 * @see org.astrogrid.store.adapter.aladin.AladinAdapterNode#getName()
131 */
132 public String getName() {
133 return node.getName();
134 }
135
136
137 /***
138 * @see org.astrogrid.store.adapter.aladin.AladinAdapterNode#isFile()
139 */
140 public boolean isFile() {
141 return node.isFile();
142 }
143
144 /***
145 * @see org.astrogrid.store.adapter.aladin.AladinAdapterNode#isContainer()
146 */
147 public boolean isContainer() {
148 return node.isContainer();
149 }
150
151
152 public boolean equals(Object obj) {
153 IterationSixNode casted = (IterationSixNode)obj;
154 return this.node.equals(casted.node);
155 }
156 public String toString() {
157 return "AladinAdapter : " + node.toString();
158 }
159 }
160 /***
161 * Iteration 6 version of an aladin adapter container
162 * @author Noel Winstanley nw@jb.man.ac.uk 05-Nov-2004
163 *
164 */
165 protected class IterationSixContainer extends IterationSixNode implements AladinAdapterContainer {
166
167 /*** Construct a new IterationSixContainer
168 * @param wrapped
169 */
170 public IterationSixContainer(Container c) {
171 super(c);
172 }
173
174 /***
175 * @see org.astrogrid.store.adapter.aladin.AladinAdapterContainer#getChildNodes()
176 */
177 public Collection getChildNodes() {
178 Collection orig = ((Container)node).getChildNodes();
179 Collection wrapped = new ArrayList(orig.size());
180 for (Iterator i = orig.iterator(); i.hasNext(); ) {
181 wrapped.add(wrap(i.next()));
182 }
183 return Collections.unmodifiableCollection(wrapped);
184 }
185
186 private IterationSixNode wrap(Object o) {
187 if (o instanceof Container) {
188 return new IterationSixContainer((Container)o);
189 } else if (o instanceof File) {
190 return new IterationSixFile((File)o);
191 } else {
192 throw new RuntimeException("Programming Error - unknown object type" + o.getClass().getName());
193 }
194 }
195
196 /***
197 * @see org.astrogrid.store.adapter.aladin.AladinAdapterContainer#addContainer(java.lang.String)
198 */
199 public AladinAdapterContainer addContainer(String name) throws AladinAdapterServiceException, AladinAdapterDuplicateException {
200 try {
201 return new IterationSixContainer( ((Container)node).addContainer(name));
202 } catch (TreeClientServiceException e) {
203 throw new AladinAdapterServiceException(e.getMessage(),e);
204 } catch (TreeClientDuplicateException e) {
205 throw new AladinAdapterDuplicateException(e.getMessage());
206 }
207 }
208
209
210 /***
211 * @see org.astrogrid.store.adapter.aladin.AladinAdapterContainer#addFile(java.lang.String)
212 */
213 public AladinAdapterFile addFile(String name) throws AladinAdapterServiceException, AladinAdapterDuplicateException {
214 try {
215 return new IterationSixFile( ((Container)node).addFile(name));
216 } catch (TreeClientServiceException e) {
217 throw new AladinAdapterServiceException(e.getMessage(),e);
218 } catch (TreeClientDuplicateException e) {
219 throw new AladinAdapterDuplicateException(e.getMessage());
220 }
221
222 }
223
224 }
225
226
227
228 /***
229 * Iteration 6 implementation of an aladin adapter file.
230 * @author Noel Winstanley nw@jb.man.ac.uk 05-Nov-2004
231 *
232 */
233 protected class IterationSixFile extends IterationSixNode implements AladinAdapterFile {
234
235 /*** Construct a new IterationSixFile
236 * @param wrapped
237 */
238 public IterationSixFile(File node){
239 super(node);
240 }
241
242 /***
243 * @see org.astrogrid.store.adapter.aladin.AladinAdapterFile#getMimeType()
244 */
245 public String getMimeType() {
246 return ((File)node).getMimeType();
247 }
248
249 /***
250 * @throws IOException
251 * @see org.astrogrid.store.adapter.aladin.AladinAdapterFile#getOutputStream()
252 */
253 public OutputStream getOutputStream() throws AladinAdapterServiceException {
254 try {
255 return ((File)node).getOutputStream();
256 } catch (TreeClientServiceException e) {
257 throw new AladinAdapterServiceException(e.getMessage(),e);
258 }
259 }
260
261 /***
262 * @see org.astrogrid.store.adapter.aladin.AladinAdapterFile#getInputStream()
263 */
264 public InputStream getInputStream() throws AladinAdapterServiceException {
265 try {
266 return ((File)node).getInputStream();
267 } catch (TreeClientServiceException e) {
268 throw new AladinAdapterServiceException(e.getMessage(),e);
269 }
270 }
271
272 /***
273 * @see org.astrogrid.store.adapter.aladin.AladinAdapterFile#getURL()
274 */
275 public URL getURL() throws AladinAdapterServiceException {
276 try {
277 return getStoreClient().getUrl(((IterationSixTreeClient.IterationSixNode)node).getPath());
278 } catch (IOException e) {
279 throw new AladinAdapterServiceException("getURL",e);
280 }
281 }
282 }
283
284
285 }
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316