Skip to main content
summaryrefslogtreecommitdiffstats
blob: 2b6abcf7886b6e575e6f971c8241d6fdc5926eb1 (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
/****************************************************************************
 * 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.xmpp.identity;

import java.net.MalformedURLException;
import java.net.URL;

import org.eclipse.core.runtime.Assert;
import org.eclipse.ecf.core.identity.BaseID;
import org.eclipse.ecf.core.identity.Namespace;
import org.eclipse.ecf.filetransfer.identity.IFileID;
import org.eclipse.ecf.internal.provider.xmpp.Messages;

/**
 * XMPPFileID for use with the XMPP outgoing file transfer.
 */
public class XMPPFileID extends BaseID implements IFileID {

	private static final long serialVersionUID = 9052434567658554404L;

	XMPPID xmppid;
	String filename;

	public XMPPFileID(XMPPID id, String fn) {
		Assert.isNotNull(id);
		Assert.isNotNull(fn);
		this.xmppid = id;
		this.filename = fn;
	}

	public XMPPID getXMPPID() {
		return xmppid;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ecf.core.identity.BaseID#namespaceToExternalForm()
	 */
	protected String namespaceToExternalForm() {
		return namespace.getScheme() + Namespace.SCHEME_SEPARATOR + xmppid.toExternalForm() + "*" + filename;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ecf.core.identity.BaseID#namespaceCompareTo(org.eclipse.ecf.core.identity.BaseID)
	 */
	protected int namespaceCompareTo(BaseID o) {
		return getName().compareTo(o.getName());
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ecf.core.identity.BaseID#namespaceEquals(org.eclipse.ecf.core.identity.BaseID)
	 */
	protected boolean namespaceEquals(BaseID o) {
		if (!(o instanceof XMPPFileID))
			return false;
		if (o == null)
			return false;
		final XMPPFileID other = (XMPPFileID) o;
		return this.xmppid.equals(other.xmppid) && this.filename.equals(other.filename);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ecf.core.identity.BaseID#namespaceGetName()
	 */
	protected String namespaceGetName() {
		return xmppid.getName() + "/" + filename; //$NON-NLS-1$
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ecf.core.identity.BaseID#namespaceHashCode()
	 */
	protected int namespaceHashCode() {
		return this.xmppid.hashCode() ^ this.filename.hashCode();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ecf.filetransfer.identity.IFileID#getFilename()
	 */
	public String getFilename() {
		return filename;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ecf.filetransfer.identity.IFileID#getURL()
	 */
	public URL getURL() throws MalformedURLException {
		throw new MalformedURLException(Messages.XMPPFileID_EXCEPTION_FILE_IDS_NOT_URLS);
	}

}

Back to the top