Restructured the project creating a router directory for the router bundle implementa...
[xmlrouter] / router / impl / src / main / java / org / wamblee / xmlrouter / impl / SingleRouterConfig.java
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 (file)
index 0000000..195f72d
--- /dev/null
@@ -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<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 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<RouterConfig> getId() {
+        return new Id<RouterConfig>(prefix);
+    }
+
+    public String getPrefix() {
+        return prefix;
+    }
+
+    @Override
+    public Config<DocumentType> documentTypeConfig() {
+        return documentTypes;
+    }
+
+    @Override
+    public Config<Transformation> transformationConfig() {
+        return transformations;
+    }
+
+    @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();
+    }
+}