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.Collections;
19 import java.util.LinkedHashMap;
21 import java.util.concurrent.atomic.AtomicLong;
23 import org.wamblee.xmlrouter.common.Id;
24 import org.wamblee.xmlrouter.config.Config;
27 * Default implementation of the {@link Config} interface.
29 * @author Erik Brakkee
33 public abstract class ConfigImpl<T> implements ExtendedConfig<T> {
35 private boolean dirty;
36 private AtomicLong next;
37 private Map<Id<T>, T> registered;
40 * Constructs the object.
42 public ConfigImpl(AtomicLong aNext) {
45 registered = new LinkedHashMap<Id<T>, T>();
51 * @see org.wamblee.xmlrouter.config.Config#add(T)
54 public synchronized Id<T> add(T aT) {
56 long seqno = next.incrementAndGet();
57 Id<T> id = new Id<T>(seqno);
58 registered.put(id, wrap(id, aT));
64 * This is called to wrap the given object by a safer version.
70 * @return Wrapped object.
72 public abstract T wrap(Id<T> aId, T aT);
78 * org.wamblee.xmlrouter.config.Config#remove(org.wamblee.xmlrouter.common
82 public synchronized boolean remove(Id<T> aId) {
85 return registered.remove(aId) != null;
89 public Map<Id<T>, T> map() {
90 return Collections.unmodifiableMap(registered);
93 private void notNull(T aT) {
95 throw new NullPointerException("Object is null");
99 private void notNull(Id<T> aId) {
101 throw new NullPointerException("Id is null");
106 public boolean isDirty() {
111 public void resetDirty() {