Skip to main content
summaryrefslogtreecommitdiffstats
blob: b1bba384e235ddd49fc03279561f1c955ceb2f8c (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
/*******************************************************************************
 * Copyright (c) 2015 Composent, Inc. 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: Scott Lewis - initial API and implementation
 ******************************************************************************/
package org.eclipse.ecf.remoteserviceadmin.ui.service.model;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.ecf.internal.remoteservices.ui.Messages;
import org.eclipse.ecf.remoteservices.ui.util.PropertyUtils;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;

/**
 * @since 3.3
 */
public class AbstractServicesNode implements IAdaptable {

	public static final String CLOSED = Messages.AbstractRSANode_NodeClosed;

	private AbstractServicesNode parent;
	private final List<AbstractServicesNode> children = new ArrayList<AbstractServicesNode>();

	public AbstractServicesNode() {
	}

	public AbstractServicesNode getParent() {
		return this.parent;
	}

	protected void setParent(AbstractServicesNode p) {
		this.parent = p;
	}

	public void addChild(AbstractServicesNode child) {
		children.add(child);
		child.setParent(this);
	}

	public void addChildAtIndex(int index, AbstractServicesNode child) {
		children.add(index, child);
		child.setParent(this);
	}

	public void removeChild(AbstractServicesNode child) {
		children.remove(child);
		child.setParent(null);
	}

	public AbstractServicesNode[] getChildren() {
		return (AbstractServicesNode[]) children.toArray(new AbstractServicesNode[children.size()]);
	}

	public boolean hasChildren() {
		return children.size() > 0;
	}

	public void clearChildren() {
		children.clear();
	}

	public static String convertStringArrayToString(String[] strings) {
		return PropertyUtils.convertStringArrayToString(strings);
	}

	public static Map<String, Object> convertServicePropsToMap(ServiceReference sr) {
		return PropertyUtils.convertServicePropsToMap(sr);
	}

	protected String convertObjectClassToString(ServiceReference sr) {
		return (sr == null) ? CLOSED : convertStringArrayToString((String[]) sr.getProperty(Constants.OBJECTCLASS));
	}

	@Override
	public Object getAdapter(Class adapter) {
		return null;
	}
}

Back to the top