X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fxmlrouter%2Fimpl%2FRobustIdentifiable.java;fp=impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fxmlrouter%2Fimpl%2FRobustIdentifiable.java;h=f3da5f401e98f0dd7ae252c8c04458c781a51ad9;hb=e52385618670b54a5c6a4f2fbfab381bef43a905;hp=0000000000000000000000000000000000000000;hpb=0db97b9f39c69528900f915dd2bb463c27debe39;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 new file mode 100644 index 0000000..f3da5f4 --- /dev/null +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/RobustIdentifiable.java @@ -0,0 +1,80 @@ +/* + * Copyright 2005-2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wamblee.xmlrouter.impl; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.wamblee.xmlrouter.common.Id; +import org.wamblee.xmlrouter.config.Identifiable; + +/** + * Robust identifiable provides robustness for identifiable objects. + * + * @author Erik Brakkee + * + * @param + */ +public class RobustIdentifiable implements Identifiable { + private static final Logger LOGGER = Logger + .getLogger(RobustIdentifiable.class.getName()); + + private Id id; + + // TODO test this class. + // TODO test that id is constant even though delegated changes its id. + + public RobustIdentifiable(Identifiable aIdentifiable) { + // TODO test id is null + // TODO getId() throws exception + try { + id = aIdentifiable.getId(); + if (id == null) { + id = new Id(Constants.UNKNOWN_ID.toString()); + throw new RuntimeException( + "Temporary to catch nulls during refactoring"); + } + } catch (Exception e) { + LOGGER + .log(Level.WARNING, "Identifiable getId() threw exception", e); + } + + } + + @Override + public Id getId() { + return id; + } + + // TODO test equals, hashcode. + + @Override + public int hashCode() { + return id.hashCode(); + } + + @Override + public boolean equals(Object aObj) { + if (aObj == null) { + return false; + } + if (!getClass().isInstance(aObj)) { + return false; + } + RobustIdentifiable obj = (RobustIdentifiable) aObj; + return id.equals(obj.getId()); + } +}