use of com.thoughtworks.qdox.model.DocletTag in project geronimo-xbean by apache.
the class QdoxMappingLoader method getParameterDescription.
private String getParameterDescription(JavaParameter parameter) {
String parameterName = parameter.getName();
DocletTag[] tags = parameter.getParentMethod().getTagsByName("param");
for (DocletTag tag : tags) {
if (tag.getParameters()[0].equals(parameterName)) {
String parameterDescription = tag.getValue().trim();
if (parameterDescription.startsWith(parameterName)) {
parameterDescription = parameterDescription.substring(parameterName.length()).trim();
}
return parameterDescription;
}
}
return null;
}
use of com.thoughtworks.qdox.model.DocletTag in project geronimo-xbean by apache.
the class QdoxMappingLoader method loadAttribute.
private AttributeMapping loadAttribute(BeanProperty beanProperty, String defaultDescription) {
DocletTag propertyTag = getPropertyTag(beanProperty);
if (getBooleanProperty(propertyTag, "hidden")) {
return null;
}
String attribute = getProperty(propertyTag, "alias", beanProperty.getName());
String attributeDescription = getAttributeDescription(beanProperty, propertyTag, defaultDescription);
String defaultValue = getProperty(propertyTag, "default");
boolean fixed = getBooleanProperty(propertyTag, "fixed");
boolean required = getBooleanProperty(propertyTag, "required");
String nestedType = getProperty(propertyTag, "nestedType");
String propertyEditor = getProperty(propertyTag, "propertyEditor");
return new AttributeMapping(attribute, beanProperty.getName(), attributeDescription, toMappingType(beanProperty.getType(), nestedType), defaultValue, fixed, required, propertyEditor);
}
use of com.thoughtworks.qdox.model.DocletTag in project geronimo-xbean by apache.
the class QdoxMappingLoader method loadElement.
private ElementMapping loadElement(JavaDocBuilder builder, JavaClass javaClass) {
DocletTag xbeanTag = javaClass.getTagByName(XBEAN_ANNOTATION);
if (xbeanTag == null) {
return null;
}
String element = getElementName(javaClass, xbeanTag);
String description = getProperty(xbeanTag, "description");
if (description == null) {
description = javaClass.getComment();
}
String namespace = getProperty(xbeanTag, "namespace", defaultNamespace);
boolean root = getBooleanProperty(xbeanTag, "rootElement");
String contentProperty = getProperty(xbeanTag, "contentProperty");
String factoryClass = getProperty(xbeanTag, "factoryClass");
Map<String, MapMapping> mapsByPropertyName = new HashMap<String, MapMapping>();
List<String> flatProperties = new ArrayList<String>();
Map<String, String> flatCollections = new HashMap<String, String>();
Set<AttributeMapping> attributes = new HashSet<AttributeMapping>();
Map<String, AttributeMapping> attributesByPropertyName = new HashMap<String, AttributeMapping>();
for (JavaClass jClass = javaClass; jClass != null; jClass = jClass.getSuperJavaClass()) {
BeanProperty[] beanProperties = jClass.getBeanProperties();
for (BeanProperty beanProperty : beanProperties) {
// we only care about properties with a setter
if (beanProperty.getMutator() != null) {
AttributeMapping attributeMapping = loadAttribute(beanProperty, "");
if (attributeMapping != null) {
attributes.add(attributeMapping);
attributesByPropertyName.put(attributeMapping.getPropertyName(), attributeMapping);
}
JavaMethod acc = beanProperty.getAccessor();
if (acc != null) {
DocletTag mapTag = acc.getTagByName(MAP_ANNOTATION);
if (mapTag != null) {
MapMapping mm = new MapMapping(mapTag.getNamedParameter("entryName"), mapTag.getNamedParameter("keyName"), Boolean.valueOf(mapTag.getNamedParameter("flat")), mapTag.getNamedParameter("dups"), mapTag.getNamedParameter("defaultKey"));
mapsByPropertyName.put(beanProperty.getName(), mm);
}
DocletTag flatColTag = acc.getTagByName(FLAT_COLLECTION_ANNOTATION);
if (flatColTag != null) {
String childName = flatColTag.getNamedParameter("childElement");
if (childName == null)
throw new InvalidModelException("Flat collections must specify the childElement attribute.");
flatCollections.put(beanProperty.getName(), childName);
}
DocletTag flatPropTag = acc.getTagByName(FLAT_PROPERTY_ANNOTATION);
if (flatPropTag != null) {
flatProperties.add(beanProperty.getName());
}
}
}
}
}
String initMethod = null;
String destroyMethod = null;
String factoryMethod = null;
for (JavaClass jClass = javaClass; jClass != null; jClass = jClass.getSuperJavaClass()) {
JavaMethod[] methods = javaClass.getMethods();
for (JavaMethod method : methods) {
if (method.isPublic() && !method.isConstructor()) {
if (initMethod == null && method.getTagByName(INIT_METHOD_ANNOTATION) != null) {
initMethod = method.getName();
}
if (destroyMethod == null && method.getTagByName(DESTROY_METHOD_ANNOTATION) != null) {
destroyMethod = method.getName();
}
if (factoryMethod == null && method.getTagByName(FACTORY_METHOD_ANNOTATION) != null) {
factoryMethod = method.getName();
}
}
}
}
List<List<ParameterMapping>> constructorArgs = new ArrayList<List<ParameterMapping>>();
JavaMethod[] methods = javaClass.getMethods();
for (JavaMethod method : methods) {
JavaParameter[] parameters = method.getParameters();
if (isValidConstructor(factoryMethod, method, parameters)) {
List<ParameterMapping> args = new ArrayList<ParameterMapping>(parameters.length);
for (JavaParameter parameter : parameters) {
AttributeMapping attributeMapping = attributesByPropertyName.get(parameter.getName());
if (attributeMapping == null) {
attributeMapping = loadParameter(parameter);
attributes.add(attributeMapping);
attributesByPropertyName.put(attributeMapping.getPropertyName(), attributeMapping);
}
args.add(new ParameterMapping(attributeMapping.getPropertyName(), toMappingType(parameter.getType(), null)));
}
constructorArgs.add(Collections.unmodifiableList(args));
}
}
HashSet<String> interfaces = new HashSet<String>();
interfaces.addAll(getFullyQualifiedNames(javaClass.getImplementedInterfaces()));
JavaClass actualClass = javaClass;
if (factoryClass != null) {
JavaClass clazz = builder.getClassByName(factoryClass);
if (clazz != null) {
log.info("Detected factory: using " + factoryClass + " instead of " + javaClass.getFullyQualifiedName());
actualClass = clazz;
} else {
log.info("Could not load class built by factory: " + factoryClass);
}
}
ArrayList<String> superClasses = new ArrayList<String>();
JavaClass p = actualClass;
if (actualClass != javaClass) {
superClasses.add(actualClass.getFullyQualifiedName());
}
while (true) {
JavaClass s = p.getSuperJavaClass();
if (s == null || s.equals(p) || "java.lang.Object".equals(s.getFullyQualifiedName())) {
break;
}
p = s;
superClasses.add(p.getFullyQualifiedName());
interfaces.addAll(getFullyQualifiedNames(p.getImplementedInterfaces()));
}
return new ElementMapping(namespace, element, javaClass.getFullyQualifiedName(), description, root, initMethod, destroyMethod, factoryMethod, contentProperty, attributes, constructorArgs, flatProperties, mapsByPropertyName, flatCollections, superClasses, interfaces);
}
use of com.thoughtworks.qdox.model.DocletTag in project geronimo-xbean by apache.
the class QdoxMappingLoader method getParameterDescription.
private String getParameterDescription(JavaParameter parameter) {
String parameterName = parameter.getName();
DocletTag[] tags = parameter.getParentMethod().getTagsByName("param");
for (DocletTag tag : tags) {
if (tag.getParameters()[0].equals(parameterName)) {
String parameterDescription = tag.getValue().trim();
if (parameterDescription.startsWith(parameterName)) {
parameterDescription = parameterDescription.substring(parameterName.length()).trim();
}
return parameterDescription;
}
}
return null;
}
use of com.thoughtworks.qdox.model.DocletTag in project geronimo-xbean by apache.
the class QdoxMappingLoader method loadAttribute.
private AttributeMapping loadAttribute(BeanProperty beanProperty, String defaultDescription) {
DocletTag propertyTag = getPropertyTag(beanProperty);
if (getBooleanProperty(propertyTag, "hidden")) {
return null;
}
String attribute = getProperty(propertyTag, "alias", beanProperty.getName());
String attributeDescription = getAttributeDescription(beanProperty, propertyTag, defaultDescription);
String defaultValue = getProperty(propertyTag, "default");
boolean fixed = getBooleanProperty(propertyTag, "fixed");
boolean required = getBooleanProperty(propertyTag, "required");
String nestedType = getProperty(propertyTag, "nestedType");
String propertyEditor = getProperty(propertyTag, "propertyEditor");
return new AttributeMapping(attribute, beanProperty.getName(), attributeDescription, toMappingType(beanProperty.getType(), nestedType), defaultValue, fixed, required, propertyEditor);
}
Aggregations