1 package org
.argeo
.slc
.equinox
;
3 import java
.util
.ArrayList
;
4 import java
.util
.Iterator
;
7 import org
.argeo
.slc
.SlcException
;
8 import org
.argeo
.slc
.execution
.ExecutionFlowDescriptor
;
9 import org
.argeo
.slc
.execution
.ExecutionModule
;
10 import org
.eclipse
.osgi
.framework
.console
.CommandInterpreter
;
11 import org
.eclipse
.osgi
.framework
.console
.CommandProvider
;
12 import org
.osgi
.framework
.Bundle
;
13 import org
.osgi
.framework
.BundleContext
;
14 import org
.osgi
.framework
.BundleException
;
15 import org
.osgi
.framework
.ServiceReference
;
16 import org
.springframework
.osgi
.context
.BundleContextAware
;
18 public class ExecutionCommandProvider
implements CommandProvider
,
20 private List
<ExecutionModule
> executionModules
;
21 private BundleContext bundleContext
;
23 public Object
_slc_exec(CommandInterpreter ci
) {
24 // TODO: check version
25 String firstArg
= ci
.nextArgument();
26 String executionName
= ci
.nextArgument();
27 String moduleName
= null;
31 bundleId
= Long
.parseLong(firstArg
);
32 } catch (NumberFormatException e
) {
37 if (bundleId
!= null) {
38 bundle
= bundleContext
.getBundle(bundleId
);
40 for (Bundle b
: bundleContext
.getBundles()) {
41 if (b
.getSymbolicName().contains(firstArg
)) {
49 moduleName
= bundle
.getSymbolicName();
55 // // FIXME: potential infinite loop
56 // while (bundle.getState() == Bundle.STARTING) {
59 // } catch (InterruptedException e) {
63 // } catch (BundleException e) {
64 // throw new SlcException(
65 // "Could not update the bundle for module " + moduleName,
71 ExecutionModule module
= null;
72 if (moduleName
!= null) {
73 for (Iterator
<ExecutionModule
> it
= executionModules
.iterator(); it
75 ExecutionModule moduleT
= it
.next();
76 if (moduleT
.getName().equals(moduleName
)) {
84 ExecutionFlowDescriptor descriptor
= new ExecutionFlowDescriptor();
85 descriptor
.setName(executionName
);
86 module
.execute(descriptor
);
87 return "Executed " + executionName
+ " from " + moduleName
;
89 return "Could not find any execution module matching these requirements.";
92 public String
getHelp() {
93 StringBuffer buf
= new StringBuffer();
94 buf
.append("---SLC Execution Commands---\n");
96 .append("\tslc_exec (<id>|<segment of bsn>) <execution bean> - execute an execution flow\n");
97 return buf
.toString();
101 public void setExecutionModules(List
<ExecutionModule
> executionModules
) {
102 this.executionModules
= executionModules
;
105 public void setBundleContext(BundleContext bundleContext
) {
106 this.bundleContext
= bundleContext
;