下面列出了javax.ws.rs.PathParam#value ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static PathParam createPathParam(Parameter parameter)
{
return new PathParam()
{
@Override
public String value()
{
PathParam annotation = parameter.getAnnotation(PathParam.class);
if (annotation != null)
{
return annotation.value();
}
return parameter.getName();
}
@Override
public Class<? extends Annotation> annotationType()
{
return PathParam.class;
}
};
}
private void compileParameters(AnnotatedType[] annotatedParameterTypes, Annotation[][] annotations) {
ImmutableList.Builder<String> parameterOrderBuilder = ImmutableList.builder();
ImmutableMap.Builder<String, Type> nameToTypeBuilder = ImmutableMap.builder();
for (int x = 0; x < annotatedParameterTypes.length; ++x) {
AnnotatedType annotatedType = annotatedParameterTypes[x];
PathParam pathParam = getPathParam(annotations[x]);
String name;
Type type;
if (pathParam != null) {
name = pathParam.value();
type = annotatedType.getType();
} else {
name = NAME_ENTITY;
type = annotatedType.getType();
}
parameterOrderBuilder.add(name);
nameToTypeBuilder.put(name, type);
}
parameterOrder = parameterOrderBuilder.build();
parameterNameToType = nameToTypeBuilder.build();
}
private String replacePathParamsWithExamples(Method method, String methodPath) {
for (Parameter parameter : method.getParameters()) {
PathParam pathParam = AnnotationUtils.findAnnotation(parameter, PathParam.class);
if (pathParam != null) {
String pathParamValue = pathParam.value();
Class<?> parameterType = parameter.getType();
if (Long.class.equals(parameterType)) {
methodPath = "workspaceId".equals(pathParamValue)
? methodPath.replace('{' + pathParamValue + '}', WORKSPACE_ID)
: methodPath.replace('{' + pathParamValue + '}', RESOURCE_ID);
} else {
if (methodPath.startsWith("/v4/workspaces")) {
methodPath = methodPath.replace('{' + pathParamValue + '}', WORKSPACE_NAME);
} else if (methodPath.startsWith("/autoscale/stack")) {
methodPath = methodPath.replace('{' + pathParamValue + '}', RESOURCE_CRN);
} else if (pathParam.value().equals(NAME)) {
methodPath = methodPath.replace('{' + pathParamValue + '}', RESOURCE_NAME);
} else if (pathParam.value().equals(CRN)) {
methodPath = methodPath.replace('{' + pathParamValue + '}', RESOURCE_CRN);
} else {
methodPath = methodPath.replace('{' + pathParamValue + '}', RESOURCE_NAME);
}
}
}
}
return methodPath;
}
@Override
public String getParameterName(PathParam parameterAnnotation) {
return parameterAnnotation.value();
}
public static Parameter getParameter(int index, Annotation[] anns, Class<?> type) {
Context ctx = AnnotationUtils.getAnnotation(anns, Context.class);
if (ctx != null) {
return new Parameter(ParameterType.CONTEXT, index, null);
}
boolean isEncoded = AnnotationUtils.getAnnotation(anns, Encoded.class) != null;
BeanParam bp = AnnotationUtils.getAnnotation(anns, BeanParam.class);
if (bp != null) {
return new Parameter(ParameterType.BEAN, index, null, isEncoded, null);
}
String dValue = AnnotationUtils.getDefaultParameterValue(anns);
PathParam a = AnnotationUtils.getAnnotation(anns, PathParam.class);
if (a != null) {
return new Parameter(ParameterType.PATH, index, a.value(), isEncoded, dValue);
}
QueryParam q = AnnotationUtils.getAnnotation(anns, QueryParam.class);
if (q != null) {
return new Parameter(ParameterType.QUERY, index, q.value(), isEncoded, dValue);
}
MatrixParam m = AnnotationUtils.getAnnotation(anns, MatrixParam.class);
if (m != null) {
return new Parameter(ParameterType.MATRIX, index, m.value(), isEncoded, dValue);
}
FormParam f = AnnotationUtils.getAnnotation(anns, FormParam.class);
if (f != null) {
return new Parameter(ParameterType.FORM, index, f.value(), isEncoded, dValue);
}
HeaderParam h = AnnotationUtils.getAnnotation(anns, HeaderParam.class);
if (h != null) {
return new Parameter(ParameterType.HEADER, index, h.value(), isEncoded, dValue);
}
CookieParam c = AnnotationUtils.getAnnotation(anns, CookieParam.class);
if (c != null) {
return new Parameter(ParameterType.COOKIE, index, c.value(), isEncoded, dValue);
}
return new Parameter(ParameterType.REQUEST_BODY, index, null);
}