X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fxmlrouter%2Fimpl%2FRobustIdentifiable.java;h=f371975fac804c378162084bc0e1a74536fbe2d9;hb=3b2c669b25bfcb5a3c3f06ff9180d85143bebb2a;hp=640e37e13385402e9414c6beb2719bb3d6e2d378;hpb=ca624324bf36e5ba8217a6af861cbf898a40adfc;p=xmlrouter diff --git a/impl/src/main/java/org/wamblee/xmlrouter/impl/RobustIdentifiable.java b/impl/src/main/java/org/wamblee/xmlrouter/impl/RobustIdentifiable.java index 640e37e..f371975 100644 --- a/impl/src/main/java/org/wamblee/xmlrouter/impl/RobustIdentifiable.java +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/RobustIdentifiable.java @@ -15,6 +15,8 @@ */ package org.wamblee.xmlrouter.impl; +import static org.wamblee.xmlrouter.impl.MessageUtil.*; + import java.util.logging.Level; import java.util.logging.Logger; @@ -22,7 +24,8 @@ import org.wamblee.xmlrouter.common.Id; import org.wamblee.xmlrouter.config.Identifiable; /** - * Robust identifiable provides robustness for identifiable objects. + * Robust identifiable provides robustness for identifiable objects. It adds + * equality based on the id. * * @author Erik Brakkee * @@ -34,30 +37,22 @@ public class RobustIdentifiable implements Identifiable { private Id id; - // TODO test this class. - // TODO test that id is constant even though delegated changes its id. - - public RobustIdentifiable(String aPrefix, Identifiable aIdentifiable) { - // TODO test id is null - // TODO getId() throws exception + public RobustIdentifiable(Identifiable aIdentifiable) { + notNull("identifiable", aIdentifiable); try { id = aIdentifiable.getId(); if (id == null) { - id = new Id(Constants.UNKNOWN_ID.toString()); - temporarilyThrowException(); - } else { - id = new Id(aPrefix + id.getId()); + throwConfigException("identifiable.getId() returned null", null); } } catch (Exception e) { - LOGGER - .log(Level.WARNING, "Identifiable getId() threw exception", e); + throwConfigException("identifiable.getId() threw exception", e); } } - private void temporarilyThrowException() { - throw new RuntimeException( - "Temporary to catch nulls during refactoring"); + private void throwConfigException(String aMsg, Exception aException) { + LOGGER.log(Level.WARNING, aMsg, aException); + throw new ConfigException(aMsg); } @Override @@ -65,8 +60,6 @@ public class RobustIdentifiable implements Identifiable { return id; } - // TODO test equals, hashcode. - @Override public int hashCode() { return id.hashCode();