[webbeans-commits] Webbeans SVN: r2064 - in extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd: helpers and 1 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Tue Mar 17 07:33:34 EDT 2009


Author: nickarls
Date: 2009-03-17 07:33:34 -0400 (Tue, 17 Mar 2009)
New Revision: 2064

Modified:
   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/XSDHelper.java
   extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ClassModel.java
Log:
some more xsd stuff

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-17 09:24:27 UTC (rev 2063)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java	2009-03-17 11:33:34 UTC (rev 2064)
@@ -18,7 +18,9 @@
 package org.jboss.webbeans.xsd;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import javax.annotation.processing.AbstractProcessor;
@@ -28,10 +30,12 @@
 import javax.annotation.processing.SupportedSourceVersion;
 import javax.lang.model.SourceVersion;
 import javax.lang.model.element.Element;
+import javax.lang.model.element.PackageElement;
 import javax.lang.model.element.TypeElement;
 import javax.lang.model.type.DeclaredType;
 import javax.lang.model.type.TypeKind;
 import javax.lang.model.util.ElementFilter;
+import javax.lang.model.util.Elements;
 
 import org.jboss.webbeans.xsd.helpers.DataSetter;
 import org.jboss.webbeans.xsd.helpers.XSDHelper;
@@ -52,29 +56,32 @@
    XSDHelper helper;
 
    @Override
-   public synchronized void init(ProcessingEnvironment processingEnv)
+   public synchronized void init(ProcessingEnvironment processingEnvironment)
    {
-      super.init(processingEnv);
-      helper = new XSDHelper(processingEnv.getFiler());
+      super.init(processingEnvironment);
+      helper = new XSDHelper(processingEnvironment);
    }
 
    @Override
-   public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv)
+   public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnvironment)
    {
+      Map<String, PackageElement> packageModels = new HashMap<String, PackageElement>();
       List<ClassModel> workingSet = new ArrayList<ClassModel>();
+
       // Iterates over the classes compiled, creates a model of the classes and
       // add them to a working set
-
-      for (Element element : roundEnv.getRootElements())
+      for (Element element : roundEnvironment.getRootElements())
       {
-         workingSet.add(inspectClass(element));
+         ClassModel classModel = inspectClass(element);
+         workingSet.add(classModel);
+         packageModels.put(classModel.getPackage(), processingEnv.getElementUtils().getPackageOf(element));
       }
-      if (!roundEnv.processingOver())
+      if (!roundEnvironment.processingOver())
       {
          // Update the package XSDs for the files changed
          helper.updateSchemas(workingSet);
          // And flush the changes to disk
-         helper.writeSchemas();
+         helper.writeSchemas(packageModels);
       }
       return false;
    }

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-17 09:24:27 UTC (rev 2063)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/Schema.java	2009-03-17 11:33:34 UTC (rev 2064)
@@ -17,9 +17,14 @@
 
 package org.jboss.webbeans.xsd;
 
+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.jboss.webbeans.xsd.model.ClassModel;
 import org.jboss.webbeans.xsd.model.TypedModel;
 
 /**
@@ -33,21 +38,21 @@
    private String packageName;
    private Document document;
    private NamespaceHandler namespaceHandler;
+   private Set<ClassModel> classModels;
 
    public Schema(String packageName)
    {
       this.packageName = packageName;
       namespaceHandler = new NamespaceHandler(packageName);
+      classModels = new HashSet<ClassModel>();
    }
 
-   public void addTypeReferences(Set<TypedModel> references)
+   public void addClass(ClassModel classModel)
    {
-      for (TypedModel reference : references)
+      classModels.add(classModel);
+      for (TypedModel reference : classModel.getTypeReferences())
       {
-         if (!reference.isPrimitive())
-         {
-            namespaceHandler.addPackage(reference.getTypePackage());
-         }
+         namespaceHandler.addPackage(reference.getTypePackage());
       }
    }
 
@@ -76,4 +81,13 @@
       return namespaceHandler.getUsedNamespaces();
    }
 
+   public void rebuild(PackageElement packageElement)
+   {
+      System.out.println("Stuff in " + packageName);
+      for (Element e : packageElement.getEnclosedElements())
+      {
+         System.out.println(e.asType().toString());
+      }
+   }
+
 }

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-17 09:24:27 UTC (rev 2063)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/XSDHelper.java	2009-03-17 11:33:34 UTC (rev 2064)
@@ -25,6 +25,8 @@
 import java.util.Map;
 
 import javax.annotation.processing.Filer;
+import javax.annotation.processing.ProcessingEnvironment;
+import javax.lang.model.element.PackageElement;
 import javax.tools.StandardLocation;
 
 import org.dom4j.Document;
@@ -46,8 +48,8 @@
 public class XSDHelper
 {
 
-   // The filed of the annotation processing environment
-   private Filer filer;
+   // The annotation processing environment
+   private ProcessingEnvironment processingEnvironment;
    // The cache of already processed classes
    private Map<String, ClassModel> classModelCache = new HashMap<String, ClassModel>();
    // The XSD documents of the affected packages
@@ -58,9 +60,9 @@
     * 
     * @param filer The filer of the processing environment
     */
