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 *
023 * <h5 class='section'>See Also:</h5><ul>
024 *    <li class='link'><a class="doclink" href="../../../../../../index.html#jrc.Proxies">REST Proxies</a>
025 *    <li class='link'><a class="doclink" href="../../../../../../index.html#juneau-rest-client">juneau-rest-client</a>
026 * </ul>
027 *
028 * @serial exclude
029 */
030public class RemoteMetadataException extends BasicRuntimeException {
031
032   private static final long serialVersionUID = 1L;
033
034   /**
035    * Constructor.
036    *
037    * @param cause The cause of this exception.
038    * @param message The {@link MessageFormat}-style message.
039    * @param args Optional {@link MessageFormat}-style arguments.
040    */
041   public RemoteMetadataException(Throwable cause, String message, Object... args) {
042      super(cause, message, args);
043   }
044
045   /**
046    * Constructor.
047    *
048    * @param m The interface method that has an invalid definition.
049    * @param message The {@link MessageFormat}-style message.
050    * @param args Optional {@link MessageFormat}-style arguments.
051    */
052   public RemoteMetadataException(Method m, String message, Object...args) {
053      this((Throwable)null, getMessage(m.getDeclaringClass(), m, message), args);
054   }
055
056   /**
057    * Constructor.
058    *
059    * @param c The interface class that has an invalid definition.
060    * @param message The {@link MessageFormat}-style message.
061    * @param args Optional {@link MessageFormat}-style arguments.
062    */
063   public RemoteMetadataException(Class<?> c, String message, Object...args) {
064      this((Throwable)null, getMessage(c, null, message), args);
065   }
066
067   private static final String getMessage(Class<?> c, Method m, String msg) {
068      StringBuilder sb = new StringBuilder("Invalid remote definition found on class ").append(c.getName());
069      if (m != null)
070         sb.append(" on method ").append(m.getName());
071      sb.append(". ").append(msg);
072      return sb.toString();
073   }
074}