From ca624324bf36e5ba8217a6af861cbf898a40adfc Mon Sep 17 00:00:00 2001 From: Erik Brakkee Date: Mon, 1 Aug 2011 22:44:41 +0200 Subject: [PATCH] now making sure that ids re prefixed by the config id. --- .../java/org/wamblee/xmlrouter/common/Id.java | 2 +- .../xmlrouter/config/RouterConfigService.java | 5 ++++- .../xmlrouter/impl/CompositeConfig.java | 7 +++++++ .../org/wamblee/xmlrouter/impl/ConfigImpl.java | 6 ++++-- .../xmlrouter/impl/RobustDocumentType.java | 4 ++-- .../wamblee/xmlrouter/impl/RobustFilter.java | 6 ++++-- .../xmlrouter/impl/RobustIdentifiable.java | 12 +++++++++--- .../xmlrouter/impl/RobustTransformation.java | 4 ++-- .../xmlrouter/impl/SingleRouterConfig.java | 13 +++++++------ .../xmlrouter/impl/XMLRouterConfigService.java | 10 ++++------ .../wamblee/xmlrouter/impl/ConfigImplTest.java | 18 ++++++++++++------ .../xmlrouter/impl/RobustDocumentTypeTest.java | 2 +- .../xmlrouter/impl/RobustFilterTest.java | 2 +- .../impl/RobustTransformationTest.java | 2 +- .../xmlrouter/impl/XMLRouterFunctionTest.java | 2 +- 15 files changed, 60 insertions(+), 35 deletions(-) diff --git a/common/src/main/java/org/wamblee/xmlrouter/common/Id.java b/common/src/main/java/org/wamblee/xmlrouter/common/Id.java index 1d31c8b..a50b8f2 100644 --- a/common/src/main/java/org/wamblee/xmlrouter/common/Id.java +++ b/common/src/main/java/org/wamblee/xmlrouter/common/Id.java @@ -62,7 +62,7 @@ public class Id implements Comparable> { if (!(aObj instanceof Id)) { return false; } - return id == ((Id) aObj).id; + return id.equals(((Id) aObj).id); } @Override diff --git a/config/src/main/java/org/wamblee/xmlrouter/config/RouterConfigService.java b/config/src/main/java/org/wamblee/xmlrouter/config/RouterConfigService.java index 5fc7f2e..60eaa61 100644 --- a/config/src/main/java/org/wamblee/xmlrouter/config/RouterConfigService.java +++ b/config/src/main/java/org/wamblee/xmlrouter/config/RouterConfigService.java @@ -25,10 +25,13 @@ import org.wamblee.xmlrouter.common.Id; */ 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. diff --git a/impl/src/main/java/org/wamblee/xmlrouter/impl/CompositeConfig.java b/impl/src/main/java/org/wamblee/xmlrouter/impl/CompositeConfig.java index 5166315..56e3e8b 100644 --- a/impl/src/main/java/org/wamblee/xmlrouter/impl/CompositeConfig.java +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/CompositeConfig.java @@ -21,6 +21,13 @@ import java.util.List; import org.wamblee.xmlrouter.common.Id; import org.wamblee.xmlrouter.config.Config; +/** + * Composite config. The composite config + * + * @author Erik Brakkee + * + * @param + */ public class CompositeConfig implements ExtendedConfig { private Id id; diff --git a/impl/src/main/java/org/wamblee/xmlrouter/impl/ConfigImpl.java b/impl/src/main/java/org/wamblee/xmlrouter/impl/ConfigImpl.java index c561e36..5beeed5 100644 --- a/impl/src/main/java/org/wamblee/xmlrouter/impl/ConfigImpl.java +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/ConfigImpl.java @@ -31,6 +31,8 @@ import org.wamblee.xmlrouter.config.Identifiable; * * @param */ +// TODO make sure that each item inside this config is prefixed with the id of +// the config. public abstract class ConfigImpl implements ExtendedConfig { @@ -60,7 +62,7 @@ public abstract class ConfigImpl implements public synchronized void add(T aT) { // TODO test duplicate ids. notNull(aT); - registered.add(wrap(aT)); + registered.add(wrap(id.getId() + ".", aT)); } /** @@ -70,7 +72,7 @@ public abstract class ConfigImpl implements * Object to wrap. * @return Wrapped object. */ - public abstract T wrap(T aT); + public abstract T wrap(String aPrefix, T aT); /* * (non-Javadoc) diff --git a/impl/src/main/java/org/wamblee/xmlrouter/impl/RobustDocumentType.java b/impl/src/main/java/org/wamblee/xmlrouter/impl/RobustDocumentType.java index 5224483..3f26f7b 100644 --- a/impl/src/main/java/org/wamblee/xmlrouter/impl/RobustDocumentType.java +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/RobustDocumentType.java @@ -45,8 +45,8 @@ public class RobustDocumentType extends RobustIdentifiable * @param aType * Document type to wrap. */ - public RobustDocumentType(DocumentType aType) { - super(aType); + public RobustDocumentType(String aPrefix, DocumentType aType) { + super(aPrefix, aType); type = aType; } diff --git a/impl/src/main/java/org/wamblee/xmlrouter/impl/RobustFilter.java b/impl/src/main/java/org/wamblee/xmlrouter/impl/RobustFilter.java index 056690a..823c64d 100644 --- a/impl/src/main/java/org/wamblee/xmlrouter/impl/RobustFilter.java +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/RobustFilter.java @@ -38,13 +38,15 @@ public class RobustFilter extends RobustIdentifiable implements Filter { /** * 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; } diff --git a/impl/src/main/java/org/wamblee/xmlrouter/impl/RobustIdentifiable.java b/impl/src/main/java/org/wamblee/xmlrouter/impl/RobustIdentifiable.java index f3da5f4..640e37e 100644 --- a/impl/src/main/java/org/wamblee/xmlrouter/impl/RobustIdentifiable.java +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/RobustIdentifiable.java @@ -37,15 +37,16 @@ public class RobustIdentifiable implements Identifiable { // TODO test this class. // TODO test that id is constant even though delegated changes its id. - public RobustIdentifiable(Identifiable aIdentifiable) { + public RobustIdentifiable(String aPrefix, Identifiable aIdentifiable) { // TODO test id is null // TODO getId() throws exception try { id = aIdentifiable.getId(); if (id == null) { id = new Id(Constants.UNKNOWN_ID.toString()); - throw new RuntimeException( - "Temporary to catch nulls during refactoring"); + temporarilyThrowException(); + } else { + id = new Id(aPrefix + id.getId()); } } catch (Exception e) { LOGGER @@ -54,6 +55,11 @@ public class RobustIdentifiable implements Identifiable { } + private void temporarilyThrowException() { + throw new RuntimeException( + "Temporary to catch nulls during refactoring"); + } + @Override public Id getId() { return id; diff --git a/impl/src/main/java/org/wamblee/xmlrouter/impl/RobustTransformation.java b/impl/src/main/java/org/wamblee/xmlrouter/impl/RobustTransformation.java index 2fa025e..cf0210d 100644 --- a/impl/src/main/java/org/wamblee/xmlrouter/impl/RobustTransformation.java +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/RobustTransformation.java @@ -45,8 +45,8 @@ public class RobustTransformation extends RobustIdentifiable * @param aTransformation * Wrapped transformation. */ - public RobustTransformation(Transformation aTransformation) { - super(aTransformation); + public RobustTransformation(String aPrefix, Transformation aTransformation) { + super(aPrefix, aTransformation); transformation = aTransformation; } diff --git a/impl/src/main/java/org/wamblee/xmlrouter/impl/SingleRouterConfig.java b/impl/src/main/java/org/wamblee/xmlrouter/impl/SingleRouterConfig.java index 5e2fffe..b069215 100644 --- a/impl/src/main/java/org/wamblee/xmlrouter/impl/SingleRouterConfig.java +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/SingleRouterConfig.java @@ -45,21 +45,22 @@ public class SingleRouterConfig implements ExtendedRouterConfig { documentTypes = new ConfigImpl(new Id( "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(new Id( "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(new Id("filters")) { @Override - public Filter wrap(Filter aFilter) { - return new RobustFilter(aFilter); + public Filter wrap(String aPrefix, Filter aFilter) { + return new RobustFilter(aPrefix, aFilter); } }; } diff --git a/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouterConfigService.java b/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouterConfigService.java index 054956d..c60e546 100644 --- a/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouterConfigService.java +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouterConfigService.java @@ -15,7 +15,6 @@ */ package org.wamblee.xmlrouter.impl; -import java.util.UUID; import java.util.concurrent.atomic.AtomicLong; import org.wamblee.xmlrouter.common.Id; @@ -39,17 +38,16 @@ public class XMLRouterConfigService implements RouterConfigService { sequence = new AtomicLong(1L); config = aConfig; routerConfigs = new ConfigImpl(new Id("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(id)); + public RouterConfig emptyConfig(String aId) { + // TODO check AP{ impacts. + return new SingleRouterConfig(new Id(aId)); } @Override diff --git a/impl/src/test/java/org/wamblee/xmlrouter/impl/ConfigImplTest.java b/impl/src/test/java/org/wamblee/xmlrouter/impl/ConfigImplTest.java index 5e3ad92..781a53a 100644 --- a/impl/src/test/java/org/wamblee/xmlrouter/impl/ConfigImplTest.java +++ b/impl/src/test/java/org/wamblee/xmlrouter/impl/ConfigImplTest.java @@ -28,14 +28,18 @@ import org.wamblee.xmlrouter.config.Identifiable; 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; } @@ -45,7 +49,7 @@ public class ConfigImplTest { @Override public Id getId() { - return type.getId(); + return new Id(prefix + type.getId().getId()); } } @@ -55,10 +59,10 @@ public class ConfigImplTest { @Before public void setUp() { sequence = new AtomicLong(1L); - config = new ConfigImpl(new Id("mytype")) { + config = new ConfigImpl(new Id(CONFIG_TYPE)) { @Override - public MyType wrap(MyType aT) { - return new MyTypeWrapper(aT); + public MyType wrap(String aPrefix, MyType aT) { + return new MyTypeWrapper(aPrefix, aT); } }; } @@ -73,6 +77,8 @@ public class ConfigImplTest { 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); @@ -91,7 +97,7 @@ public class ConfigImplTest { assertEquals(1, config.values().size()); - assertTrue(config.remove(new Id("type1"))); + assertTrue(config.remove(new Id(CONFIG_TYPE + "." + "type1"))); assertTrue(config.values().isEmpty()); } diff --git a/impl/src/test/java/org/wamblee/xmlrouter/impl/RobustDocumentTypeTest.java b/impl/src/test/java/org/wamblee/xmlrouter/impl/RobustDocumentTypeTest.java index 254826c..aa724e2 100644 --- a/impl/src/test/java/org/wamblee/xmlrouter/impl/RobustDocumentTypeTest.java +++ b/impl/src/test/java/org/wamblee/xmlrouter/impl/RobustDocumentTypeTest.java @@ -34,7 +34,7 @@ public class RobustDocumentTypeTest { @Before public void setUp() { documentType = mock(DocumentType.class); - robust = new RobustDocumentType(documentType); + robust = new RobustDocumentType("app1", documentType); source = mock(DOMSource.class); } diff --git a/impl/src/test/java/org/wamblee/xmlrouter/impl/RobustFilterTest.java b/impl/src/test/java/org/wamblee/xmlrouter/impl/RobustFilterTest.java index 3725112..4c8218d 100644 --- a/impl/src/test/java/org/wamblee/xmlrouter/impl/RobustFilterTest.java +++ b/impl/src/test/java/org/wamblee/xmlrouter/impl/RobustFilterTest.java @@ -34,7 +34,7 @@ public class RobustFilterTest { @Before public void setUp() { filter = mock(Filter.class); - robust = new RobustFilter(filter); + robust = new RobustFilter("filter", filter); source = mock(DOMSource.class); } diff --git a/impl/src/test/java/org/wamblee/xmlrouter/impl/RobustTransformationTest.java b/impl/src/test/java/org/wamblee/xmlrouter/impl/RobustTransformationTest.java index 25327cb..e3a0d47 100644 --- a/impl/src/test/java/org/wamblee/xmlrouter/impl/RobustTransformationTest.java +++ b/impl/src/test/java/org/wamblee/xmlrouter/impl/RobustTransformationTest.java @@ -34,7 +34,7 @@ public class RobustTransformationTest { @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); } diff --git a/impl/src/test/java/org/wamblee/xmlrouter/impl/XMLRouterFunctionTest.java b/impl/src/test/java/org/wamblee/xmlrouter/impl/XMLRouterFunctionTest.java index 5d84107..e2e08b4 100644 --- a/impl/src/test/java/org/wamblee/xmlrouter/impl/XMLRouterFunctionTest.java +++ b/impl/src/test/java/org/wamblee/xmlrouter/impl/XMLRouterFunctionTest.java @@ -63,7 +63,7 @@ public class XMLRouterFunctionTest { 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; } -- 2.31.1