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