bloritsch 2003/01/30 10:11:54
Modified: sourceresolve/src/java/org/apache/excalibur/source/impl
SourceResolverImpl.java
sourceresolve/src/test/org/apache/excalibur/source
SourceResolverImplTestCase.java
Log:
SourceResolve should work equally well in Fortress and ECM
Revision Changes Path
1.28 +91 -60
jakarta-avalon-excalibur/sourceresolve/src/java/org/apache/excalibur/source/impl/SourceResolverImpl.java
Index: SourceResolverImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/sourceresolve/src/java/org/apache/excalibur/source/impl/SourceResolverImpl.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- SourceResolverImpl.java 30 Jan 2003 07:57:10 -0000 1.27
+++ SourceResolverImpl.java 30 Jan 2003 18:11:53 -0000 1.28
@@ -77,8 +77,8 @@
import org.apache.excalibur.source.SourceResolver;
/**
- * This is the default implemenation of a {@link SourceResolver}.
- *
+ * This is the default implemenation of a {@link SourceResolver}.
+ *
* The source resolving is done relative to a base directory/URI (if
* the given location is relative). This implementation looks for the
* base URI in the {@link Context} object of the "container" for the
@@ -86,7 +86,7 @@
* {@link File} object or a {@link URL} object.
* If the entry does not exist, the system property "user.dir" is used
* as the base URI instead.
- *
+ *
* @see org.apache.excalibur.source.SourceResolver
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
@@ -112,9 +112,6 @@
*/
protected URL m_baseURL;
- /** The default factory (if it is thread safe) */
- protected SourceFactory m_defaultFactory;
-
/**
* Get the context
*/
@@ -166,12 +163,32 @@
throws ServiceException
{
m_manager = manager;
- m_factorySelector = (ServiceSelector)m_manager.lookup( SourceFactory.ROLE +
"Selector" );
- m_defaultFactory = (SourceFactory) m_factorySelector.select( "*" );
- if ( !(m_defaultFactory instanceof ThreadSafe) )
+
+ // Best solution, part of Fortress and above
+ if ( m_manager.hasService( SourceFactory.ROLE ) )
{
- m_factorySelector.release(m_defaultFactory);
- m_defaultFactory = null;
+ Object test = m_manager.lookup( SourceFactory.ROLE );
+ if ( test instanceof ServiceSelector )
+ {
+ m_factorySelector = (ServiceSelector) test;
+ }
+ else
+ {
+ m_manager.release( test );
+ }
+ }
+ // back compatibility hack for ECM
+ else if ( m_manager.hasService( SourceFactory.ROLE + "Selector" ) )
+ {
+ Object test = m_manager.lookup( SourceFactory.ROLE + "Selector" );
+ if ( test instanceof ServiceSelector )
+ {
+ m_factorySelector = (ServiceSelector) test;
+ }
+ else
+ {
+ m_manager.release( test );
+ }
}
}
@@ -179,11 +196,6 @@
{
if( null != m_manager )
{
- if ( null != m_defaultFactory )
- {
- m_factorySelector.release( m_defaultFactory );
- m_defaultFactory = null;
- }
m_manager.release( m_factorySelector );
m_factorySelector = null;
}
@@ -281,7 +293,7 @@
Source source = null;
// search for a SourceFactory implementing the protocol
final int protocolPos = systemID.indexOf( ':' );
- if( protocolPos != -1 )
+ if( protocolPos != -1 && m_factorySelector != null)
{
final String protocol = systemID.substring( 0, protocolPos );
SourceFactory factory = null;
@@ -292,7 +304,7 @@
}
catch( final ServiceException ce )
{
- // no selector available, use fallback
+ // no selector available, use fallback
}
finally
{
@@ -302,27 +314,40 @@
if( null == source )
{
- // no factory found, so use default factory
- if ( null != m_defaultFactory)
+ if ( null == m_factorySelector )
{
- // thread safe default factory
- source = m_defaultFactory.getSource( systemID, parameters );
- }
- else
- {
- try
- {
- m_defaultFactory = (SourceFactory)
m_factorySelector.select("*");
- source = m_defaultFactory.getSource( systemID, parameters );
- }
- catch (ServiceException se )
+ SourceFactory factory = null;
+
+ try
+ {
+ factory = (SourceFactory) m_manager.lookup(SourceFactory.ROLE);
+ source = factory.getSource( systemID, parameters );
+ }
+ catch (ServiceException se )
{
throw new SourceException( "Unable to select source factory for
" + systemID, se );
- }
- finally
+ }
+ finally
{
- m_factorySelector.release( m_defaultFactory );
- m_defaultFactory = null;
+ m_manager.release(factory);
+ }
+ }
+ else
+ {
+ SourceFactory factory = null;
+
+ try
+ {
+ factory = (SourceFactory) m_factorySelector.select("*");
+ source = factory.getSource( systemID, parameters );
+ }
+ catch (ServiceException se )
+ {
+ throw new SourceException( "Unable to select source factory for
" + systemID, se );
+ }
+ finally
+ {
+ m_factorySelector.release(factory);
}
}
}
@@ -341,40 +366,46 @@
// search for a SourceFactory implementing the protocol
final String scheme = source.getScheme();
SourceFactory factory = null;
- try
+
+ if ( null == m_factorySelector )
{
- factory = (SourceFactory)m_factorySelector.select( scheme );
- factory.release( source );
+ try
+ {
+ factory = (SourceFactory) m_manager.lookup(SourceFactory.ROLE);
+ factory.release(source);
+ }
+ catch (ServiceException se )
+ {
+ throw new CascadingRuntimeException( "Unable to select source
factory for " + source.getURI(), se );
+ }
+ finally
+ {
+ m_manager.release( factory );
+ }
}
- catch( ServiceException ce )
+ else
{
- // no factory found, so use default factory
- if ( null != m_defaultFactory)
+ try
{
- // thread safe default factory
- m_defaultFactory.release( source );
- }
- else
+ factory = (SourceFactory) m_factorySelector.select(scheme);
+ factory.release(source);
+ }
+ catch (ServiceException se )
{
- try
+ try
{
- m_defaultFactory = (SourceFactory)
m_factorySelector.select("*");
- m_defaultFactory.release( source );
- }
- catch (ServiceException se )
+ factory = (SourceFactory) m_factorySelector.select("*");
+ factory.release(source);
+ }
+ catch (ServiceException sse )
{
throw new CascadingRuntimeException( "Unable to select source
factory for " + source.getURI(), se );
- }
- finally
- {
- m_factorySelector.release( m_defaultFactory );
- m_defaultFactory = null;
}
}
- }
- finally
- {
- m_factorySelector.release( factory );
+ finally
+ {
+ m_factorySelector.release( factory );
+ }
}
}
}
1.3 +2 -8
jakarta-avalon-excalibur/sourceresolve/src/test/org/apache/excalibur/source/SourceResolverImplTestCase.java
Index: SourceResolverImplTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/sourceresolve/src/test/org/apache/excalibur/source/SourceResolverImplTestCase.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SourceResolverImplTestCase.java 29 Jan 2003 17:31:09 -0000 1.2
+++ SourceResolverImplTestCase.java 30 Jan 2003 18:11:53 -0000 1.3
@@ -38,7 +38,7 @@
resolver.enableLogging( logger );
//
- // create the context argument and set the root directory and
+ // create the context argument and set the root directory and
// contextualize the resolver
//
// NOTE: javadoc needed on contextualize method
@@ -49,7 +49,7 @@
resolver.contextualize( context );
//
- // create a service selector to be included in a service manager
+ // create a service selector to be included in a service manager
// to be supplied to the resolver
//
@@ -71,12 +71,6 @@
resolver.service( manager );
- //
- // parameterize the resolver - Why?
- // NOTE: Missing javadoc
- //
-
- resolver.parameterize( new Parameters() );
logger.debug( "resolver created - but is this correct ?" );
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]