KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > vfs > servers > Server


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.vfs.servers;
20
21 import java.lang.reflect.*;
22 import java.net.*;
23
24 import org.openharmonise.vfs.*;
25 import org.openharmonise.vfs.authentication.*;
26
27
28 /**
29  * Used as the instance of a specific connection
30  * to a Virtual File System implementation. A Virtual File System implementation
31  * has the ability to connect to a type of file system, but has no information about
32  * specific servers. The Server object carries the server specific information, connection
33  * details, VFS implementation to use and access to any authentication information.
34  *
35  * @author Matthew Large
36  * @version $Revision: 1.1 $
37  *
38  */

39 public class Server {
40
41     /**
42      * URI to the server.
43      */

44     private URI m_uri = null;
45     
46     /**
47      * Virtual file system to be used.
48      */

49     private AbstractVirtualFileSystem m_vfs = null;
50     
51     /**
52      * Constructs a new server.
53      *
54      * @param uri URI of file system to access
55      * @param sVFSClassName full classname of VirtualFileSystem implementation to use
56      */

57     public Server(URI uri, String JavaDoc sVFSClassName) {
58         super();
59         this.m_uri = uri;
60         this.m_vfs = this.createVFS(uri, sVFSClassName, null, null);
61     }
62     
63     /**
64      * Constructs a new server.
65      *
66      * @param uri URI of file system to access
67      * @param sVFSClassName full classname of VirtualFileSystem implementation to use
68      * @param authInfo authentication information to use
69      */

70     public Server(URI uri, String JavaDoc sVFSClassName, AuthInfo authInfo) {
71         super();
72         this.m_uri = uri;
73         this.m_vfs = this.createVFS(uri, sVFSClassName, authInfo, null);
74     }
75     
76     /**
77      * Constructs a new server.
78      *
79      * @param uri URI of file system to access
80      * @param sVFSClassName full classname of VirtualFileSystem implementation to use
81      * @param authStore authentication store to use
82      */

83     public Server(URI uri, String JavaDoc sVFSClassName, AbstractAuthenticationStore authStore) {
84         super();
85         this.m_uri = uri;
86         this.m_vfs = this.createVFS(uri, sVFSClassName, null, authStore);
87     }
88     
89     /**
90      * Creates a virtual file system implementation from the given
91      * information.
92      *
93      * @param uri URI of file system to access
94      * @param sVFSClassName full classname of VirtualFileSystem implementation to use
95      * @param authInfo authentication information to use
96      * @param authStore authentication store to use
97      * @return AbstractVirtualFileSystem, VFS implementation to be used
98      */

99     private AbstractVirtualFileSystem createVFS(URI uri, String JavaDoc sVFSClassName, AuthInfo authInfo, AbstractAuthenticationStore authStore) {
100         AbstractVirtualFileSystem vfsRetn = null;
101         Class JavaDoc[] params = null;
102         Object JavaDoc[] vals = null;
103         if( authInfo==null && authStore==null ) {
104             params = new Class JavaDoc[]{URI.class};
105             vals = new Object JavaDoc[]{uri};
106         } else if( authInfo!=null ) {
107             params = new Class JavaDoc[]{URI.class, AuthInfo.class};
108             vals = new Object JavaDoc[]{uri, authInfo};
109         } else if( authStore!=null ) {
110             params = new Class JavaDoc[]{URI.class, AbstractAuthenticationStore.class};
111             vals = new Object JavaDoc[]{uri, authStore};
112         }
113         
114         try {
115             vfsRetn = (AbstractVirtualFileSystem) Class.forName(sVFSClassName).getConstructor(params).newInstance( vals );
116         } catch (IllegalArgumentException JavaDoc e) {
117             e.printStackTrace();
118         } catch (SecurityException JavaDoc e) {
119             e.printStackTrace();
120         } catch (InstantiationException JavaDoc e) {
121             e.printStackTrace();
122         } catch (IllegalAccessException JavaDoc e) {
123             e.printStackTrace();
124         } catch (InvocationTargetException e) {
125             e.printStackTrace();
126         } catch (NoSuchMethodException JavaDoc e) {
127             e.printStackTrace();
128         } catch (ClassNotFoundException JavaDoc e) {
129             e.printStackTrace();
130         }
131         
132         return vfsRetn;
133     }
134     
135     /**
136      * Returns the virtual file system for this server.
137      *
138      * @return Virtual file system
139      */

140     public AbstractVirtualFileSystem getVFS() {
141         return this.m_vfs;
142     }
143     
144     /**
145      * Returns the uri for this server.
146      *
147      * @return uri
148      */

149     public URI getURI() {
150         return this.m_uri;
151     }
152
153 }
154
Popular Tags