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 java.lang.reflect.*; 016 017import org.apache.juneau.*; 018import org.apache.juneau.http.remote.RemoteMethod; 019import org.apache.juneau.http.remote.RemoteReturn; 020import org.apache.juneau.http.annotation.*; 021import org.apache.juneau.httppart.bean.*; 022import org.apache.juneau.reflect.*; 023 024/** 025 * Represents the metadata about the returned object of a method on a remote proxy interface. 026 * 027 * <ul class='seealso'> 028 * <li class='link'>{@doc juneau-rest-client.RestProxies} 029 * </ul> 030 */ 031public final class RemoteMethodReturn { 032 033 private final Type returnType; 034 private final RemoteReturn returnValue; 035 private final ResponseBeanMeta meta; 036 037 @SuppressWarnings("deprecation") 038 RemoteMethodReturn(MethodInfo m) { 039 ClassInfo rt = m.getReturnType(); 040 041 org.apache.juneau.rest.client.remote.RemoteMethod orm = m.getAnnotation(org.apache.juneau.rest.client.remote.RemoteMethod.class); 042 if (orm == null) 043 orm = m.getResolvedReturnType().getAnnotation(org.apache.juneau.rest.client.remote.RemoteMethod.class); 044 RemoteMethod rm = m.getAnnotation(RemoteMethod.class); 045 if (rm == null) 046 rm = m.getResolvedReturnType().getAnnotation(RemoteMethod.class); 047 048 RemoteReturn rv = null; 049 if (rt.is(void.class)) 050 rv = RemoteReturn.NONE; 051 else if (orm != null) 052 switch (orm.returns()) { 053 case BEAN: rv = RemoteReturn.BEAN; break; 054 case BODY: rv = RemoteReturn.BODY; break; 055 case NONE: rv = RemoteReturn.NONE; break; 056 case STATUS: rv = RemoteReturn.STATUS; break; 057 } 058 else if (rm != null) 059 rv = rm.returns(); 060 else 061 rv = RemoteReturn.BODY; 062 063 if (rt.hasAnnotation(Response.class) && rt.isInterface()) { 064 this.meta = ResponseBeanMeta.create(m, PropertyStore.DEFAULT); 065 rv = RemoteReturn.BEAN; 066 } else { 067 this.meta = null; 068 } 069 070 this.returnType = m.getReturnType().innerType(); 071 this.returnValue = rv; 072 } 073 074 /** 075 * Returns schema information about the HTTP part. 076 * 077 * @return Schema information about the HTTP part, or <jk>null</jk> if not found. 078 */ 079 public ResponseBeanMeta getResponseBeanMeta() { 080 return meta; 081 } 082 083 /** 084 * Returns the class type of the method return. 085 * 086 * @return The class type of the method return. 087 */ 088 public Type getReturnType() { 089 return returnType; 090 } 091 092 /** 093 * Specifies whether the return value is the body of the request or the HTTP status. 094 * 095 * @return The type of value returned. 096 */ 097 public RemoteReturn getReturnValue() { 098 return returnValue; 099 } 100}