Author: swiderski.maciej
Date: 2010-06-15 11:50:38 -0400 (Tue, 15 Jun 2010)
New Revision: 6417
Added:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/FactoryFinder.java
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmElFactoryImpl.java
Log:
JBPM-2800: catch NoSuchMethodError and creates ExpressionFactory in different way (using
FactoryFinder)
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmElFactoryImpl.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmElFactoryImpl.java 2010-06-15
11:23:28 UTC (rev 6416)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmElFactoryImpl.java 2010-06-15
15:50:38 UTC (rev 6417)
@@ -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);
Added:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/FactoryFinder.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/FactoryFinder.java
(rev 0)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/FactoryFinder.java 2010-06-15
15:50:38 UTC (rev 6417)
@@ -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 (constru!
ctor != null)
+ return constructor.newInstance(new Ob!
ject[] {
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
<code>serviceName</code> with properties (if not null).
+ * Alternatively it will look up for property file from
<code>JAVA_HOME\lib\PROPERTY_FILE_NAME</code> prior to initialize.
+ *
+ * @param serviceName service name which provider should be found for
+ * @param defaultServiceProvider default service provider that should be returned in
case <code>serviceName</code> provider was not found
+ * @para!
m properties properties that will be passed to implementation class
+ * @param propertyFileName name of the property file can be found in
<code>JAVA_HOME\lib</code>
+ *
+ * @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 defaultServiceProvider, 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.getSy!
stemResourceAsStream(serviceResourcePath);
+ else
+ !
inputs
tream = 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(se!
rviceNameFromFile, classloader, properties);
+ }
+ } catch (Exception exception2) {
+ }
+ try {
+ String serviceNameProperty = System.getProperty(serviceName);
+ if (serviceNameProperty != null)
+ return newInstance(serviceNameProperty, classloader, properties);
+ } catch (SecurityException securityexception) {
+ }
+ if (defaultServiceProvider == null)
+ throw new JbpmException((new StringBuilder()).append("Provider for
").append(serviceName).append(" cannot be found").toString(), null);
+ else
+ return newInstance(defaultServiceProvider, classloader, properties);
+ }
+}