JingDAO Tutorial: DAO Configuration
By using the Avalon configuration API, you can also perform per-DAO
configuration. An example is given in the
<?xml version="1.0" encoding="ISO-8859-1"?>
<container>
<manager id="default">
<daos>
<dao name="simple" uri="class://org.jadetower.dao.test.daos.impl.SimpleConfDaoImpl">
<name>Hello World!</name>
</dao>
</daos>
</manager>
</container>
Notice the "simple" DAO has it's one XML content. This XML configuration can be in any form and accessed by the DAO implementation via the Avalon configuration API:
package org.jadetower.dao.test.daos.impl;
import org.jadetower.dao.test.daos.SimpleDAO;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
public class SimpleConfDaoImpl
implements SimpleDAO, Configurable
{
protected String m_name = "unconfigured";
public SimpleConfDaoImpl() {
}
public String getName() {
return m_name;
}
public void configure(Configuration configuration) {
Configuration nameElement = configuration.getChild("name",true);
m_name = nameElement.getValue(null);
}
}
This allows for more specific configuration for each DAO. In general, using the map-based context provides a simplier, global configuration scheme, but in some cases for complex DAO's or services, you may want to take advantage of the Avalon API. |