Now using RouterConfig internally inside the XML Router.
[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 java.util.concurrent.atomic.AtomicLong;
19
20 import org.wamblee.xmlrouter.common.Id;
21 import org.wamblee.xmlrouter.config.Config;
22 import org.wamblee.xmlrouter.config.DocumentType;
23 import org.wamblee.xmlrouter.config.Filter;
24 import org.wamblee.xmlrouter.config.Transformation;
25
26 /**
27  * Represents a single configuration set of a single configuration client of the
28  * XML router.
29  * 
30  * @author Erik Brakkee
31  */
32 public class SingleRouterConfig implements ExtendedRouterConfig {
33     private AtomicLong sequenceNumbers;
34     private ExtendedConfig<DocumentType> documentTypes;
35     private ExtendedConfig<Transformation> transformations;
36     private ExtendedConfig<Filter> filters;
37
38     /**
39      * Constructs a router configuration.
40      * 
41      * @param aSequenceNumberGenerator
42      *            Sequence number generator to use.
43      */
44     public SingleRouterConfig(AtomicLong aSequenceNumberGenerator) {
45         sequenceNumbers = aSequenceNumberGenerator;
46         documentTypes = new ConfigImpl<DocumentType>(sequenceNumbers) {
47             @Override
48             public DocumentType wrap(Id<DocumentType> aId, DocumentType aT) {
49                 return new RobustDocumentType(aId, aT);
50             }
51         };
52         transformations = new ConfigImpl<Transformation>(sequenceNumbers) {
53             @Override
54             public Transformation wrap(Id<Transformation> aId,
55                 Transformation aTransformation) {
56                 return new RobustTransformation(aId, aTransformation);
57             }
58         };
59         filters = new ConfigImpl<Filter>(sequenceNumbers) {
60             @Override
61             public Filter wrap(Id<Filter> aId, Filter aFilter) {
62                 return new RobustFilter(aId, aFilter);
63             }
64         };
65     }
66
67     @Override
68     public Config<DocumentType> documentTypeConfig() {
69         return documentTypes;
70     }
71
72     @Override
73     public Config<Transformation> transformationConfig() {
74         return transformations;
75     }
76
77     @Override
78     public Config<Filter> filterConfig() {
79         return filters;
80     }
81
82     @Override
83     public boolean isDirty() {
84         return documentTypes.isDirty() || transformations.isDirty() ||
85             filters.isDirty();
86     }
87
88     @Override
89     public void resetDirty() {
90         documentTypes.resetDirty();
91         filters.resetDirty();
92         transformations.resetDirty();
93     }
94
95 }