blob: 9af9521569f14bd793b136c0f4f800a714f38016 (
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
|
/*******************************************************************************
* Copyright (c) 2011, 2012 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.services;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.tcf.protocol.IPeer;
import org.eclipse.tcf.protocol.Protocol;
import org.eclipse.tcf.te.runtime.services.interfaces.constants.IPropertiesAccessServiceConstants;
import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode;
/**
* Peer model properties access service implementation.
*/
public class PropertiesAccessService extends org.eclipse.tcf.te.tcf.core.model.services.PropertiesAccessService {
/* (non-Javadoc)
* @see org.eclipse.tcf.te.runtime.services.interfaces.IPropertiesAccessService#getTargetAddress(java.lang.Object)
*/
@Override
public Map<String, String> getTargetAddress(Object context) {
final Map<String, String> result = new HashMap<String, String>();
final IPeer peer;
if (context instanceof IPeer) {
peer = (IPeer)context;
}
else if (context instanceof IPeerNode) {
peer = ((IPeerNode)context).getPeer();
}
else {
peer = null;
}
if (peer != null) {
Protocol.invokeAndWait(new Runnable() {
@Override
public void run() {
Map<String, String> attributes = peer.getAttributes();
String value = attributes.get(IPeer.ATTR_NAME);
if (value != null && !"".equals(value.trim())) { //$NON-NLS-1$
result.put(IPropertiesAccessServiceConstants.PROP_NAME, value);
}
value = attributes.get(IPeer.ATTR_IP_HOST);
if (value != null && !"".equals(value.trim())) { //$NON-NLS-1$
result.put(IPropertiesAccessServiceConstants.PROP_ADDRESS, value);
}
value = attributes.get(IPeer.ATTR_IP_PORT);
if (value != null && !"".equals(value.trim())) { //$NON-NLS-1$
result.put(IPropertiesAccessServiceConstants.PROP_PORT, value);
}
}
});
}
return !result.isEmpty() ? Collections.unmodifiableMap(result) : null;
}
}
|