simplifications.
[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.Config;
20 import org.wamblee.xmlrouter.config.DocumentType;
21 import org.wamblee.xmlrouter.config.Filter;
22 import org.wamblee.xmlrouter.config.RouterConfig;
23 import org.wamblee.xmlrouter.config.Transformation;
24
25 // TODO implement equality based on ids for the single routerconfig. 
26 // TODO implement copying of routerconfig. 
27
28 /**
29  * Represents a single configuration set of a single configuration client of the
30  * XML router.
31  * 
32  * @author Erik Brakkee
33  */
34 public class SingleRouterConfig implements ExtendedRouterConfig {
35     private Id<RouterConfig> id;
36     private ExtendedConfig<DocumentType> documentTypes;
37     private ExtendedConfig<Transformation> transformations;
38     private ExtendedConfig<Filter> filters;
39
40     /**
41      * Constructs a router configuration.
42      * 
43      * @param aId
44      *            Unique id for this configuration.
45      */
46     public SingleRouterConfig(Id<RouterConfig> aId) {
47         id = aId;
48         documentTypes = new ConfigImpl<DocumentType>(new Id<Config>(
49             aId.getId() + ".documenttypes")) {
50             @Override
51             public DocumentType wrap(String aPrefix, DocumentType aT) {
52                 return new RobustDocumentType(aPrefix, aT);
53             }
54         };
55         transformations = new ConfigImpl<Transformation>(new Id<Config>(
56             aId.getId() + ".transformations")) {
57             @Override
58             public Transformation wrap(String aPrefix,
59                 Transformation aTransformation) {
60                 return new RobustTransformation(aPrefix, aTransformation);
61             }
62         };
63         filters = new ConfigImpl<Filter>(new Id<Config>(aId.getId() +
64             ".filters")) {
65             @Override
66             public Filter wrap(String aPrefix, Filter aFilter) {
67                 return new RobustFilter(aPrefix, aFilter);
68             }
69         };
70     }
71
72     @Override
73     public Id<RouterConfig> getId() {
74         return id;
75     }
76
77     @Override
78     public Config<DocumentType> documentTypeConfig() {
79         return documentTypes;
80     }
81
82     @Override
83     public Config<Transformation> transformationConfig() {
84         return transformations;
85     }
86
87     @Override
88     public Config<Filter> filterConfig() {
89         return filters;
90     }
91 }