use of org.glassfish.jersey.linking.mapping.ResourceMappingContext in project jersey by jersey.
the class InjectLinkFieldDescriptor method getLinkTemplate.
/**
* TODO javadoc.
*/
public static String getLinkTemplate(ResourceMappingContext rmc, InjectLink link) {
String template = null;
if (!link.resource().equals(Class.class)) {
ResourceMappingContext.Mapping map = rmc.getMapping(link.resource());
if (map != null) {
template = map.getTemplate().getTemplate().toString();
} else {
// extract template from specified class' @Path annotation
Path path = link.resource().getAnnotation(Path.class);
template = path == null ? "" : path.value();
}
// extract template from specified class' @Path annotation
if (link.method().length() > 0) {
// append value of method's @Path annotation
MethodList methods = new MethodList(link.resource());
methods = methods.withMetaAnnotation(HttpMethod.class);
Iterator<AnnotatedMethod> iterator = methods.iterator();
while (iterator.hasNext()) {
AnnotatedMethod method = iterator.next();
if (!method.getMethod().getName().equals(link.method())) {
continue;
}
StringBuilder builder = new StringBuilder();
builder.append(template);
Path methodPath = method.getAnnotation(Path.class);
if (methodPath != null) {
String methodTemplate = methodPath.value();
if (!(template.endsWith("/") || methodTemplate.startsWith("/"))) {
builder.append("/");
}
builder.append(methodTemplate);
}
CharSequence querySubString = extractQueryParams(method);
if (querySubString.length() > 0) {
builder.append("{?");
builder.append(querySubString);
builder.append("}");
}
template = builder.toString();
break;
}
}
} else {
template = link.value();
}
return template;
}
Aggregations