001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.rest.client.remote; 014 015import java.lang.reflect.*; 016import java.text.*; 017 018import org.apache.juneau.*; 019 020/** 021 * Exceptions caused by invalid REST proxy classes. 022 */ 023public class RemoteMetadataException extends FormattedRuntimeException { 024 025 private static final long serialVersionUID = 1L; 026 027 /** 028 * Constructor. 029 * 030 * @param cause The cause of this exception. 031 * @param message The {@link MessageFormat}-style message. 032 * @param args Optional {@link MessageFormat}-style arguments. 033 */ 034 public RemoteMetadataException(Throwable cause, String message, Object... args) { 035 super(cause, getMessage(cause, message, null), args); 036 } 037 038 /** 039 * Constructor. 040 * 041 * @param m The interface method that has an invalid definition. 042 * @param message The {@link MessageFormat}-style message. 043 * @param args Optional {@link MessageFormat}-style arguments. 044 */ 045 public RemoteMetadataException(Method m, String message, Object...args) { 046 this((Throwable)null, getMessage(m.getDeclaringClass(), m, message), args); 047 } 048 049 /** 050 * Constructor. 051 * 052 * @param c The interface class that has an invalid definition. 053 * @param message The {@link MessageFormat}-style message. 054 * @param args Optional {@link MessageFormat}-style arguments. 055 */ 056 public RemoteMetadataException(Class<?> c, String message, Object...args) { 057 this((Throwable)null, getMessage(c, null, message), args); 058 } 059 060 private static final String getMessage(Class<?> c, Method m, String msg) { 061 StringBuilder sb = new StringBuilder("Invalid remote definition found on class ").append(c.getName()); 062 if (m != null) 063 sb.append(" on method ").append(m.getName()); 064 sb.append(". ").append(msg); 065 return sb.toString(); 066 } 067}