org.apache.avalon.cornerstone.blocks.datasources
Class DefaultDataSourceSelector

java.lang.Object
  extended byorg.apache.avalon.framework.logger.AbstractLogEnabled
      extended byorg.apache.avalon.cornerstone.blocks.datasources.DefaultDataSourceSelector
All Implemented Interfaces:
Configurable, Contextualizable, DataSourceSelector, Disposable, Initializable, LogEnabled, ServiceSelector

public class DefaultDataSourceSelector
extends AbstractLogEnabled
implements DataSourceSelector, Contextualizable, Configurable, Initializable, Disposable

A default implementation for DataSourceSelector. The Configuration is like this:

 <myBlock>
   <data-source name="default"
     class="org.apache.avalon.excalibur.datasource.JdbcDataSource">
     <!-- configuration for JdbcDataSource -->
     <pool-controller min="5" max="10" connection-class="my.overrided.ConnectionClass">
       <keep-alive>select 1</keep-alive>
     </pool-controller>
     <driver>com.database.jdbc.JdbcDriver</driver>
     <dburl>jdbc:driver://host/mydb</dburl>
     <user>username</user>
     <password>password</password>
   </data-source>
 </myBlock>
 

Author:
Avalon Development Team

Field Summary
 
Fields inherited from interface org.apache.avalon.cornerstone.services.datasources.DataSourceSelector
ROLE
 
Constructor Summary
DefaultDataSourceSelector()
           
 
Method Summary
 void configure(Configuration configuration)
          Pass the Configuration to the Configurable class.
 void contextualize(Context context)
          Contextualization of the component by the container.
 void dispose()
          The dispose operation is called at the end of a components lifecycle.
 void initialize()
          Initialize the component.
 boolean isSelectable(java.lang.Object hint)
          Check to see if a Object exists relative to the supplied policy.
 void release(java.lang.Object component)
          Return the Object when you are finished with it.
 java.lang.Object select(java.lang.Object hint)
          Select the Object associated with the given policy.
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultDataSourceSelector

public DefaultDataSourceSelector()
Method Detail

contextualize

public void contextualize(Context context)
                   throws ContextException
Contextualization of the component by the container.

Specified by:
contextualize in interface Contextualizable
Parameters:
context - the supplied context object
Throws:
ContextException - if context is invalid

configure

public void configure(Configuration configuration)
Description copied from interface: Configurable
Pass the Configuration to the Configurable class.

Specified by:
configure in interface Configurable
Parameters:
configuration - the class configurations. Must not be null.

initialize

public void initialize()
                throws java.lang.Exception
Description copied from interface: Initializable
Initialize the component. Initialization includes allocating any resources required throughout the component's lifecycle.

Specified by:
initialize in interface Initializable
Throws:
java.lang.Exception - if an error occurs

dispose

public void dispose()
Description copied from interface: Disposable
The dispose operation is called at the end of a components lifecycle. This method will be called after Startable.stop() method (if implemented by component). Components use this method to release and destroy any resources that the Component owns.

Specified by:
dispose in interface Disposable

isSelectable

public boolean isSelectable(java.lang.Object hint)
Description copied from interface: ServiceSelector
Check to see if a Object exists relative to the supplied policy.

Specified by:
isSelectable in interface ServiceSelector
Parameters:
hint - a Object containing the selection criteria
Returns:
True if the component is available, False if it not.

select

public java.lang.Object select(java.lang.Object hint)
                        throws ServiceException
Description copied from interface: ServiceSelector
Select the Object associated with the given policy. For instance, If the ServiceSelector has a Generator stored and referenced by a URL, the following call could be used:
 try
 {
     Generator input;
     input = (Generator)selector.select( new URL("foo://demo/url") );
 }
 catch (...)
 {
     ...
 }
 

Specified by:
select in interface ServiceSelector
Parameters:
hint - A criteria against which a Object is selected.
Returns:
an Object value
Throws:
ServiceException - If the requested Object cannot be supplied

release

public void release(java.lang.Object component)
Description copied from interface: ServiceSelector
Return the Object when you are finished with it. This allows the ServiceSelector to handle the End-Of-Life Lifecycle events associated with the Object. Please note, that no Exception should be thrown at this point. This is to allow easy use of the ServiceSelector system without having to trap Exceptions on a release.

Specified by:
release in interface ServiceSelector
Parameters:
component - The Object we are releasing, may also be a null reference


Copyright © 1997-2005 The Apache Software Foundation. All Rights Reserved.