69ffcb
From 928bd5a98dc500a31197a56c8f6c5e19a3a273f8 Mon Sep 17 00:00:00 2001
69ffcb
From: Mikolaj Izdebski <mizdebsk@redhat.com>
69ffcb
Date: Fri, 21 Nov 2014 10:51:38 +0100
69ffcb
Subject: [PATCH 3/3] Port to QDox 2.0
69ffcb
69ffcb
---
69ffcb
 pom.xml                                            |   2 +-
69ffcb
 .../blueprint/generator/QdoxMappingLoader.java     | 144 +++++++++++---------
69ffcb
 .../xbean/spring/generator/QdoxMappingLoader.java  | 148 ++++++++++++---------
69ffcb
 .../org/apache/xbean/spring/generator/Type.java    |   7 +-
69ffcb
 4 files changed, 166 insertions(+), 135 deletions(-)
69ffcb
69ffcb
diff --git a/pom.xml b/pom.xml
69ffcb
index 6e53649..9132fe4 100644
69ffcb
--- a/pom.xml
69ffcb
+++ b/pom.xml
69ffcb
@@ -297,7 +297,7 @@
69ffcb
             <dependency>
69ffcb
                 <groupId>com.thoughtworks.qdox</groupId>
69ffcb
                 <artifactId>qdox</artifactId>
69ffcb
-                <version>1.6.3</version>
69ffcb
+                <version>2.0-M5</version>
69ffcb
             </dependency>
69ffcb
             
69ffcb
             <dependency>
69ffcb
diff --git a/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/generator/QdoxMappingLoader.java b/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/generator/QdoxMappingLoader.java
69ffcb
index 6635937..e17fd08 100644
69ffcb
--- a/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/generator/QdoxMappingLoader.java
69ffcb
+++ b/xbean-blueprint/src/main/java/org/apache/xbean/blueprint/generator/QdoxMappingLoader.java
69ffcb
@@ -20,6 +20,7 @@ import java.io.File;
69ffcb
 import java.io.IOException;
69ffcb
 import java.net.URL;
69ffcb
 import java.util.ArrayList;
69ffcb
+import java.util.Collection;
69ffcb
 import java.util.Collections;
69ffcb
 import java.util.Enumeration;
69ffcb
 import java.util.HashMap;
69ffcb
@@ -31,14 +32,17 @@ import java.util.TreeSet;
69ffcb
 import java.util.jar.JarEntry;
69ffcb
 import java.util.jar.JarFile;
69ffcb
 
69ffcb
-import com.thoughtworks.qdox.JavaDocBuilder;
69ffcb
+import com.thoughtworks.qdox.JavaProjectBuilder;
69ffcb
 import com.thoughtworks.qdox.model.BeanProperty;
69ffcb
 import com.thoughtworks.qdox.model.DocletTag;
69ffcb
 import com.thoughtworks.qdox.model.JavaClass;
69ffcb
+import com.thoughtworks.qdox.model.JavaConstructor;
69ffcb
 import com.thoughtworks.qdox.model.JavaMethod;
69ffcb
+import com.thoughtworks.qdox.model.JavaModel;
69ffcb
 import com.thoughtworks.qdox.model.JavaParameter;
69ffcb
 import com.thoughtworks.qdox.model.JavaSource;
69ffcb
-import com.thoughtworks.qdox.model.Type;
69ffcb
+import com.thoughtworks.qdox.model.JavaType;
69ffcb
+
69ffcb
 import org.apache.commons.logging.Log;
69ffcb
 import org.apache.commons.logging.LogFactory;
69ffcb
 
69ffcb
@@ -62,7 +66,7 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
     private final String defaultNamespace;
69ffcb
     private final File[] srcDirs;
69ffcb
     private final String[] excludedClasses;
69ffcb
-    private Type collectionType;
69ffcb
+    private JavaClass collectionType;
69ffcb
 
69ffcb
     public QdoxMappingLoader(String defaultNamespace, File[] srcDirs, String[] excludedClasses) {
69ffcb
         this.defaultNamespace = defaultNamespace;
69ffcb
@@ -79,7 +83,7 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
     }
69ffcb
 
69ffcb
     public Set<NamespaceMapping> loadNamespaces() throws IOException {
69ffcb
-        JavaDocBuilder builder = new JavaDocBuilder();
69ffcb
+        JavaProjectBuilder builder = new JavaProjectBuilder();
69ffcb
 
69ffcb
         log.debug("Source directories: ");
69ffcb
 
69ffcb
@@ -92,11 +96,11 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
             getSourceFiles(sourceDirectory, excludedClasses, builder);
69ffcb
         }
69ffcb
 
69ffcb
-        collectionType = builder.getClassByName("java.util.Collection").asType();
69ffcb
+        collectionType = builder.getClassByName("java.util.Collection");
69ffcb
         return loadNamespaces(builder);
69ffcb
     }
69ffcb
 
