JETTY-1331 java 1.5

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2842 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2011-03-01 22:32:11 +00:00
parent 14418ad032
commit 9eadc0ccad
3 changed files with 45 additions and 11 deletions

View File

@ -15,7 +15,6 @@ package org.eclipse.jetty.xml;
import java.net.URL; import java.net.URL;
import java.util.Map; import java.util.Map;
import java.util.ServiceLoader;
/** /**
* A ConfigurationProcessor for non XmlConfiguration format files. * A ConfigurationProcessor for non XmlConfiguration format files.

View File

@ -36,7 +36,6 @@ import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.ServiceLoader;
import java.util.Set; import java.util.Set;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
@ -61,14 +60,35 @@ import org.xml.sax.SAXException;
*/ */
public class XmlConfiguration public class XmlConfiguration
{ {
private static Class<?>[] __primitives = private static final Class<?>[] __primitives =
{ Boolean.TYPE, Character.TYPE, Byte.TYPE, Short.TYPE, Integer.TYPE, Long.TYPE, Float.TYPE, Double.TYPE, Void.TYPE }; { Boolean.TYPE, Character.TYPE, Byte.TYPE, Short.TYPE, Integer.TYPE, Long.TYPE, Float.TYPE, Double.TYPE, Void.TYPE };
private static Class<?>[] __primitiveHolders = private static final Class<?>[] __primitiveHolders =
{ Boolean.class, Character.class, Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class, Void.class }; { Boolean.class, Character.class, Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class, Void.class };
private static final Integer ZERO = new Integer(0); private static final Integer ZERO = new Integer(0);
private static ServiceLoader<ConfigurationProcessorFactory> __factoryLoader = ServiceLoader.load(ConfigurationProcessorFactory.class); private static final Iterable<?> __factoryLoader;
static
{
Iterable<?> loader=null;
try
{
// Use reflection to look up 1.6 service loader
// loader=ServiceLoader.load(ConfigurationProcessorFactory.class);
Class<?> slc = ClassLoader.getSystemClassLoader().loadClass("java.util.ServiceLoader");
Method load = slc.getMethod("load",Class.class);
loader=(Iterable<?>)load.invoke(null,ConfigurationProcessorFactory.class);
}
catch(Exception e)
{
e.printStackTrace();
Log.ignore(e);
}
finally
{
__factoryLoader=loader;
}
}
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
private static XmlParser __parser; private static XmlParser __parser;
@ -177,11 +197,22 @@ public class XmlConfiguration
{ {
_processor=new JettyXmlConfiguration(); _processor=new JettyXmlConfiguration();
} }
else else if (__factoryLoader!=null)
{ {
for ( ConfigurationProcessorFactory factory : __factoryLoader) for ( Object factory : __factoryLoader)
{ {
_processor = factory.getConfigurationProcessor(_dtd,config.getTag()); // use reflection to get 1.6 methods
Method gcp;
try
{
gcp = factory.getClass().getMethod("getConfigurationProcessor",String.class,String.class);
_processor = (ConfigurationProcessor) gcp.invoke(factory,_dtd,config.getTag());
}
catch (Exception e)
{
e.printStackTrace();
Log.ignore(e);
}
if (_processor!=null) if (_processor!=null)
break; break;
} }
@ -189,6 +220,10 @@ public class XmlConfiguration
if (_processor==null) if (_processor==null)
throw new IllegalStateException("Unknown configuration type: "+config.getTag()+" in "+this); throw new IllegalStateException("Unknown configuration type: "+config.getTag()+" in "+this);
} }
else
{
throw new IllegalArgumentException("Unknown XML tag:"+config.getTag());
}
_processor.init(_url,_config,_idMap, _propertyMap); _processor.init(_url,_config,_idMap, _propertyMap);
} }

View File

@ -13,15 +13,15 @@
package org.eclipse.jetty.xml; package org.eclipse.jetty.xml;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.net.URL; import java.net.URL;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.junit.Test; import org.junit.Test;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class XmlConfigurationTest public class XmlConfigurationTest
{ {
protected String _configure="org/eclipse/jetty/xml/configure.xml"; protected String _configure="org/eclipse/jetty/xml/configure.xml";