Author: nickarls
Date: 2009-03-16 18:43:16 -0400 (Mon, 16 Mar 2009)
New Revision: 2056
Added:
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/NamespaceGenerator.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/test/
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/test/Foo.java
Modified:
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageInfo.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/XSDHelper.java
Log:
Namespace stuff
Modified: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageInfo.java
===================================================================
--- extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageInfo.java 2009-03-16
22:20:41 UTC (rev 2055)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageInfo.java 2009-03-16
22:43:16 UTC (rev 2056)
@@ -15,6 +15,7 @@
private Document schema;
private String packageName;
private Map<String, Set<String>> typeReferences;
+ private String namespace;
public PackageInfo(String packageName)
{
@@ -26,8 +27,7 @@
{
for (TypedModel reference : references)
{
- String key = reference.isPrimitive() ? "" :
reference.getTypePackage();
- Set<String> typeNames = typeReferences.get(key);
+ Set<String> typeNames = typeReferences.get(reference.getTypePackage());
if (typeNames == null)
{
typeNames = new HashSet<String>();
@@ -71,4 +71,14 @@
{
return typeReferences;
}
+
+ public String getNamespace()
+ {
+ return namespace;
+ }
+
+ public void setNamespace(String namespace)
+ {
+ this.namespace = namespace;
+ }
}
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-16
22:20:41 UTC (rev 2055)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/PackageSchemaGenerator.java 2009-03-16
22:43:16 UTC (rev 2056)
@@ -120,7 +120,6 @@
}
// Place the new class model in the cache
helper.cacheClassModel(classModel);
- System.out.println(classModel);
return classModel;
}
Added:
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/NamespaceGenerator.java
===================================================================
---
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/NamespaceGenerator.java
(rev 0)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/NamespaceGenerator.java 2009-03-16
22:43:16 UTC (rev 2056)
@@ -0,0 +1,48 @@
+package org.jboss.webbeans.xsd.helpers;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+public class NamespaceGenerator
+{
+ private static final Set<String> URN_JAVA_EE = new
HashSet<String>(Arrays.asList("java.lang", "java.util",
"javax.annotation", "javax.inject", "javax.context",
"javax.interceptor", "javax.decorator", "javax.event",
"javax.ejb", "javax.persistence", "javax.xml.ws",
"javax.jms", "javax.sql"));
+
+ public Map<String, Integer> counters = new HashMap<String, Integer>();
+
+ public String getNamespace(String packageName)
+ {
+ String shortName = getShortName(packageName);
+ if (URN_JAVA_EE.contains(getBasePackage(packageName)))
+ {
+ return "xmlns=\"urn:java:ee\"";
+ }
+ Integer count = counters.get(shortName);
+ String countString = "";
+ if (count == null)
+ {
+ count = new Integer(1);
+ counters.put(shortName, count);
+ }
+ else
+ {
+ count++;
+ countString = String.valueOf(count);
+ }
+ return "xmlns:" + shortName + countString + "=\"java:urn:"
+ packageName + "\"";
+ }
+
+ private String getBasePackage(String packageName)
+ {
+ return packageName.substring(0, getShortName(packageName).length());
+ }
+
+ private String getShortName(String packageName)
+ {
+ int lastDot = packageName.lastIndexOf(".");
+ return lastDot < 0 ? packageName : packageName.substring(lastDot + 1);
+ }
+
+}
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-16
22:20:41 UTC (rev 2055)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/XSDHelper.java 2009-03-16
22:43:16 UTC (rev 2056)
@@ -50,7 +50,6 @@
*/
public class XSDHelper
{
- public static final Set<String> URN_JAVA_EE = new
HashSet<String>(Arrays.asList("java.lang", "java.util",
"javax.annotation", "javax.inject", "javax.context",
"javax.interceptor", "javax.decorator", "javax.event",
"javax.ejb", "javax.persistence", "javax.xml.ws",
"javax.jms", "javax.sql"));
// The filed of the annotation processing environment
private Filer filer;
@@ -58,6 +57,7 @@
private Map<String, ClassModel> classModelCache = new HashMap<String,
ClassModel>();
// The XSD documents of the affected packages
private Map<String, PackageInfo> packageInfoMap = new HashMap<String,
PackageInfo>();
+ private NamespaceGenerator namespaceGenerator = new NamespaceGenerator();
/**
* Creates a new helper
@@ -72,7 +72,7 @@
/**
* Reads package info
*
- * @param packageName The package name
+ * @param packageName The package name
* @return The package info of the package
* @throws DocumentException If the schema could not be parsed
* @throws IOException If the schema could not be read
@@ -174,7 +174,7 @@
*
* @param packageName The package name
* @param schema The schema
- * @throws IOException If the file could not be written
+ * @throws IOException If the file could not be written
*/
private void writeSchema(String packageName, Document schema) throws IOException
{
@@ -208,7 +208,8 @@
{
String packageName = classModel.getPackage();
PackageInfo packageInfo = packageInfoMap.get(packageName);
- if (packageInfo == null) {
+ if (packageInfo == null)
+ {
try
{
packageInfo = readPackageInfo(packageName);
@@ -224,10 +225,6 @@
packageInfoMap.put(packageName, packageInfo);
}
updateClassInSchema(classModel, packageInfo);
- System.out.println("-------------");
- for (Entry<String, Set<String>> e :
packageInfo.getTypeReferences().entrySet()) {
- System.out.println(e.getKey() + "=>" + e.getValue());
- }
}
}
@@ -236,7 +233,11 @@
*/
public void writeSchemas()
{
- for (PackageInfo packageInfo : packageInfoMap.values()) {
+ for (PackageInfo packageInfo : packageInfoMap.values())
+ {
+
packageInfo.setNamespace(namespaceGenerator.getNamespace(packageInfo.getPackageName()));
+ System.out.println(packageInfo.getPackageName() + " (" +
packageInfo.getNamespace() + ")");
+ System.out.println(packageInfo.getTypeReferences());
writePackageInfo(packageInfo);
}
}
@@ -262,18 +263,6 @@
}
/**
- * Gets the short name of a package (the last part)
- *
- * @param packageName The package name
- * @return A short name
- */
- private String getShortName(String packageName)
- {
- int lastDot = packageName.lastIndexOf(".");
- return lastDot < 0 ? packageName : packageName.substring(lastDot + 1);
- }
-
- /**
* Gets a cached class model
*
* @param FQN The FQN of the class
Added: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/test/Foo.java
===================================================================
--- extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/test/Foo.java
(rev 0)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/test/Foo.java 2009-03-16
22:43:16 UTC (rev 2056)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.xsd.test.test;
+
+public class Foo
+{
+
+}