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 static org.apache.juneau.internal.CollectionUtils.*; 016import static org.apache.juneau.internal.StringUtils.*; 017import java.lang.reflect.*; 018import java.util.*; 019 020import org.apache.juneau.reflect.*; 021 022/** 023 * Contains the meta-data about a REST proxy class. 024 * 025 * <p> 026 * Captures the information in {@link org.apache.juneau.http.remote.RemoteResource @RemoteResource} and {@link org.apache.juneau.http.remote.RemoteMethod @RemoteMethod} annotations for 027 * caching and reuse. 028 * 029 * <ul class='seealso'> 030 * <li class='link'>{@doc juneau-rest-client.RestProxies} 031 * </ul> 032 */ 033public class RemoteResourceMeta { 034 035 private final Map<Method,RemoteMethodMeta> methods; 036 private final String path; 037 038 /** 039 * Constructor. 040 * 041 * @param c The interface class annotated with a {@link org.apache.juneau.http.remote.RemoteResource @RemoteResource} annotation (optional). 042 */ 043 @SuppressWarnings("deprecation") 044 public RemoteResourceMeta(Class<?> c) { 045 String path = ""; 046 047 ClassInfo ci = ClassInfo.of(c); 048 for (RemoteResource r : ci.getAnnotationsParentFirst(RemoteResource.class)) 049 if (! r.path().isEmpty()) 050 path = trimSlashes(r.path()); 051 for (org.apache.juneau.http.remote.RemoteResource r : ci.getAnnotationsParentFirst(org.apache.juneau.http.remote.RemoteResource.class)) 052 if (! r.path().isEmpty()) 053 path = trimSlashes(r.path()); 054 055 Map<Method,RemoteMethodMeta> methods = new LinkedHashMap<>(); 056 for (MethodInfo m : ci.getPublicMethods()) 057 if (m.isPublic()) 058 methods.put(m.inner(), new RemoteMethodMeta(path, m.inner(), false, "GET")); 059 060 this.methods = unmodifiableMap(methods); 061 this.path = path; 062 } 063 064 /** 065 * Returns the metadata about the specified method on this resource proxy. 066 * 067 * @param m The method to look up. 068 * @return Metadata about the method or <jk>null</jk> if no metadata was found. 069 */ 070 public RemoteMethodMeta getMethodMeta(Method m) { 071 return methods.get(m); 072 } 073 074 /** 075 * Returns the HTTP path of this interface. 076 * 077 * @return 078 * The HTTP path of this interface. 079 * <br>Never <jk>null</jk>. 080 * <br>Never has leading or trailing slashes. 081 */ 082 public String getPath() { 083 return path; 084 } 085}