X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=router%2Fimpl%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fxmlrouter%2Fimpl%2FSingleRouterConfig.java;fp=router%2Fimpl%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fxmlrouter%2Fimpl%2FSingleRouterConfig.java;h=195f72da66295517bce3aec611c3fe05f3fd0cc8;hb=8e41cb29f75362a792292d21b481bd06a9506296;hp=0000000000000000000000000000000000000000;hpb=9dbc2844950b55ae552fe74840954ea71b754c7a;p=xmlrouter diff --git a/router/impl/src/main/java/org/wamblee/xmlrouter/impl/SingleRouterConfig.java b/router/impl/src/main/java/org/wamblee/xmlrouter/impl/SingleRouterConfig.java new file mode 100644 index 0000000..195f72d --- /dev/null +++ b/router/impl/src/main/java/org/wamblee/xmlrouter/impl/SingleRouterConfig.java @@ -0,0 +1,147 @@ +/* + * 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.impl; + +import org.wamblee.xmlrouter.common.Id; +import org.wamblee.xmlrouter.config.DocumentType; +import org.wamblee.xmlrouter.config.Filter; +import org.wamblee.xmlrouter.config.Transformation; + +/** + * Represents a single configuration set of a single configuration client of the + * XML router. + * + * @author Erik Brakkee + */ +public class SingleRouterConfig implements ExtendedRouterConfig { + + public static final class DocumentConfig extends ConfigImpl { + 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 { + 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 { + 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 aPrefix + * Unique id for this configuration. + */ + 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); + } + + @Override + public Id getId() { + return new Id(prefix); + } + + public String getPrefix() { + return prefix; + } + + @Override + public Config documentTypeConfig() { + return documentTypes; + } + + @Override + public Config transformationConfig() { + return transformations; + } + + @Override + public Config 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(); + } +}