Author: nickarls
Date: 2009-03-18 01:53:53 -0400 (Wed, 18 Mar 2009)
New Revision: 2080
Modified:
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/NamespaceHandler.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/Schema.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/DataSetter.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/XSDHelper.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ClassModel.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/MethodModel.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/NamedModel.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/TypedModel.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/Foo.java
Log:
Some more xsd stuff
Modified: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/NamespaceHandler.java
===================================================================
---
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/NamespaceHandler.java 2009-03-18
01:38:30 UTC (rev 2079)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/NamespaceHandler.java 2009-03-18
05:53:53 UTC (rev 2080)
@@ -128,20 +128,6 @@
return lastDot < 0 ? packageName : packageName.substring(lastDot + 1);
}
- // TODO testing, remove
- public static void main(String[] params)
- {
- NamespaceHandler ng = new NamespaceHandler("com.acme.foo");
- System.out.println(ng.getShortNamespace("com.acme.foo"));
- System.out.println(ng.getShortNamespace("com.acme.foo.foo"));
- System.out.println(ng.getShortNamespace("com.acme.foo.foo.foo"));
- System.out.println(ng.getShortNamespace("java.util"));
- for (String ns : ng.getUsedNamespaces())
- {
- System.out.println(ns);
- }
- }
-
public void addPackage(String packageName)
{
if (schemaNamespaces.containsKey(packageName))
Modified:
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java
===================================================================
---
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java 2009-03-18
01:38:30 UTC (rev 2079)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java 2009-03-18
05:53:53 UTC (rev 2080)
@@ -94,9 +94,8 @@
private ClassModel inspectClass(Element element)
{
TypeElement typeElement = (TypeElement) element;
-
- ClassModel classModel = new ClassModel();
-
+ ClassModel classModel = new ClassModel(typeElement.getQualifiedName().toString());
+
// If the class has superclass's, scan them recursively
if (typeElement.getSuperclass().getKind() != TypeKind.NONE)
{
@@ -104,11 +103,8 @@
}
// Gets the parent from the cache. We know it's there since we has scanned
- // the
- // hierarchy already
- ClassModel parent =
helper.getCachedClassModel(typeElement.getSuperclass().toString());
- // Populate the class level info (name, parent etc)
- DataSetter.populateClassModel(classModel, element, parent);
+ // the hierarchy already
+
classModel.setParent(helper.getCachedClassModel(typeElement.getSuperclass().toString()));
// Filter out the fields and populate the model
for (Element field : ElementFilter.fieldsIn(element.getEnclosedElements()))
{
@@ -126,7 +122,6 @@
}
// Place the new class model in the cache
helper.cacheClassModel(classModel);
- System.out.println(classModel);
return classModel;
}
Modified: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/Schema.java
===================================================================
--- extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/Schema.java 2009-03-18
01:38:30 UTC (rev 2079)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/Schema.java 2009-03-18
05:53:53 UTC (rev 2080)
@@ -20,10 +20,10 @@
import java.util.HashSet;
import java.util.Set;
-import javax.lang.model.element.Element;
import javax.lang.model.element.PackageElement;
import org.dom4j.Document;
+import org.dom4j.DocumentFactory;
import org.jboss.webbeans.xsd.model.ClassModel;
import org.jboss.webbeans.xsd.model.TypedModel;
@@ -83,11 +83,39 @@
public void rebuild(PackageElement packageElement)
{
- System.out.println("Stuff in " + packageName);
- for (Element e : packageElement.getEnclosedElements())
+ for (String namespace : namespaceHandler.getUsedNamespaces())
{
- System.out.println(e.asType().toString());
+ document.getRootElement().addNamespace("x", namespace);
}
+ for (ClassModel classModel : classModels)
+ {
+ org.dom4j.Element classElement =
DocumentFactory.getInstance().createElement("element");
+ classElement.addAttribute("name", classModel.getSimpleName());
+ document.getRootElement().add(classElement);
+ }
+ // System.out.println("Current contents of package " + packageName);
+ // for (Element e : packageElement.getEnclosedElements())
+ // {
+ // System.out.println(e.asType().toString());
+ // }
}
+ @Override
+ public String toString()
+ {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("Package: " + packageName + "\n");
+ buffer.append("Used namespaces\n");
+ for (String namespace : namespaceHandler.getUsedNamespaces())
+ {
+ buffer.append(" " + namespace + "\n");
+ }
+ buffer.append("Contained classes:\n");
+ for (ClassModel classModel : classModels)
+ {
+ buffer.append(classModel + "\n");
+ }
+ return buffer.toString();
+ }
+
}
Modified:
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/DataSetter.java
===================================================================
---
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/DataSetter.java 2009-03-18
01:38:30 UTC (rev 2079)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/DataSetter.java 2009-03-18
05:53:53 UTC (rev 2080)
@@ -20,9 +20,7 @@
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier;
-import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
-import javax.lang.model.type.TypeKind;
import org.jboss.webbeans.xsd.model.ClassModel;
import org.jboss.webbeans.xsd.model.MethodModel;
@@ -50,20 +48,6 @@
}
/**
- * Inspects a type element and populates a class model
- *
- * @param classModel The class model to populate
- * @param element The element to inspect
- * @param parent The parent of the class
- */
- public static void populateClassModel(ClassModel classModel, Element element,
ClassModel parent)
- {
- TypeElement typeElement = (TypeElement) element;
- classModel.setName(typeElement.getQualifiedName().toString());
- classModel.setParent(parent);
- }
-
- /**
* Inspects a field element and populates a class model
*
* @param classModel The class model to populate
@@ -75,9 +59,7 @@
{
return;
}
- String name = element.getSimpleName().toString();
- NamedModel field = new NamedModel();
- field.setName(name);
+ NamedModel field = new NamedModel(element.getSimpleName().toString());
classModel.addField(field);
}
@@ -95,26 +77,16 @@
}
ExecutableElement executableElement = (ExecutableElement) element;
- String name = element.getSimpleName().toString();
-
- TypedModel returnType = new TypedModel();
- returnType.setType(executableElement.getReturnType().toString());
- returnType.setPrimitive(executableElement.getReturnType().getKind().isPrimitive()
|| executableElement.getReturnType().getKind() == TypeKind.VOID);
-
- MethodModel method = new MethodModel();
- method.setName(name);
-
+ MethodModel method = new MethodModel(element.getSimpleName().toString());
+
for (VariableElement parameterElement : executableElement.getParameters())
{
- String paramType = parameterElement.asType().toString();
- boolean paramPrimitive = parameterElement.asType().getKind().isPrimitive();
- TypedModel parameter = new TypedModel();
- parameter.setType(paramType);
- parameter.setPrimitive(paramPrimitive);
+ boolean primitive = parameterElement.asType().getKind().isPrimitive();
+ TypedModel parameter = new TypedModel(parameterElement.asType().toString(),
primitive);
method.addParameter(parameter);
}
// OK, cheating a little with a common model for methods and constructors
- if ("<init>".equals(name))
+ if ("<init>".equals(method.getName()))
{
classModel.addConstructor(method);
}
@@ -123,5 +95,5 @@
classModel.addMethod(method);
}
}
-
+
}
Modified:
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/XSDHelper.java
===================================================================
---
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/XSDHelper.java 2009-03-18
01:38:30 UTC (rev 2079)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/XSDHelper.java 2009-03-18
05:53:53 UTC (rev 2080)
@@ -30,7 +30,10 @@
import org.dom4j.Document;
import org.dom4j.DocumentException;
+import org.dom4j.DocumentFactory;
import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+import org.dom4j.QName;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
@@ -74,9 +77,17 @@
{
Schema schema = new Schema(packageName);
Document document = readSchema(packageName);
- if (document == null) {
+ if (document == null)
+ {
document = DocumentHelper.createDocument();
- document.addElement("schema");
+ QName rootQName = DocumentFactory.getInstance().createQName("schema",
"xs", "http://www.w3.org/2001/XMLSchema");
+ Element rootElement = DocumentFactory.getInstance().createElement(rootQName);
+ rootElement.addAttribute("elementFormDefault",
"qualified");
+ rootElement.addAttribute("targetNamespace", "urn:java:" +
packageName);
+ rootElement.addAttribute("elementFormDefault",
"qualified");
+ rootElement.addNamespace("xsi",
"http://www.w3.org/2001/XMLSchema-instance");
+ rootElement.addAttribute("xsi:schemaLocation",
"http://www.w3.org/2001/XMLSchema
http://www.w3.org/2001/XMLSchema.xsd");
+ document.setRootElement(rootElement);
}
schema.setDocument(document);
return schema;
@@ -165,14 +176,15 @@
/**
* Writes the schemas back to disk
- * @param packageModels
+ *
+ * @param packageModels
*/
public void writeSchemas(Map<String, PackageElement> packageModels)
{
for (Schema schema : schemaMap.values())
{
schema.rebuild(packageModels.get(schema.getPackageName()));
- System.out.println(schema.getPackageName() + " (" +
schema.getNamespaces() + ")");
+ System.out.println(schema.getDocument().asXML());
try
{
writeSchema(schema);
Modified: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ClassModel.java
===================================================================
---
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ClassModel.java 2009-03-18
01:38:30 UTC (rev 2079)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ClassModel.java 2009-03-18
05:53:53 UTC (rev 2080)
@@ -40,6 +40,11 @@
// The constructors of the class
private List<MethodModel> constructors = new ArrayList<MethodModel>();
+ public ClassModel(String name)
+ {
+ super(name);
+ }
+
/**
* Adds a field to the class model
*
Modified:
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/MethodModel.java
===================================================================
---
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/MethodModel.java 2009-03-18
01:38:30 UTC (rev 2079)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/MethodModel.java 2009-03-18
05:53:53 UTC (rev 2080)
@@ -24,12 +24,17 @@
* The model of a method
*
* @author Nicklas Karlsson
- *
+ *
*/
public class MethodModel extends NamedModel
{
private List<TypedModel> parameters = new ArrayList<TypedModel>();
+ public MethodModel(String name)
+ {
+ super(name);
+ }
+
public List<TypedModel> getParameters()
{
return parameters;
@@ -52,7 +57,7 @@
{
return name.hashCode() + parameters.hashCode();
}
-
+
@Override
public String toString()
{
Modified: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/NamedModel.java
===================================================================
---
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/NamedModel.java 2009-03-18
01:38:30 UTC (rev 2079)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/NamedModel.java 2009-03-18
05:53:53 UTC (rev 2080)
@@ -27,14 +27,14 @@
{
protected String name;
- public String getName()
+ public NamedModel(String name)
{
- return name;
+ this.name = name;
}
- public void setName(String name)
+ public String getName()
{
- this.name = name;
+ return name;
}
@Override
Modified: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/TypedModel.java
===================================================================
---
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/TypedModel.java 2009-03-18
01:38:30 UTC (rev 2079)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/TypedModel.java 2009-03-18
05:53:53 UTC (rev 2080)
@@ -28,6 +28,12 @@
protected String type;
protected boolean primitive;
+ public TypedModel(String type, boolean primitive)
+ {
+ this.type = type;
+ this.primitive = primitive;
+ }
+
public String getType()
{
return type;
Modified: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/Foo.java
===================================================================
--- extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/Foo.java 2009-03-18
01:38:30 UTC (rev 2079)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/Foo.java 2009-03-18
05:53:53 UTC (rev 2080)
@@ -13,6 +13,7 @@
public int poo;
public Bar bar;
public org.jboss.webbeans.xsd.test.test.Foo foo2;
+ public org.jboss.webbeans.xsd.test.test.test.Tar tar2;
public Tar tar;
@Initializer
@@ -26,7 +27,7 @@
return foo;
}
- public void testy() {
+ public void testy(org.jboss.webbeans.xsd.test.test.Foo a,
org.jboss.webbeans.xsd.test.test.test.Tar b) {
}