Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2018-03-05 17:43:38 -0500
committerslewis2018-03-05 17:43:38 -0500
commita1e2e7aa30f08c1d9e33a1c653b325ef930e8802 (patch)
treec32f2ca3b3445746b9f3c9cbd5409a6f9168127b
parentf245ae29d20f798a2bfb7f8d5797c527a94168bf (diff)
downloadorg.eclipse.ecf-a1e2e7aa30f08c1d9e33a1c653b325ef930e8802.tar.gz
org.eclipse.ecf-a1e2e7aa30f08c1d9e33a1c653b325ef930e8802.tar.xz
org.eclipse.ecf-a1e2e7aa30f08c1d9e33a1c653b325ef930e8802.zip
Update to use gogo for console commands
-rw-r--r--framework/bundles/org.eclipse.ecf.console/.classpath2
-rw-r--r--framework/bundles/org.eclipse.ecf.console/.project5
-rw-r--r--framework/bundles/org.eclipse.ecf.console/.settings/org.eclipse.jdt.core.prefs16
-rw-r--r--framework/bundles/org.eclipse.ecf.console/META-INF/MANIFEST.MF9
-rw-r--r--framework/bundles/org.eclipse.ecf.console/OSGI-INF/org.eclipse.ecf.internal.console.ContainerCommand.xml20
-rw-r--r--framework/bundles/org.eclipse.ecf.console/build.properties6
-rw-r--r--framework/bundles/org.eclipse.ecf.console/src/org/eclipse/ecf/console/AbstractCommand.java174
-rw-r--r--framework/bundles/org.eclipse.ecf.console/src/org/eclipse/ecf/internal/console/Activator.java41
-rw-r--r--framework/bundles/org.eclipse.ecf.console/src/org/eclipse/ecf/internal/console/ContainerCommand.java116
-rw-r--r--framework/bundles/org.eclipse.ecf.console/src/org/eclipse/ecf/internal/console/ECFCommandProvider.java226
-rw-r--r--framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/GUID.java24
-rw-r--r--framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/LongID.java2
12 files changed, 346 insertions, 295 deletions
diff --git a/framework/bundles/org.eclipse.ecf.console/.classpath b/framework/bundles/org.eclipse.ecf.console/.classpath
index 6f3b481ac..098194ca4 100644
--- a/framework/bundles/org.eclipse.ecf.console/.classpath
+++ b/framework/bundles/org.eclipse.ecf.console/.classpath
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/CDC-1.1%Foundation-1.1"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
diff --git a/framework/bundles/org.eclipse.ecf.console/.project b/framework/bundles/org.eclipse.ecf.console/.project
index 74be33c2f..9061ec66a 100644
--- a/framework/bundles/org.eclipse.ecf.console/.project
+++ b/framework/bundles/org.eclipse.ecf.console/.project
@@ -20,6 +20,11 @@
<arguments>
</arguments>
</buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ds.core.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
diff --git a/framework/bundles/org.eclipse.ecf.console/.settings/org.eclipse.jdt.core.prefs b/framework/bundles/org.eclipse.ecf.console/.settings/org.eclipse.jdt.core.prefs
index f1d094124..7341ab168 100644
--- a/framework/bundles/org.eclipse.ecf.console/.settings/org.eclipse.jdt.core.prefs
+++ b/framework/bundles/org.eclipse.ecf.console/.settings/org.eclipse.jdt.core.prefs
@@ -1,7 +1,11 @@
-#Sun Jan 17 17:53:31 PST 2010
eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
-org.eclipse.jdt.core.compiler.compliance=1.4
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
-org.eclipse.jdt.core.compiler.source=1.3
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.7
diff --git a/framework/bundles/org.eclipse.ecf.console/META-INF/MANIFEST.MF b/framework/bundles/org.eclipse.ecf.console/META-INF/MANIFEST.MF
index 600cf583a..f73494c56 100644
--- a/framework/bundles/org.eclipse.ecf.console/META-INF/MANIFEST.MF
+++ b/framework/bundles/org.eclipse.ecf.console/META-INF/MANIFEST.MF
@@ -5,15 +5,16 @@ Bundle-SymbolicName: org.eclipse.ecf.console
Automatic-Module-Name: org.eclipse.ecf.console
Bundle-Vendor: %plugin.provider
Bundle-Version: 1.1.0.qualifier
-Bundle-Activator: org.eclipse.ecf.internal.console.Activator
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: CDC-1.1/Foundation-1.1,
- J2SE-1.3
+ J2SE-1.5
Import-Package: org.eclipse.ecf.core;version="[3.0.0,4.0.0)",
org.eclipse.ecf.core.identity;version="[3.0.0,4.0.0)",
org.eclipse.ecf.core.util;version="[3.0.0,4.0.0)",
- org.eclipse.osgi.framework.console;version="[1.0.0,2.0.0)",
org.osgi.framework;version="[1.3.0,2.0.0)",
org.osgi.util.tracker;version="[1.3.0,2.0.0)"
Bundle-Localization: plugin
-Require-Bundle: org.eclipse.equinox.common;bundle-version="[3.0.0,4.0.0)"
+Require-Bundle: org.eclipse.equinox.common;bundle-version="[3.0.0,4.0.0)",
+ org.apache.felix.gogo.runtime;bundle-version="0.10.0"
+Service-Component: OSGI-INF/org.eclipse.ecf.internal.console.ContainerCommand.xml
+Export-Package: org.eclipse.ecf.console;version="1.0.0"
diff --git a/framework/bundles/org.eclipse.ecf.console/OSGI-INF/org.eclipse.ecf.internal.console.ContainerCommand.xml b/framework/bundles/org.eclipse.ecf.console/OSGI-INF/org.eclipse.ecf.internal.console.ContainerCommand.xml
new file mode 100644
index 000000000..e77a536c4
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf.console/OSGI-INF/org.eclipse.ecf.internal.console.ContainerCommand.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0" immediate="true" name="org.eclipse.ecf.internal.console.ContainerCommand">
+ <property name="osgi.command.scope" value="ecf"/>
+ <property name="osgi.command.function">listcontainers
+lcs
+listnamespaces
+lns
+listtypedescriptions
+lctds
+listconfigs
+lcfgs
+ </property>
+ <service>
+ <provide interface="org.eclipse.ecf.internal.console.ContainerCommand"/>
+ <provide interface="org.apache.felix.service.command.Converter"/>
+ </service>
+ <reference cardinality="1..1" field="containerManager" interface="org.eclipse.ecf.core.IContainerManager" name="containerManager"/>
+ <reference cardinality="1..1" field="idFactory" interface="org.eclipse.ecf.core.identity.IIDFactory" name="idFactory"/>
+ <implementation class="org.eclipse.ecf.internal.console.ContainerCommand"/>
+</scr:component> \ No newline at end of file
diff --git a/framework/bundles/org.eclipse.ecf.console/build.properties b/framework/bundles/org.eclipse.ecf.console/build.properties
index ef11c7d3e..2f7cdf4a0 100644
--- a/framework/bundles/org.eclipse.ecf.console/build.properties
+++ b/framework/bundles/org.eclipse.ecf.console/build.properties
@@ -3,6 +3,8 @@ output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.properties,\
- about.html
+ about.html,\
+ OSGI-INF/org.eclipse.ecf.internal.console.ContainerCommand.xml,\
+ OSGI-INF/
src.includes = about.html
-jre.compilation.profile = J2SE-1.4
+jre.compilation.profile = JavaSE-1.7
diff --git a/framework/bundles/org.eclipse.ecf.console/src/org/eclipse/ecf/console/AbstractCommand.java b/framework/bundles/org.eclipse.ecf.console/src/org/eclipse/ecf/console/AbstractCommand.java
new file mode 100644
index 000000000..eaf283e84
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf.console/src/org/eclipse/ecf/console/AbstractCommand.java
@@ -0,0 +1,174 @@
+/*******************************************************************************
+ * 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.console;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Formatter;
+import java.util.List;
+
+import org.apache.felix.service.command.Converter;
+import org.eclipse.ecf.core.ContainerTypeDescription;
+import org.eclipse.ecf.core.IContainer;
+import org.eclipse.ecf.core.IContainerManager;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IIDFactory;
+import org.eclipse.ecf.core.identity.Namespace;
+
+public abstract class AbstractCommand {
+
+ protected abstract IContainerManager getContainerManager();
+
+ protected abstract IIDFactory getIDFactory();
+
+ protected List<IContainer> getContainers() {
+ return Arrays.asList(getContainerManager().getAllContainers().clone());
+ }
+
+ protected List<Namespace> getNamespaces() {
+ return new ArrayList<Namespace>(getIDFactory().getNamespaces());
+ }
+
+ @SuppressWarnings("unchecked")
+ protected List<ContainerTypeDescription> getConfigs() {
+ return new ArrayList<ContainerTypeDescription>(getContainerManager().getContainerFactory().getDescriptions());
+
+ }
+
+ protected ContainerTypeDescription getContainerTypeDescription(ID containerID) {
+ return getContainerManager().getContainerTypeDescription(containerID);
+ }
+
+ protected IContainer getContainerForId(String id) {
+ for (IContainer c : getContainerManager().getAllContainers().clone())
+ if (c.getID().getName().equals(id))
+ return c;
+ return null;
+ }
+
+ protected String printClassArrays(Class<?>[][] types) {
+ if (types == null)
+ return "";
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < types.length; i++) {
+ Class<?>[] paramTypes = types[i];
+ sb.append("<init>").append("(");
+ for (int j = 0; j < paramTypes.length; j++) {
+ Class<?> pType = paramTypes[j];
+ sb.append(pType.getName());
+ if (j + 1 < paramTypes.length)
+ sb.append(",");
+ }
+ sb.append(")");
+ if (i + 1 < types.length)
+ sb.append(";");
+ }
+ return sb.toString();
+ }
+
+ protected String formatContainer(IContainer c, int level, Converter escape) {
+ ID cID = c.getID();
+ ID conID = c.getConnectedID();
+ String conIDStr = (conID == null) ? "" : conID.getName();
+ Class<?> cClass = c.getClass();
+ switch (level) {
+ case Converter.LINE:
+ try (Formatter f = new Formatter();) {
+ f.format("%s %s %s", cID.getName(), cClass.getName(), conIDStr);
+ return f.toString();
+ }
+ case Converter.INSPECT:
+ try (Formatter f = new Formatter();) {
+ f.format(
+ "ID%s\n" + "\tIDNamespace=%s\n" + "\tImplClass=%s\n" + "\tConnectedTo=%s\n"
+ + "\tConnectNamespace=%s\n" + "\tConfig=%s",
+ cID.getName(), cID.getNamespace().getName(), cClass.getName(), conIDStr,
+ c.getConnectNamespace().getName(), getContainerTypeDescription(cID).getName());
+ return f.toString();
+ }
+ default:
+ return null;
+ }
+ }
+
+ protected String formatNamespace(Namespace ns, int level, Converter escape) {
+ switch (level) {
+ case Converter.PART:
+ return null;
+ case Converter.LINE:
+ try (Formatter f = new Formatter();) {
+ f.format("%s", ns.getName());
+ return f.toString();
+ }
+ case Converter.INSPECT:
+ try (Formatter f = new Formatter();) {
+ f.format(
+ "ID=%s\n" + "\tScheme=%s\n" + "\tImplClass=%s\n" + "\tDescription=%s\n"
+ + "\tFactoryConstructors=%s\n" + "\tSupportedSchemes=%s",
+ ns.getName(), ns.getScheme(), ns.getClass().getName(), ns.getDescription(),
+ printClassArrays(ns.getSupportedParameterTypes()),
+ printStringArray(ns.getSupportedSchemes()));
+ return f.toString();
+ }
+ default:
+ return null;
+ }
+ }
+
+ protected String formatConfig(ContainerTypeDescription ctd, int level, Converter escape) {
+ switch (level) {
+ case Converter.PART:
+ return null;
+ case Converter.LINE:
+ try (Formatter f = new Formatter();) {
+ f.format("%s", ctd.getName());
+ return f.toString();
+ }
+ case Converter.INSPECT:
+ try (Formatter f = new Formatter();) {
+ f.format(
+ "ID=%s\n" + "\tDescription=%s\n" + "\tSupportedConfigs=%s\n" + "\tSupportedIntents=%s\n"
+ + "\tFactoryConstructors=%s\n" + "\tAdapterTypes=%s\n" + "\tHidden=%b\n" + "\tServer=%b",
+ ctd.getName(), ctd.getDescription(), printStringArray(ctd.getSupportedConfigs()),
+ printStringArray(ctd.getSupportedIntents()),
+ printClassArrays(ctd.getSupportedParameterTypes()),
+ printStringArray(ctd.getSupportedAdapterTypes()),
+ ctd.isHidden(), ctd.isServer());
+ return f.toString();
+ }
+ default:
+ return null;
+ }
+ }
+
+ protected String printStringArray(String[] strarr) {
+ return (strarr == null) ? "" : Arrays.asList(strarr).toString();
+ }
+
+ 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;
+ }
+
+}
diff --git a/framework/bundles/org.eclipse.ecf.console/src/org/eclipse/ecf/internal/console/Activator.java b/framework/bundles/org.eclipse.ecf.console/src/org/eclipse/ecf/internal/console/Activator.java
deleted file mode 100644
index 4bb63edef..000000000
--- a/framework/bundles/org.eclipse.ecf.console/src/org/eclipse/ecf/internal/console/Activator.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package org.eclipse.ecf.internal.console;
-
-import org.eclipse.osgi.framework.console.CommandProvider;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
-
-public class Activator implements BundleActivator {
-
- private BundleContext context;
-
- private ECFCommandProvider commandProvider;
- private ServiceRegistration commandProviderRegistration;
-
- /*
- * (non-Javadoc)
- * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
- */
- public void start(BundleContext context) throws Exception {
- this.context = context;
- this.commandProvider = new ECFCommandProvider(this.context);
- commandProviderRegistration = this.context.registerService(CommandProvider.class.getName(), commandProvider, null);
- }
-
- /*
- * (non-Javadoc)
- * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
- */
- public void stop(BundleContext context) throws Exception {
- if (commandProviderRegistration != null) {
- commandProviderRegistration.unregister();
- commandProviderRegistration = null;
- }
- if (commandProvider != null) {
- commandProvider.dispose();
- commandProvider = null;
- }
- this.context = null;
- }
-
-}
diff --git a/framework/bundles/org.eclipse.ecf.console/src/org/eclipse/ecf/internal/console/ContainerCommand.java b/framework/bundles/org.eclipse.ecf.console/src/org/eclipse/ecf/internal/console/ContainerCommand.java
new file mode 100644
index 000000000..96016ce7d
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf.console/src/org/eclipse/ecf/internal/console/ContainerCommand.java
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * 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.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 {
+
+ @Reference
+ private IContainerManager containerManager;
+ @Reference
+ private IIDFactory idFactory;
+
+ protected IContainerManager getContainerManager() {
+ return this.containerManager;
+ }
+
+ protected IIDFactory getIDFactory() {
+ return this.idFactory;
+ }
+
+ @Descriptor("List ECF container instances")
+ public List<IContainer> listcontainers() {
+ return getContainers();
+ }
+
+ @Descriptor("List ECF container instances")
+ public List<IContainer> lc() {
+ return listcontainers();
+ }
+
+ public IContainer listcontainers(@Descriptor("Container ID to list (String)")IContainer container) {
+ return container;
+ }
+
+ public IContainer lc(@Descriptor("Container ID to list (String)")IContainer container) {
+ return container;
+ }
+
+ @Descriptor("List ECF ID namespaces")
+ public List<Namespace> listnamespaces() {
+ return getNamespaces();
+ }
+
+ @Descriptor("List ECF ID namespaces")
+ public List<Namespace> lns() {
+ return listnamespaces();
+ }
+
+ 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() {
+ return getConfigs();
+ }
+
+ @Descriptor("List ECF container configs")
+ public List<ContainerTypeDescription> lctd() {
+ return listtypedescriptions();
+ }
+
+ @Descriptor("List ECF container configs")
+ public List<ContainerTypeDescription> listconfigs() {
+ return getConfigs();
+ }
+
+ public List<ContainerTypeDescription> lcfgs() {
+ return listconfigs();
+ }
+
+ 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;
+ }
+
+}
diff --git a/framework/bundles/org.eclipse.ecf.console/src/org/eclipse/ecf/internal/console/ECFCommandProvider.java b/framework/bundles/org.eclipse.ecf.console/src/org/eclipse/ecf/internal/console/ECFCommandProvider.java
deleted file mode 100644
index b358d73eb..000000000
--- a/framework/bundles/org.eclipse.ecf.console/src/org/eclipse/ecf/internal/console/ECFCommandProvider.java
+++ /dev/null
@@ -1,226 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2009 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.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.ecf.core.ContainerTypeDescription;
-import org.eclipse.ecf.core.IContainer;
-import org.eclipse.ecf.core.IContainerFactory;
-import org.eclipse.ecf.core.IContainerManager;
-import org.eclipse.ecf.core.identity.ID;
-import org.eclipse.ecf.core.identity.IDFactory;
-import org.eclipse.ecf.core.identity.Namespace;
-import org.eclipse.osgi.framework.console.CommandInterpreter;
-import org.osgi.framework.BundleContext;
-import org.osgi.util.tracker.ServiceTracker;
-
-public class ECFCommandProvider implements
- org.eclipse.osgi.framework.console.CommandProvider {
-
- public static final String NEW_LINE = System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
-
- private BundleContext context;
- private ServiceTracker containerManagerTracker;
-
- public ECFCommandProvider(BundleContext context) {
- this.context = context;
- }
-
- private IContainerManager getContainerManager() {
- if (containerManagerTracker == null) {
- containerManagerTracker = new ServiceTracker(this.context,IContainerManager.class.getName(),null);
- containerManagerTracker.open();
- }
- return (IContainerManager) containerManagerTracker.getService();
- }
-
- private IContainerFactory getContainerFactory() {
- return getContainerManager().getContainerFactory();
- }
-
- public void dispose() {
- if (containerManagerTracker != null) {
- containerManagerTracker.close();
- containerManagerTracker = null;
- }
- this.context = null;
- }
-
- private IContainer createContainer(CommandInterpreter interpreter, String containerTypeDescriptionName, String[] args) {
- IContainerFactory containerFactory = getContainerFactory();
- try {
- if (containerTypeDescriptionName == null) return containerFactory.createContainer();
- else if (args == null) return containerFactory.createContainer(containerTypeDescriptionName);
- else return containerFactory.createContainer(containerTypeDescriptionName,args);
- } catch (Exception e) {
- printException(interpreter,"Could not create container with type="+containerTypeDescriptionName,e);
- return null;
- }
- }
-
- private void printException(CommandInterpreter interpreter, String message, Throwable t) {
- interpreter.println("--Exception--");
- if (message != null) interpreter.println(message);
- if (t != null) interpreter.printStackTrace(t);
- interpreter.println("--End Exception--");
- }
-
- private String[] getArgs(CommandInterpreter interpreter) {
- List result = new ArrayList();
- String arg = null;
- while ((arg = interpreter.nextArgument()) != null) result.add(arg);
- return (String[]) result.toArray(new String[] {});
- }
-
- private String[] getRemainingArgs(String[] args, int startPosition) {
- int targetLength = args.length-startPosition;
- String[] result = new String[targetLength];
- System.arraycopy(args, startPosition, result, 0, targetLength);
- return result;
- }
-
- public void _createcontainer(CommandInterpreter interpreter) {
- String[] args = getArgs(interpreter);
- String factoryName = (args.length==0)?null:args[0];
- String[] targetArgs = (args.length==0)?null:getRemainingArgs(args,1);
- IContainer c = createContainer(interpreter, factoryName, targetArgs);
- if (c != null) {
- interpreter.print("container created. ");
- printID(interpreter, c.getID());
- }
- }
-
- private void printContainer(CommandInterpreter interpreter, IContainer container, boolean verbose) {
- interpreter.println("--Container--");
- printID(interpreter, container.getID());
- if (verbose) {
- interpreter.print("\tclass=");
- interpreter.println(container.getClass().getName());
- ID connectedID = container.getConnectedID();
- if (connectedID != null) {
- interpreter.print("\tConnected to: ");
- printID(interpreter, connectedID);
- } else interpreter.println("\tNot connected.");
- Namespace ns = container.getConnectNamespace();
- if (ns != null) {
- interpreter.print("\tConnect namespace: ");
- interpreter.println(ns.getName());
- } else interpreter.println("\tNo connect namespace.");
- ContainerTypeDescription desc = getContainerManager().getContainerTypeDescription(container.getID());
- if (desc != null) printDescription(interpreter, desc);
- }
- interpreter.println("--End Container--");
- }
-
- private void printDescription(CommandInterpreter interpreter, ContainerTypeDescription desc) {
- interpreter.print("\tFactory name=");
- interpreter.println(desc.getName());
- interpreter.print("\tFactory description=");
- interpreter.println(desc.getDescription());
- String[] arr = desc.getSupportedIntents();
- if (arr != null) {
- interpreter.print("\tSupported intents=");
- interpreter.println(Arrays.asList(arr));
- }
- arr = desc.getSupportedConfigs();
- if (arr != null) {
- interpreter.print("\tSupported configs=");
- interpreter.println(Arrays.asList(arr));
- }
- arr = desc.getSupportedAdapterTypes();
- if (arr != null) {
- interpreter.print("\tSupported adapters=");
- interpreter.println(Arrays.asList(arr));
- }
- interpreter.println("\tHidden="+desc.isHidden());
- interpreter.println("\tServer="+desc.isServer());
- }
-
- public void _listcontainers(CommandInterpreter interpreter) {
- String[] args = getArgs(interpreter);
- boolean verbose = (args.length < 1)?false:new Boolean(args[0]).booleanValue();
- IContainer[] containers = getContainerManager().getAllContainers();
- if (containers == null || containers.length == 0) interpreter.println("No containers found.");
- for(int i=0; i < containers.length; i++) {
- printContainer(interpreter, containers[i], verbose);
- }
- }
-
- public void _listfactories(CommandInterpreter interpreter) {
- List descs = getContainerManager().getContainerFactory().getDescriptions();
- if (descs == null || descs.size() == 0) interpreter.println("No factories.");
- for(Iterator i=descs.iterator(); i.hasNext(); ) {
- ContainerTypeDescription desc = (ContainerTypeDescription) i.next();
- printDescription(interpreter, desc);
- }
- }
-
- private void printID(CommandInterpreter interpreter, ID id) {
- interpreter.print("\tID:");
- if (id == null) {
- interpreter.println("null");
- return;
- }
- interpreter.print("ns="+id.getNamespace().getName());
- interpreter.print(";name=");
- interpreter.print(id.getName());
- interpreter.println();
- }
-
- public void _destroycontainer(CommandInterpreter interpreter) {
- String[] args = getArgs(interpreter);
- if (args == null || args.length != 2) {
- interpreter.println("Incorrect number of arguments for container destroy");
- return;
- }
- ID id = createID(interpreter, args[0],args[1]);
- if (id == null) return;
- IContainer container = getContainerManager().removeContainer(id);
- if (container == null) {
- interpreter.println("Container not found to remove");
- return;
- }
- // Dispose the container instance
- container.dispose();
- interpreter.println("Container destroyed.");
- }
-
- private ID createID(CommandInterpreter interpreter, String namespace, String val) {
- try {
- return IDFactory.getDefault().createID(namespace, val);
- } catch (Exception e) {
- interpreter.printStackTrace(e);
- return null;
- }
- }
-
- public String getHelp() {
- StringBuffer help = new StringBuffer();
- help.append(NEW_LINE);
- help.append("---");
- help.append("Eclipse Communication Framework (ECF) Commands");
- help.append("---");
- help.append(NEW_LINE);
- help.append("\tlistfactories -- List all container factories.");
- help.append(NEW_LINE);
- help.append("\tlistcontainers [verbose] -- List all existing containers.");
- help.append(NEW_LINE);
- help.append("\tcreatecontainer [<containerFactoryName> [<arg0> <arg1>...]] -- Create new container.");
- help.append(NEW_LINE);
- help.append("\tdestroycontainer <namespace> <id> -- Remove and dispose container specified by namespace/id combination.");
- help.append(NEW_LINE);
- return help.toString();
- }
-
-}
diff --git a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/GUID.java b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/GUID.java
index 27f2156bf..c084da12d 100644
--- a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/GUID.java
+++ b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/GUID.java
@@ -24,7 +24,7 @@ public class GUID extends StringID {
private static final long serialVersionUID = -8546568877571886386L;
public GUIDNamespace() {
- super(GUID.class.getName(), "GUID Namespace"); //$NON-NLS-1$
+ super(GUID.class.getName(), "GUID Namespace. Default based upon 20-byte SecureRandom in Base64 format"); //$NON-NLS-1$
}
public ID createInstance(Object[] args) throws IDCreateException {
@@ -56,7 +56,7 @@ public class GUID extends StringID {
* getSupportedParameterTypesForCreateInstance()
*/
public Class<?>[][] getSupportedParameterTypes() {
- return new Class[][] { {}, { Integer.class } };
+ return new Class[][] { {}, { Integer.class }, { String.class } };
}
}
@@ -80,15 +80,13 @@ public class GUID extends StringID {
* @param byteLength
* the length of the target number (in bytes)
*/
- protected GUID(Namespace n, String algo, String provider, int byteLength)
- throws IDCreateException {
+ protected GUID(Namespace n, String algo, String provider, int byteLength) throws IDCreateException {
super(n, ""); //$NON-NLS-1$
// Get SecureRandom instance for class
try {
getRandom(algo, provider);
} catch (Exception e) {
- throw new IDCreateException(
- "GUID creation failure: " + e.getMessage()); //$NON-NLS-1$
+ throw new IDCreateException("GUID creation failure: " + e.getMessage()); //$NON-NLS-1$
}
// make sure we have reasonable byteLength
if (byteLength <= 0)
@@ -116,17 +114,16 @@ public class GUID extends StringID {
* Get SecureRandom instance for creation of random number.
*
* @param algo
- * the String algorithm specification (e.g. "SHA1PRNG") for
- * creation of the SecureRandom instance
+ * the String algorithm specification (e.g. "SHA1PRNG") for creation
+ * of the SecureRandom instance
* @param provider
- * the provider of the implementation of the given algorighm
- * (e.g. "SUN")
+ * the provider of the implementation of the given algorighm (e.g.
+ * "SUN")
* @return SecureRandom
* @exception Exception
* thrown if SecureRandom instance cannot be created/accessed
*/
- protected static synchronized SecureRandom getRandom(String algo,
- String provider) throws Exception {
+ protected static synchronized SecureRandom getRandom(String algo, String provider) throws Exception {
// Given algo and provider, get SecureRandom instance
if (random == null) {
initializeRandom(algo, provider);
@@ -134,8 +131,7 @@ public class GUID extends StringID {
return random;
}
- protected static synchronized void initializeRandom(String algo,
- String provider) throws Exception {
+ protected static synchronized void initializeRandom(String algo, String provider) throws Exception {
if (provider == null) {
if (algo == null) {
try {
diff --git a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/LongID.java b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/LongID.java
index 8a0124b23..9e3b94be8 100644
--- a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/LongID.java
+++ b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/LongID.java
@@ -53,7 +53,7 @@ public class LongID extends BaseID {
* getSupportedParameterTypesForCreateInstance()
*/
public Class<?>[][] getSupportedParameterTypes() {
- return new Class[][] { { Long.class } };
+ return new Class[][] { { Long.class }, { String.class } };
}
}

Back to the top