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 */ 017package org.apache.juneau.objecttools; 018 019import java.net.*; 020import java.text.*; 021 022import org.apache.juneau.*; 023 024/** 025 * Generic exception thrown from the {@link ObjectRest} class. 026 * 027 * <p> 028 * Typically, this is a user-error, such as trying to address a non-existent node in the tree. 029 * 030 * <p> 031 * The status code is an HTTP-equivalent code. It will be one of the following: 032 * <ul class='spaced-list'> 033 * <li> 034 * {@link HttpURLConnection#HTTP_BAD_REQUEST HTTP_BAD_REQUEST} 035 * - Attempting to do something impossible. 036 * <li> 037 * {@link HttpURLConnection#HTTP_NOT_FOUND HTTP_NOT_FOUND} 038 * - Attempting to access a non-existent node in the tree. 039 * <li> 040 * {@link HttpURLConnection#HTTP_FORBIDDEN HTTP_FORBIDDEN} 041 * - Attempting to overwrite the root object. 042 * </ul> 043 * 044 * 045 * @serial exclude 046 */ 047public class ObjectRestException extends BasicRuntimeException { 048 049 private static final long serialVersionUID = 1L; 050 051 private int status; 052 053 /** 054 * Constructor. 055 * 056 * @param status The HTTP-equivalent status code. 057 * @param message The detailed message. 058 * @param args Optional {@link MessageFormat}-style arguments. 059 */ 060 public ObjectRestException(int status, String message, Object...args) { 061 this(null, status, message, args); 062 } 063 064 /** 065 * Constructor. 066 * 067 * @param cause The cause of this exception. 068 * @param status HTTP status code. 069 * @param message The {@link MessageFormat}-style message. 070 * @param args Optional {@link MessageFormat}-style arguments. 071 */ 072 public ObjectRestException(Throwable cause, int status, String message, Object...args) { 073 super(cause, message, args); 074 this.status = status; 075 } 076 077 /** 078 * The HTTP-equivalent status code. 079 * 080 * <p> 081 * See above for details. 082 * 083 * @return The HTTP-equivalent status code. 084 */ 085 public int getStatus() { return status; } 086 087 @Override /* Overridden from BasicRuntimeException */ 088 public ObjectRestException setMessage(String message, Object...args) { 089 super.setMessage(message, args); 090 return this; 091 } 092}