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.remote;
014
015import static org.apache.juneau.internal.StringUtils.*;
016
017import java.lang.reflect.*;
018
019import org.apache.juneau.internal.*;
020
021/**
022 * Contains the meta-data about a Java method on a remote class.
023 *
024 * <p>
025 * Captures the information in {@link RemoteInterface @RemoteInterface} annotations for caching and reuse.
026 *
027 * <h5 class='section'>See Also:</h5>
028 * <ul class='doctree'>
029 *    <li class='link'>{@doc juneau-rest-server.restRPC}
030 * </ul>
031 */
032public class RemoteInterfaceMethod {
033
034   private final String url, path;
035   private final Method method;
036
037   /**
038    * Constructor.
039    *
040    * @param restUrl The absolute URL of the REST interface backing the interface proxy.
041    * @param m The Java method.
042    */
043   public RemoteInterfaceMethod(final String restUrl, Method m) {
044      this.method = m;
045      this.path =  m.getName() + '/' + HttpUtils.getMethodArgsSignature(m, true);
046      this.url = trimSlashes(restUrl) + '/' + urlEncode(path);
047   }
048
049   /**
050    * Returns the absolute URL of the REST interface invoked by this Java method.
051    *
052    * @return The absolute URL of the REST interface, never <jk>null</jk>.
053    */
054   public String getUrl() {
055      return url;
056   }
057
058   /**
059    * Returns the HTTP path of this method.
060    *
061    * @return
062    *    The HTTP path of this method relative to the parent interface.
063    *    <br>Never <jk>null</jk>.
064    *    <br>Never has leading or trailing slashes.
065    */
066   public String getPath() {
067      return path;
068   }
069
070   /**
071    * Returns the underlying Java method that this metadata is about.
072    *
073    * @return
074    *    The underlying Java method that this metadata is about.
075    *    <br>Never <jk>null</jk>.
076    */
077   public Method getJavaMethod() {
078      return method;
079   }
080}