avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/excalibur/xmlbundle BundleSelector.java DefaultBundleFactory.java XmlBundle.java
Date Thu, 07 Nov 2002 23:09:02 GMT
donaldp     2002/11/07 15:09:02

  Modified:    xmlbundle/src/java/org/apache/excalibur/xmlbundle
                        BundleSelector.java DefaultBundleFactory.java
                        XmlBundle.java
  Log:
  To Serviceable from Composable...
  
  Revision  Changes    Path
  1.18      +33 -19    jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/excalibur/xmlbundle/BundleSelector.java
  
  Index: BundleSelector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/excalibur/xmlbundle/BundleSelector.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- BundleSelector.java	7 Jul 2002 08:30:30 -0000	1.17
  +++ BundleSelector.java	7 Nov 2002 23:09:02 -0000	1.18
  @@ -13,10 +13,11 @@
   import org.apache.avalon.excalibur.component.ExcaliburComponentSelector;
   import org.apache.avalon.framework.component.Component;
   import org.apache.avalon.framework.component.ComponentException;
  -import org.apache.avalon.framework.component.ComponentManager;
  -import org.apache.avalon.framework.component.ComponentSelector;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  +import org.apache.avalon.framework.service.ServiceException;
  +import org.apache.avalon.framework.service.ServiceManager;
  +import org.apache.avalon.framework.service.ServiceSelector;
   
   /**
    * This is the method for getting instances of ResourceBundles.
  @@ -34,11 +35,12 @@
       public static final String ROLE = BundleSelector.class.getName();
   
       /** Component Manager */
  -    protected ComponentManager manager = null;
  +    protected ServiceManager m_manager;
   
  -    public void compose( ComponentManager manager )
  +    public void service( final ServiceManager manager )
  +        throws ServiceException
       {
  -        this.manager = manager;
  +        m_manager = manager;
       }
   
       /** Cache for the names of the bundles that were not found */
  @@ -115,18 +117,30 @@
                   }
               }
           }
  -        return (Component)bundle;
  +
  +        if( null != bundle && bundle instanceof Component )
  +        {
  +            return (Component)bundle;
  +        }
  +        else if( null != bundle && !( bundle instanceof Component ) )
  +        {
  +            final String message = "Bundle does not implement Component interface " +
  +                "and thus can not be returned from " +
  +                "ComponentSelector: " + bundleInfo;
  +            getLogger().debug( message );
  +        }
  +        return null;
       }
   
       private Bundle loadBundle( BundleInfo bundleInfo )
       {
  -        ComponentSelector matcherSelector = null;
  -        ComponentSelector bundleFactorySelector = null;
  +        ServiceSelector matcherSelector = null;
  +        ServiceSelector bundleFactorySelector = null;
           BundleFactory bundleFactory = null;
           Bundle bundle = null;
           try
           {
  -            matcherSelector = (ComponentSelector)manager.lookup( BundleMatcher.ROLE + "Selector"
);
  +            matcherSelector = (ServiceSelector)m_manager.lookup( BundleMatcher.ROLE + "Selector"
);
               String type = null;
               for( int i = 0; i < matchers.length; i++ )
               {
  @@ -135,24 +149,24 @@
                   {
                       matcher = (BundleMatcher)matcherSelector.select( matchers[ i ].getAttribute(
"matcher" ) );
                       type = matcher.getType( bundleInfo );
  -                    matcherSelector.release( (Component)matcher );
  +                    matcherSelector.release( matcher );
                   }
  -                catch( ComponentException e )
  +                catch( ServiceException e )
                   {
                       getLogger().error( "Error while matching bundle!", e );
                   }
                   finally
                   {
  -                    if( matcher != null ) matcherSelector.release( (Component)matcher );
  +                    if( matcher != null ) matcherSelector.release( matcher );
                   }
                   if( type != null ) break;
               }
               if( type == null ) type = defaultType;
  -            bundleFactorySelector = (ComponentSelector)manager.lookup( BundleFactory.ROLE
+ "Selector" );
  +            bundleFactorySelector = (ServiceSelector)m_manager.lookup( BundleFactory.ROLE
+ "Selector" );
               bundleFactory = (BundleFactory)bundleFactorySelector.select( type );
               bundle = bundleFactory.createInstance( bundleInfo );
           }
  -        catch( ComponentException e )
  +        catch( ServiceException e )
           {
               getLogger().error( "Error while matching bundle!", e );
           }
  @@ -162,11 +176,11 @@
           }
           finally
           {
  -            if( matcherSelector != null ) manager.release( matcherSelector );
  +            if( matcherSelector != null ) m_manager.release( matcherSelector );
               if( bundleFactorySelector != null )
               {
  -                if( bundleFactory != null ) bundleFactorySelector.release( (Component)bundleFactory
);
  -                manager.release( bundleFactorySelector );
  +                if( bundleFactory != null ) bundleFactorySelector.release( bundleFactory
);
  +                m_manager.release( bundleFactorySelector );
               }
           }
           return bundle;
  @@ -216,7 +230,7 @@
           {
               if( getLogger().isDebugEnabled() ) getLogger().debug( "updating cache: " +
bundleInfo );
               //super.addComponentInstance(bundleInfo, (Component) bundle);
  -            cache.put( bundleInfo, (Component)bundle );
  +            cache.put( bundleInfo, bundle );
           }
       }
   
  
  
  
  1.5       +30 -31    jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/excalibur/xmlbundle/DefaultBundleFactory.java
  
  Index: DefaultBundleFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/excalibur/xmlbundle/DefaultBundleFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultBundleFactory.java	7 Jul 2002 08:30:30 -0000	1.4
  +++ DefaultBundleFactory.java	7 Nov 2002 23:09:02 -0000	1.5
  @@ -9,15 +9,14 @@
   
   import java.io.FileNotFoundException;
   import org.apache.avalon.framework.activity.Initializable;
  -import org.apache.avalon.framework.component.Component;
  -import org.apache.avalon.framework.component.ComponentManager;
  -import org.apache.avalon.framework.component.ComponentSelector;
  -import org.apache.avalon.framework.component.Composable;
   import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  +import org.apache.avalon.framework.container.ContainerUtil;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
  -import org.apache.avalon.framework.logger.LogEnabled;
  +import org.apache.avalon.framework.service.ServiceManager;
  +import org.apache.avalon.framework.service.ServiceSelector;
  +import org.apache.avalon.framework.service.Serviceable;
   
   /**
    * Used to map locale information to URI space, to find the relevant bundle.
  @@ -27,9 +26,8 @@
    */
   public class DefaultBundleFactory
       extends AbstractLogEnabled
  -    implements BundleFactory, Configurable, Composable, Initializable
  +    implements BundleFactory, Configurable, Serviceable, Initializable
   {
  -
       public static final class ConfigurationKeys
       {
           public static final String BUNDLE = "bundle";
  @@ -38,20 +36,20 @@
       }
   
       /** FQCN of the returned bundles */
  -    private String bundleClassName = null;
  +    private String m_bundleClassName;
   
       /** Bundle configuration */
  -    private Configuration bundleConf = null;
  +    private Configuration m_bundleConf;
   
       /** Mapper lookup hint **/
  -    private String mapperHint = null;
  +    private String m_mapperHint;
   
       /** Component Manager */
  -    protected ComponentManager manager = null;
  +    protected ServiceManager m_manager;
   
  -    public void compose( ComponentManager manager )
  +    public void service( ServiceManager manager )
       {
  -        this.manager = manager;
  +        m_manager = manager;
       }
   
       /**
  @@ -61,15 +59,15 @@
        */
       public void configure( Configuration configuration ) throws ConfigurationException
       {
  -        if( bundleClassName == null ) bundleClassName = configuration.getAttribute( ConfigurationKeys.BUNDLE
);
  -        if( mapperHint == null ) mapperHint = configuration.getAttribute( ConfigurationKeys.MAPPER
);
  -        if( bundleConf == null ) bundleConf = configuration.getChild( ConfigurationKeys.BUNDLE_CONF
);
  +        if( null == m_bundleClassName ) m_bundleClassName = configuration.getAttribute(
ConfigurationKeys.BUNDLE );
  +        if( null == m_mapperHint ) m_mapperHint = configuration.getAttribute( ConfigurationKeys.MAPPER
);
  +        if( null == m_bundleConf ) m_bundleConf = configuration.getChild( ConfigurationKeys.BUNDLE_CONF
);
   
           if( getLogger().isDebugEnabled() )
           {
               getLogger().debug(
  -                "BundleLoader configured with bundle=" + bundleClassName +
  -                ", mapper=" + mapperHint +
  +                "BundleLoader configured with bundle=" + m_bundleClassName +
  +                ", mapper=" + m_mapperHint +
                   "" );
           }
       }
  @@ -89,24 +87,25 @@
           Bundle bundle = null;
           Bundle parentBundle = null;
           BundleInfo parentBundleInfo = bi.getParent();
  -        ComponentSelector mapperSelector = null;
  +        ServiceSelector mapperSelector = null;
           BundleInfoMapper mapper = null;
  -        ComponentSelector bundleSelector = null;
  +        ServiceSelector bundleSelector = null;
           try
           {
  -            mapperSelector = (ComponentSelector)manager.lookup( BundleInfoMapper.ROLE +
"Selector" );
  -            mapper = (BundleInfoMapper)mapperSelector.select( mapperHint );
  -            bundleSelector = (ComponentSelector)manager.lookup( Bundle.ROLE + "Selector"
);
  +            mapperSelector = (ServiceSelector)m_manager.lookup( BundleInfoMapper.ROLE +
"Selector" );
  +            mapper = (BundleInfoMapper)mapperSelector.select( m_mapperHint );
  +            bundleSelector = (ServiceSelector)m_manager.lookup( Bundle.ROLE + "Selector"
);
               if( getLogger().isDebugEnabled() ) getLogger().debug( "Loading bundle: " +
bi );
               if( parentBundleInfo != null )
                   parentBundle = (Bundle)bundleSelector.select( parentBundleInfo );
               bundle = getBundleInstance();
  -            if( bundle instanceof LogEnabled ) ( (LogEnabled)bundle ).enableLogging( getLogger()
);
  -            if( bundle instanceof Configurable ) ( (Configurable)bundle ).configure( bundleConf
);
  +            ContainerUtil.enableLogging(bundle, getLogger() );
  +            ContainerUtil.configure( bundle, m_bundleConf );
               bundle.setBundleInfo( bi );
               bundle.setMapper( mapper );
               bundle.setParent( parentBundle );
  -            if( bundle instanceof Composable ) ( (Composable)bundle ).compose( this.manager
);
  +
  +            ContainerUtil.service( bundle, m_manager );
               bundle.setLastModified( System.currentTimeMillis() );
               if( bundle instanceof Initializable ) ( (Initializable)bundle ).initialize();
           }
  @@ -124,10 +123,10 @@
           {
               if( mapperSelector != null )
               {
  -                if( mapper != null ) mapperSelector.release( (Component)mapper );
  -                manager.release( mapperSelector );
  +                if( mapper != null ) mapperSelector.release( mapper );
  +                m_manager.release( mapperSelector );
               }
  -            if( bundleSelector != null ) manager.release( bundleSelector );
  +            if( bundleSelector != null ) m_manager.release( bundleSelector );
           }
           return bundle;
       }
  @@ -136,7 +135,7 @@
       {
           try
           {
  -            return (Bundle)Thread.currentThread().getContextClassLoader().loadClass( bundleClassName
).newInstance();
  +            return (Bundle)Thread.currentThread().getContextClassLoader().loadClass( m_bundleClassName
).newInstance();
           }
           catch( InstantiationException e )
           {
  
  
  
  1.15      +47 -67    jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/excalibur/xmlbundle/XmlBundle.java
  
  Index: XmlBundle.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/excalibur/xmlbundle/XmlBundle.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- XmlBundle.java	7 Jul 2002 08:30:30 -0000	1.14
  +++ XmlBundle.java	7 Nov 2002 23:09:02 -0000	1.15
  @@ -7,8 +7,6 @@
    */
   package org.apache.excalibur.xmlbundle;
   
  -/** JDK classes **/
  -
   import java.util.HashMap;
   import java.util.Map;
   import java.util.MissingResourceException;
  @@ -16,12 +14,11 @@
   import org.apache.avalon.excalibur.xml.xpath.XPathProcessor;
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Initializable;
  -import org.apache.avalon.framework.component.Component;
  -import org.apache.avalon.framework.component.ComponentManager;
  -import org.apache.avalon.framework.component.Composable;
   import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  +import org.apache.avalon.framework.service.ServiceManager;
  +import org.apache.avalon.framework.service.Serviceable;
   import org.apache.excalibur.source.Source;
   import org.apache.excalibur.source.SourceResolver;
   import org.w3c.dom.Document;
  @@ -38,7 +35,7 @@
    */
   public class XmlBundle
       extends AbstractBundle
  -    implements Configurable, Initializable, Disposable, Composable
  +    implements Configurable, Initializable, Disposable, Serviceable
   {
   
       /** Constants for configuration keys */
  @@ -49,36 +46,32 @@
       }
   
       /** Cache for storing string values for existing XPaths */
  -    private Map cache = new HashMap();
  +    private Map m_cache = new HashMap();
   
       /** Cache for storing non-existing XPaths */
  -    private Map cacheNotFound = new HashMap();
  +    private Map m_cacheNotFound = new HashMap();
   
       /** DOM-tree containing the bundle content */
  -    private Document doc;
  +    private Document m_doc;
   
       /** Component Manager */
  -    protected ComponentManager manager;
  +    protected ServiceManager m_manager;
   
       /** XPath Processor */
  -    private XPathProcessor processor;
  -
  -    /** bundle info mapper */
  -    private BundleInfoMapper mapper;
  +    private XPathProcessor m_processor;
   
       /** Load all the keys when initializing? */
  -    private boolean loadOnInit = true;
  +    private boolean m_loadOnInit = true;
   
       /** Use the XML root element in key names when pre-loading? */
  -    private boolean useRootElement = false;
  +    private boolean m_useRootElement;
   
  -    public void compose( ComponentManager manager )
  +    public void service( ServiceManager manager )
       {
  -        this.manager = manager;
  +        m_manager = manager;
           try
           {
  -            this.processor = (XPathProcessor)this.manager.lookup( XPathProcessor.ROLE );
  -            this.mapper = (BundleInfoMapper)this.manager.lookup( BundleInfoMapper.ROLE
);
  +            m_processor = (XPathProcessor)m_manager.lookup( XPathProcessor.ROLE );
           }
           catch( Exception e )
           {
  @@ -88,14 +81,12 @@
   
       public void configure( Configuration configuration ) throws ConfigurationException
       {
  -        this.loadOnInit = configuration.getAttributeAsBoolean( ConfigurationKeys.LOAD_ON_INIT,
true );
  -        this.useRootElement = configuration.getAttributeAsBoolean( ConfigurationKeys.USE_ROOT,
false );
  +        m_loadOnInit = configuration.getAttributeAsBoolean( ConfigurationKeys.LOAD_ON_INIT,
true );
  +        m_useRootElement = configuration.getAttributeAsBoolean( ConfigurationKeys.USE_ROOT,
false );
       }
   
       /**
        * Initalize the bundle
  -     *
  -     * @param document          XML source document (DOM)
        */
       public void initialize() throws Exception
       {
  @@ -106,24 +97,19 @@
        * Initalize the bundle
        *
        * @param uri               URI of the XML source
  -     * @throws IOException   if an IO error occurs while reading the file
  -     * @throws ParserConfigurationException if no parser is configured
  -     * @throws SAXException  if an error occurs while parsing the file
  +     * @throws Exception   if an IO error occurs while reading the file
        */
       public void initialize( String uri ) throws Exception
       {
  -        SourceResolver resolver = (SourceResolver)this.manager.lookup( SourceResolver.ROLE
);
  +        SourceResolver resolver = (SourceResolver)m_manager.lookup( SourceResolver.ROLE
);
           initialize( resolver.resolveURI( uri ) );
  -        this.manager.release( resolver );
  +        m_manager.release( resolver );
       }
   
       /**
        * Initalize the bundle
        *
  -     * @param file              XML source file
  -     * @throws IOException   if an IO error occurs while reading the file
  -     * @throws ParserConfigurationException if no parser is configured
  -     * @throws SAXException  if an error occurs while parsing the file
  +     * @param source XML source file
        */
       public void initialize( Source source ) throws Exception
       {
  @@ -135,28 +121,23 @@
       /**
        * Initalize the bundle
        *
  -     * @param inStream          XML source stream
  -     * @throws IOException   if an IO error occurs while reading the file
  -     * @throws ParserConfigurationException if no parser is configured
  -     * @throws SAXException  if an error occurs while parsing the file
  +     * @param inSource XML source stream
        */
       public void initialize( InputSource inSource ) throws Exception
       {
  -        Parser parser = (Parser)this.manager.lookup( Parser.ROLE );
  -        this.doc = parser.parseDocument( inSource );
  +        Parser parser = (Parser)m_manager.lookup( Parser.ROLE );
  +        m_doc = parser.parseDocument( inSource );
           load();
       }
   
       /**
  -     * Load (pre-cache) the contents
  -     *
  -     * @param document          XML source document (DOM)
  +     * Load (pre-m_cache) the contents
        */
       private void load() throws Exception
       {
  -        if( this.loadOnInit )
  +        if( m_loadOnInit )
           {
  -            cacheAll( doc.getDocumentElement(), useRootElement ? '/' + doc.getDocumentElement().getTagName()
: "" );
  +            cacheAll( m_doc.getDocumentElement(), m_useRootElement ? '/' + m_doc.getDocumentElement().getTagName()
: "" );
           }
       }
   
  @@ -167,7 +148,7 @@
        * names become XPath paths.
        * E.g: this.is.java.property.key --> /this/is/java/property/key
        *
  -     * @param key           user key
  +     * @param userKey        user key
        * @return              system key
        */
       public String convertKey( String userKey )
  @@ -182,37 +163,37 @@
        */
       public Document getDocument()
       {
  -        return this.doc;
  +        return m_doc;
       }
   
       /**
  -     * Does the &quot;key-cache&quot; contain the value with such key?
  +     * Does the &quot;key-m_cache&quot; contain the value with such key?
        *
        * @param   key     the key to the value to be returned
        * @return  true if contains, false otherwise
        */
       protected boolean cacheContains( String key )
       {
  -        boolean result = cache.containsKey( key );
  -        if( getLogger().isDebugEnabled() ) getLogger().debug( getBundleInfo() + ": cache
contains key '" + key + "': " + result );
  +        boolean result = m_cache.containsKey( key );
  +        if( getLogger().isDebugEnabled() ) getLogger().debug( getBundleInfo() + ": m_cache
contains key '" + key + "': " + result );
           return result;
       }
   
       /**
  -     * Does the &quot;key-not-found-cache&quot; contain such key?
  +     * Does the &quot;key-not-found-m_cache&quot; contain such key?
        *
        * @param   key     the key to the value to be returned
        * @return  true if contains, false otherwise
        */
       protected boolean cacheNotFoundContains( String key )
       {
  -        boolean result = cacheNotFound.containsKey( key );
  +        boolean result = m_cacheNotFound.containsKey( key );
           if( getLogger().isDebugEnabled() ) getLogger().debug( getBundleInfo() + ": cache_not_found
contains key '" + key + "': " + result );
           return result;
       }
   
       /**
  -     * Cache the key and value in &quot;key-cache&quot;.
  +     * Cache the key and value in &quot;key-m_cache&quot;.
        *
        * @param   key     the key
        * @param   value   the value
  @@ -220,35 +201,35 @@
       protected void cacheKey( String key, String value )
       {
           if( getLogger().isDebugEnabled() ) getLogger().debug( getBundleInfo() + ": caching:
" + key + " = " + value );
  -        cache.put( key, value );
  +        m_cache.put( key, value );
       }
   
       /**
  -     * Cache the key in &quot;key-not-found-cache&quot;.
  +     * Cache the key in &quot;key-not-found-m_cache&quot;.
        *
        * @param   key     the key
        */
       protected void cacheNotFoundKey( String key )
       {
           if( getLogger().isDebugEnabled() ) getLogger().debug( getBundleInfo() + ": caching
not_found: " + key );
  -        cacheNotFound.put( key, "" );
  +        m_cacheNotFound.put( key, "" );
       }
   
       /**
  -     * Gets the value by the key from the &quot;key-cache&quot;.
  +     * Gets the value by the key from the &quot;key-m_cache&quot;.
        *
        * @param   key     the key
        * @return          the value
        */
       protected String getFromCache( String key )
       {
  -        if( getLogger().isDebugEnabled() ) getLogger().debug( getBundleInfo() + ": returning
from cache: " + key );
  -        return (String)cache.get( key );
  +        if( getLogger().isDebugEnabled() ) getLogger().debug( getBundleInfo() + ": returning
from m_cache: " + key );
  +        return (String)m_cache.get( key );
       }
   
       /**
        * Steps through the bundle tree and stores all text element values
  -     * in bundle's cache. Also stores attributes for all element nodes.
  +     * in bundle's m_cache. Also stores attributes for all element nodes.
        *
        * @param   parent          parent node, must be an element
        * @param   pathToParent    XPath to the parent node
  @@ -270,7 +251,6 @@
                   if( attrs != null )
                   {
                       Node temp = null;
  -                    String pathToAttr = null;
                       int attrnum = attrs.getLength();
                       for( int j = 0; j < attrnum; j++ )
                       {
  @@ -323,8 +303,8 @@
   
           if( value == null && !cacheNotFoundContains( key ) )
           {
  -            if( doc != null )
  -                value = _getString( this.doc.getDocumentElement(), key );
  +            if( m_doc != null )
  +                value = _getString( m_doc.getDocumentElement(), key );
   
               if( value == null )
               {
  @@ -364,7 +344,7 @@
       /**
        * Get the text value of the node.
        *
  -     * @param   node    the node
  +     * @param   element    the node
        * @return          the value
        */
       protected static String getTextValue( Node element )
  @@ -403,7 +383,7 @@
        */
       protected Node _getNode( String key )
       {
  -        return _getNode( this.doc.getDocumentElement(), key );
  +        return _getNode( m_doc.getDocumentElement(), key );
       }
   
       /**
  @@ -419,7 +399,7 @@
           Node node = null;
           try
           {
  -            node = this.processor.selectSingleNode( rootNode, key );
  +            node = m_processor.selectSingleNode( rootNode, key );
           }
           catch( Exception e )
           {
  @@ -430,6 +410,6 @@
   
       public void dispose()
       {
  -        this.manager.release( (Component)this.processor );
  +        m_manager.release( m_processor );
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message