Author: nickarls
Date: 2009-03-17 05:24:27 -0400 (Tue, 17 Mar 2009)
New Revision: 2063
Added:
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/test/test/
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/test/test/Tar.java
Modified:
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/NamespaceHandler.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/test/Foo.java
Log:
xsd: minor refactorings
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-17
08:51:29 UTC (rev 2062)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/NamespaceHandler.java 2009-03-17
09:24:27 UTC (rev 2063)
@@ -50,6 +50,7 @@
public NamespaceHandler(String localPackage)
{
this.localPackage = localPackage;
+ addPackage(localPackage);
}
/**
@@ -109,6 +110,44 @@
{
return schemaNamespaces.get(packageName).shortNamespace;
}
+ else
+ {
+ throw new IllegalArgumentException("Package name " + packageName +
" is not known to namespace handler of package " + localPackage);
+ }
+ }
+
+ /**
+ * Gets the short name (last part) of a package
+ *
+ * @param packageName The package name to parse
+ * @return The short name
+ */
+ private String getShortName(String packageName)
+ {
+ int lastDot = packageName.lastIndexOf(".");
+ 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))
+ {
+ return;
+ }
String shortNamespace = "";
boolean ee = false;
if (localPackage.equals(packageName))
@@ -138,33 +177,6 @@
shortNamespace = getShortName(packageName) + countString;
}
schemaNamespaces.put(packageName, new SchemaNamespace(packageName, shortNamespace,
ee));
- return shortNamespace;
}
- /**
- * Gets the short name (last part) of a package
- *
- * @param packageName The package name to parse
- * @return The short name
- */
- private String getShortName(String packageName)
- {
- int lastDot = packageName.lastIndexOf(".");
- 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);
- }
- }
-
}
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
08:51:29 UTC (rev 2062)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/Schema.java 2009-03-17
09:24:27 UTC (rev 2063)
@@ -17,9 +17,6 @@
package org.jboss.webbeans.xsd;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
import java.util.Set;
import org.dom4j.Document;
@@ -33,15 +30,13 @@
*/
public class Schema
{
- private Document document;
private String packageName;
- private Map<String, Set<String>> typeReferences;
+ private Document document;
private NamespaceHandler namespaceHandler;
public Schema(String packageName)
{
this.packageName = packageName;
- typeReferences = new HashMap<String, Set<String>>();
namespaceHandler = new NamespaceHandler(packageName);
}
@@ -49,13 +44,10 @@
{
for (TypedModel reference : references)
{
- Set<String> typeNames = typeReferences.get(reference.getTypePackage());
- if (typeNames == null)
+ if (!reference.isPrimitive())
{
- typeNames = new HashSet<String>();
- typeReferences.put(reference.getTypePackage(), typeNames);
+ namespaceHandler.addPackage(reference.getTypePackage());
}
- typeNames.add(reference.getType());
}
}
@@ -79,23 +71,6 @@
this.packageName = packageName;
}
- public Map<String, Set<String>> getTypeReferences()
- {
- return typeReferences;
- }
-
- // TODO: dummy, remove
- public void refreshNamespaces()
- {
- for (String p : typeReferences.keySet())
- {
- if (!"".equals(p))
- {
- String dummy = namespaceHandler.getShortNamespace(p);
- }
- }
- }
-
public Set<String> getNamespaces()
{
return namespaceHandler.getUsedNamespaces();
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
08:51:29 UTC (rev 2062)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/helpers/XSDHelper.java 2009-03-17
09:24:27 UTC (rev 2063)
@@ -204,10 +204,7 @@
{
for (Schema schema : schemaMap.values())
{
- // TODO: dummy, remove
- schema.refreshNamespaces();
System.out.println(schema.getPackageName() + " (" +
schema.getNamespaces() + ")");
- System.out.println(schema.getTypeReferences());
writePackageInfo(schema);
}
}
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-17
08:51:29 UTC (rev 2062)
+++ extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/Foo.java 2009-03-17
09:24:27 UTC (rev 2063)
@@ -3,6 +3,8 @@
import javax.inject.Current;
import javax.inject.Initializer;
+import org.jboss.webbeans.xsd.test.test.test.Tar;
+
@Current
public class Foo
{
@@ -10,6 +12,8 @@
public String foo;
public int poo;
public Bar bar;
+ public org.jboss.webbeans.xsd.test.test.Foo foo2;
+ public Tar tar;
@Initializer
public Foo(String foo)
Added: extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/test/test/Tar.java
===================================================================
--- extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/test/test/Tar.java
(rev 0)
+++
extensions/trunk/xsd/src/main/java/org/jboss/webbeans/xsd/test/test/test/Tar.java 2009-03-17
09:24:27 UTC (rev 2063)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.xsd.test.test.test;
+
+public class Tar
+{
+
+}
Show replies by date