diff --git a/geronimo-el_2.2_spec/pom.xml b/geronimo-el_2.2_spec/pom.xml index 5f3965d3f..563a35d37 100644 --- a/geronimo-el_2.2_spec/pom.xml +++ b/geronimo-el_2.2_spec/pom.xml @@ -34,7 +34,7 @@ geronimo-el_2.2_spec bundle Apache Geronimo Expression Language Spec 2.2 - 1.0.5-SNAPSHOT + 1.1-SNAPSHOT Expression Languague API 2.2 http://geronimo.apache.org/maven/${siteId}/${project.version} @@ -55,15 +55,6 @@ http://svn.apache.org/viewcvs.cgi/geronimo/specs/trunk/geronimo-el_2.2_spec/ - - - org.apache.geronimo.specs - geronimo-osgi-locator - 1.0 - provided - - - @@ -77,12 +68,13 @@ Sun Microsystems, Inc. 2.2 javax.el*;version=2.2 - org.apache.geronimo.osgi.registry.api;resolution:=optional,* - org.apache.geronimo.osgi.locator - org.apache.geronimo.osgi.locator.Activator ='2.2,2.1,2.0,1.0' ]]> + diff --git a/geronimo-el_2.2_spec/src/main/java/javax/el/ExpressionFactory.java b/geronimo-el_2.2_spec/src/main/java/javax/el/ExpressionFactory.java index 4063f8df1..eb5e54a9d 100644 --- a/geronimo-el_2.2_spec/src/main/java/javax/el/ExpressionFactory.java +++ b/geronimo-el_2.2_spec/src/main/java/javax/el/ExpressionFactory.java @@ -18,12 +18,13 @@ package javax.el; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.Properties; - -import org.apache.geronimo.osgi.locator.ProviderLocator; +import java.util.ServiceLoader; /** * @@ -57,12 +58,12 @@ public static ExpressionFactory newInstance() { } public static ExpressionFactory newInstance(Properties properties) { - Class implClass = loadExpressionFactoryImplClass(); + ExpressionFactory factory = loadExpressionFactoryImpl(); if (properties == null) { - return newInstance0(implClass); + return factory; } try { - Constructor constructor = implClass.getConstructor(Properties.class); + Constructor constructor = factory.getClass().getConstructor(Properties.class); try { return (ExpressionFactory) constructor.newInstance(properties); } catch (IllegalArgumentException e) { @@ -77,7 +78,7 @@ public static ExpressionFactory newInstance(Properties properties) { } catch (SecurityException e) { throw new ELException("Fail to get constuctor from ExpressionFactory implementation class", e); } catch (NoSuchMethodException e) { - return newInstance0(implClass); + return factory; } } @@ -91,7 +92,7 @@ private static ExpressionFactory newInstance0(Class implClass) { } } - private static String lookupExpressionFactoryImplClass() { + private static ExpressionFactory lookupExpressionFactoryImpl(ClassLoader cl) throws ClassNotFoundException { String implClassName = lookupByJREPropertyFile(); if (implClassName == null) { @@ -100,48 +101,69 @@ private static String lookupExpressionFactoryImplClass() { implClassName = PLATFORM_DEFAULT_FACTORY_CLASS; } } - return implClassName; + return newInstance0(cl.loadClass(implClassName)); } - private static Class lookupByServiceEntryURL(ClassLoader cl) throws ClassNotFoundException { - // use the common lookup/parsing logic for the service files. - return ProviderLocator.getServiceClass(ExpressionFactory.class.getName(), ExpressionFactory.class, cl); + private static ExpressionFactory lookupByServiceEntryURL(ClassLoader cl) throws ClassNotFoundException { + Thread thread = Thread.currentThread(); + ClassLoader original = thread.getContextClassLoader(); + try { + thread.setContextClassLoader(cl); + for (ExpressionFactory factory : ServiceLoader.load(ExpressionFactory.class)) { + return factory; + } + } + finally { + thread.setContextClassLoader(original); + } + return null; } private static String lookupByJREPropertyFile() { try { - return ProviderLocator.lookupByJREPropertyFile(JAVA_RUNTIME_PROPERTY_FILE_LOCATION, SYSTEM_PROPERTY_NAME); + String jreDirectory = System.getProperty("java.home"); + File configurationFile = new File(jreDirectory + File.separator + JAVA_RUNTIME_PROPERTY_FILE_LOCATION); + if (configurationFile.exists() && configurationFile.canRead()) { + Properties properties = new Properties(); + InputStream in = null; + try { + in = new FileInputStream(configurationFile); + properties.load(in); + return properties.getProperty(SYSTEM_PROPERTY_NAME); + } finally { + if (in != null) { + try { + in.close(); + } catch (Exception e) { + } + } + } + } + return null; } catch (IOException e) { throw new ELException("Fail to read configuration file", e); } } - private static Class loadExpressionFactoryImplClass() { + private static ExpressionFactory loadExpressionFactoryImpl() { - String implClassName = null; try { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl == null) { cl = ClassLoader.getSystemClassLoader(); } // check the META-INF/services defintions first - Class cls = lookupByServiceEntryURL(cl); - if (cls != null) { - return cls; + ExpressionFactory factory = lookupByServiceEntryURL(cl); + if (factory != null) { + return factory; } // try resolving using the alternate property lookups (always returns // something, since there is a default - implClassName = lookupExpressionFactoryImplClass(); - return ProviderLocator.loadClass(implClassName, ExpressionFactory.class, cl); + return lookupExpressionFactoryImpl(cl); } catch (ClassNotFoundException e) { // can be thrown either as a result of a classloading failure in the service // lookup or a failure to directly load the class - if (implClassName != null) { - throw new ELException("Fail to load implementation class " + implClassName, e); - } - else { - throw new ELException("Fail to load implementation class", e); - } + throw new ELException("Fail to load implementation class", e); } } }