2 * Copyright 2005-2011 the original author or authors.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.wamblee.xmlrouter.impl;
18 import java.util.concurrent.atomic.AtomicLong;
20 import org.wamblee.xmlrouter.common.Id;
21 import org.wamblee.xmlrouter.config.DocumentType;
22 import org.wamblee.xmlrouter.config.Filter;
23 import org.wamblee.xmlrouter.config.Transformation;
26 * Router configuration service providing an atomic configuration API for the
29 * @author Erik Brakkee
31 public class XMLRouterConfigService implements RouterConfigService {
33 private String application;
34 private AtomicLong sequence;
35 private XMLRouterConfiguration config;
36 private Config<RouterConfig> routerConfigs;
38 public XMLRouterConfigService(String aApplication,
39 XMLRouterConfiguration aConfig) {
40 application = aApplication;
41 sequence = new AtomicLong(1L);
43 routerConfigs = new ConfigImpl<RouterConfig>(RouterConfig.class,
45 public RouterConfig wrap(final RouterConfig aT) {
46 return new RouterConfig() {
48 public Id<RouterConfig> getId() {
53 public Config<DocumentType> documentTypeConfig() {
54 return aT.documentTypeConfig();
58 public Config<Filter> filterConfig() {
59 return aT.filterConfig();
63 public Config<Transformation> transformationConfig() {
64 return aT.transformationConfig();
72 public RouterConfig emptyConfig(String aId) {
73 return new SingleRouterConfig(application + "." + aId);
77 public void apply(RouterConfig aConfig, Id<RouterConfig> aOldConfig) {
78 if (aOldConfig != null) {
79 if (!routerConfigs.remove(new Id<RouterConfig>(application + "." +
80 aOldConfig.getId()))) {
81 throw new ConfigException("Unknown routerconfig '" +
85 routerConfigs.add(aConfig);
90 public void clear(Id<RouterConfig> aConfig) {
91 routerConfigs.remove(aConfig);
95 private void update() {
96 ExtendedRouterConfig newconfig = new CompositeRouterConfig(
97 new Id<RouterConfig>("routerconfig"), routerConfigs.values());
98 config.setRouterConfig(newconfig);