* @author Erik Brakkee
*/
public class SingleRouterConfig implements ExtendedRouterConfig {
+
+ public static final class DocumentConfig extends ConfigImpl<DocumentType> {
+ public DocumentConfig(Id<Config> aId) {
+ super(aId);
+ }
+
+ public DocumentConfig(DocumentConfig aConfig) {
+ super(aConfig);
+ }
+
+ @Override
+ public DocumentType wrap(String aPrefix, DocumentType aT) {
+ return new RobustDocumentType(aPrefix, aT);
+ }
+ }
+
+ public static final class TransformationConfig extends
+ ConfigImpl<Transformation> {
+ public TransformationConfig(Id<Config> aId) {
+ super(aId);
+ }
+
+ public TransformationConfig(TransformationConfig aConfig) {
+ super(aConfig);
+ }
+
+ @Override
+ public Transformation wrap(String aPrefix,
+ Transformation aTransformation) {
+ return new RobustTransformation(aPrefix, aTransformation);
+ }
+ }
+
+ public static final class FilterConfig extends ConfigImpl<Filter> {
+ public FilterConfig(Id<Config> aId) {
+ super(aId);
+ }
+
+ public FilterConfig(FilterConfig aConfig) {
+ super(aConfig);
+ }
+
+ @Override
+ public Filter wrap(String aPrefix, Filter aFilter) {
+ return new RobustFilter(aPrefix, aFilter);
+ }
+ }
+
private Id<RouterConfig> id;
- private ExtendedConfig<DocumentType> documentTypes;
- private ExtendedConfig<Transformation> transformations;
- private ExtendedConfig<Filter> filters;
+ private DocumentConfig documentTypes;
+ private TransformationConfig transformations;
+ private FilterConfig filters;
/**
* Constructs a router configuration.
*/
public SingleRouterConfig(Id<RouterConfig> aId) {
id = aId;
- documentTypes = new ConfigImpl<DocumentType>(new Id<Config>(
- aId.getId() + ".documenttypes")) {
- @Override
- public DocumentType wrap(String aPrefix, DocumentType aT) {
- return new RobustDocumentType(aPrefix, aT);
- }
- };
- transformations = new ConfigImpl<Transformation>(new Id<Config>(
- aId.getId() + ".transformations")) {
- @Override
- public Transformation wrap(String aPrefix,
- Transformation aTransformation) {
- return new RobustTransformation(aPrefix, aTransformation);
- }
- };
- filters = new ConfigImpl<Filter>(new Id<Config>(aId.getId() +
- ".filters")) {
- @Override
- public Filter wrap(String aPrefix, Filter aFilter) {
- return new RobustFilter(aPrefix, aFilter);
- }
- };
+ documentTypes = new DocumentConfig(new Id<Config>(aId.getId() +
+ ".documenttypes"));
+ transformations = new TransformationConfig(new Id<Config>(aId.getId() +
+ ".transformations"));
+ filters = new FilterConfig(new Id<Config>(aId.getId() + ".filters"));
+ }
+
+ public SingleRouterConfig(SingleRouterConfig aConfig) {
+ id = aConfig.id;
+ documentTypes = new DocumentConfig(aConfig.documentTypes);
+ transformations = new TransformationConfig(aConfig.transformations);
+ filters = new FilterConfig(aConfig.filters);
}
@Override
}
}
+ public static final class MyTypeConfig extends ConfigImpl<MyType> {
+ public MyTypeConfig(Id<Config> aId) {
+ super(aId);
+ }
+
+ public MyTypeConfig(MyTypeConfig aConfig) {
+ super(aConfig);
+ }
+
+ @Override
+ public MyType wrap(String aPrefix, MyType aT) {
+ return new MyTypeWrapper(aPrefix, aT);
+ }
+ }
+
private AtomicLong sequence;
- private ExtendedConfig<MyType> config;
+ private MyTypeConfig config;
@Before
public void setUp() {
sequence = new AtomicLong(1L);
- config = new ConfigImpl<MyType>(new Id<Config>(CONFIG_TYPE)) {
- @Override
- public MyType wrap(String aPrefix, MyType aT) {
- return new MyTypeWrapper(aPrefix, aT);
- }
- };
+ config = new MyTypeConfig(new Id<Config>(CONFIG_TYPE));
}
@Test
assertTrue(config2.remove(type2.getId()));
assertFalse(config1.equals(config2));
}
+
+ @Test
+ public void testCopy() {
+ testAdd();
+ assertEquals(2, config.values().size());
+ MyTypeConfig copy = new MyTypeConfig(config);
+ assertEquals(config.getId(), config.getId());
+ assertEquals(config, copy);
+
+ // verify the copy is not shallow
+ assertTrue(config.remove(new Id<MyType>("type1")));
+ assertEquals(1, config.values().size());
+ assertFalse(config.equals(copy));
+ }
}
public class SingleRouterConfigTest {
- private ExtendedRouterConfig config;
+ private SingleRouterConfig config;
@Before
public void setUp() {
assertEquals(config1, config2);
assertEquals(config1.hashCode(), config2.hashCode());
}
+
+ @Test
+ public void testCopy() {
+ testDocumentType();
+ testFilter();
+ testTransformation();
+
+ SingleRouterConfig copy = new SingleRouterConfig(config);
+ assertEquals(config.getId(), copy.getId());
+ assertEquals(config, copy);
+
+ // verify the copy is not shallow.
+
+ config.documentTypeConfig().remove(new Id<DocumentType>("type1"));
+ config.transformationConfig().remove(new Id<Transformation>("t1"));
+ config.filterConfig().remove(new Id<Filter>("f1"));
+ assertEquals(1, config.documentTypeConfig().values().size());
+ assertEquals(1, config.transformationConfig().values().size());
+ assertEquals(1, config.filterConfig().values().size());
+ assertFalse(config.equals(copy));
+ }
}