001 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
002 *
003 * Copyright 2000-2013, Michael Meyling <mime@qedeq.org>.
004 *
005 * "Hilbert II" is free software; you can redistribute
006 * it and/or modify it under the terms of the GNU General Public
007 * License as published by the Free Software Foundation; either
008 * version 2 of the License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU General Public License for more details.
014 */
015
016 package org.qedeq.kernel.se.common;
017
018 import org.qedeq.base.utility.EqualsUtility;
019
020 /**
021 * Data validation error for a QEDEQ module. An error has always a reference to its
022 * location. Maybe an additional reference for another location is provided.
023 * <br/>
024 * An error code, message and location should fix a certain data validation error, so only these
025 * informations are used for {@link #hashCode()} and {@link #equals(Object)}.
026 *
027 * @author Michael Meyling
028 */
029 public abstract class ModuleDataException extends QedeqException {
030
031 /** Error location. */
032 private final ModuleContext context;
033
034 /** Reference location to explain the error. */
035 private final ModuleContext referenceContext;
036
037 /**
038 * Constructor.
039 *
040 * @param errorCode Error code of this message.
041 * @param message Error message.
042 * @param context Error location.
043 * @param referenceContext Reference location.
044 * @param cause Detailed exception information.
045 */
046 public ModuleDataException(final int errorCode, final String message,
047 final ModuleContext context, final ModuleContext referenceContext,
048 final Exception cause) {
049 super(errorCode, message, cause);
050 // use copy constructor
051 this.context = (context == null ? null : new ModuleContext(context));
052 this.referenceContext = (referenceContext == null ? null
053 : new ModuleContext(referenceContext));
054 }
055
056 /**
057 * Constructor.
058 *
059 * @param errorCode Error code of this message.
060 * @param message Error message.
061 * @param context Error location.
062 * @param referenceContext Reference location.
063 */
064 public ModuleDataException(final int errorCode, final String message,
065 final ModuleContext context, final ModuleContext referenceContext) {
066 super(errorCode, message);
067 // use copy constructor
068 this.context = (context == null ? null : new ModuleContext(context));
069 this.referenceContext = (referenceContext == null ? null
070 : new ModuleContext(referenceContext));
071 }
072
073 /**
074 * Constructor.
075 *
076 * @param errorCode Error code of this message.
077 * @param message Error message.
078 * @param context Error location.
079 * @param cause Detailed exception information.
080 */
081 public ModuleDataException(final int errorCode, final String message,
082 final ModuleContext context, final Exception cause) {
083 super(errorCode, message, cause);
084 // use copy constructor
085 this.context = (context == null ? null : new ModuleContext(context));
086 this.referenceContext = null;
087 }
088
089 /**
090 * Constructor. Copies module context, so original can be changed.
091 *
092 * @param errorCode Error code of this message.
093 * @param message Error message.
094 * @param context Error location.
095 */
096 public ModuleDataException(final int errorCode, final String message,
097 final ModuleContext context) {
098 super(errorCode, message);
099 // use copy constructor
100 this.context = (context == null ? null : new ModuleContext(context));
101 this.referenceContext = null;
102 }
103
104 /**
105 * Get context information about error location.
106 *
107 * @return Error location context.
108 */
109 public final ModuleContext getContext() {
110 return context;
111 }
112
113 /**
114 * Get additional context information about another associated location.
115 *
116 * @return Additional error location context.
117 */
118 public final ModuleContext getReferenceContext() {
119 return referenceContext;
120 }
121
122 public final int hashCode() {
123 return getErrorCode() ^ context.hashCode() ^ getMessage().hashCode();
124 }
125
126 public final boolean equals(final Object obj) {
127 if (!(obj instanceof ModuleDataException)) {
128 return false;
129 }
130 final ModuleDataException other = (ModuleDataException) obj;
131 return (getErrorCode() == other.getErrorCode())
132 && EqualsUtility.equals(getMessage(), other.getMessage())
133 && EqualsUtility.equals(context, other.context);
134 }
135
136
137 }
|