X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fxmlrouter%2Fimpl%2FConfigImpl.java;h=980bd07601277b1c52b1580df5e44a8a2a7f135c;hb=ef3c789029b09fe8bc279a07a7b2208e286957f0;hp=54c0c6d2357604103284b1d818c754a2e1fdc551;hpb=19413a6699295b4bbebc1b3bdb9838fd4370e581;p=xmlrouter diff --git a/impl/src/main/java/org/wamblee/xmlrouter/impl/ConfigImpl.java b/impl/src/main/java/org/wamblee/xmlrouter/impl/ConfigImpl.java index 54c0c6d..980bd07 100644 --- a/impl/src/main/java/org/wamblee/xmlrouter/impl/ConfigImpl.java +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/ConfigImpl.java @@ -15,13 +15,16 @@ */ package org.wamblee.xmlrouter.impl; +import static org.wamblee.xmlrouter.impl.MessageUtil.*; + +import java.util.ArrayList; import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.concurrent.atomic.AtomicLong; +import java.util.Iterator; +import java.util.List; import org.wamblee.xmlrouter.common.Id; import org.wamblee.xmlrouter.config.Config; +import org.wamblee.xmlrouter.config.Identifiable; /** * Default implementation of the {@link Config} interface. @@ -30,19 +33,24 @@ import org.wamblee.xmlrouter.config.Config; * * @param */ -public abstract class ConfigImpl implements ExtendedConfig { +public abstract class ConfigImpl> implements + ExtendedConfig { - private boolean dirty; - private AtomicLong next; - private Map, T> registered; + private Id id; + private List registered; /** * Constructs the object. */ - public ConfigImpl(AtomicLong aNext) { - dirty = false; - next = aNext; - registered = new LinkedHashMap, T>(); + public ConfigImpl(Id aId) { + notNull("id", aId); + id = aId; + registered = new ArrayList(); + } + + @Override + public Id getId() { + return id; } /* @@ -51,25 +59,19 @@ public abstract class ConfigImpl implements ExtendedConfig { * @see org.wamblee.xmlrouter.config.Config#add(T) */ @Override - public synchronized Id add(T aT) { - notNull(aT); - long seqno = next.incrementAndGet(); - Id id = new Id(seqno); - registered.put(id, wrap(id, aT)); - dirty = true; - return id; + public synchronized void add(T aT) { + notNull("aT", aT); + registered.add(wrap(id.getId() + ".", aT)); } /** * This is called to wrap the given object by a safer version. * - * @param aId - * Id. * @param aT * Object to wrap. * @return Wrapped object. */ - public abstract T wrap(Id aId, T aT); + public abstract T wrap(String aPrefix, T aT); /* * (non-Javadoc) @@ -80,35 +82,20 @@ public abstract class ConfigImpl implements ExtendedConfig { */ @Override public synchronized boolean remove(Id aId) { - notNull(aId); - dirty = true; - return registered.remove(aId) != null; - } - - @Override - public Map, T> map() { - return Collections.unmodifiableMap(registered); - } - - private void notNull(T aT) { - if (aT == null) { - throw new NullPointerException("Object is null"); - } - } - - private void notNull(Id aId) { - if (aId == null) { - throw new NullPointerException("Id is null"); + notNull("aId", aId); + Iterator i = registered.iterator(); + while (i.hasNext()) { + T t = i.next(); + if (t.getId().equals(aId)) { + i.remove(); + return true; + } } + return false; } @Override - public boolean isDirty() { - return dirty; - } - - @Override - public void resetDirty() { - dirty = false; + public List values() { + return Collections.unmodifiableList(registered); } }