001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.camel.processor.exceptionpolicy;
018
019 import org.apache.camel.model.WhenDefinition;
020
021 /**
022 * Exception policy key is a compound key for storing:
023 * <b>exception class</b> + <b>when</b> => <b>exception type</b>.
024 * <p/>
025 * This is used by Camel to store the onException types configued that has or has not predicates attached (when).
026 */
027 public final class ExceptionPolicyKey {
028
029 private final Class exceptionClass;
030 private final WhenDefinition when;
031
032 public ExceptionPolicyKey(Class exceptionClass, WhenDefinition when) {
033 this.exceptionClass = exceptionClass;
034 this.when = when;
035 }
036
037 public Class getExceptionClass() {
038 return exceptionClass;
039 }
040
041 public WhenDefinition getWhen() {
042 return when;
043 }
044
045 public static ExceptionPolicyKey newInstance(Class exceptionClass) {
046 return new ExceptionPolicyKey(exceptionClass, null);
047 }
048
049 public static ExceptionPolicyKey newInstance(Class exceptionClass, WhenDefinition when) {
050 return new ExceptionPolicyKey(exceptionClass, when);
051 }
052
053 @Override
054 public boolean equals(Object o) {
055 if (this == o) {
056 return true;
057 }
058 if (o == null || getClass() != o.getClass()) {
059 return false;
060 }
061
062 ExceptionPolicyKey that = (ExceptionPolicyKey) o;
063
064 if (!exceptionClass.equals(that.exceptionClass)) {
065 return false;
066 }
067 if (when != null ? !when.equals(that.when) : that.when != null) {
068 return false;
069 }
070
071 return true;
072 }
073
074 @Override
075 public int hashCode() {
076 int result = exceptionClass.hashCode();
077 result = 31 * result + (when != null ? when.hashCode() : 0);
078 return result;
079 }
080
081 @Override
082 public String toString() {
083 return "ExceptionPolicyKey[" + exceptionClass + (when != null ? " " + when : "") + "]";
084 }
085 }