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 static org.wamblee.xmlrouter.impl.MessageUtil.*;
20 import java.util.ArrayList;
21 import java.util.Collections;
22 import java.util.Iterator;
23 import java.util.List;
25 import org.wamblee.xmlrouter.common.Id;
26 import org.wamblee.xmlrouter.config.Config;
27 import org.wamblee.xmlrouter.config.Identifiable;
29 // TODO think real hard about the prefixing. We want a consistent view for clients.
30 // perhaps only provide a method to add items and hide all access to the ids.
33 * Default implementation of the {@link Config} interface.
35 * @author Erik Brakkee
39 // TODO make sure that each item inside this config is prefixed with the id of
41 public abstract class ConfigImpl<T extends Identifiable<T>> implements
44 private Id<Config> id;
45 private List<T> registered;
48 * Constructs the object.
50 public ConfigImpl(Id<Config> aId) {
51 // TODO test for null.
53 registered = new ArrayList<T>();
57 public Id<Config> getId() {
64 * @see org.wamblee.xmlrouter.config.Config#add(T)
67 public synchronized void add(T aT) {
69 registered.add(wrap(id.getId() + ".", aT));
73 * This is called to wrap the given object by a safer version.
77 * @return Wrapped object.
79 public abstract T wrap(String aPrefix, T aT);
85 * org.wamblee.xmlrouter.config.Config#remove(org.wamblee.xmlrouter.common
89 public synchronized boolean remove(Id<T> aId) {
91 Iterator<T> i = registered.iterator();
94 if (t.getId().equals(aId)) {
103 public List<T> values() {
104 return Collections.unmodifiableList(registered);