james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kevin Jackson" <foamd...@gmail.com>
Subject Accessing JdbcDataSource config in custom service
Date Mon, 01 Oct 2007 06:32:20 GMT

Further to my request for help concerning removing spam mail after 15 days:

In my james config.xml I have:

<!-- configure to remove old mails from repository -->
   <mailclean enabled="true">
     <cleanup name="spams">
       <!-- 24*60*60*1000 = 1 day -->
       <mail-cleaner delay="15" schema="public" table="spams"/>

In my CleanMailRepoService code I have: (taken from FetchScheduler)

Configuration[] confs = conf.getChildren( "cleanup" );
            for(int i=0; i<confs.length; i++) {
            	Configuration conf = confs[i];
                String cleanName = conf.getAttribute( "name" );
                Integer interval = new Integer( conf.getChild(
"interval" ).getValue() );

                MailCleaner mc = new MailCleaner();

                /* avalon specific initialization */
mc,getLogger().getChildLogger( cleanName ) );
                ContainerUtil.service( mc,manager );
                ContainerUtil.configure( mc,conf );

and in my MailCleaner code I have:

public void configure(Configuration conf) throws ConfigurationException {
		Configuration jdbcConf = conf.getChild( "database-connections"
).getChild( "data-source" );
		ds = new JdbcDataSource();
		ds.configure( jdbcConf );
		Configuration mConf = conf.getChild( "mail-cleaner" );
		delay = mConf.getAttributeAsInteger( "delay" );
		schema = mConf.getAttribute( "schema" );
		table = mConf.getAttribute( "table" );

Finally my CleanMailRepoService xinfo:


  <!-- section to describe block -->

  <!-- services that are offered by this block -->

      <service name="org.apache.avalon.cornerstone.services.datasources.DataSourceSelector"
      <service name="org.apache.avalon.cornerstone.services.scheduler.TimeScheduler"

Now I want to access the <database-connections> config from the
config.xml, but I can only access it if I duplicate that config in my
<mailclean> section (and I don't want to do that)

Is there a way of injecting the JdbcDataSource into my code without
having a duplicate block of config?

Another option is not to perform any configuration in the
CleanMailRepoService (but I have to do this to setup the scheduler).

Any advice on how to get my desired result in the most avalon-like way
is much appreciated.


To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org

View raw message