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;
-// TODO implement equality based on ids for the single routerconfig.
-// TODO implement copying of routerconfig.
-
/**
* Represents a single configuration set of a single configuration client of the
* XML router.
* @author Erik Brakkee
*/
public class SingleRouterConfig implements ExtendedRouterConfig {
- private Id<RouterConfig> id;
- private ExtendedConfig<DocumentType> documentTypes;
- private ExtendedConfig<Transformation> transformations;
- private ExtendedConfig<Filter> filters;
+
+ public static final class DocumentConfig extends ConfigImpl<DocumentType> {
+ public DocumentConfig(String aId) {
+ super(DocumentType.class, aId);
+ }
+
+ public DocumentConfig(DocumentConfig aConfig) {
+ super(aConfig);
+ }
+
+ @Override
+ public DocumentType wrap(DocumentType aT) {
+ return new RobustDocumentType(aT);
+ }
+ }
+
+ public static final class TransformationConfig extends
+ ConfigImpl<Transformation> {
+ public TransformationConfig(String aId) {
+ super(Transformation.class, aId);
+ }
+
+ public TransformationConfig(TransformationConfig aConfig) {
+ super(aConfig);
+ }
+
+ @Override
+ public Transformation wrap(Transformation aTransformation) {
+ return new RobustTransformation(aTransformation);
+ }
+ }
+
+ public static final class FilterConfig extends ConfigImpl<Filter> {
+ public FilterConfig(String aId) {
+ super(Filter.class, aId);
+ }
+
+ public FilterConfig(FilterConfig aConfig) {
+ super(aConfig);
+ }
+
+ @Override
+ public Filter wrap(Filter aFilter) {
+ return new RobustFilter("", aFilter);
+ }
+ }
+
+ private String prefix;
+
+ private DocumentConfig documentTypes;
+ private TransformationConfig transformations;
+ private FilterConfig filters;
/**
* Constructs a router configuration.
*
- * @param aId
+ * @param aPrefix
* Unique id for this 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);
- }
- };
+ 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) {
+ prefix = aConfig.prefix;
+ documentTypes = new DocumentConfig(aConfig.documentTypes);
+ transformations = new TransformationConfig(aConfig.transformations);
+ filters = new FilterConfig(aConfig.filters);
}
- // TODO test getId.
@Override
public Id<RouterConfig> getId() {
- return id;
+ return new Id<RouterConfig>(prefix);
+ }
+
+ public String getPrefix() {
+ return prefix;
}
@Override
public Config<Filter> filterConfig() {
return filters;
}
+
+ @Override
+ public boolean equals(Object aObj) {
+ if (aObj == null) {
+ return false;
+ }
+ if (!(aObj instanceof SingleRouterConfig)) {
+ return false;
+ }
+ SingleRouterConfig obj = (SingleRouterConfig) aObj;
+
+ return documentTypes.equals(obj.documentTypes) &&
+ transformations.equals(obj.transformations) &&
+ filters.equals(obj.filters);
+ }
+
+ @Override
+ public int hashCode() {
+ return documentTypes.hashCode() + transformations.hashCode() +
+ filters.hashCode();
+ }
}