if (!(aObj instanceof Id)) {
return false;
}
- return id == ((Id<T>) aObj).id;
+ return id.equals(((Id<T>) aObj).id);
}
@Override
*/
public interface RouterConfigService {
+ // TODO must deal with conflicts with ids provided by applications and those
+ // used by the xmlrouter internally.
+
/**
* @return New empty configuration.
*/
- RouterConfig emptyConfig();
+ RouterConfig emptyConfig(String aId);
/**
* Applies a given configuration.
import org.wamblee.xmlrouter.common.Id;
import org.wamblee.xmlrouter.config.Config;
+/**
+ * Composite config. The composite config
+ *
+ * @author Erik Brakkee
+ *
+ * @param <T>
+ */
public class CompositeConfig<T> implements ExtendedConfig<T> {
private Id<Config> id;
*
* @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> implements
ExtendedConfig<T> {
public synchronized void add(T aT) {
// TODO test duplicate ids.
notNull(aT);
- registered.add(wrap(aT));
+ registered.add(wrap(id.getId() + ".", aT));
}
/**
* Object to wrap.
* @return Wrapped object.
*/
- public abstract T wrap(T aT);
+ public abstract T wrap(String aPrefix, T aT);
/*
* (non-Javadoc)
* @param aType
* Document type to wrap.
*/
- public RobustDocumentType(DocumentType aType) {
- super(aType);
+ public RobustDocumentType(String aPrefix, DocumentType aType) {
+ super(aPrefix, aType);
type = aType;
}
/**
* Constructs the wrapper.
*
+ * @param aPrefix
+ * prefix to use for ids.
* @param aId
* Id.
* @param aFilter
* Filter to wrap.
*/
- public RobustFilter(Filter aFilter) {
- super(aFilter);
+ public RobustFilter(String aPrefix, Filter aFilter) {
+ super(aPrefix, aFilter);
filter = aFilter;
}
// TODO test this class.
// TODO test that id is constant even though delegated changes its id.
- public RobustIdentifiable(Identifiable<T> aIdentifiable) {
+ public RobustIdentifiable(String aPrefix, Identifiable<T> aIdentifiable) {
// TODO test id is null
// TODO getId() throws exception
try {
id = aIdentifiable.getId();
if (id == null) {
id = new Id<T>(Constants.UNKNOWN_ID.toString());
- throw new RuntimeException(
- "Temporary to catch nulls during refactoring");
+ temporarilyThrowException();
+ } else {
+ id = new Id<T>(aPrefix + id.getId());
}
} catch (Exception e) {
LOGGER
}
+ private void temporarilyThrowException() {
+ throw new RuntimeException(
+ "Temporary to catch nulls during refactoring");
+ }
+
@Override
public Id<T> getId() {
return id;
* @param aTransformation
* Wrapped transformation.
*/
- public RobustTransformation(Transformation aTransformation) {
- super(aTransformation);
+ public RobustTransformation(String aPrefix, Transformation aTransformation) {
+ super(aPrefix, aTransformation);
transformation = aTransformation;
}
documentTypes = new ConfigImpl<DocumentType>(new Id<Config>(
"documentTypes")) {
@Override
- public DocumentType wrap(DocumentType aT) {
- return new RobustDocumentType(aT);
+ public DocumentType wrap(String aPrefix, DocumentType aT) {
+ return new RobustDocumentType(aPrefix, aT);
}
};
transformations = new ConfigImpl<Transformation>(new Id<Config>(
"transformations")) {
@Override
- public Transformation wrap(Transformation aTransformation) {
- return new RobustTransformation(aTransformation);
+ public Transformation wrap(String aPrefix,
+ Transformation aTransformation) {
+ return new RobustTransformation(aPrefix, aTransformation);
}
};
filters = new ConfigImpl<Filter>(new Id<Config>("filters")) {
@Override
- public Filter wrap(Filter aFilter) {
- return new RobustFilter(aFilter);
+ public Filter wrap(String aPrefix, Filter aFilter) {
+ return new RobustFilter(aPrefix, aFilter);
}
};
}
*/
package org.wamblee.xmlrouter.impl;
-import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;
import org.wamblee.xmlrouter.common.Id;
sequence = new AtomicLong(1L);
config = aConfig;
routerConfigs = new ConfigImpl<RouterConfig>(new Id<Config>("config")) {
- public RouterConfig wrap(RouterConfig aT) {
+ public RouterConfig wrap(String aPrefix, RouterConfig aT) {
return aT;
}
};
}
@Override
- public RouterConfig emptyConfig() {
- // TODO check and document API impacts.
- String id = UUID.randomUUID().toString();
- return new SingleRouterConfig(new Id<RouterConfig>(id));
+ public RouterConfig emptyConfig(String aId) {
+ // TODO check AP{ impacts.
+ return new SingleRouterConfig(new Id<RouterConfig>(aId));
}
@Override
public class ConfigImplTest {
+ private static final String CONFIG_TYPE = "transformation";
+
private static interface MyType extends Identifiable {
}
private static class MyTypeWrapper implements MyType {
+ private String prefix;
private MyType type;
- public MyTypeWrapper(MyType aType) {
+ public MyTypeWrapper(String aPrefix, MyType aType) {
+ prefix = aPrefix;
type = aType;
}
@Override
public Id getId() {
- return type.getId();
+ return new Id(prefix + type.getId().getId());
}
}
@Before
public void setUp() {
sequence = new AtomicLong(1L);
- config = new ConfigImpl<MyType>(new Id<Config>("mytype")) {
+ config = new ConfigImpl<MyType>(new Id<Config>(CONFIG_TYPE)) {
@Override
- public MyType wrap(MyType aT) {
- return new MyTypeWrapper(aT);
+ public MyType wrap(String aPrefix, MyType aT) {
+ return new MyTypeWrapper(aPrefix, aT);
}
};
}
assertEquals(1, config.values().size());
assertTrue(config.values().get(0) instanceof MyTypeWrapper);
assertSame(type1, ((MyTypeWrapper) config.values().get(0)).getType());
+ assertEquals(CONFIG_TYPE + "." + type1.getId().getId(), config.values()
+ .get(0).getId().getId());
// add another one.
MyType type2 = mock(MyType.class);
assertEquals(1, config.values().size());
- assertTrue(config.remove(new Id("type1")));
+ assertTrue(config.remove(new Id(CONFIG_TYPE + "." + "type1")));
assertTrue(config.values().isEmpty());
}
@Before
public void setUp() {
documentType = mock(DocumentType.class);
- robust = new RobustDocumentType(documentType);
+ robust = new RobustDocumentType("app1", documentType);
source = mock(DOMSource.class);
}
@Before
public void setUp() {
filter = mock(Filter.class);
- robust = new RobustFilter(filter);
+ robust = new RobustFilter("filter", filter);
source = mock(DOMSource.class);
}
@Before
public void setUp() {
transformation = mock(Transformation.class);
- robust = new RobustTransformation(transformation);
+ robust = new RobustTransformation("transformation", transformation);
source = mock(DOMSource.class);
resSource = mock(DOMSource.class);
}
DocumentType type = mock(DocumentType.class);
when(type.isInstance(any(DOMSource.class))).thenReturn(true);
when(type.getName()).thenReturn(aType);
- RouterConfig routerConfig = configService.emptyConfig();
+ RouterConfig routerConfig = configService.emptyConfig("app");
routerConfig.documentTypeConfig().add(type);
return routerConfig;
}