1 /* 2 * Copyright (C) 2007-2012 Argeo GmbH 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 package org.argeo.slc.osgi; 17 18 import org.apache.commons.logging.Log; 19 import org.apache.commons.logging.LogFactory; 20 import org.argeo.slc.core.execution.AbstractSpringExecutionModule; 21 import org.argeo.slc.execution.ExecutionContext; 22 23 @Deprecated 24 public class OsgiExecutionModule extends AbstractSpringExecutionModule { 25 private final static Log log = LogFactory.getLog(OsgiExecutionModule.class); 26 27 public OsgiExecutionModule() { 28 log.error("######## ERROR - DEPRECATED APPROACH USED ########"); 29 log.error(OsgiExecutionModule.class.getName() + " is deprecated. "); 30 log 31 .error("It will be removed in the next release. Remove its bean definition."); 32 log 33 .error("And replace: <service interface=\"org.argeo.slc.execution.ExecutionModule\" ref=\"executionModule\" />"); 34 log 35 .error("by: <beans:import resource=\"classpath:org/argeo/slc/osgi/execution/spring.xml\" /> "); 36 log.error("in osgi.xml.\n\n"); 37 } 38 39 public void setExecutionContext(ExecutionContext executionContext) { 40 // do nothing, just for compatibility 41 } 42 43 /* 44 * private BundleContext bundleContext; 45 * 46 * @Override public void execute(ExecutionFlowDescriptor 47 * executionFlowDescriptor) { if (descriptorConverter != null) 48 * executionContext.addVariables(descriptorConverter 49 * .convertValues(executionFlowDescriptor)); 50 * 51 * ExecutionFlow flow = findExecutionFlow(getName(), getVersion(), 52 * executionFlowDescriptor.getName()); flow.run(); } 53 * 54 * @Override protected Map<String, ExecutionFlow> listFlows() { String 55 * filter = "(org.argeo.slc.execution.module.name=" + getName() + ")"; 56 * ServiceReference[] sfs; try { sfs = 57 * bundleContext.getServiceReferences(ExecutionFlow.class .getName(), 58 * filter); } catch (InvalidSyntaxException e) { throw new SlcException( 59 * "Cannot retrieve service reference for flow " + filter, e); } 60 * 61 * Map<String, ExecutionFlow> flows = new HashMap<String, ExecutionFlow>(); 62 * for (ServiceReference sf : sfs) { ExecutionFlow flow = (ExecutionFlow) 63 * bundleContext.getService(sf); flows.put(flow.getName(), flow); } return 64 * flows; } 65 * 66 * public String getName() { return 67 * bundleContext.getBundle().getSymbolicName(); } 68 * 69 * public String getVersion() { return 70 * bundleContext.getBundle().getHeaders().get("Bundle-Version") .toString(); 71 * } 72 * 73 * public void setBundleContext(BundleContext bundleContext) { 74 * this.bundleContext = bundleContext; } 75 * 76 * protected ExecutionFlow findExecutionFlow(String moduleName, String 77 * moduleVersion, String flowName) { String filter = 78 * "(&(org.argeo.slc.execution.module.name=" + moduleName + 79 * ")(org.argeo.slc.execution.flow.name=" + flowName + "))"; 80 * log.debug("OSGi filter: " + filter); 81 * 82 * Assert.isTrue(OsgiFilterUtils.isValidFilter(filter), "valid filter"); 83 * ServiceReference[] sfs; try { sfs = 84 * bundleContext.getServiceReferences(ExecutionFlow.class .getName(), 85 * filter); } catch (InvalidSyntaxException e) { throw new 86 * SlcException("Cannot retrieve service reference for " + filter, e); } 87 * 88 * if (sfs == null || sfs.length == 0) throw new 89 * SlcException("No execution flow found for " + filter); else if 90 * (sfs.length > 1) throw new 91 * SlcException("More than one execution flow found for " + filter); return 92 * (ExecutionFlow) bundleContext.getService(sfs[0]); } 93 */ 94 95 }