All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jk.web.embedded.spring.ErrorPage Maven / Gradle / Ivy

There is a newer version: 5.4.7-R2
Show newest version
/*
 * Copyright 2002-2019 Jalal Kiswani. 
 * E-mail: [email protected]
 *
 * 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 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 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 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 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;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy