--- /dev/null
+/*
+ * Copyright 2005-2011 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.xmlrouter.config;
+
+import java.util.Collection;
+
+/**
+ * This class represents a particular configuration of the XML router as
+ * provided by one configuration provider. There can be multiple configuration
+ * providers, each providing it's own part of the configuration.
+ *
+ * @author Erik Brakkee
+ */
+public final class Configuration {
+
+ private Collection<DocumentType> documentTypes;
+ private Collection<Transformation> transformations;
+ private Collection<Filter> filters;
+
+ /**
+ * Constructs the configuration object. Null objects will be ignored.
+ * DocumentTypes must have unique content-based ids (see
+ * {@link Identifiable}), with the same for transformations and filters.
+ * Objects with the same id as another object processed earlier will be
+ * ignored.
+ *
+ * @param aDocumentTypes
+ * Document types.
+ * @param aTransformations
+ * Transformations.
+ * @param aFilters
+ * Filters.
+ */
+ public Configuration(Collection<DocumentType> aDocumentTypes,
+ Collection<Transformation> aTransformations, Collection<Filter> aFilters) {
+ documentTypes = aDocumentTypes;
+ transformations = aTransformations;
+ }
+
+ public Collection<DocumentType> getDocumentTypes() {
+ return documentTypes;
+ }
+
+ public Collection<Transformation> getTransformations() {
+ return transformations;
+ }
+
+ public Collection<Filter> getFilters() {
+ return filters;
+ }
+}
--- /dev/null
+/*
+ * Copyright 2005-2011 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.xmlrouter.config;
+
+/**
+ * The configuration provider must be imp0lemneted to provide a part of the
+ * configuration. The XML Router calls the configuration provider repeatedly to
+ * find out the current configuration.
+ *
+ * How the XML router obtains an instance of the configuration provider depends
+ * on how the \ XML router is deployed. In an OSGi type deployment, this could
+ * be for instance through an extender pattern whereby the XML router discovers
+ * configuration providers at runtime.
+ *
+ * @author Erik Brakkee
+ *
+ */
+public interface ConfigurationProvider {
+
+ /**
+ * Gets the current configuration to use. An implementation may cache the
+ * configuration objects an return it a second time or it may return a new
+ * configuration object each time.
+ *
+ * @return Configuration, may not be null.
+ */
+ Configuration getConfiguration();
+}
import java.util.Set;
import org.wamblee.xmlrouter.common.Id;
-import org.wamblee.xmlrouter.config.Config;
-import org.wamblee.xmlrouter.config.ConfigException;
import org.wamblee.xmlrouter.config.Identifiable;
/**
public class CompositeConfig<T extends Identifiable<T>> implements
ExtendedConfig<T> {
- private static final Id<Config> ID = new Id<Config>("compositeconfig");
+ private static final String PREFIX = "compositeconfig";
private static final String READ_ONLY_INSTANCE = "read only instance";
private Class<T> type;
- private Set<Id<Config>> ids;
+ private Set<String> prefixes;
private List<Id<T>> valueIds;
private List<T> values;
public CompositeConfig(Class<T> aType) {
type = aType;
- ids = new HashSet<Id<Config>>();
+ prefixes = new HashSet<String>();
valueIds = new ArrayList<Id<T>>();
values = new ArrayList<T>();
}
}
@Override
- public Id<Config> getId() {
- return ID;
+ public String getPrefix() {
+ return PREFIX;
}
public void addConfig(Config<T> aConfig) {
notNull("aConfig", aConfig);
- if (ids.contains(aConfig.getId())) {
- throw new ConfigException("duplicate id '" +
- aConfig.getId().toString() + "'");
+ if (prefixes.contains(aConfig.getPrefix())) {
+ throw new ConfigException("duplicate prefix '" +
+ aConfig.getPrefix() + "'");
}
- String prefix = aConfig.getId().getId() + ".";
+ String prefix = aConfig.getPrefix() + ".";
for (T item : aConfig.values()) {
Id<T> newId = new Id<T>(prefix + item.getId());
if (valueIds.contains(newId)) {
}
}
- ids.add(aConfig.getId());
+ prefixes.add(aConfig.getPrefix());
for (T item : aConfig.values()) {
Id<T> newId = new Id<T>(prefix + item.getId());
import java.util.Collection;
import org.wamblee.xmlrouter.common.Id;
-import org.wamblee.xmlrouter.config.Config;
import org.wamblee.xmlrouter.config.DocumentType;
import org.wamblee.xmlrouter.config.Filter;
-import org.wamblee.xmlrouter.config.RouterConfig;
import org.wamblee.xmlrouter.config.Transformation;
public class CompositeRouterConfig implements ExtendedRouterConfig {
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.wamblee.xmlrouter.config;
+package org.wamblee.xmlrouter.impl;
import java.util.Collection;
import org.wamblee.xmlrouter.common.Id;
+import org.wamblee.xmlrouter.config.Identifiable;
/**
* Interface for managing a set of configuration items of a given type with
* @param <T>
* Type for which ids are generated.
*/
-public interface Config<T extends Identifiable> extends Identifiable<Config> {
+public interface Config<T extends Identifiable> {
+
+ /**
+ * @return Prefix to use for ids of contained identifiable objects.
+ */
+ String getPrefix();
/**
* @return The type of contained object.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.wamblee.xmlrouter.config;
+package org.wamblee.xmlrouter.impl;
/**
- * Exception thrown in case of duplicates.
+ * Exception thrown in case of configuration errors.
*
* @author Erik Brakkee
*/
import java.util.Map;
import org.wamblee.xmlrouter.common.Id;
-import org.wamblee.xmlrouter.config.Config;
-import org.wamblee.xmlrouter.config.ConfigException;
import org.wamblee.xmlrouter.config.Identifiable;
/**
ExtendedConfig<T> {
private Class<T> type;
- private Id<Config> id;
+ private String prefix;
private Map<Id<T>, T> registered;
/**
* Constructs the object.
*/
- public ConfigImpl(Class<T> aType, Id<Config> aId) {
+ public ConfigImpl(Class<T> aType, String aPrefix) {
notNull("type", aType);
- notNull("id", aId);
+ notNull("id", aPrefix);
type = aType;
- id = aId;
+ prefix = aPrefix;
registered = new HashMap<Id<T>, T>();
}
*/
public ConfigImpl(ConfigImpl<T> aConfig) {
notNull("config", aConfig);
- id = aConfig.id;
+ prefix = aConfig.prefix;
registered = new HashMap<Id<T>, T>();
for (Map.Entry<Id<T>, T> entry : aConfig.registered.entrySet()) {
registered.put(entry.getKey(), entry.getValue());
}
@Override
- public Id<Config> getId() {
- return id;
+ public String getPrefix() {
+ return prefix;
}
/*
*/
package org.wamblee.xmlrouter.impl;
-import org.wamblee.xmlrouter.config.Config;
import org.wamblee.xmlrouter.config.Identifiable;
public interface ExtendedConfig<T extends Identifiable<T>> extends Config<T> {
*/
package org.wamblee.xmlrouter.impl;
-import org.wamblee.xmlrouter.config.RouterConfig;
/**
* Extended interface for the router configuration used internally.
import java.util.logging.Logger;
import org.wamblee.xmlrouter.common.Id;
-import org.wamblee.xmlrouter.config.ConfigException;
import org.wamblee.xmlrouter.config.Identifiable;
/**
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.wamblee.xmlrouter.config;
+package org.wamblee.xmlrouter.impl;
+
+import org.wamblee.xmlrouter.config.DocumentType;
+import org.wamblee.xmlrouter.config.Filter;
+import org.wamblee.xmlrouter.config.Identifiable;
+import org.wamblee.xmlrouter.config.Transformation;
/**
* Configuration API for the XML router.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.wamblee.xmlrouter.config;
+package org.wamblee.xmlrouter.impl;
import org.wamblee.xmlrouter.common.Id;
package org.wamblee.xmlrouter.impl;
import org.wamblee.xmlrouter.common.Id;
-import org.wamblee.xmlrouter.config.Config;
import org.wamblee.xmlrouter.config.DocumentType;
import org.wamblee.xmlrouter.config.Filter;
-import org.wamblee.xmlrouter.config.RouterConfig;
import org.wamblee.xmlrouter.config.Transformation;
/**
public class SingleRouterConfig implements ExtendedRouterConfig {
public static final class DocumentConfig extends ConfigImpl<DocumentType> {
- public DocumentConfig(Id<Config> aId) {
+ public DocumentConfig(String aId) {
super(DocumentType.class, aId);
}
public static final class TransformationConfig extends
ConfigImpl<Transformation> {
- public TransformationConfig(Id<Config> aId) {
+ public TransformationConfig(String aId) {
super(Transformation.class, aId);
}
}
public static final class FilterConfig extends ConfigImpl<Filter> {
- public FilterConfig(Id<Config> aId) {
+ public FilterConfig(String aId) {
super(Filter.class, aId);
}
}
}
- private Id<RouterConfig> id;
+ private String prefix;
private DocumentConfig documentTypes;
private TransformationConfig transformations;
/**
* Constructs a router configuration.
*
- * @param aId
+ * @param aPrefix
* Unique id for this configuration.
*/
- public SingleRouterConfig(Id<RouterConfig> aId) {
- id = aId;
- 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(String aPrefix) {
+ prefix = aPrefix;
+ documentTypes = new DocumentConfig(aPrefix + ".documenttypes");
+ transformations = new TransformationConfig(aPrefix + ".transformations");
+ filters = new FilterConfig(aPrefix + ".filters");
}
public SingleRouterConfig(SingleRouterConfig aConfig) {
- id = aConfig.id;
+ prefix = aConfig.prefix;
documentTypes = new DocumentConfig(aConfig.documentTypes);
transformations = new TransformationConfig(aConfig.transformations);
filters = new FilterConfig(aConfig.filters);
@Override
public Id<RouterConfig> getId() {
- return id;
+ return new Id<RouterConfig>(prefix);
+ }
+
+ public String getPrefix() {
+ return prefix;
}
@Override
import java.util.concurrent.atomic.AtomicLong;
import org.wamblee.xmlrouter.common.Id;
-import org.wamblee.xmlrouter.config.Config;
-import org.wamblee.xmlrouter.config.ConfigException;
import org.wamblee.xmlrouter.config.DocumentType;
import org.wamblee.xmlrouter.config.Filter;
-import org.wamblee.xmlrouter.config.RouterConfig;
-import org.wamblee.xmlrouter.config.RouterConfigService;
import org.wamblee.xmlrouter.config.Transformation;
/**
sequence = new AtomicLong(1L);
config = aConfig;
routerConfigs = new ConfigImpl<RouterConfig>(RouterConfig.class,
- new Id<Config>(aApplication)) {
+ aApplication) {
public RouterConfig wrap(final RouterConfig aT) {
return new RouterConfig() {
@Override
@Override
public RouterConfig emptyConfig(String aId) {
- return new SingleRouterConfig(new Id<RouterConfig>(application + "." +
- aId));
+ return new SingleRouterConfig(application + "." + aId);
}
@Override
import org.wamblee.general.Pair;
import org.wamblee.xmlrouter.common.Id;
-import org.wamblee.xmlrouter.config.RouterConfig;
/**
* Implements the XML Router configuration interface including the required
import org.junit.Test;
import org.wamblee.xmlrouter.common.Id;
-import org.wamblee.xmlrouter.config.Config;
-import org.wamblee.xmlrouter.config.ConfigException;
import org.wamblee.xmlrouter.config.Identifiable;
public class CompositeConfigTest {
public void testAddConfig() {
CompositeConfig<StringClassInterface> composite = composite();
Config<StringClassInterface> c1 = new ConfigImpl(
- StringClassInterface.class, id("c1")) {
+ StringClassInterface.class, "c1") {
@Override
public Identifiable wrap(Identifiable aT) {
return aT;
}
};
Config<StringClassInterface> c2 = new ConfigImpl(
- StringClassInterface.class, id("c2")) {
+ StringClassInterface.class, "c2") {
@Override
public Identifiable wrap(Identifiable aT) {
return aT;
public void testDuplicatesNotAllowed() {
CompositeConfig<StringClassInterface> composite = composite();
Config<StringClassInterface> c1 = new ConfigImpl(
- StringClassInterface.class, id("c1")) {
+ StringClassInterface.class, "c1") {
@Override
public Identifiable wrap(Identifiable aT) {
return aT;
}
};
Config<StringClassInterface> c2 = new ConfigImpl(
- StringClassInterface.class, id("c1")) {
+ StringClassInterface.class, "c1") {
@Override
public Identifiable wrap(Identifiable aT) {
return aT;
public void testDuplicateItem() {
CompositeConfig<StringClassInterface> composite = composite();
Config<StringClassInterface> c1 = new ConfigImpl(
- StringClassInterface.class, id("c.x")) {
+ StringClassInterface.class, "c.x") {
@Override
public Identifiable wrap(Identifiable aT) {
return aT;
}
};
Config<StringClassInterface> c2 = new ConfigImpl(
- StringClassInterface.class, id("c")) {
+ StringClassInterface.class, "c") {
@Override
public Identifiable wrap(Identifiable aT) {
return aT;
import org.junit.Before;
import org.junit.Test;
import org.wamblee.xmlrouter.common.Id;
-import org.wamblee.xmlrouter.config.Config;
import org.wamblee.xmlrouter.config.Identifiable;
public class ConfigImplTest {
}
public static final class MyTypeConfig extends ConfigImpl<MyType> {
- public MyTypeConfig(Id<Config> aId) {
+ public MyTypeConfig(String aId) {
super(MyType.class, aId);
}
@Before
public void setUp() {
sequence = new AtomicLong(1L);
- config = new MyTypeConfig(new Id<Config>(CONFIG_TYPE));
+ config = new MyTypeConfig(CONFIG_TYPE);
}
@Test
@Test
public void testEquals() {
- Config<MyType> config1 = new MyTypeConfig(new Id<Config>(CONFIG_TYPE));
+ Config<MyType> config1 = new MyTypeConfig(CONFIG_TYPE);
assertFalse(config1.equals(null));
assertFalse(config1.equals("hello"));
- Config<MyType> config2 = new MyTypeConfig(new Id<Config>(CONFIG_TYPE));
+ Config<MyType> config2 = new MyTypeConfig(CONFIG_TYPE);
assertEquals(config1, config2);
assertEquals(config1.hashCode(), config2.hashCode());
testAdd();
assertEquals(2, config.values().size());
MyTypeConfig copy = new MyTypeConfig(config);
- assertEquals(config.getId(), config.getId());
+ assertEquals(config.getPrefix(), copy.getPrefix());
assertEquals(config, copy);
// verify the copy is not shallow
import org.junit.Before;
import org.junit.Test;
import org.wamblee.xmlrouter.common.Id;
-import org.wamblee.xmlrouter.config.ConfigException;
import org.wamblee.xmlrouter.config.Identifiable;
public class RobustIdentifiableTest {
import org.wamblee.xmlrouter.common.Id;
import org.wamblee.xmlrouter.config.DocumentType;
import org.wamblee.xmlrouter.config.Filter;
-import org.wamblee.xmlrouter.config.RouterConfig;
import org.wamblee.xmlrouter.config.Transformation;
public class SingleRouterConfigTest {
@Before
public void setUp() {
- config = new SingleRouterConfig(new Id<RouterConfig>("routerconfig"));
+ config = new SingleRouterConfig("routerconfig");
assertEquals("routerconfig", config.getId().getId());
}
@Test
public void testEqualityEmptyConfig() {
- RouterConfig config1 = new SingleRouterConfig(new Id<RouterConfig>(
- "routerconfig"));
- RouterConfig config2 = new SingleRouterConfig(new Id<RouterConfig>(
- "routerconfig"));
+ RouterConfig config1 = new SingleRouterConfig("routerconfig");
+ RouterConfig config2 = new SingleRouterConfig("routerconfig");
assertEquals(config1, config2);
}
@Test
public void testEqualsNonEmpty() {
- RouterConfig config1 = new SingleRouterConfig(new Id<RouterConfig>(
- "routerconfig"));
+ RouterConfig config1 = new SingleRouterConfig("routerconfig");
assertFalse(config1.equals(null));
assertFalse(config.equals("hello"));
- RouterConfig config2 = new SingleRouterConfig(new Id<RouterConfig>(
- "routerconfig"));
+ RouterConfig config2 = new SingleRouterConfig("routerconfig");
DocumentType type1 = mock(DocumentType.class);
when(type1.getId()).thenReturn(new Id<DocumentType>("type1"));
DocumentType type2 = mock(DocumentType.class);
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.wamblee.xmlrouter.common.Id;
-import org.wamblee.xmlrouter.config.ConfigException;
import org.wamblee.xmlrouter.config.DocumentType;
import org.wamblee.xmlrouter.config.Filter;
-import org.wamblee.xmlrouter.config.RouterConfig;
import org.wamblee.xmlrouter.config.Transformation;
public class XMLRouterConfigServiceTest {
import org.wamblee.general.SystemClock;
import org.wamblee.xmlrouter.common.Id;
import org.wamblee.xmlrouter.config.DocumentType;
-import org.wamblee.xmlrouter.config.RouterConfig;
import org.wamblee.xmlrouter.config.Transformation;
import org.wamblee.xmlrouter.listener.EventInfo;
import org.wamblee.xmlrouter.listener.EventListener;
import org.wamblee.xmlrouter.common.Id;
import org.wamblee.xmlrouter.config.DocumentType;
import org.wamblee.xmlrouter.config.Filter;
-import org.wamblee.xmlrouter.config.RouterConfig;
import org.wamblee.xmlrouter.config.Transformation;
import org.wamblee.xmlrouter.listener.EventInfo;
import org.wamblee.xmlrouter.listener.EventListener;
Logger logger = Logger.getLogger(XMLRouter.class.getName());
setLogLevel(logger, Level.FINEST);
- routerConfig = new SingleRouterConfig(new Id<RouterConfig>(
- "routerconfig"));
+ routerConfig = new SingleRouterConfig("routerconfig");
config = new XMLRouterConfigurationImpl(routerConfig);
EventListener logListener = new LoggingEventListener(Level.INFO);
listener = spy(logListener);