### Eclipse Workspace Patch 1.0 #P jbpm4 Index: modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmElFactoryImpl.java =================================================================== --- modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmElFactoryImpl.java (revision 6403) +++ modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmElFactoryImpl.java (working copy) @@ -39,6 +39,7 @@ import org.jbpm.internal.log.Log; import org.jbpm.pvm.internal.env.EnvironmentImpl; import org.jbpm.pvm.internal.model.ScopeInstanceImpl; +import org.jbpm.pvm.internal.util.FactoryFinder; /** @@ -108,8 +109,14 @@ // TODO these ExpressionFactory properties could be integrated in the configuration Properties properties = new Properties(); properties.setProperty("javax.el.methodInvocations", "true"); - ExpressionFactory expressionFactory = ExpressionFactory.newInstance(properties); - + ExpressionFactory expressionFactory = null; + try { + expressionFactory = ExpressionFactory.newInstance(properties); + + } catch (NoSuchMethodError e) { + // to support previous version of el-api + expressionFactory = (ExpressionFactory) FactoryFinder.find(ExpressionFactory.class.getName(), null, null, "el.properties"); + } BeanManager beanManager = getBeanManager(); if (beanManager!=null) { expressionFactory = beanManager.wrapExpressionFactory(expressionFactory); Index: modules/pvm/src/main/java/org/jbpm/pvm/internal/util/FactoryFinder.java =================================================================== --- modules/pvm/src/main/java/org/jbpm/pvm/internal/util/FactoryFinder.java (revision 0) +++ modules/pvm/src/main/java/org/jbpm/pvm/internal/util/FactoryFinder.java (revision 0) @@ -0,0 +1,130 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jbpm.pvm.internal.util; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.lang.reflect.Constructor; +import java.util.Properties; + +import org.jbpm.api.JbpmException; +/** + * + * FactoryFinder based on javax.el.FactoryFinder + * + * @author Maciej Swiderski + */ +public class FactoryFinder { + + FactoryFinder() { + } + + private static Object newInstance(String s, ClassLoader classloader, Properties properties) { + Class< ? > class1; + try { + if (classloader == null) + class1 = Class.forName(s); + else + class1 = classloader.loadClass(s); + if (properties != null) { + Constructor< ? > constructor = null; + try { + constructor = class1.getConstructor(new Class[] { java.util.Properties.class }); + } catch (Exception exception1) { + } + if (constructor != null) + return constructor.newInstance(new Object[] { properties }); + } + + return class1.newInstance(); + + } catch (ClassNotFoundException classnotfoundexception) { + throw new JbpmException((new StringBuilder()).append("Provider ").append(s).append(" not found").toString(), classnotfoundexception); + } catch (Exception exception) { + throw new JbpmException((new StringBuilder()).append("Provider ").append(s).append(" could not be instantiated: ").append(exception).toString(), exception); + } + + } + + /** + * Finds and initializes service provider for service given as serviceName with properties (if not null). + * Alternatively it will look up for property file from JAVA_HOME\lib\PROPERTY_FILE_NAME prior to initialize. + * + * @param serviceName service name which provider should be found for + * @param defaultServiceName default service name that should be returned in case serviceName provider was not found + * @param properties properties that will be passed to implementation class + * @param propertyFileName name of the property file can be found in JAVA_HOME\lib + * + * @return new instance of implementation class found for given serviceName or if not found instance of defaultServiceName if given + * + * @throws JBPMException in case of provider was not found + * + */ + public static Object find(String serviceName, String defaultServiceName, Properties properties, String propertyFileName) { + ClassLoader classloader; + try { + classloader = Thread.currentThread().getContextClassLoader(); + } catch (Exception exception) { + throw new JbpmException(exception.toString(), exception); + } + String serviceResourcePath = (new StringBuilder()).append("META-INF/services/").append(serviceName).toString(); + try { + java.io.InputStream inputstream = null; + if (classloader == null) + inputstream = ClassLoader.getSystemResourceAsStream(serviceResourcePath); + else + inputstream = classloader.getResourceAsStream(serviceResourcePath); + if (inputstream != null) { + BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(inputstream, "UTF-8")); + String line = bufferedreader.readLine(); + bufferedreader.close(); + if (line != null && !"".equals(line)) + return newInstance(line, classloader, properties); + } + } catch (Exception exception1) { + } + try { + String javaHomeProperty = System.getProperty("java.home"); + String propertyFilePath = (new StringBuilder()).append(javaHomeProperty).append(File.separator).append("lib").append(File.separator).append(propertyFileName).toString(); + File file = new File(propertyFilePath); + if (file.exists()) { + Properties properties1 = new Properties(); + properties1.load(new FileInputStream(file)); + String serviceNameFromFile = properties1.getProperty(serviceName); + return newInstance(serviceNameFromFile, classloader, properties); + } + } catch (Exception exception2) { + } + try { + String serviceNameProperty = System.getProperty(serviceName); + if (serviceNameProperty != null) + return newInstance(serviceNameProperty, classloader, properties); + } catch (SecurityException securityexception) { + } + if (defaultServiceName == null) + throw new JbpmException((new StringBuilder()).append("Provider for ").append(serviceName).append(" cannot be found").toString(), null); + else + return newInstance(defaultServiceName, classloader, properties); + } +} Property changes on: modules\pvm\src\main\java\org\jbpm\pvm\internal\util\FactoryFinder.java ___________________________________________________________________ Added: svn:keywords + Id Revision Added: svn:eol-style + LF