Author: heiko.braun(a)jboss.com
Date: 2007-07-20 06:22:32 -0400 (Fri, 20 Jul 2007)
New Revision: 3958
Modified:
branches/hbraun/trunk/integration/spi/src/main/java/org/jboss/wsf/framework/DefaultSPIProviderResolver.java
Log:
Simplify service loading
Modified:
branches/hbraun/trunk/integration/spi/src/main/java/org/jboss/wsf/framework/DefaultSPIProviderResolver.java
===================================================================
---
branches/hbraun/trunk/integration/spi/src/main/java/org/jboss/wsf/framework/DefaultSPIProviderResolver.java 2007-07-20
08:25:33 UTC (rev 3957)
+++
branches/hbraun/trunk/integration/spi/src/main/java/org/jboss/wsf/framework/DefaultSPIProviderResolver.java 2007-07-20
10:22:32 UTC (rev 3958)
@@ -23,9 +23,6 @@
import org.jboss.logging.Logger;
import org.jboss.wsf.common.ServiceLoader;
-import org.jboss.wsf.framework.deployment.DeploymentModelFactoryImpl;
-import org.jboss.wsf.framework.deployment.WebXMLRewriterFactoryImpl;
-import org.jboss.wsf.framework.invocation.ResourceInjectorFactoryImpl;
import org.jboss.wsf.spi.SPIProvider;
import org.jboss.wsf.spi.SPIProviderResolver;
import org.jboss.wsf.spi.WSFException;
@@ -63,40 +60,52 @@
// SPI provided by framework
- if(spiType.equals(DeploymentModelFactory.class))
+ if(DeploymentModelFactory.class.equals(spiType))
{
- returnType = (T)new DeploymentModelFactoryImpl();
+ returnType = (T) loadService(
+ spiType,
"org.jboss.wsf.framework.deployment.DeploymentModelFactoryImpl"
+ );
}
- else if (spiType.equals(ResourceInjectorFactory.class))
+ else if (ResourceInjectorFactory.class.equals(spiType))
{
- returnType = (T) new ResourceInjectorFactoryImpl();
+ returnType = (T) loadService(
+ spiType,
"org.jboss.wsf.framework.invocation.ResourceInjectorFactoryImpl"
+ );
}
- else if(spiType.equals(WebXMLRewriterFactory.class))
+ else if(WebXMLRewriterFactory.class.equals(spiType))
{
- returnType = (T) new WebXMLRewriterFactoryImpl();
+ returnType = (T) loadService(
+ spiType,
"org.jboss.wsf.framework.deployment.WebXMLRewriterFactoryImpl"
+ );
}
// SPI provided by either container or stack integration
- else if(spiType.equals(InvocationModelFactory.class))
+ else if(InvocationModelFactory.class.equals(spiType))
{
- // container integration needs to provide these
- InvocationModelFactory factory = (InvocationModelFactory )
- ServiceLoader.loadService(InvocationModelFactory.class.getName(), null);
-
- if(null == factory)
- throw new WSFException("Unable to load
spi.invocation.InvocationModelFactory");
-
- returnType = (T) factory;
+ returnType = (T) loadService(spiType, null);
}
// help debugging
if(null == returnType)
- log.debug("Failed to provide SPI
'"+spiType+"'");
+ throw new WSFException("Failed to provide SPI
'"+spiType+"'");
else
log.debug(spiType + " Implementation: " + returnType);
return returnType;
}
+
+ /**
+ * Load SPI implementation through ServiceLoader
+ * @param spiType
+ * @param defaultImpl
+ * @return the spiType implementation
+ */
+ private <T> T loadService(Class<T> spiType, String defaultImpl)
+ {
+ return (T) ServiceLoader.loadService(spiType.getName(), defaultImpl);
+ }
}
+
+
}