use of com.sun.javadoc.AnnotationValue in project RESTdoclet by IG-Group.
the class ControllerBuilder method initMethods.
/**
* Initialises the methods in this controller annotated with
* <code>@RequestMapping</code> in the source class.
*
* @param classDoc the controller's Java documentation object.
*/
private void initMethods(Controller controller, final ClassDoc classDoc) {
LOG.info(controller.getName());
// Controller-level $RequestMapping annotation?
String baseUri = "";
AnnotationValue urlAnnotation = elementValue(classDoc, RequestMapping.class, "value");
if (urlAnnotation != null) {
String[] methodUris = parseValueAnnotation(urlAnnotation);
// Assume just one...
baseUri = methodUris[0];
}
// Initialise methods
ArrayList<Method> methods = new ArrayList<Method>();
for (int i = 0; classDoc.methods(false) != null && i < classDoc.methods(false).length; i++) {
if (isAnnotated(classDoc.methods(false)[i], RequestMapping.class) && !ignore(classDoc.methods(false)[i])) {
methods.add(new MethodBuilder().build(new Method(), classDoc.methods(false)[i], baseUri));
}
}
controller.setMethods(methods);
if (methods.size() == 0) {
LOG.warn("No methods found with @RequestMapping tag");
}
}
use of com.sun.javadoc.AnnotationValue in project RESTdoclet by IG-Group.
the class MethodBuilder method initProduces.
private void initProduces(Method method, final MethodDoc methodDoc) {
final AnnotationValue value = elementValue(methodDoc, RequestMapping.class, "produces");
LOG.debug(method.getName());
if (value != null) {
method.setProduces(value.toString().replace("\"", ""));
LOG.debug("PRODUCES " + method.getProduces());
}
}
use of com.sun.javadoc.AnnotationValue in project RESTdoclet by IG-Group.
the class MethodBuilder method initRequestMethod.
/**
* Initialises the HTTP request-method this method is mapped to.
*
* @param methodDoc the method's Java documentation object.
*/
private void initRequestMethod(Method method, final MethodDoc methodDoc) {
final AnnotationValue value = elementValue(methodDoc, RequestMapping.class, "method");
LOG.debug(method.getName());
if (value == null) {
/* default */
LOG.debug("No method found.... defaulting to GET");
method.setRequestMethod(RequestMethod.GET.toString());
} else {
/*
* Java 1.6: AnnotationValue.toString() returns qualified classname
* example:
* org.springframework.web.bind.annotation.RequestMethod.GET Java
* 1.5: AnnotationValue.toString() returns simple classname example:
* GET
*/
if (value.toString().contains(".")) {
method.setRequestMethod(value.toString().substring(value.toString().lastIndexOf(".") + 1));
} else {
method.setRequestMethod(value.toString());
}
}
LOG.debug(method.getRequestMethod());
}
use of com.sun.javadoc.AnnotationValue in project RESTdoclet by IG-Group.
the class MethodBuilder method initHeaders.
private void initHeaders(Method method, final MethodDoc methodDoc) {
final AnnotationValue value = elementValue(methodDoc, RequestMapping.class, "headers");
LOG.debug(method.getName());
if (value != null) {
method.setHeaders(value.toString().replace("\"", ""));
LOG.debug("HEADERS " + method.getHeaders());
}
}
use of com.sun.javadoc.AnnotationValue in project RESTdoclet by IG-Group.
the class AnnotationUtils method elementValue.
/**
* Gets an element-value pair of an annotation an argument of a method is
* annotated with.
*
* @param param the argument to check for annotations.
* @param type the type of annotation to look for.
* @param elementName the name of the element in the annotation to look for.
* @return the value of the element in the annotation or <code>null</code>
* if the annotation is not found or the name of the element is not
* found.
*/
public static AnnotationValue elementValue(final Parameter param, final Class<?> type, final String elementName) {
AnnotationValue value = null;
final ElementValuePair[] pairs = elementValues(param, type);
for (final ElementValuePair pair : pairs) {
if (StringUtils.equals(elementName, pair.element().name())) {
value = pair.value();
break;
}
}
return value;
}
Aggregations