-   public XSDHelper(Filer filer)
+   public XSDHelper(ProcessingEnvironment processingEnvironment)
    {
-      this.filer = filer;
+      this.processingEnvironment = processingEnvironment;
    }
 
    /**
@@ -105,7 +107,7 @@
       InputStream in = null;
       try
       {
-         in = filer.getResource(StandardLocation.CLASS_OUTPUT, packageName, "schema.xsd").openInputStream();
+         in = processingEnvironment.getFiler().getResource(StandardLocation.CLASS_OUTPUT, packageName, "schema.xsd").openInputStream();
          return new SAXReader().read(in);
       }
       catch (IOException e)
@@ -151,7 +153,7 @@
       try
       {
          OutputFormat format = OutputFormat.createPrettyPrint();
-         out = filer.createResource(StandardLocation.CLASS_OUTPUT, packageName, "schema.xsd").openOutputStream();
+         out = processingEnvironment.getFiler().createResource(StandardLocation.CLASS_OUTPUT, packageName, "schema.xsd").openOutputStream();
          XMLWriter writer = new XMLWriter(out, format);
          writer.write(schema);
          writer.flush();
@@ -193,43 +195,25 @@
             }
             schemaMap.put(packageName, schema);
          }
-         updateClassInSchema(classModel, schema);
+         schema.addClass(classModel);
       }
    }
 
    /**
     * Writes the schemas back to disk
+    * @param packageModels 
     */
-   public void writeSchemas()
+   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() + ")");
          writePackageInfo(schema);
       }
    }
 
    /**
-    * Updates a schema with XSD from a file model
-    * 
-    * @param schema The schema
-    * @param classModel The class model
-    */
-   private void updateClassInSchema(ClassModel classModel, Schema schema)
-   {
-      Document document = schema.getDocument();
-      Node oldClassModel = document.selectSingleNode("//" + classModel.getSimpleName());
-      if (oldClassModel != null)
-      {
-         // Remove the old class definition
-         document.getRootElement().remove(oldClassModel);
-      }
-      // Create a new one
-      document.getRootElement().addElement(classModel.getSimpleName());
-      schema.addTypeReferences(classModel.getTypeReferences());
-   }
-
-   /**
     * Gets a cached class model
     * 
     * @param FQN The FQN of the class

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-17 09:24:27 UTC (rev 2063)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/model/ClassModel.java	2009-03-17 11:33:34 UTC (rev 2064)
@@ -165,21 +165,34 @@
       Set<TypedModel> typeReferences = new HashSet<TypedModel>();
       for (FieldModel field : getMergedFields())
       {
-         typeReferences.add(field);
+         if (!field.isPrimitive())
+         {
+            typeReferences.add(field);
+         }
       }
       for (MethodModel method : getMergedMethods())
       {
-         typeReferences.add(method.getReturnType());
+         TypedModel returnValue = method.getReturnType();
+         if (!returnValue.isPrimitive())
+         {
+            typeReferences.add(returnValue);
+         }
          for (ParameterModel parameter : method.getParameters())
          {
-            typeReferences.add(parameter);
+            if (!parameter.isPrimitive())
+            {
+               typeReferences.add(parameter);
+            }
          }
       }
       for (MethodModel constructor : getMergedConstructors())
       {
          for (ParameterModel parameter : constructor.getParameters())
          {
-            typeReferences.add(parameter);
+            if (!parameter.isPrimitive())
+            {
+               typeReferences.add(parameter);
+            }
          }
       }
       return typeReferences;




More information about the weld-commits mailing list