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