+++ /dev/null
-/*
- * 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 static org.wamblee.xmlrouter.impl.MessageUtil.*;
-
-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. It adds
- * equality based on the id.
- *
- * @author Erik Brakkee
- *
- * @param <T>
- */
-public class RobustIdentifiable<T> implements Identifiable<T> {
- private static final Logger LOGGER = Logger
- .getLogger(RobustIdentifiable.class.getName());
-
- private Id<T> id;
-
- public RobustIdentifiable(Identifiable<T> aIdentifiable) {
- notNull("identifiable", aIdentifiable);
- try {
- id = aIdentifiable.getId();
- if (id == null) {
- throwConfigException("identifiable.getId() returned null", null);
- }
- } catch (Exception e) {
- throwConfigException("identifiable.getId() threw exception", e);
- }
-
- }
-
- private void throwConfigException(String aMsg, Exception aException) {
- LOGGER.log(Level.WARNING, aMsg, aException);
- throw new ConfigException(aMsg);
- }
-
- @Override
- public Id<T> getId() {
- return id;
- }
-
- @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<T> obj = (RobustIdentifiable<T>) aObj;
- return id.equals(obj.getId());
- }
-}