001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.vfs.servers;
020:
021: import java.lang.reflect.*;
022: import java.net.*;
023:
024: import org.openharmonise.vfs.*;
025: import org.openharmonise.vfs.authentication.*;
026:
027: /**
028: * Used as the instance of a specific connection
029: * to a Virtual File System implementation. A Virtual File System implementation
030: * has the ability to connect to a type of file system, but has no information about
031: * specific servers. The Server object carries the server specific information, connection
032: * details, VFS implementation to use and access to any authentication information.
033: *
034: * @author Matthew Large
035: * @version $Revision: 1.1 $
036: *
037: */
038: public class Server {
039:
040: /**
041: * URI to the server.
042: */
043: private URI m_uri = null;
044:
045: /**
046: * Virtual file system to be used.
047: */
048: private AbstractVirtualFileSystem m_vfs = null;
049:
050: /**
051: * Constructs a new server.
052: *
053: * @param uri URI of file system to access
054: * @param sVFSClassName full classname of VirtualFileSystem implementation to use
055: */
056: public Server(URI uri, String sVFSClassName) {
057: super ();
058: this .m_uri = uri;
059: this .m_vfs = this .createVFS(uri, sVFSClassName, null, null);
060: }
061:
062: /**
063: * Constructs a new server.
064: *
065: * @param uri URI of file system to access
066: * @param sVFSClassName full classname of VirtualFileSystem implementation to use
067: * @param authInfo authentication information to use
068: */
069: public Server(URI uri, String sVFSClassName, AuthInfo authInfo) {
070: super ();
071: this .m_uri = uri;
072: this .m_vfs = this .createVFS(uri, sVFSClassName, authInfo, null);
073: }
074:
075: /**
076: * Constructs a new server.
077: *
078: * @param uri URI of file system to access
079: * @param sVFSClassName full classname of VirtualFileSystem implementation to use
080: * @param authStore authentication store to use
081: */
082: public Server(URI uri, String sVFSClassName,
083: AbstractAuthenticationStore authStore) {
084: super ();
085: this .m_uri = uri;
086: this .m_vfs = this
087: .createVFS(uri, sVFSClassName, null, authStore);
088: }
089:
090: /**
091: * Creates a virtual file system implementation from the given
092: * information.
093: *
094: * @param uri URI of file system to access
095: * @param sVFSClassName full classname of VirtualFileSystem implementation to use
096: * @param authInfo authentication information to use
097: * @param authStore authentication store to use
098: * @return AbstractVirtualFileSystem, VFS implementation to be used
099: */
100: private AbstractVirtualFileSystem createVFS(URI uri,
101: String sVFSClassName, AuthInfo authInfo,
102: AbstractAuthenticationStore authStore) {
103: AbstractVirtualFileSystem vfsRetn = null;
104: Class[] params = null;
105: Object[] vals = null;
106: if (authInfo == null && authStore == null) {
107: params = new Class[] { URI.class };
108: vals = new Object[] { uri };
109: } else if (authInfo != null) {
110: params = new Class[] { URI.class, AuthInfo.class };
111: vals = new Object[] { uri, authInfo };
112: } else if (authStore != null) {
113: params = new Class[] { URI.class,
114: AbstractAuthenticationStore.class };
115: vals = new Object[] { uri, authStore };
116: }
117:
118: try {
119: vfsRetn = (AbstractVirtualFileSystem) Class.forName(
120: sVFSClassName).getConstructor(params).newInstance(
121: vals);
122: } catch (IllegalArgumentException e) {
123: e.printStackTrace();
124: } catch (SecurityException e) {
125: e.printStackTrace();
126: } catch (InstantiationException e) {
127: e.printStackTrace();
128: } catch (IllegalAccessException e) {
129: e.printStackTrace();
130: } catch (InvocationTargetException e) {
131: e.printStackTrace();
132: } catch (NoSuchMethodException e) {
133: e.printStackTrace();
134: } catch (ClassNotFoundException e) {
135: e.printStackTrace();
136: }
137:
138: return vfsRetn;
139: }
140:
141: /**
142: * Returns the virtual file system for this server.
143: *
144: * @return Virtual file system
145: */
146: public AbstractVirtualFileSystem getVFS() {
147: return this .m_vfs;
148: }
149:
150: /**
151: * Returns the uri for this server.
152: *
153: * @return uri
154: */
155: public URI getURI() {
156: return this.m_uri;
157: }
158:
159: }
|