Turned the API packages into bundles.
[xmlrouter] / impl / src / main / java / org / wamblee / xmlrouter / impl / SingleRouterConfig.java
1 /*
2  * Copyright 2005-2011 the original author or authors.
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.wamblee.xmlrouter.impl;
17
18 import org.wamblee.xmlrouter.common.Id;
19 import org.wamblee.xmlrouter.config.DocumentType;
20 import org.wamblee.xmlrouter.config.Filter;
21 import org.wamblee.xmlrouter.config.Transformation;
22
23 /**
24  * Represents a single configuration set of a single configuration client of the
25  * XML router.
26  * 
27  * @author Erik Brakkee
28  */
29 public class SingleRouterConfig implements ExtendedRouterConfig {
30
31     public static final class DocumentConfig extends ConfigImpl<DocumentType> {
32         public DocumentConfig(String aId) {
33             super(DocumentType.class, aId);
34         }
35
36         public DocumentConfig(DocumentConfig aConfig) {
37             super(aConfig);
38         }
39
40         @Override
41         public DocumentType wrap(DocumentType aT) {
42             return new RobustDocumentType(aT);
43         }
44     }
45
46     public static final class TransformationConfig extends
47         ConfigImpl<Transformation> {
48         public TransformationConfig(String aId) {
49             super(Transformation.class, aId);
50         }
51
52         public TransformationConfig(TransformationConfig aConfig) {
53             super(aConfig);
54         }
55
56         @Override
57         public Transformation wrap(Transformation aTransformation) {
58             return new RobustTransformation(aTransformation);
59         }
60     }
61
62     public static final class FilterConfig extends ConfigImpl<Filter> {
63         public FilterConfig(String aId) {
64             super(Filter.class, aId);
65         }
66
67         public FilterConfig(FilterConfig aConfig) {
68             super(aConfig);
69         }
70
71         @Override
72         public Filter wrap(Filter aFilter) {
73             return new RobustFilter("", aFilter);
74         }
75     }
76
77     private String prefix;
78
79     private DocumentConfig documentTypes;
80     private TransformationConfig transformations;
81     private FilterConfig filters;
82
83     /**
84      * Constructs a router configuration.
85      * 
86      * @param aPrefix
87      *            Unique id for this configuration.
88      */
89     public SingleRouterConfig(String aPrefix) {
90         prefix = aPrefix;
91         documentTypes = new DocumentConfig(aPrefix + ".documenttypes");
92         transformations = new TransformationConfig(aPrefix + ".transformations");
93         filters = new FilterConfig(aPrefix + ".filters");
94     }
95
96     public SingleRouterConfig(SingleRouterConfig aConfig) {
97         prefix = aConfig.prefix;
98         documentTypes = new DocumentConfig(aConfig.documentTypes);
99         transformations = new TransformationConfig(aConfig.transformations);
100         filters = new FilterConfig(aConfig.filters);
101     }
102
103     @Override
104     public Id<RouterConfig> getId() {
105         return new Id<RouterConfig>(prefix);
106     }
107
108     public String getPrefix() {
109         return prefix;
110     }
111
112     @Override
113     public Config<DocumentType> documentTypeConfig() {
114         return documentTypes;
115     }
116
117     @Override
118     public Config<Transformation> transformationConfig() {
119         return transformations;
120     }
121
122     @Override
123     public Config<Filter> filterConfig() {
124         return filters;
125     }
126
127     @Override
128     public boolean equals(Object aObj) {
129         if (aObj == null) {
130             return false;
131         }
132         if (!(aObj instanceof SingleRouterConfig)) {
133             return false;
134         }
135         SingleRouterConfig obj = (SingleRouterConfig) aObj;
136
137         return documentTypes.equals(obj.documentTypes) &&
138             transformations.equals(obj.transformations) &&
139             filters.equals(obj.filters);
140     }
141
142     @Override
143     public int hashCode() {
144         return documentTypes.hashCode() + transformations.hashCode() +
145             filters.hashCode();
146     }
147 }