69ffcb
-    private Set<NamespaceMapping> loadNamespaces(JavaDocBuilder builder) {
69ffcb
+    private Set<NamespaceMapping> loadNamespaces(JavaProjectBuilder builder) {
69ffcb
         // load all of the elements
69ffcb
         List<ElementMapping> elements = loadElements(builder);
69ffcb
 
69ffcb
@@ -131,14 +135,14 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
         return Collections.unmodifiableSet(namespaces);
69ffcb
     }
69ffcb
 
69ffcb
-    private List<ElementMapping> loadElements(JavaDocBuilder builder) {
69ffcb
-        JavaSource[] javaSources = builder.getSources();
69ffcb
+    private List<ElementMapping> loadElements(JavaProjectBuilder builder) {
69ffcb
+        Collection<JavaSource> javaSources = builder.getSources();
69ffcb
         List<ElementMapping> elements = new ArrayList<ElementMapping>();
69ffcb
         for (JavaSource javaSource : javaSources) {
69ffcb
-            if (javaSource.getClasses().length == 0) {
69ffcb
+            if (javaSource.getClasses().isEmpty()) {
69ffcb
                 log.info("No Java Classes defined in: " + javaSource.getURL());
69ffcb
             } else {
69ffcb
-                JavaClass[] classes = javaSource.getClasses();
69ffcb
+                Collection<JavaClass> classes = javaSource.getClasses();
69ffcb
                 for (JavaClass javaClass : classes) {
69ffcb
                     ElementMapping element = loadElement(builder, javaClass);
69ffcb
                     if (element != null && !javaClass.isAbstract()) {
69ffcb
@@ -152,7 +156,7 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
         return elements;
69ffcb
     }
69ffcb
 
69ffcb
-    private ElementMapping loadElement(JavaDocBuilder builder, JavaClass javaClass) {
69ffcb
+    private ElementMapping loadElement(JavaProjectBuilder builder, JavaClass javaClass) {
69ffcb
         DocletTag xbeanTag = javaClass.getTagByName(XBEAN_ANNOTATION);
69ffcb
         if (xbeanTag == null) {
69ffcb
             return null;
69ffcb
@@ -176,7 +180,7 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
         Map<String, AttributeMapping> attributesByPropertyName = new HashMap<String, AttributeMapping>();
69ffcb
 
69ffcb
         for (JavaClass jClass = javaClass; jClass != null; jClass = jClass.getSuperJavaClass()) {
69ffcb
-            BeanProperty[] beanProperties = jClass.getBeanProperties();
69ffcb
+            Collection<BeanProperty> beanProperties = jClass.getBeanProperties();
69ffcb
             for (BeanProperty beanProperty : beanProperties) {
69ffcb
                 // we only care about properties with a setter
69ffcb
                 if (beanProperty.getMutator() != null) {
69ffcb
@@ -219,9 +223,9 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
         String destroyMethod = null;
69ffcb
         String factoryMethod = null;
69ffcb
         for (JavaClass jClass = javaClass; jClass != null; jClass = jClass.getSuperJavaClass()) {
69ffcb
-            JavaMethod[] methods = javaClass.getMethods();
69ffcb
+            Collection<JavaMethod> methods = javaClass.getMethods();
69ffcb
             for (JavaMethod method : methods) {
69ffcb
-                if (method.isPublic() && !method.isConstructor()) {
69ffcb
+                if (method.isPublic()) {
69ffcb
                     if (initMethod == null && method.getTagByName(INIT_METHOD_ANNOTATION) != null) {
69ffcb
                         initMethod = method.getName();
69ffcb
                     }
69ffcb
@@ -237,22 +241,43 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
         }
69ffcb
 
69ffcb
         List<List<ParameterMapping>> constructorArgs = new ArrayList<List<ParameterMapping>>();
69ffcb
-        JavaMethod[] methods = javaClass.getMethods();
69ffcb
-        for (JavaMethod method : methods) {
69ffcb
-            JavaParameter[] parameters = method.getParameters();
69ffcb
-            if (isValidConstructor(factoryMethod, method, parameters)) {
69ffcb
-                List<ParameterMapping> args = new ArrayList<ParameterMapping>(parameters.length);
69ffcb
-                for (JavaParameter parameter : parameters) {
69ffcb
-                    AttributeMapping attributeMapping = attributesByPropertyName.get(parameter.getName());
69ffcb
-                    if (attributeMapping == null) {
69ffcb
-                        attributeMapping = loadParameter(parameter);
69ffcb
-
69ffcb
-                        attributes.add(attributeMapping);
69ffcb
-                        attributesByPropertyName.put(attributeMapping.getPropertyName(), attributeMapping);
69ffcb
+        if (factoryMethod == null) {
69ffcb
+            Collection<JavaConstructor> constructors = javaClass.getConstructors();
69ffcb
+            for (JavaConstructor constructor : constructors) {
69ffcb
+                Collection<JavaParameter> parameters = constructor.getParameters();
69ffcb
+                if (constructor.isPublic() && parameters.size() > 0) {
69ffcb
+                    List<ParameterMapping> args = new ArrayList<ParameterMapping>(parameters.size());
69ffcb
+                    for (JavaParameter parameter : parameters) {
69ffcb
+                        AttributeMapping attributeMapping = attributesByPropertyName.get(parameter.getName());
69ffcb
+                        if (attributeMapping == null) {
69ffcb
+                            attributeMapping = loadParameter(parameter, constructor);
69ffcb
+
69ffcb
+                            attributes.add(attributeMapping);
69ffcb
+                            attributesByPropertyName.put(attributeMapping.getPropertyName(), attributeMapping);
69ffcb
+                        }
69ffcb
+                        args.add(new ParameterMapping(attributeMapping.getPropertyName(), toMappingType(parameter.getType(), null)));
69ffcb
                     }
69ffcb
-                    args.add(new ParameterMapping(attributeMapping.getPropertyName(), toMappingType(parameter.getType(), null)));
69ffcb
+                    constructorArgs.add(Collections.unmodifiableList(args));
69ffcb
+                }
69ffcb
+            }
69ffcb
+        } else {
69ffcb
+            Collection<JavaMethod> methods = javaClass.getMethods();
69ffcb
+            for (JavaMethod method : methods) {
69ffcb
+                Collection<JavaParameter> parameters = method.getParameters();
69ffcb
+                if (method.isPublic() && parameters.size() > 0 && method.getName().equals(factoryMethod)) {
69ffcb
+                    List<ParameterMapping> args = new ArrayList<ParameterMapping>(parameters.size());
69ffcb
+                    for (JavaParameter parameter : parameters) {
69ffcb
+                        AttributeMapping attributeMapping = attributesByPropertyName.get(parameter.getName());
69ffcb
+                        if (attributeMapping == null) {
69ffcb
+                            attributeMapping = loadParameter(parameter, method);
69ffcb
+
69ffcb
+                            attributes.add(attributeMapping);
69ffcb
+                            attributesByPropertyName.put(attributeMapping.getPropertyName(), attributeMapping);
69ffcb
+                        }
69ffcb
+                        args.add(new ParameterMapping(attributeMapping.getPropertyName(), toMappingType(parameter.getType(), null)));
69ffcb
+                    }
69ffcb
+                    constructorArgs.add(Collections.unmodifiableList(args));
69ffcb
                 }
69ffcb
-                constructorArgs.add(Collections.unmodifiableList(args));
69ffcb
             }
69ffcb
         }
69ffcb
 
69ffcb
@@ -303,7 +328,7 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
                 interfaces);
69ffcb
     }
69ffcb
 
69ffcb
-    private List<String> getFullyQualifiedNames(JavaClass[] implementedInterfaces) {
69ffcb
+    private List<String> getFullyQualifiedNames(Collection<JavaClass> implementedInterfaces) {
69ffcb
         ArrayList<String> l = new ArrayList<String>();
69ffcb
         for (JavaClass implementedInterface : implementedInterfaces) {
69ffcb
             l.add(implementedInterface.getFullyQualifiedName());
69ffcb
@@ -395,19 +420,19 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
         return defaultDescription;
69ffcb
     }
69ffcb
 
69ffcb
-    private AttributeMapping loadParameter(JavaParameter parameter) {
69ffcb
+    private AttributeMapping loadParameter(JavaParameter parameter, JavaModel methodOrConstructor) {
69ffcb
         String parameterName = parameter.getName();
69ffcb
         String parameterDescription = getParameterDescription(parameter);
69ffcb
 
69ffcb
         // first attempt to load the attribute from the java beans accessor methods
69ffcb
-        JavaClass javaClass = parameter.getParentMethod().getParentClass();
69ffcb
+        JavaClass javaClass = parameter.getParentClass();
69ffcb
         BeanProperty beanProperty = javaClass.getBeanProperty(parameterName);
69ffcb
         if (beanProperty != null) {
69ffcb
             AttributeMapping attributeMapping = loadAttribute(beanProperty, parameterDescription);
69ffcb
             // if the attribute mapping is null, the property was tagged as hidden and this is an error
69ffcb
             if (attributeMapping == null) {
69ffcb
                 throw new InvalidModelException("Hidden property usage: " +
69ffcb
-                        "The construction method " + toMethodLocator(parameter.getParentMethod()) +
69ffcb
+                        "The construction method " + toMethodLocator(parameter.getParentClass(), methodOrConstructor) +
69ffcb
                         " can not use a hidded property " + parameterName);
69ffcb
             }
69ffcb
             return attributeMapping;
69ffcb
@@ -426,9 +451,9 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
 
69ffcb
     private String getParameterDescription(JavaParameter parameter) {
69ffcb
         String parameterName = parameter.getName();
69ffcb
-        DocletTag[] tags = parameter.getParentMethod().getTagsByName("param");
69ffcb
+        Collection<DocletTag> tags = parameter.getTagsByName("param");
69ffcb
         for (DocletTag tag : tags) {
69ffcb
-            if (tag.getParameters()[0].equals(parameterName)) {
69ffcb
+            if (tag.getParameters().get(0).equals(parameterName)) {
69ffcb
                 String parameterDescription = tag.getValue().trim();
69ffcb
                 if (parameterDescription.startsWith(parameterName)) {
69ffcb
                     parameterDescription = parameterDescription.substring(parameterName.length()).trim();
69ffcb
@@ -439,18 +464,6 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
         return null;
69ffcb
     }
69ffcb
 
69ffcb
-    private boolean isValidConstructor(String factoryMethod, JavaMethod method, JavaParameter[] parameters) {
69ffcb
-        if (!method.isPublic() || parameters.length == 0) {
69ffcb
-            return false;
69ffcb
-        }
69ffcb
-
69ffcb
-        if (factoryMethod == null) {
69ffcb
-            return method.isConstructor();
69ffcb
-        } else {
69ffcb
-            return method.getName().equals(factoryMethod);
69ffcb
-        }
69ffcb
-    }
69ffcb
-
69ffcb
     private static String getProperty(DocletTag propertyTag, String propertyName) {
69ffcb
         return getProperty(propertyTag, propertyName, null);
69ffcb
     }
69ffcb
@@ -477,14 +490,17 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
         return false;
69ffcb
     }
69ffcb
 
69ffcb
-    private org.apache.xbean.blueprint.generator.Type toMappingType(Type type, String nestedType) {
69ffcb
+    private org.apache.xbean.blueprint.generator.Type toMappingType(JavaType type, String nestedType) {
69ffcb
         try {
69ffcb
-            if (type.isArray()) {
69ffcb
-                return org.apache.xbean.blueprint.generator.Type.newArrayType(type.getValue(), type.getDimensions());
69ffcb
-            } else if (type.isA(collectionType)) {
69ffcb
-                if (nestedType == null) nestedType = "java.lang.Object";
69ffcb
-                return org.apache.xbean.blueprint.generator.Type.newCollectionType(type.getValue(),
69ffcb
-                        org.apache.xbean.blueprint.generator.Type.newSimpleType(nestedType));
69ffcb
+	    if (type instanceof JavaClass) {
69ffcb
+                JavaClass clazz = (JavaClass)type;
69ffcb
+                if (clazz.isArray()) {
69ffcb
+                    return org.apache.xbean.blueprint.generator.Type.newArrayType(type.getValue(), clazz.getDimensions());
69ffcb
+                } else if (clazz.isA(collectionType)) {
69ffcb
+                    if (nestedType == null) nestedType = "java.lang.Object";
69ffcb
+                    return org.apache.xbean.blueprint.generator.Type.newCollectionType(type.getValue(),
69ffcb
+                            org.apache.xbean.blueprint.generator.Type.newSimpleType(nestedType));
69ffcb
+                }
69ffcb
             }
69ffcb
         } catch (Throwable t) {
69ffcb
             log.debug("Could not load type mapping", t);
69ffcb
@@ -492,26 +508,28 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
         return org.apache.xbean.blueprint.generator.Type.newSimpleType(type.getValue());
69ffcb
     }
69ffcb
 
69ffcb
-    private static String toMethodLocator(JavaMethod method) {
69ffcb
+    private static String toMethodLocator(JavaClass parentClass, JavaModel methodOrConstructor) {
69ffcb
+        JavaMethod method = methodOrConstructor instanceof JavaMethod ? (JavaMethod) methodOrConstructor : null;
69ffcb
+        JavaConstructor constructor = methodOrConstructor instanceof JavaConstructor ? (JavaConstructor) methodOrConstructor : null;
69ffcb
         StringBuffer buf = new StringBuffer();
69ffcb
-        buf.append(method.getParentClass().getFullyQualifiedName());
69ffcb
-        if (!method.isConstructor()) {
69ffcb
+        buf.append(parentClass.getFullyQualifiedName());
69ffcb
+        if (method != null) {
69ffcb
             buf.append(".").append(method.getName());
69ffcb
         }
69ffcb
         buf.append("(");
69ffcb
-        JavaParameter[] parameters = method.getParameters();
69ffcb
-        for (int i = 0; i < parameters.length; i++) {
69ffcb
-            JavaParameter parameter = parameters[i];
69ffcb
+        List<JavaParameter> parameters = method != null ? method.getParameters() : constructor.getParameters();
69ffcb
+        for (int i = 0; i < parameters.size(); i++) {
69ffcb
+            JavaParameter parameter = parameters.get(i);
69ffcb
             if (i > 0) {
69ffcb
                 buf.append(", ");
69ffcb
             }
69ffcb
             buf.append(parameter.getName());
69ffcb
         }
69ffcb
-        buf.append(") : ").append(method.getLineNumber());
69ffcb
+        buf.append(") : ").append(method != null ? method.getLineNumber() : constructor.getLineNumber());
69ffcb
         return buf.toString();
69ffcb
     }
69ffcb
 
69ffcb
-    private static void getSourceFiles(File base, String[] excludedClasses, JavaDocBuilder builder) throws IOException {
69ffcb
+    private static void getSourceFiles(File base, String[] excludedClasses, JavaProjectBuilder builder) throws IOException {
69ffcb
         if (base.isDirectory()) {
69ffcb
             listAllFileNames(base, "", excludedClasses, builder);
69ffcb
         } else {
69ffcb
@@ -519,7 +537,7 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
         }
69ffcb
     }
69ffcb
 
69ffcb
-    private static void listAllFileNames(File base, String prefix, String[] excludedClasses, JavaDocBuilder builder) throws IOException {
69ffcb
+    private static void listAllFileNames(File base, String prefix, String[] excludedClasses, JavaProjectBuilder builder) throws IOException {
69ffcb
         if (!base.canRead() || !base.isDirectory()) {
69ffcb
             throw new IllegalArgumentException(base.getAbsolutePath());
69ffcb
         }
69ffcb
@@ -536,7 +554,7 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
         }
69ffcb
     }
69ffcb
 
69ffcb
-    private static void listAllJarEntries(File base, String[] excludedClasses, JavaDocBuilder builder) throws IOException {
69ffcb
+    private static void listAllJarEntries(File base, String[] excludedClasses, JavaProjectBuilder builder) throws IOException {
69ffcb
         JarFile jarFile = new JarFile(base);
69ffcb
         for (Enumeration entries = jarFile.entries(); entries.hasMoreElements(); ) {
69ffcb
             JarEntry entry = (JarEntry) entries.nextElement();
69ffcb
diff --git a/xbean-spring/src/main/java/org/apache/xbean/spring/generator/QdoxMappingLoader.java b/xbean-spring/src/main/java/org/apache/xbean/spring/generator/QdoxMappingLoader.java
69ffcb
index 94bd7a1..228117e 100644
69ffcb
--- a/xbean-spring/src/main/java/org/apache/xbean/spring/generator/QdoxMappingLoader.java
69ffcb
+++ b/xbean-spring/src/main/java/org/apache/xbean/spring/generator/QdoxMappingLoader.java
69ffcb
@@ -20,6 +20,7 @@ import java.io.File;
69ffcb
 import java.io.IOException;
69ffcb
 import java.net.URL;
69ffcb
 import java.util.ArrayList;
69ffcb
+import java.util.Collection;
69ffcb
 import java.util.Collections;
69ffcb
 import java.util.Enumeration;
69ffcb
 import java.util.HashMap;
69ffcb
@@ -31,14 +32,17 @@ import java.util.TreeSet;
69ffcb
 import java.util.jar.JarEntry;
69ffcb
 import java.util.jar.JarFile;
69ffcb
 
69ffcb
-import com.thoughtworks.qdox.JavaDocBuilder;
69ffcb
+import com.thoughtworks.qdox.JavaProjectBuilder;
69ffcb
 import com.thoughtworks.qdox.model.BeanProperty;
69ffcb
 import com.thoughtworks.qdox.model.DocletTag;
69ffcb
 import com.thoughtworks.qdox.model.JavaClass;
69ffcb
+import com.thoughtworks.qdox.model.JavaConstructor;
69ffcb
 import com.thoughtworks.qdox.model.JavaMethod;
69ffcb
+import com.thoughtworks.qdox.model.JavaModel;
69ffcb
 import com.thoughtworks.qdox.model.JavaParameter;
69ffcb
 import com.thoughtworks.qdox.model.JavaSource;
69ffcb
-import com.thoughtworks.qdox.model.Type;
69ffcb
+import com.thoughtworks.qdox.model.JavaType;
69ffcb
+
69ffcb
 import org.apache.commons.logging.Log;
69ffcb
 import org.apache.commons.logging.LogFactory;
69ffcb
 
69ffcb
@@ -62,7 +66,7 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
     private final String defaultNamespace;
69ffcb
     private final File[] srcDirs;
69ffcb
     private final String[] excludedClasses;
69ffcb
-    private Type collectionType;
69ffcb
+    private JavaClass collectionType;
69ffcb
 
69ffcb
     public QdoxMappingLoader(String defaultNamespace, File[] srcDirs, String[] excludedClasses) {
69ffcb
         this.defaultNamespace = defaultNamespace;
69ffcb
@@ -79,7 +83,7 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
     }
69ffcb
 
69ffcb
     public Set<NamespaceMapping> loadNamespaces() throws IOException {
69ffcb
-        JavaDocBuilder builder = new JavaDocBuilder();
69ffcb
+        JavaProjectBuilder builder = new JavaProjectBuilder();
69ffcb
 
69ffcb
         log.debug("Source directories: ");
69ffcb
 
69ffcb
@@ -92,11 +96,11 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
             getSourceFiles(sourceDirectory, excludedClasses, builder);
69ffcb
         }
69ffcb
 
69ffcb
-        collectionType = builder.getClassByName("java.util.Collection").asType();
69ffcb
+        collectionType = builder.getClassByName("java.util.Collection");
69ffcb
         return loadNamespaces(builder);
69ffcb
     }
69ffcb
 
69ffcb
-    private Set<NamespaceMapping> loadNamespaces(JavaDocBuilder builder) {
69ffcb
+    private Set<NamespaceMapping> loadNamespaces(JavaProjectBuilder builder) {
69ffcb
         // load all of the elements
69ffcb
         List<ElementMapping> elements = loadElements(builder);
69ffcb
 
69ffcb
@@ -131,14 +135,14 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
         return Collections.unmodifiableSet(namespaces);
69ffcb
     }
69ffcb
 
69ffcb
-    private List<ElementMapping> loadElements(JavaDocBuilder builder) {
69ffcb
-        JavaSource[] javaSources = builder.getSources();
69ffcb
+    private List<ElementMapping> loadElements(JavaProjectBuilder builder) {
69ffcb
+        Collection<JavaSource> javaSources = builder.getSources();
69ffcb
         List<ElementMapping> elements = new ArrayList<ElementMapping>();
69ffcb
         for (JavaSource javaSource : javaSources) {
69ffcb
-            if (javaSource.getClasses().length == 0) {
69ffcb
+            if (javaSource.getClasses().isEmpty()) {
69ffcb
                 log.info("No Java Classes defined in: " + javaSource.getURL());
69ffcb
             } else {
69ffcb
-                JavaClass[] classes = javaSource.getClasses();
69ffcb
+                Collection<JavaClass> classes = javaSource.getClasses();
69ffcb
                 for (JavaClass javaClass : classes) {
69ffcb
                     ElementMapping element = loadElement(builder, javaClass);
69ffcb
                     if (element != null && !javaClass.isAbstract()) {
69ffcb
@@ -152,7 +156,7 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
         return elements;
69ffcb
     }
69ffcb
 
69ffcb
-    private ElementMapping loadElement(JavaDocBuilder builder, JavaClass javaClass) {
69ffcb
+    private ElementMapping loadElement(JavaProjectBuilder builder, JavaClass javaClass) {
69ffcb
         DocletTag xbeanTag = javaClass.getTagByName(XBEAN_ANNOTATION);
69ffcb
         if (xbeanTag == null) {
69ffcb
             return null;
69ffcb
@@ -176,7 +180,7 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
         Map<String, AttributeMapping> attributesByPropertyName = new HashMap<String, AttributeMapping>();
69ffcb
 
69ffcb
         for (JavaClass jClass = javaClass; jClass != null; jClass = jClass.getSuperJavaClass()) {
69ffcb
-            BeanProperty[] beanProperties = jClass.getBeanProperties();
69ffcb
+            Collection<BeanProperty> beanProperties = jClass.getBeanProperties();
69ffcb
             for (BeanProperty beanProperty : beanProperties) {
69ffcb
                 // we only care about properties with a setter
69ffcb
                 if (beanProperty.getMutator() != null) {
69ffcb
@@ -219,9 +223,9 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
         String destroyMethod = null;
69ffcb
         String factoryMethod = null;
69ffcb
         for (JavaClass jClass = javaClass; jClass != null; jClass = jClass.getSuperJavaClass()) {
69ffcb
-            JavaMethod[] methods = javaClass.getMethods();
69ffcb
+            Collection<JavaMethod> methods = javaClass.getMethods();
69ffcb
             for (JavaMethod method : methods) {
69ffcb
-                if (method.isPublic() && !method.isConstructor()) {
69ffcb
+                if (method.isPublic()) {
69ffcb
                     if (initMethod == null && method.getTagByName(INIT_METHOD_ANNOTATION) != null) {
69ffcb
                         initMethod = method.getName();
69ffcb
                     }
69ffcb
@@ -237,27 +241,48 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
         }
69ffcb
 
69ffcb
         List<List<ParameterMapping>> constructorArgs = new ArrayList<List<ParameterMapping>>();
69ffcb
-        JavaMethod[] methods = javaClass.getMethods();
69ffcb
-        for (JavaMethod method : methods) {
69ffcb
-            JavaParameter[] parameters = method.getParameters();
69ffcb
-            if (isValidConstructor(factoryMethod, method, parameters)) {
69ffcb
-                List<ParameterMapping> args = new ArrayList<ParameterMapping>(parameters.length);
69ffcb
-                for (JavaParameter parameter : parameters) {
69ffcb
-                    AttributeMapping attributeMapping = attributesByPropertyName.get(parameter.getName());
69ffcb
-                    if (attributeMapping == null) {
69ffcb
-                        attributeMapping = loadParameter(parameter);
69ffcb
-
69ffcb
-                        attributes.add(attributeMapping);
69ffcb
-                        attributesByPropertyName.put(attributeMapping.getPropertyName(), attributeMapping);
69ffcb
+        if (factoryMethod == null) {
69ffcb
+            Collection<JavaConstructor> constructors = javaClass.getConstructors();
69ffcb
+            for (JavaConstructor constructor : constructors) {
69ffcb
+                Collection<JavaParameter> parameters = constructor.getParameters();
69ffcb
+                if (constructor.isPublic() && parameters.size() > 0) {
69ffcb
+                    List<ParameterMapping> args = new ArrayList<ParameterMapping>(parameters.size());
69ffcb
+                    for (JavaParameter parameter : parameters) {
69ffcb
+                        AttributeMapping attributeMapping = attributesByPropertyName.get(parameter.getName());
69ffcb
+                        if (attributeMapping == null) {
69ffcb
+                            attributeMapping = loadParameter(parameter, constructor);
69ffcb
+
69ffcb
+                            attributes.add(attributeMapping);
69ffcb
+                            attributesByPropertyName.put(attributeMapping.getPropertyName(), attributeMapping);
69ffcb
+                        }
69ffcb
+                        args.add(new ParameterMapping(attributeMapping.getPropertyName(), toMappingType(parameter.getType(), null)));
69ffcb
                     }
69ffcb
-                    args.add(new ParameterMapping(attributeMapping.getPropertyName(), toMappingType(parameter.getType(), null)));
69ffcb
+                    constructorArgs.add(Collections.unmodifiableList(args));
69ffcb
+                }
69ffcb
+            }
69ffcb
+        } else {
69ffcb
+            Collection<JavaMethod> methods = javaClass.getMethods();
69ffcb
+            for (JavaMethod method : methods) {
69ffcb
+                Collection<JavaParameter> parameters = method.getParameters();
69ffcb
+                if (method.isPublic() && parameters.size() > 0 && method.getName().equals(factoryMethod)) {
69ffcb
+                    List<ParameterMapping> args = new ArrayList<ParameterMapping>(parameters.size());
69ffcb
+                    for (JavaParameter parameter : parameters) {
69ffcb
+                        AttributeMapping attributeMapping = attributesByPropertyName.get(parameter.getName());
69ffcb
+                        if (attributeMapping == null) {
69ffcb
+                            attributeMapping = loadParameter(parameter, method);
69ffcb
+
69ffcb
+                            attributes.add(attributeMapping);
69ffcb
+                            attributesByPropertyName.put(attributeMapping.getPropertyName(), attributeMapping);
69ffcb
+                        }
69ffcb
+                        args.add(new ParameterMapping(attributeMapping.getPropertyName(), toMappingType(parameter.getType(), null)));
69ffcb
+                    }
69ffcb
+                    constructorArgs.add(Collections.unmodifiableList(args));
69ffcb
                 }
69ffcb
-                constructorArgs.add(Collections.unmodifiableList(args));
69ffcb
             }
69ffcb
         }
69ffcb
 
69ffcb
         HashSet<String> interfaces = new HashSet<String>();
69ffcb
-        interfaces.addAll(getFullyQualifiedNames(javaClass.getImplementedInterfaces()));
69ffcb
+        interfaces.addAll(getFullyQualifiedNames(javaClass.getInterfaces()));
69ffcb
 
69ffcb
         JavaClass actualClass = javaClass;
69ffcb
         if (factoryClass != null) {
69ffcb
@@ -282,7 +307,7 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
             }
69ffcb
             p = s;
69ffcb
             superClasses.add(p.getFullyQualifiedName());
69ffcb
-            interfaces.addAll(getFullyQualifiedNames(p.getImplementedInterfaces()));
69ffcb
+            interfaces.addAll(getFullyQualifiedNames(p.getInterfaces()));
69ffcb
         }
69ffcb
 
69ffcb
         return new ElementMapping(namespace,
69ffcb
@@ -303,7 +328,7 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
                 interfaces);
69ffcb
     }
69ffcb
 
69ffcb
-    private List<String> getFullyQualifiedNames(JavaClass[] implementedInterfaces) {
69ffcb
+    private List<String> getFullyQualifiedNames(Collection<JavaClass> implementedInterfaces) {
69ffcb
         ArrayList<String> l = new ArrayList<String>();
69ffcb
         for (JavaClass implementedInterface : implementedInterfaces) {
69ffcb
             l.add(implementedInterface.getFullyQualifiedName());
69ffcb
@@ -395,19 +420,19 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
         return defaultDescription;
69ffcb
     }
69ffcb
 
69ffcb
-    private AttributeMapping loadParameter(JavaParameter parameter) {
69ffcb
+    private AttributeMapping loadParameter(JavaParameter parameter, JavaModel methodOrConstructor) {
69ffcb
         String parameterName = parameter.getName();
69ffcb
         String parameterDescription = getParameterDescription(parameter);
69ffcb
 
69ffcb
         // first attempt to load the attribute from the java beans accessor methods
69ffcb
-        JavaClass javaClass = parameter.getParentMethod().getParentClass();
69ffcb
+        JavaClass javaClass = parameter.getDeclaringClass();
69ffcb
         BeanProperty beanProperty = javaClass.getBeanProperty(parameterName);
69ffcb
         if (beanProperty != null) {
69ffcb
             AttributeMapping attributeMapping = loadAttribute(beanProperty, parameterDescription);
69ffcb
             // if the attribute mapping is null, the property was tagged as hidden and this is an error
69ffcb
             if (attributeMapping == null) {
69ffcb
                 throw new InvalidModelException("Hidden property usage: " +
69ffcb
-                        "The construction method " + toMethodLocator(parameter.getParentMethod()) +
69ffcb
+                        "The construction method " + toMethodLocator(parameter.getDeclaringClass(), methodOrConstructor) +
69ffcb
                         " can not use a hidded property " + parameterName);
69ffcb
             }
69ffcb
             return attributeMapping;
69ffcb
@@ -426,9 +451,9 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
 
69ffcb
     private String getParameterDescription(JavaParameter parameter) {
69ffcb
         String parameterName = parameter.getName();
69ffcb
-        DocletTag[] tags = parameter.getParentMethod().getTagsByName("param");
69ffcb
+        Collection<DocletTag> tags = parameter.getTagsByName("param");
69ffcb
         for (DocletTag tag : tags) {
69ffcb
-            if (tag.getParameters()[0].equals(parameterName)) {
69ffcb
+            if (tag.getParameters().get(0).equals(parameterName)) {
69ffcb
                 String parameterDescription = tag.getValue().trim();
69ffcb
                 if (parameterDescription.startsWith(parameterName)) {
69ffcb
                     parameterDescription = parameterDescription.substring(parameterName.length()).trim();
69ffcb
@@ -439,18 +464,6 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
         return null;
69ffcb
     }
69ffcb
 
69ffcb
-    private boolean isValidConstructor(String factoryMethod, JavaMethod method, JavaParameter[] parameters) {
69ffcb
-        if (!method.isPublic() || parameters.length == 0) {
69ffcb
-            return false;
69ffcb
-        }
69ffcb
-
69ffcb
-        if (factoryMethod == null) {
69ffcb
-            return method.isConstructor();
69ffcb
-        } else {
69ffcb
-            return method.getName().equals(factoryMethod);
69ffcb
-        }
69ffcb
-    }
69ffcb
-
69ffcb
     private static String getProperty(DocletTag propertyTag, String propertyName) {
69ffcb
         return getProperty(propertyTag, propertyName, null);
69ffcb
     }
69ffcb
@@ -477,14 +490,17 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
         return false;
69ffcb
     }
69ffcb
 
69ffcb
-    private org.apache.xbean.spring.generator.Type toMappingType(Type type, String nestedType) {
69ffcb
+    private org.apache.xbean.spring.generator.Type toMappingType(JavaType type, String nestedType) {
69ffcb
         try {
69ffcb
-            if (type.isArray()) {
69ffcb
-                return org.apache.xbean.spring.generator.Type.newArrayType(type.getValue(), type.getDimensions());
69ffcb
-            } else if (type.isA(collectionType)) {
69ffcb
-                if (nestedType == null) nestedType = "java.lang.Object";
69ffcb
-                return org.apache.xbean.spring.generator.Type.newCollectionType(type.getValue(),
69ffcb
-                        org.apache.xbean.spring.generator.Type.newSimpleType(nestedType));
69ffcb
+	    if (type instanceof JavaClass) {
69ffcb
+                JavaClass clazz = (JavaClass)type;
69ffcb
+                if (clazz.isArray()) {
69ffcb
+                    return org.apache.xbean.spring.generator.Type.newArrayType(type.getValue(), clazz.getDimensions());
69ffcb
+                } else if (clazz.isA(collectionType)) {
69ffcb
+                    if (nestedType == null) nestedType = "java.lang.Object";
69ffcb
+                    return org.apache.xbean.spring.generator.Type.newCollectionType(type.getValue(),
69ffcb
+                            org.apache.xbean.spring.generator.Type.newSimpleType(nestedType));
69ffcb
+                }
69ffcb
             }
69ffcb
         } catch (Throwable t) {
69ffcb
             log.debug("Could not load type mapping", t);
69ffcb
@@ -492,26 +508,28 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
         return org.apache.xbean.spring.generator.Type.newSimpleType(type.getValue());
69ffcb
     }
69ffcb
 
69ffcb
-    private static String toMethodLocator(JavaMethod method) {
69ffcb
+    private static String toMethodLocator(JavaClass parentClass, JavaModel methodOrConstructor) {
69ffcb
+        JavaMethod method = methodOrConstructor instanceof JavaMethod ? (JavaMethod) methodOrConstructor : null;
69ffcb
+        JavaConstructor constructor = methodOrConstructor instanceof JavaConstructor ? (JavaConstructor) methodOrConstructor : null;
69ffcb
         StringBuffer buf = new StringBuffer();
69ffcb
-        buf.append(method.getParentClass().getFullyQualifiedName());
69ffcb
-        if (!method.isConstructor()) {
69ffcb
+        buf.append(parentClass.getFullyQualifiedName());
69ffcb
+        if (method != null) {
69ffcb
             buf.append(".").append(method.getName());
69ffcb
         }
69ffcb
         buf.append("(");
69ffcb
-        JavaParameter[] parameters = method.getParameters();
69ffcb
-        for (int i = 0; i < parameters.length; i++) {
69ffcb
-            JavaParameter parameter = parameters[i];
69ffcb
+        List<JavaParameter> parameters = method != null ? method.getParameters() : constructor.getParameters();
69ffcb
+        for (int i = 0; i < parameters.size(); i++) {
69ffcb
+            JavaParameter parameter = parameters.get(i);
69ffcb
             if (i > 0) {
69ffcb
                 buf.append(", ");
69ffcb
             }
69ffcb
             buf.append(parameter.getName());
69ffcb
         }
69ffcb
-        buf.append(") : ").append(method.getLineNumber());
69ffcb
+        buf.append(") : ").append(method != null ? method.getLineNumber() : constructor.getLineNumber());
69ffcb
         return buf.toString();
69ffcb
     }
69ffcb
 
69ffcb
-    private static void getSourceFiles(File base, String[] excludedClasses, JavaDocBuilder builder) throws IOException {
69ffcb
+    private static void getSourceFiles(File base, String[] excludedClasses, JavaProjectBuilder builder) throws IOException {
69ffcb
         if (base.isDirectory()) {
69ffcb
             listAllFileNames(base, "", excludedClasses, builder);
69ffcb
         } else {
69ffcb
@@ -519,7 +537,7 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
         }
69ffcb
     }
69ffcb
 
69ffcb
-    private static void listAllFileNames(File base, String prefix, String[] excludedClasses, JavaDocBuilder builder) throws IOException {
69ffcb
+    private static void listAllFileNames(File base, String prefix, String[] excludedClasses, JavaProjectBuilder builder) throws IOException {
69ffcb
         if (!base.canRead() || !base.isDirectory()) {
69ffcb
             throw new IllegalArgumentException(base.getAbsolutePath());
69ffcb
         }
69ffcb
@@ -536,7 +554,7 @@ public class QdoxMappingLoader implements MappingLoader {
69ffcb
         }
69ffcb
     }
69ffcb
 
69ffcb
-    private static void listAllJarEntries(File base, String[] excludedClasses, JavaDocBuilder builder) throws IOException {
69ffcb
+    private static void listAllJarEntries(File base, String[] excludedClasses, JavaProjectBuilder builder) throws IOException {
69ffcb
         JarFile jarFile = new JarFile(base);
69ffcb
         for (Enumeration entries = jarFile.entries(); entries.hasMoreElements(); ) {
69ffcb
             JarEntry entry = (JarEntry) entries.nextElement();
69ffcb
diff --git a/xbean-spring/src/main/java/org/apache/xbean/spring/generator/Type.java b/xbean-spring/src/main/java/org/apache/xbean/spring/generator/Type.java
69ffcb
index 5eac64c..0d9fa63 100644
69ffcb
--- a/xbean-spring/src/main/java/org/apache/xbean/spring/generator/Type.java
69ffcb
+++ b/xbean-spring/src/main/java/org/apache/xbean/spring/generator/Type.java
69ffcb
@@ -41,12 +41,7 @@ public class Type {
69ffcb
     public static Type newArrayType(String type, int dimensions) {
69ffcb
         if (type == null) throw new NullPointerException("type");
69ffcb
         if (dimensions < 1) throw new IllegalArgumentException("dimensions must be atleast one");
69ffcb
-        StringBuffer buf = new StringBuffer(type.length() + (dimensions * 2));
69ffcb
-        buf.append(type);
69ffcb
-        for (int i = 0; i < dimensions; i ++) {
69ffcb
-            buf.append("[]");
69ffcb
-        }
69ffcb
-        return new Type(buf.toString(), newSimpleType(type));
69ffcb
+        return new Type(type, newSimpleType(type.replaceAll("\\[\\]", "")));
69ffcb
     }
69ffcb
 
69ffcb
     public static Type newCollectionType(String collectionType, Type elementType) {
69ffcb
-- 
69ffcb
2.9.3
69ffcb