Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: fd699eccaadaff3d8dfa2d0255037f998890916f (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*******************************************************************************
 * Copyright (c) 2018 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.internal.console;

import java.util.List;

import org.apache.felix.service.command.CommandSession;
import org.apache.felix.service.command.Converter;
import org.apache.felix.service.command.Descriptor;
import org.eclipse.ecf.console.AbstractCommand;
import org.eclipse.ecf.core.ContainerTypeDescription;
import org.eclipse.ecf.core.IContainer;
import org.eclipse.ecf.core.IContainerManager;
import org.eclipse.ecf.core.identity.IIDFactory;
import org.eclipse.ecf.core.identity.Namespace;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

@Component(immediate = true, property = { "osgi.command.scope=ecf", "osgi.command.function=listcontainers",
		"osgi.command.function=lcs", "osgi.command.function=listnamespaces", "osgi.command.function=lns",
		"osgi.command.function=listtypedescriptions", "osgi.command.function=lctds",
		"osgi.command.function=listconfigs",
		"osgi.command.function=lcfgs" }, service = { ContainerCommand.class, Converter.class })
public class ContainerCommand extends AbstractCommand implements Converter {

	private IContainerManager containerManager;
	private IIDFactory idFactory;

	@Reference
	void bindContainerManager(IContainerManager cm) {
		this.containerManager = cm;
	}

	void unbindContainerManager(IContainerManager cm) {
		this.containerManager = null;
	}

	@Reference
	void bindIdentityFactory(IIDFactory idf) {
		this.idFactory = idf;
	}

	void unbindIdentityFactory(IIDFactory idf) {
		this.idFactory = null;
	}

	protected IContainerManager getContainerManager() {
		return this.containerManager;
	}

	protected IIDFactory getIDFactory() {
		return this.idFactory;
	}

	@Descriptor("List ECF container instances")
	public List<IContainer> listcontainers(CommandSession cs) {
		consoleLine(cs,CONTAINER_LINE_FORMAT, "ID", "ImplClass", "Connected\n");
		return getContainers();
	}

	@Descriptor("List ECF container instances")
	public List<IContainer> lcs(CommandSession cs) {
		return listcontainers(cs);
	}

	public IContainer listcontainers(@Descriptor("Container ID to list (String)") IContainer container) {
		return container;
	}

	public IContainer lcs(@Descriptor("Container ID to list (String)") IContainer container) {
		return container;
	}

	@Descriptor("List ECF ID namespaces")
	public List<Namespace> listnamespaces(CommandSession cs) {
		consoleLine(cs, NAMESPACE_LINE_FORMAT, "Namespace Name\n");
		return getNamespaces();
	}

	@Descriptor("List ECF ID namespaces")
	public List<Namespace> lns(CommandSession cs) {
		return listnamespaces(cs);
	}

	public Namespace listnamespaces(@Descriptor("Namespace name to list (String)") Namespace ns) {
		return ns;
	}

	public Namespace lns(@Descriptor("Namespace name to list (String)") Namespace ns) {
		return ns;
	}

	@Descriptor("List ECF container configs")
	public List<ContainerTypeDescription> listtypedescriptions(CommandSession cs) {
		consoleLine(cs, CTD_LINE_FORMAT, "ContainerTypeDescription Name\n");
		return getConfigs();
	}

	@Descriptor("List ECF container configs")
	public List<ContainerTypeDescription> lctds(CommandSession cs) {
		return listtypedescriptions(cs);
	}

	@Descriptor("List ECF container configs")
	public List<ContainerTypeDescription> listconfigs(CommandSession cs) {
		cs.getConsole().format(CTD_LINE_FORMAT, "Config Name\n");
		return getConfigs();
	}

	public List<ContainerTypeDescription> lcfgs(CommandSession cs) {
		return listconfigs(cs);
	}

	public ContainerTypeDescription listtypedescriptions(
			@Descriptor("Config name to list (String)") ContainerTypeDescription ctd) {
		return ctd;
	}

	public ContainerTypeDescription lctds(@Descriptor("Config name to list (String)") ContainerTypeDescription ctd) {
		return ctd;
	}

	public ContainerTypeDescription listconfigs(
			@Descriptor("Config name to list (String)") ContainerTypeDescription ctd) {
		return ctd;
	}

	public ContainerTypeDescription lcfgs(@Descriptor("Config name to list (String)") ContainerTypeDescription ctd) {
		return ctd;
	}

	public Object convert(Class<?> desiredType, Object in) throws Exception {
		if (desiredType == IContainer.class && in instanceof String)
			return getContainerForId((String) in);
		else if (desiredType == Namespace.class && in instanceof String)
			return getIDFactory().getNamespaceByName((String) in);
		else if (desiredType == ContainerTypeDescription.class)
			return getContainerManager().getContainerFactory().getDescriptionByName((String) in);
		return null;
	}

	public String format(Object target, int level, Converter escape) {
		if (target instanceof IContainer)
			return formatContainer((IContainer) target, level, escape);
		else if (target instanceof Namespace)
			return formatNamespace((Namespace) target, level, escape);
		else if (target instanceof ContainerTypeDescription)
			return formatConfig((ContainerTypeDescription) target, level, escape);
		return null;
	}

}

Back to the top