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.remoteable;
014
015import java.lang.reflect.*;
016import java.text.*;
017
018import org.apache.juneau.*;
019
020/**
021 * Exceptions caused by invalid Remoteable classes.
022 */
023public class RemoteableMetadataException extends FormattedRuntimeException {
024
025   private static final long serialVersionUID = 1L;
026
027   /**
028    * Constructor.
029    * 
030    * @param m The interface method that has an invalid definition.
031    * @param message The {@link MessageFormat}-style message.
032    * @param args Optional {@link MessageFormat}-style arguments.
033    */
034   public RemoteableMetadataException(Method m, String message, Object...args) {
035      super(getMessage(m.getDeclaringClass(), m, message), args);
036   }
037
038   /**
039    * Constructor.
040    * 
041    * @param c The interface class that has an invalid definition.
042    * @param message The {@link MessageFormat}-style message.
043    * @param args Optional {@link MessageFormat}-style arguments.
044    */
045   public RemoteableMetadataException(Class<?> c, String message, Object...args) {
046      super(getMessage(c, null, message), args);
047   }
048
049   private static final String getMessage(Class<?> c, Method m, String msg) {
050      StringBuilder sb = new StringBuilder("Invalid remoteable definition found on class ").append(c.getName());
051      if (m != null)
052         sb.append(" on method ").append(m.getName());
053      sb.append(". ").append(msg);
054      return sb.toString();
055   }
056}