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.logging.Level;
19 import java.util.logging.Logger;
21 import org.wamblee.xmlrouter.common.Id;
22 import org.wamblee.xmlrouter.config.Identifiable;
25 * Robust identifiable provides robustness for identifiable objects.
27 * @author Erik Brakkee
31 public class RobustIdentifiable<T> implements Identifiable<T> {
32 private static final Logger LOGGER = Logger
33 .getLogger(RobustIdentifiable.class.getName());
37 // TODO test this class.
38 // TODO test that id is constant even though delegated changes its id.
40 public RobustIdentifiable(String aPrefix, Identifiable<T> aIdentifiable) {
41 // TODO test id is null
42 // TODO getId() throws exception
44 id = aIdentifiable.getId();
46 id = new Id<T>(Constants.UNKNOWN_ID.toString());
47 temporarilyThrowException();
49 id = new Id<T>(aPrefix + id.getId());
51 } catch (Exception e) {
53 .log(Level.WARNING, "Identifiable getId() threw exception", e);
58 private void temporarilyThrowException() {
59 throw new RuntimeException(
60 "Temporary to catch nulls during refactoring");
64 public Id<T> getId() {
68 // TODO test equals, hashcode.
71 public int hashCode() {
76 public boolean equals(Object aObj) {
80 if (!getClass().isInstance(aObj)) {
83 RobustIdentifiable<T> obj = (RobustIdentifiable<T>) aObj;
84 return id.equals(obj.getId());