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 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 * @deprecated Internal class.
024 */
025@Deprecated
026public class RemoteableMeta {
027
028   private final Map<Method,RemoteableMethodMeta> methods;
029
030   /**
031    * Constructor.
032    *
033    * @param c The interface class annotated with a {@link Remoteable @Remoteable} annotation (optional).
034    * @param restUrl The absolute URL of the remote REST interface that implements this proxy interface.
035    */
036   public RemoteableMeta(Class<?> c, String restUrl) {
037      Remoteable r = getAnnotation(Remoteable.class, c);
038
039      String expose = r == null ? "DECLARED" : r.expose();
040      if (! isOneOf(expose, "ALL", "DECLARED", "ANNOTATED"))
041         throw new RemoteableMetadataException(c, "Invalid value specified for ''expose'' annotation.  Valid values are [ALL,ANNOTATED,DECLARED].");
042
043      Map<Method,RemoteableMethodMeta> _methods = new LinkedHashMap<>();
044      for (Method m : expose.equals("DECLARED") ? c.getDeclaredMethods() : c.getMethods()) {
045         if (isPublic(m)) {
046            RemoteMethod rm = c.getAnnotation(RemoteMethod.class);
047            if (rm != null || ! expose.equals("ANNOTATED"))
048               _methods.put(m, new RemoteableMethodMeta(restUrl, m));
049         }
050      }
051
052      this.methods = unmodifiableMap(_methods);
053   }
054
055   /**
056    * Returns the metadata about the specified method on this interface proxy.
057    *
058    * @param m The method to look up.
059    * @return Metadata about the method, or <jk>null</jk> if no metadata was found.
060    */
061   public RemoteableMethodMeta getMethodMeta(Method m) {
062      return methods.get(m);
063   }
064}