package com.iggroup.restdoc.doclet;
/**
* An abstract parameter.
*
* Abstraction is used when a parameter is searched by a predicate.
*/
public abstract class AbstractParameter {
/**
* Gets the name of this parameter.
*
* @return the parameter's name.
*/
public abstract String getName();
/**
* Gets the Java type of this parameter.
*
* @return the parameter's Java type.
*/
public abstract String getType();
}
package com.iggroup.restdoc.doclet;
/**
* This parameter is for HTTP response content-type sent as a HTTP request-header.
*/
public class AcceptApplicationParameter extends ApplicationParameter {
/**
* The name of HTTP response content-type header.
*/
public static final String NAME = "Accept";
/**
* No-argument constructor.
*/
public AcceptApplicationParameter() {
super(NAME, "Response Content-Type");
}
}
package com.iggroup.restdoc.doclet;
import static org.apache.commons.lang.StringUtils.trimToNull;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
/**
* This class creates an application-parameter.
*
* These parameters are method-arguments annotated with @RequestParam
*
*
The HTTP response content-type (see {@link AcceptApplicationParameter}) is used by default. * *
Since version 2.x, these parameters were no longer serialised.
*/
public class ApplicationParameter extends AbstractParameter implements Comparable
* The name of this parameter is the value of This constructor is used while generating services.
*
* @param type the controller's Java type.
* @param javadoc the controller's documentation.
* @param methods the controller's methods.
*/
public Controller(final String type, final String javadoc, final Collectionjava.lang.String.
*/
private String type = String.class.getSimpleName();
/**
* The documentation of this parameter.
*/
private String javadoc;
/**
* No-argument constructor for this class to be used as a bean or by JiBX binding.
*/
public ApplicationParameter() {
super();
}
/**
* Constructs this parameter with its name.
*
* @param name the parameter's name.
*/
public ApplicationParameter(final String name) {
super();
this.name = trimToNull(name);
}
/**
* Constructs this parameter with its name and its documentation.
*
* @param name the parameter's name.
* @param javadoc the parameter's documentation.
*/
public ApplicationParameter(final String name, final String javadoc) {
this(name);
this.javadoc = trimToNull(javadoc);
}
/**
* {@inheritDoc}
*/
public String getName() {
return name;
}
/**
* Sets the name of this parameter.
*
* @param name the parameter's name.
*/
public void setName(final String name) {
this.name = trimToNull(name);
}
/**
* {@inheritDoc}
*/
public String getType() {
return type;
}
/**
* Sets the Java type of this parameter.
*
* @param type the parameter's Java type.
*/
public void setType(final String type) {
this.type = trimToNull(type);
}
/**
* Gets the documentation of this parameter.
*
* @return the parameter's documentation.
*/
public String getJavadoc() {
return javadoc;
}
/**
* Sets the documentation of this parameter.
*
* @param javadoc the parameter's documentation.
*/
public void setJavadoc(final String javadoc) {
this.javadoc = trimToNull(javadoc);
}
/**
* {@inheritDoc}
*/
public boolean equals(final Object obj) {
boolean result;
if (obj instanceof ApplicationParameter) {
final ApplicationParameter param = (ApplicationParameter) obj;
result = new EqualsBuilder()
.append(name, param.name)
.append(type, param.type)
.isEquals();
} else {
result = false;
}
return result;
}
/**
* {@inheritDoc}
*/
public int hashCode() {
return new HashCodeBuilder()
.append(name)
.append(type)
.toHashCode();
}
/**
* {@inheritDoc}
*/
public int compareTo(final ApplicationParameter param) {
int result;
if (param == null) {
result = 1;
} else {
result = new CompareToBuilder()
.append(name, param.name)
.append(type, param.type)
.toComparison();
}
return result;
}
/**
* {@inheritDoc}
*/
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("name", name)
.append("type", type)
.append("javadoc", javadoc)
.toString();
}
}
package com.iggroup.restdoc.doclet;
import static com.iggroup.restdoc.doclet.util.AnnotationUtils.elementValue;
import static org.apache.commons.lang.StringUtils.isBlank;
import java.util.Collection;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.springframework.web.bind.annotation.RequestBody;
import com.iggroup.restdoc.doclet.util.AnnotationUtils;
import com.iggroup.restdoc.doclet.util.DocletUtils;
import com.sun.javadoc.AnnotationValue;
import com.sun.javadoc.ClassDoc;
import com.sun.javadoc.ParamTag;
import com.sun.javadoc.Parameter;
/**
* This class creates documentation for a body-parameter.
*/
public class BodyParameter extends AbstractParameter implements
Comparable@bodyAttribute
* annotation. If not defined, the name of its argument is used.
*
* @param param
* the parameter's Java documentation object.
* @param tags
* the Java documentation tags of the parameters of the method
* this parameter belongs to.
*/
public BodyParameter(final Parameter param, final ParamTag[] tags) {
super();
initName(param);
initType(param);
initJavadoc(param, tags);
initFields(param.type().asClassDoc());
}
/**
* Initialises the name of this parameter.
*
* @param param
* the parameter's Java documentation object.
*/
private void initName(final Parameter param) {
final AnnotationValue value = elementValue(param, RequestBody.class,
"value");
if (value == null) {
name = param.name();
} else {
if (isBlank(value.value().toString())) {
name = param.name();
} else {
name = value.value().toString().trim();
}
}
}
/**
* Initialises the Java type of this parameter.
*
* @param param
* the parameter's Java documentation object.
*/
private void initType(final Parameter param) {
type = AnnotationUtils.getTypeName(param.type());
}
/**
* Initialises the documentation of this parameter.
*
* @param param
* the parameter's Java documentation object.
* @param tags
* the Java documentation tags of the parameters of the method
* this parameter belongs to.
*/
private void initJavadoc(final Parameter param, final ParamTag[] tags) {
for (ParamTag tag : tags) {
if (param.name().equals(tag.parameterName())) {
javadoc = AnnotationUtils.getTypeDoc(param.type());
if (javadoc.isEmpty()) { // no class doc found, revert to tag comment
javadoc = tag.parameterComment();
}
break;
}
}
}
/**
* Initialises the field-parameters in this body-parameter.
*
* @param classDoc
* the parameter's Java documentation object.
*/
private void initFields(final ClassDoc classDoc) {
fields = DocletUtils.getPublicFields(classDoc);
}
/**
* {@inheritDoc}
*/
public String getName() {
return name;
}
/**
* Sets the name of this parameter.
*
* @param name
* the parameter's name.
*/
public void setName(final String name) {
this.name = name;
}
/**
* {@inheritDoc}
*/
public String getType() {
return type;
}
/**
* Sets the Java type of this parameter.
*
* @param type
* the parameter's Java type.
*/
public void setType(final String type) {
this.type = type;
}
/**
* Gets the documentation of this parameter.
*
* @return the parameter's documentation.
*/
public String getJavadoc() {
return javadoc;
}
/**
* Sets the documentation of this parameter.
*
* @param javadoc
* the parameter's documentation.
*/
public void setJavadoc(final String javadoc) {
this.javadoc = javadoc;
}
/**
* Gets the field-parameters of this parameter.
*
* @return the parameter's field-parameters.
*/
public Collection@Controller.
*/
public class Controller implements Comparablefoo.Baz, its documentation will be created in
* foo/Baz.controller.xml.
*/
public static final String FILE_SUFFIX = ".controller.xml";
/**
* The Java type of this controller.
*/
private String type;
/**
* The documentation of this controller.
*/
private String javadoc;
/**
* The methods annotated with @RequestMapping in the source class.
*/
private Collection@RequestMapping.
*
* @RequestMapping in the
* source class.
*
* @param classDoc the controller's Java documentation object.
*/
private void initMethods(final ClassDoc classDoc) {
methods = new ArrayList@RequestMapping in the source
* class.
*
* @return the controller's methods.
*/
public Collection@RequestMapping in the source
* class.
*
* @param methods the controller's methods.
*/
public void setMethods(final Collection