Author: nickarls
Date: 2009-03-18 08:29:51 -0400 (Wed, 18 Mar 2009)
New Revision: 2090
Modified:
extensions/trunk/xsd/pom.xml
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/NamedModel.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/TypedModel.java
Log:
some xsd stuff
Modified: extensions/trunk/xsd/pom.xml
===================================================================
--- extensions/trunk/xsd/pom.xml 2009-03-18 11:16:03 UTC (rev 2089)
+++ extensions/trunk/xsd/pom.xml 2009-03-18 12:29:51 UTC (rev 2090)
@@ -34,7 +34,13 @@
<artifactId>log4j</artifactId>
</dependency>
+<!--
<dependency>
+ <groupId>jaxen</groupId>
+ <artifactId>jaxen</artifactId>
+ </dependency>
+-->
+ <dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
</dependency>
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
11:16:03 UTC (rev 2089)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/Schema.java 2009-03-18
12:29:51 UTC (rev 2090)
@@ -21,9 +21,10 @@
import java.util.Set;
import javax.lang.model.element.PackageElement;
+import javax.lang.model.element.TypeElement;
import org.dom4j.Document;
-import org.dom4j.DocumentFactory;
+import org.dom4j.Element;
import org.jboss.webbeans.xsd.NamespaceHandler.SchemaNamespace;
import org.jboss.webbeans.xsd.model.ClassModel;
import org.jboss.webbeans.xsd.model.TypedModel;
@@ -48,6 +49,11 @@
classModels = new HashSet<ClassModel>();
}
+ public String getPackageName()
+ {
+ return packageName;
+ }
+
public void addClass(ClassModel classModel)
{
classModels.add(classModel);
@@ -67,31 +73,55 @@
this.document = document;
}
- public String getPackageName()
+ private boolean isClassInPackage(PackageElement packageElement, String FQN)
{
- return packageName;
+ for (javax.lang.model.element.Element classElement :
packageElement.getEnclosedElements())
+ {
+ TypeElement typeElement = (TypeElement) classElement;
+ if (typeElement.getQualifiedName().toString().equals(FQN))
+ {
+ return true;
+ }
+ }
+ return false;
}
- public void setPackageName(String packageName)
- {
- this.packageName = packageName;
- }
-
-// public Set<String> getNamespaces()
-// {
-// return namespaceHandler.getUsedNamespaces();
-// }
-
public void rebuild(PackageElement packageElement)
{
for (SchemaNamespace schemaNamespace :
namespaceHandler.getSchemaNamespaces().values())
{
document.getRootElement().addNamespace(schemaNamespace.shortNamespace,
schemaNamespace.urn);
}
+
+ for (Object xsdClass : document.selectNodes("//xs:schema//xs:element"))
+ {
+ String className = ((Element) xsdClass).attributeValue("name");
+ if (!isClassInPackage(packageElement, packageName + "." + className))
+ {
+ ((Element) xsdClass).detach();
+ }
+ }
+
for (ClassModel classModel : classModels)
{
+ // Remove old version of class xsd (if present)
+ for (Object previousClass :
document.selectNodes("//xs:schema//xs:element[@name=\"" +
classModel.getSimpleName() + "\"]"))
+ {
+ ((Element) previousClass).detach();
+ }
document.getRootElement().add(classModel.toXSD(namespaceHandler));
}
+
+ /**
+ * XSD: Foo Bar Tar
+ *
+ * ClassModels: Foo
+ *
+ * Package: Foo Bar
+ *
+ * => update Foo, remove Tar
+ */
+
// System.out.println("Current contents of package " + packageName);
// for (Element e : packageElement.getEnclosedElements())
// {
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
11:16:03 UTC (rev 2089)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/DataSetter.java 2009-03-18
12:29:51 UTC (rev 2090)
@@ -88,6 +88,7 @@
// OK, cheating a little with a common model for methods and constructors
if ("<init>".equals(method.getName()))
{
+ method.setName(classModel.getSimpleName());
classModel.addConstructor(method);
}
else
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
11:16:03 UTC (rev 2089)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/XSDHelper.java 2009-03-18
12:29:51 UTC (rev 2090)
@@ -187,10 +187,7 @@
System.out.println(schema.getDocument().asXML());
try
{
- if (1 == 2)
- {
- writeSchema(schema);
- }
+ writeSchema(schema);
}
catch (IOException e)
{
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
11:16:03 UTC (rev 2089)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ClassModel.java 2009-03-18
12:29:51 UTC (rev 2090)
@@ -235,21 +235,26 @@
return new ClassModel(typeElement.getQualifiedName().toString());
}
+ @Override
public Element toXSD(NamespaceHandler namespaceHandler)
{
- Element classElement =
DocumentFactory.getInstance().createElement("element");
+ Element classElement =
DocumentFactory.getInstance().createElement("xs:element");
classElement.addAttribute("name", getSimpleName());
+ Element complexElement =
DocumentFactory.getInstance().createElement("xs:complexType");
+ Element anyElement =
DocumentFactory.getInstance().createElement("xs:any");
+ complexElement.add(anyElement);
+ classElement.add(complexElement);
for (MethodModel constructor : getMergedConstructors())
{
- classElement.add(constructor.toXSD(namespaceHandler));
+ anyElement.add(constructor.toXSD(namespaceHandler));
}
for (NamedModel field : getMergedFields())
{
- classElement.add(field.toXSD(namespaceHandler));
+ anyElement.add(field.toXSD(namespaceHandler));
}
for (MethodModel method : getMergedMethods())
{
- classElement.add(method.toXSD(namespaceHandler));
+ anyElement.add(method.toXSD(namespaceHandler));
}
return classElement;
}
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
11:16:03 UTC (rev 2089)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/NamedModel.java 2009-03-18
12:29:51 UTC (rev 2090)
@@ -41,6 +41,11 @@
return name;
}
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
@Override
public String toString()
{
@@ -62,7 +67,7 @@
public Element toXSD(NamespaceHandler namespaceHandler)
{
- Element item = DocumentFactory.getInstance().createElement("element");
+ Element item =
DocumentFactory.getInstance().createElement("xs:element");
item.addAttribute("name", name);
return item;
}
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
11:16:03 UTC (rev 2089)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/TypedModel.java 2009-03-18
12:29:51 UTC (rev 2090)
@@ -94,9 +94,9 @@
public Element toXSD(NamespaceHandler namespaceHandler)
{
- String namespace = isPrimitive() ? "" :
namespaceHandler.getShortNamespace(type);
- Element item = DocumentFactory.getInstance().createElement("element");
- item.addAttribute("type", type);
+ String namespace = isPrimitive() ? ("xs:" + type) :
(namespaceHandler.getShortNamespace(type) + ":" + getTypeSimpleName());
+ Element item =
DocumentFactory.getInstance().createElement("xs:element");
+ item.addAttribute("type", namespace);
return item;
}
Show replies by date