*/
public interface RouterConfigService {
- // TODO must deal with conflicts with ids provided by applications and those
- // used by the xmlrouter internally.
-
/**
* @return New empty configuration.
*/
public class CompositeConfig<T extends Identifiable<T>> implements
ExtendedConfig<T> {
+ private static final Id<Config> ID = new Id<Config>("compositeconfig");
private static final String READ_ONLY_INSTANCE = "read only instance";
private Set<Id<Config>> ids;
- private Id<Config> id;
private List<Id<T>> valueIds;
private List<T> values;
- public CompositeConfig(Id<Config> aId) {
- notNull("aId", aId);
+ public CompositeConfig() {
ids = new HashSet<Id<Config>>();
- id = aId;
valueIds = new ArrayList<Id<T>>();
values = new ArrayList<T>();
}
@Override
public Id<Config> getId() {
- return id;
+ return ID;
}
public void addConfig(Config<T> aConfig) {
import org.wamblee.xmlrouter.config.RouterConfig;
import org.wamblee.xmlrouter.config.Transformation;
-// TODO test this class.
public class CompositeRouterConfig implements ExtendedRouterConfig {
- private Id<RouterConfig> id;
+ private static final Id<RouterConfig> ID = new Id<RouterConfig>(
+ "compositerouterconfig");
private CompositeConfig<DocumentType> documentTypes;
private CompositeConfig<Transformation> transformations;
private CompositeConfig<Filter> filters;
public CompositeRouterConfig(Id<RouterConfig> aId,
Collection<RouterConfig> aConfigs) {
- id = aId;
- documentTypes = new CompositeConfig<DocumentType>(new Id<Config>(
- "documentTypes"));
- transformations = new CompositeConfig<Transformation>(new Id<Config>(
- "transformations"));
- filters = new CompositeConfig<Filter>(new Id<Config>("filters"));
+ documentTypes = new CompositeConfig<DocumentType>();
+ transformations = new CompositeConfig<Transformation>();
+ filters = new CompositeConfig<Filter>();
for (RouterConfig config : aConfigs) {
documentTypes.addConfig(config.documentTypeConfig());
transformations.addConfig(config.transformationConfig());
}
}
- // TODO test id.
-
@Override
public Id<RouterConfig> getId() {
- return id;
+ return ID;
}
@Override
*
* @param <T>
*/
-// TODO make sure that each item inside this config is prefixed with the id of
-// the config.
public abstract class ConfigImpl<T extends Identifiable<T>> implements
ExtendedConfig<T> {
};
}
- // TODO test getId.
@Override
public Id<RouterConfig> getId() {
return id;
import org.wamblee.xmlrouter.config.RouterConfigService;
import org.wamblee.xmlrouter.config.Transformation;
-// TODO pass unique id of config service in the constructor to allow multiple instances with
-// unique ids (ServiceFactory)
-
/**
* Router configuration service providing an atomic configuration API for the
* XML router.
@Test
public void testEmptyConfig() {
- Config<IntClass> composite = composite("c");
- assertEquals(id("c"), composite.getId());
+ Config<IntClass> composite = composite();
assertTrue(composite.values().isEmpty());
}
@Test(expected = RuntimeException.class)
public void testAddNotAllowed() {
- composite("c").add(new IntClass(10));
+ composite().add(new IntClass(10));
}
@Test(expected = RuntimeException.class)
public void testRemoveNotAllowed() {
- composite("c").remove(new Id<IntClass>("xxx"));
+ composite().remove(new Id<IntClass>("xxx"));
}
@Test
public void testAddConfig() {
- CompositeConfig<IntClass> composite = composite("c");
+ CompositeConfig<IntClass> composite = composite();
Config<IntClass> c1 = new ConfigImpl(id("c1")) {
@Override
public Identifiable wrap(String aPrefix, Identifiable aT) {
@Test(expected = ConfigException.class)
public void testDuplicatesNotAllowed() {
- CompositeConfig<IntClass> composite = composite("c");
+ CompositeConfig<IntClass> composite = composite();
Config<IntClass> c1 = new ConfigImpl(id("c1")) {
@Override
public Identifiable wrap(String aPrefix, Identifiable aT) {
@Test
public void testDuplicateItem() {
- CompositeConfig<IntClass> composite = composite("c");
+ CompositeConfig<IntClass> composite = composite();
Config<IntClass> c1 = new ConfigImpl(id("c1")) {
@Override
public Identifiable wrap(String aPrefix, Identifiable aT) {
assertTrue(composite.values().contains(i1));
}
- private CompositeConfig<IntClass> composite(String aId) {
- return new CompositeConfig<IntClass>(id(aId));
+ private CompositeConfig<IntClass> composite() {
+ return new CompositeConfig<IntClass>();
}
private Id<Config> id(String aId) {
@Before
public void setUp() {
config = new SingleRouterConfig(new Id<RouterConfig>("routerconfig"));
+ assertEquals("routerconfig", config.getId().getId());
}
@Test