X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fxmlrouter%2Fimpl%2FSingleRouterConfig.java;h=4ecaad4a35d633679620f791426242f868784b35;hb=5582d07a1ba9821cc789ea63b71f246e89d13cae;hp=36016ca302ee8df806e1264e690555a72d70ee9e;hpb=19413a6699295b4bbebc1b3bdb9838fd4370e581;p=xmlrouter 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 36016ca..4ecaad4 100644 --- a/impl/src/main/java/org/wamblee/xmlrouter/impl/SingleRouterConfig.java +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/SingleRouterConfig.java @@ -15,14 +15,15 @@ */ package org.wamblee.xmlrouter.impl; -import java.util.concurrent.atomic.AtomicLong; - 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 copying of routerconfig. + /** * Represents a single configuration set of a single configuration client of the * XML router. @@ -30,38 +31,85 @@ import org.wamblee.xmlrouter.config.Transformation; * @author Erik Brakkee */ public class SingleRouterConfig implements ExtendedRouterConfig { - private AtomicLong sequenceNumbers; - private ExtendedConfig documentTypes; - private ExtendedConfig transformations; - private ExtendedConfig filters; + + public static final class DocumentConfig extends ConfigImpl { + public DocumentConfig(Id aId) { + super(DocumentType.class, aId); + } + + public DocumentConfig(DocumentConfig aConfig) { + super(aConfig); + } + + @Override + public DocumentType wrap(String aPrefix, DocumentType aT) { + return new RobustDocumentType("", aT); + } + } + + public static final class TransformationConfig extends + ConfigImpl { + public TransformationConfig(Id aId) { + super(Transformation.class, aId); + } + + public TransformationConfig(TransformationConfig aConfig) { + super(aConfig); + } + + @Override + public Transformation wrap(String aPrefix, + Transformation aTransformation) { + return new RobustTransformation("", aTransformation); + } + } + + public static final class FilterConfig extends ConfigImpl { + public FilterConfig(Id aId) { + super(Filter.class, aId); + } + + public FilterConfig(FilterConfig aConfig) { + super(aConfig); + } + + @Override + public Filter wrap(String aPrefix, Filter aFilter) { + return new RobustFilter("", aFilter); + } + } + + private Id id; + + private DocumentConfig documentTypes; + private TransformationConfig transformations; + private FilterConfig filters; /** * Constructs a router configuration. * - * @param aSequenceNumberGenerator - * Sequence number generator to use. + * @param aId + * Unique id for this configuration. */ - public SingleRouterConfig(AtomicLong aSequenceNumberGenerator) { - sequenceNumbers = aSequenceNumberGenerator; - documentTypes = new ConfigImpl(sequenceNumbers) { - @Override - public DocumentType wrap(Id aId, DocumentType aT) { - return new RobustDocumentType(aId, aT); - } - }; - transformations = new ConfigImpl(sequenceNumbers) { - @Override - public Transformation wrap(Id aId, - Transformation aTransformation) { - return new RobustTransformation(aId, aTransformation); - } - }; - filters = new ConfigImpl(sequenceNumbers) { - @Override - public Filter wrap(Id aId, Filter aFilter) { - return new RobustFilter(aId, aFilter); - } - }; + public SingleRouterConfig(Id aId) { + id = aId; + documentTypes = new DocumentConfig(new Id(aId.getId() + + ".documenttypes")); + transformations = new TransformationConfig(new Id(aId.getId() + + ".transformations")); + filters = new FilterConfig(new Id(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 Id getId() { + return id; } @Override @@ -80,16 +128,23 @@ public class SingleRouterConfig implements ExtendedRouterConfig { } @Override - public boolean isDirty() { - return documentTypes.isDirty() || transformations.isDirty() || - filters.isDirty(); + 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 void resetDirty() { - documentTypes.resetDirty(); - filters.resetDirty(); - transformations.resetDirty(); + public int hashCode() { + return documentTypes.hashCode() + transformations.hashCode() + + filters.hashCode(); } - }