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.rest.client.remote;
018
019import java.lang.reflect.*;
020import java.text.*;
021
022import org.apache.juneau.*;
023
024/**
025 * Exceptions caused by invalid REST proxy classes.
026 *
027 * <h5 class='section'>See Also:</h5><ul>
028 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/RestProxyBasics">REST Proxy Basics</a>
029 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestClientBasics">juneau-rest-client Basics</a>
030 * </ul>
031 *
032 * @serial exclude
033 */
034public class RemoteMetadataException extends BasicRuntimeException {
035
036   private static final long serialVersionUID = 1L;
037
038   /**
039    * Constructor.
040    *
041    * @param cause The cause of this exception.
042    * @param message The {@link MessageFormat}-style message.
043    * @param args Optional {@link MessageFormat}-style arguments.
044    */
045   public RemoteMetadataException(Throwable cause, String message, Object... args) {
046      super(cause, message, args);
047   }
048
049   /**
050    * Constructor.
051    *
052    * @param m The interface method 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(Method m, String message, Object...args) {
057      this((Throwable)null, getMessage(m.getDeclaringClass(), m, message), args);
058   }
059
060   /**
061    * Constructor.
062    *
063    * @param c The interface class that has an invalid definition.
064    * @param message The {@link MessageFormat}-style message.
065    * @param args Optional {@link MessageFormat}-style arguments.
066    */
067   public RemoteMetadataException(Class<?> c, String message, Object...args) {
068      this((Throwable)null, getMessage(c, null, message), args);
069   }
070
071   private static final String getMessage(Class<?> c, Method m, String msg) {
072      StringBuilder sb = new StringBuilder("Invalid remote definition found on class ").append(c.getName());
073      if (m != null)
074         sb.append(" on method ").append(m.getName());
075      sb.append(". ").append(msg);
076      return sb.toString();
077   }
078}