2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org
.argeo
.slc
.osgi
;
19 import org
.apache
.commons
.logging
.Log
;
20 import org
.apache
.commons
.logging
.LogFactory
;
21 import org
.argeo
.slc
.core
.execution
.AbstractSpringExecutionModule
;
22 import org
.argeo
.slc
.execution
.ExecutionContext
;
25 public class OsgiExecutionModule
extends AbstractSpringExecutionModule
{
26 private final static Log log
= LogFactory
.getLog(OsgiExecutionModule
.class);
28 public OsgiExecutionModule() {
29 log
.error("######## ERROR - DEPRECATED APPROACH USED ########");
30 log
.error(OsgiExecutionModule
.class.getName() + " is deprecated. ");
32 .error("It will be removed in the next release. Remove its bean definition.");
34 .error("And replace: <service interface=\"org.argeo.slc.execution.ExecutionModule\" ref=\"executionModule\" />");
36 .error("by: <beans:import resource=\"classpath:org/argeo/slc/osgi/execution/spring.xml\" /> ");
37 log
.error("in osgi.xml.\n\n");
40 public void setExecutionContext(ExecutionContext executionContext
) {
41 // do nothing, just for compatibility
45 * private BundleContext bundleContext;
47 * @Override public void execute(ExecutionFlowDescriptor
48 * executionFlowDescriptor) { if (descriptorConverter != null)
49 * executionContext.addVariables(descriptorConverter
50 * .convertValues(executionFlowDescriptor));
52 * ExecutionFlow flow = findExecutionFlow(getName(), getVersion(),
53 * executionFlowDescriptor.getName()); flow.run(); }
55 * @Override protected Map<String, ExecutionFlow> listFlows() { String
56 * filter = "(org.argeo.slc.execution.module.name=" + getName() + ")";
57 * ServiceReference[] sfs; try { sfs =
58 * bundleContext.getServiceReferences(ExecutionFlow.class .getName(),
59 * filter); } catch (InvalidSyntaxException e) { throw new SlcException(
60 * "Cannot retrieve service reference for flow " + filter, e); }
62 * Map<String, ExecutionFlow> flows = new HashMap<String, ExecutionFlow>();
63 * for (ServiceReference sf : sfs) { ExecutionFlow flow = (ExecutionFlow)
64 * bundleContext.getService(sf); flows.put(flow.getName(), flow); } return
67 * public String getName() { return
68 * bundleContext.getBundle().getSymbolicName(); }
70 * public String getVersion() { return
71 * bundleContext.getBundle().getHeaders().get("Bundle-Version") .toString();
74 * public void setBundleContext(BundleContext bundleContext) {
75 * this.bundleContext = bundleContext; }
77 * protected ExecutionFlow findExecutionFlow(String moduleName, String
78 * moduleVersion, String flowName) { String filter =
79 * "(&(org.argeo.slc.execution.module.name=" + moduleName +
80 * ")(org.argeo.slc.execution.flow.name=" + flowName + "))";
81 * log.debug("OSGi filter: " + filter);
83 * Assert.isTrue(OsgiFilterUtils.isValidFilter(filter), "valid filter");
84 * ServiceReference[] sfs; try { sfs =
85 * bundleContext.getServiceReferences(ExecutionFlow.class .getName(),
86 * filter); } catch (InvalidSyntaxException e) { throw new
87 * SlcException("Cannot retrieve service reference for " + filter, e); }
89 * if (sfs == null || sfs.length == 0) throw new
90 * SlcException("No execution flow found for " + filter); else if
91 * (sfs.length > 1) throw new
92 * SlcException("More than one execution flow found for " + filter); return
93 * (ExecutionFlow) bundleContext.getService(sfs[0]); }