com.jk.web.embedded.spring.ErrorPage Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jk-framework-standalone Show documentation
Show all versions of jk-framework-standalone Show documentation
A wrapper for tomcat webserver that enables faster web application development in Java
/*
* Copyright 2002-2021 Dr. Jalal Kiswani.
* Email: [email protected]
* Check out https://smart-api.com for more details
*
* All the opensource projects of Dr. Jalal Kiswani are free for personal and academic use only,
* for commercial usage and support, please contact the author.
*
* 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 com.jk.web.embedded.spring;
import org.springframework.util.ObjectUtils;
// TODO: Auto-generated Javadoc
/**
* The Class ErrorPage.
*/
public class ErrorPage {
/** The status. */
private final HttpStatus status;
/** The exception. */
private final Class extends Throwable> exception;
/** The path. */
private final String path;
/**
* Instantiates a new error page.
*
* @param path the path
*/
public ErrorPage(String path) {
this.status = null;
this.exception = null;
this.path = path;
}
/**
* Instantiates a new error page.
*
* @param status the status
* @param path the path
*/
public ErrorPage(HttpStatus status, String path) {
this.status = status;
this.exception = null;
this.path = path;
}
/**
* Instantiates a new error page.
*
* @param exception the exception
* @param path the path
*/
public ErrorPage(Class extends Throwable> exception, String path) {
this.status = null;
this.exception = exception;
this.path = path;
}
/**
* Gets the path.
*
* @return the path
*/
public String getPath() {
return this.path;
}
/**
* Gets the exception.
*
* @return the exception
*/
public Class extends Throwable> getException() {
return this.exception;
}
/**
* Gets the status.
*
* @return the status
*/
public HttpStatus getStatus() {
return this.status;
}
/**
* Gets the status code.
*
* @return the status code
*/
public int getStatusCode() {
return (this.status != null ? this.status.value() : 0);
}
/**
* Gets the exception name.
*
* @return the exception name
*/
public String getExceptionName() {
return (this.exception != null ? this.exception.getName() : null);
}
/**
* Checks if is global.
*
* @return true, if is global
*/
public boolean isGlobal() {
return (this.status == null && this.exception == null);
}
/**
* Hash code.
*
* @return the int
*/
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ObjectUtils.nullSafeHashCode(getExceptionName());
result = prime * result + ObjectUtils.nullSafeHashCode(this.path);
result = prime * result + this.getStatusCode();
return result;
}
/**
* Equals.
*
* @param obj the obj
* @return true, if successful
*/
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (obj instanceof ErrorPage) {
ErrorPage other = (ErrorPage) obj;
boolean rtn = true;
rtn = rtn && ObjectUtils.nullSafeEquals(getExceptionName(),
other.getExceptionName());
rtn = rtn && ObjectUtils.nullSafeEquals(this.path, other.path);
rtn = rtn && this.status == other.status;
return rtn;
}
return false;
}
}