Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: fa7ee71ffb71750350154aa6f358b118bc82ea09 (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
/*******************************************************************************
 * Copyright (c) 2011 Wind River Systems, 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:
 * Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tcf.te.tcf.locator.internal.adapters;

import java.io.IOException;
import java.net.URI;
import java.util.Map;

import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.Path;
import org.eclipse.tcf.protocol.Protocol;
import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable;

/**
 * Persistable implementation handling peer attributes.
 */
public class PeerModelPersistableAdapter implements IPersistable {

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable#getStorageID()
	 */
	@Override
	public String getStorageID() {
		return "org.eclipse.tcf.te.tcf.locator.persistence"; //$NON-NLS-1$
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable#getURI(java.lang.Object)
	 */
    @Override
	public URI getURI(final Object data) {
		Assert.isNotNull(data);

		URI uri = null;

		// Only peer model objects are supported
		if (data instanceof IPeerModel) {
			// Get the file path the peer model has been created from
			final String[] path = new String[1];
			if (Protocol.isDispatchThread()) {
				path[0] = ((IPeerModel)data).getPeer().getAttributes().get("Path"); //$NON-NLS-1$
			} else {
				Protocol.invokeAndWait(new Runnable() {
					@Override
					public void run() {
						path[0] = ((IPeerModel)data).getPeer().getAttributes().get("Path"); //$NON-NLS-1$
					}
				});
			}

			if (path[0] != null && !"".equals(path[0].trim())) { //$NON-NLS-1$
				uri = new Path(path[0].trim()).toFile().toURI();
			}
		}

		return uri;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable#exportFrom(java.lang.Object)
	 */
    @Override
	public Map<String, Object> exportFrom(Object data) throws IOException {
		Assert.isNotNull(data);

		Map<String, Object> result = null;

		// Only peer model objects are supported
		if (data instanceof IPeerModel) {
		}

		return result;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable#importTo(java.lang.Object, java.util.Map)
	 */
	@Override
	public void importTo(Object data, Map<String, Object> external) throws IOException {
		Assert.isNotNull(data);
		Assert.isNotNull(external);

		// Only peer model objects are supported
		if (data instanceof IPeerModel) {
		}
	}

}

Back to the top