001 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
002 *
003 * Copyright 2000-2011, 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 *
024 * @author Michael Meyling
025 */
026 public abstract class ModuleDataException extends QedeqException {
027
028 /** Error location. */
029 private final ModuleContext context;
030
031 /** Reference location to explain the error. */
032 private final ModuleContext referenceContext;
033
034 /**
035 * Constructor.
036 *
037 * @param errorCode Error code of this message.
038 * @param message Error message.
039 * @param context Error location.
040 * @param referenceContext Reference location.
041 * @param cause Detailed exception information.
042 */
043 public ModuleDataException(final int errorCode, final String message,
044 final ModuleContext context, final ModuleContext referenceContext,
045 final Exception cause) {
046 super(errorCode, message, cause);
047 // use copy constructor
048 this.context = (context == null ? null : new ModuleContext(context));
049 this.referenceContext = (referenceContext == null ? null
050 : new ModuleContext(referenceContext));
051 }
052
053 /**
054 * Constructor.
055 *
056 * @param errorCode Error code of this message.
057 * @param message Error message.
058 * @param context Error location.
059 * @param referenceContext Reference location.
060 */
061 public ModuleDataException(final int errorCode, final String message,
062 final ModuleContext context, final ModuleContext referenceContext) {
063 super(errorCode, message);
064 // use copy constructor
065 this.context = (context == null ? null : new ModuleContext(context));
066 this.referenceContext = (referenceContext == null ? null
067 : new ModuleContext(referenceContext));
068 }
069
070 /**
071 * Constructor.
072 *
073 * @param errorCode Error code of this message.
074 * @param message Error message.
075 * @param context Error location.
076 * @param cause Detailed exception information.
077 */
078 public ModuleDataException(final int errorCode, final String message,
079 final ModuleContext context, final Exception cause) {
080 super(errorCode, message, cause);
081 // use copy constructor
082 this.context = (context == null ? null : new ModuleContext(context));
083 this.referenceContext = null;
084 }
085
086 /**
087 * Constructor. Copies module context, so original can be changed.
088 *
089 * @param errorCode Error code of this message.
090 * @param message Error message.
091 * @param context Error location.
092 */
093 public ModuleDataException(final int errorCode, final String message,
094 final ModuleContext context) {
095 super(errorCode, message);
096 // use copy constructor
097 this.context = (context == null ? null : new ModuleContext(context));
098 this.referenceContext = null;
099 }
100
101 /**
102 * Get context information about error location.
103 *
104 * @return Error location context.
105 */
106 public final ModuleContext getContext() {
107 return context;
108 }
109
110 /**
111 * Get additional context information about another associated location.
112 *
113 * @return Additional error location context.
114 */
115 public final ModuleContext getReferenceContext() {
116 return referenceContext;
117 }
118
119 public final int hashCode() {
120 return getErrorCode() ^ context.hashCode() ^ getMessage().hashCode()
121 ^ (referenceContext != null ? referenceContext.hashCode() : 13);
122 }
123
124 public final boolean equals(final Object obj) {
125 if (!(obj instanceof ModuleDataException)) {
126 return false;
127 }
128 final ModuleDataException other = (ModuleDataException) obj;
129 return (getErrorCode() == other.getErrorCode())
130 && EqualsUtility.equals(getMessage(), other.getMessage())
131 && EqualsUtility.equals(context, other.context)
132 && EqualsUtility.equals(referenceContext, other.referenceContext);
133 }
134
135
136 }
|