Author: alex.guizar(a)jboss.com
Date: 2010-06-16 19:22:42 -0400 (Wed, 16 Jun 2010)
New Revision: 6419
Added:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/FactoryFinder.java
Removed:
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
jbpm4/trunk/pom.xml
Log:
JBPM-2800: make de.odysseus.el.ExpressionFactoryImpl the default service provider;
update factory finder code to match juel v2.2.1;
hide factory finder class
Copied: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/FactoryFinder.java
(from rev 6417,
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/el/FactoryFinder.java
(rev 0)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/FactoryFinder.java 2010-06-16
23:22:42 UTC (rev 6419)
@@ -0,0 +1,189 @@
+/*
+ * 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.el;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Properties;
+
+import javax.el.ELException;
+import javax.el.ExpressionFactory;
+
+/**
+ * FactoryFinder based on javax.el.FactoryFinder
+ */
+class FactoryFinder {
+
+ private FactoryFinder() {
+ }
+
+ /**
+ * Create an ExpressionFactory instance.
+ *
+ * @param properties Properties passed to the constructor of the implementation.
+ * @return an instance of ExpressionFactory
+ * @param className The name of the ExpressionFactory class.
+ * @param classLoader The class loader to be used to load the class.
+ * @return An instance of ExpressionFactory.
+ * @throws ELException if the class !
could not be found or if it is not a subclass of
+ * !
Express
ionFactory or if the class could not be instantiated.
+ */
+ private static ExpressionFactory newInstance(Properties properties, String className,
+ ClassLoader classLoader) {
+ Class<?> clazz;
+ try {
+ clazz = classLoader.loadClass(className.trim());
+ }
+ catch (ClassNotFoundException e) {
+ throw new ELException("expression factory class not found", e);
+ }
+
+ Class<? extends ExpressionFactory> factoryClass =
clazz.asSubclass(ExpressionFactory.class);
+ try {
+ if (properties != null) {
+ try {
+ Constructor<? extends ExpressionFactory> constructor =
factoryClass.getConstructor(Properties.class);
+ try {
+ return constructor.newInstance(properties);
+ }
+ catch (InvocationTargetException e) {
+ throw new ELException(constructor + " threw exception",
e.getCause());
+ }
+ }
+ catch (NoSuchMethodException e) {
+ // do nothing
+ }!
+ }
+ return factoryClass.newInstance();
+ }
+ catch (InstantiationException e) {
+ throw new ELException("failed to instantiate: " + factoryClass, e);
+ }
+ catch (IllegalAccessException e) {
+ throw new ELException(FactoryFinder.class + " has no access to " +
factoryClass, e);
+ }
+ }
+
+ /**
+ * 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/propertyFileName</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
+ * @param 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 imp!
lementat
ion class found for given serviceName or if not found
+ * instance of defaultServiceName if given
+ * @throws ELException 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 (SecurityException e) {
+ classLoader = ExpressionFactory.class.getClassLoader();
+ }
+
+ String className = getClassName(serviceName, defaultServiceProvider,
propertyFileName, classLoader);
+ return newInstance(properties, className, classLoader);
+ }
+
+ private static String getClassName(String serviceName, String defaultServiceProvider,
+ String propertyFileName, ClassLoader classLoader) {
+ InputStream serviceInput =
classLoader.getResourceAsStream("META-INF/services/"
+ + serviceName);
+ if (serviceInput != nu!
ll) {
+ try {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(serviceInput,
"UTF-8"));
+ String className = reader.readLine();
+ if (className != null) return className;
+ reader.close();
+ }
+ catch (IOException e) {
+ // do nothing
+ }
+ finally {
+ try {
+ serviceInput.close();
+ }
+ catch (IOException e) {
+ // do nothing
+ }
+ }
+ }
+
+ try {
+ String home = System.getProperty("java.home");
+ if (home != null) {
+ File propertyFile = new File(home + File.separator + "lib",
propertyFileName);
+ if (propertyFile.canRead()) {
+ InputStream propertyInput = null;
+ try {
+ propertyInput = new FileInputStream(propertyFile);
+ Properties props = new Properties();
+ props.load(propertyInput);
+
+ String className = props.getProperty(ExpressionFactory.class.ge!
tName());
+ if (className != null) return className!
;
+
}
+ catch (IOException e) {
+ // do nothing
+ }
+ finally {
+ if (propertyInput != null) {
+ try {
+ propertyInput.close();
+ }
+ catch (IOException e) {
+ // do nothing
+ }
+ }
+ }
+ }
+ }
+ }
+ catch (SecurityException se) {
+ // do nothing
+ }
+
+ try {
+ String className = System.getProperty(serviceName);
+ if (className != null) return className;
+ }
+ catch (SecurityException se) {
+ // do nothing
+ }
+
+ return defaultServiceProvider;
+ }
+}
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-16
11:13:38 UTC (rev 6418)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmElFactoryImpl.java 2010-06-16
23:22:42 UTC (rev 6419)
@@ -21,8 +21,6 @@
*/
package org.jbpm.pvm.internal.el;
-import java.util.Properties;
-
import javax.el.ArrayELResolver;
import javax.el.BeanELResolver;
import javax.el.CompositeELResolver;
@@ -39,9 +37,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;
-
/**
* @author Tom Baeyens
*/
@@ -106,22 +102,20 @@
}
public ExpressionFactory createExpressionFactory() {
- // TODO these ExpressionFactory properties could be integrated in the configuration
- Properties properties = new Properties();
- properties.setProperty("javax.el.methodInvocations", "true");
- ExpressionFactory expressionFactory = null;
+ ExpressionFactory expressionFactory;
try {
- expressionFactory = ExpressionFactory.newInstance(properties);
-
+ expressionFactory = ExpressionFactory.newInstance();
} catch (NoSuchMethodError e) {
// to support previous version of el-api
- expressionFactory = (ExpressionFactory)
FactoryFinder.find(ExpressionFactory.class.getName(), null, null,
"el.properties");
+ expressionFactory = (ExpressionFactory) FactoryFinder.find(ExpressionFactory.class
+ .getName(),"de.odysseus.el.ExpressionFactoryImpl", null,
"el.properties");
}
+
BeanManager beanManager = getBeanManager();
if (beanManager!=null) {
expressionFactory = beanManager.wrapExpressionFactory(expressionFactory);
}
-
+
return expressionFactory;
}
Deleted:
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 2010-06-16
11:13:38 UTC (rev 6418)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/FactoryFinder.java 2010-06-16
23:22:42 UTC (rev 6419)
@@ -1,130 +0,0 @@
-/*
- * 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);
- }
-}
Modified: jbpm4/trunk/pom.xml
===================================================================
--- jbpm4/trunk/pom.xml 2010-06-16 11:13:38 UTC (rev 6418)
+++ jbpm4/trunk/pom.xml 2010-06-16 23:22:42 UTC (rev 6419)
@@ -467,7 +467,7 @@
<repository>
<id>jboss-public-repository-group</id>
<name>JBoss Public Maven Repository Group</name>
- <
url>https://repository.jboss.org/nexus/content/groups/public/</url>
+ <
url>http://repository.jboss.org/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
@@ -482,7 +482,7 @@
<pluginRepository>
<id>jboss-public-repository-group</id>
<name>JBoss Public Maven Repository Group</name>
- <
url>https://repository.jboss.org/nexus/content/groups/public/</url>
+ <
url>http://repository.jboss.org/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>