Skip to main content
summaryrefslogtreecommitdiffstats
blob: 5bde55cf5e63014c44af9374c765cef9f48b321b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/****************************************************************************
 * Copyright (c) 2007 Composent, Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Composent, Inc. - initial API and implementation
 *****************************************************************************/

package org.eclipse.ecf.provider.filetransfer.browse;

import java.io.File;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.ecf.core.identity.IDFactory;
import org.eclipse.ecf.filetransfer.*;
import org.eclipse.ecf.filetransfer.identity.FileIDFactory;
import org.eclipse.ecf.filetransfer.identity.IFileID;
import org.eclipse.ecf.internal.provider.filetransfer.Activator;
import org.eclipse.ecf.provider.filetransfer.identity.FileTransferNamespace;

/**
 * Local representation of an {@link IRemoteFile}.
 */
public class LocalRemoteFile implements IRemoteFile {

	File file = null;

	IRemoteFileInfo info;

	/**
	 * @param file
	 */
	public LocalRemoteFile(File file) {
		this.file = file;
		Assert.isNotNull(file);
		this.info = new IRemoteFileInfo() {

			IRemoteFileAttributes attributes = new LocalRemoteFileAttributes(LocalRemoteFile.this.file);

			public IRemoteFileAttributes getAttributes() {
				return attributes;
			}

			public long getLastModified() {
				return LocalRemoteFile.this.file.lastModified();
			}

			public long getLength() {
				return LocalRemoteFile.this.file.length();
			}

			public String getName() {
				return LocalRemoteFile.this.file.getName();
			}

			public boolean isDirectory() {
				return LocalRemoteFile.this.file.isDirectory();
			}

			public void setAttributes(IRemoteFileAttributes attributes) {
				// can't set attributes
			}

			public void setLastModified(long time) {
				// can't set post hoc
			}

			public void setName(String name) {
				// Can't modify post hoc
			}
		};
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ecf.filetransfer.IRemoteFile#getID()
	 */
	public IFileID getID() {
		try {
			return FileIDFactory.getDefault().createFileID(IDFactory.getDefault().getNamespaceByName(FileTransferNamespace.PROTOCOL), file.toURL());
		} catch (Exception e) {
			// Should never happen
			return null;
		}
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ecf.filetransfer.IRemoteFile#getInfo()
	 */
	public IRemoteFileInfo getInfo() {
		return info;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
	 */
	public Object getAdapter(Class adapter) {
		IAdapterManager adapterManager = Activator.getDefault().getAdapterManager();
		if (adapterManager == null)
			return null;
		return adapterManager.loadAdapter(this, adapter.getName());
	}

	public String toString() {
		StringBuffer buf = new StringBuffer("LocalRemoteFile["); //$NON-NLS-1$
		buf.append("id=").append(getID()).append(";"); //$NON-NLS-1$//$NON-NLS-2$
		buf.append("name=").append(getInfo().getName()).append(";"); //$NON-NLS-1$ //$NON-NLS-2$
		buf.append("isDir=").append(getInfo().isDirectory()).append(";"); //$NON-NLS-1$ //$NON-NLS-2$
		buf.append("length=").append(getInfo().getLength()).append(";"); //$NON-NLS-1$ //$NON-NLS-2$
		buf.append("lastMod=").append(getInfo().getLastModified()).append(";"); //$NON-NLS-1$ //$NON-NLS-2$
		buf.append("attr=").append(getInfo().getAttributes()).append("]"); //$NON-NLS-1$ //$NON-NLS-2$
		return buf.toString();
	}
}

Back to the top