Index: build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/SchemaGenerator.java =================================================================== --- build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/SchemaGenerator.java (revision 34844) +++ build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/SchemaGenerator.java (working copy) @@ -126,6 +126,12 @@ boolean printRecursionPaths = false; /** + * Bindings of XSD type names to class names. If defined, the generated schema will + * bind these complex types as if they were non-complex, bound the named classes. + */ + private Map typeBindings; + + /** * Logger */ Logger logger = org.geotools.util.logging.Logging.getLogger("org.geotools.xml"); @@ -239,6 +245,42 @@ } /** + * Add the explicit bindings of XSD types to fully-qualified class names. + * If a type has a binding, it will be treated as non-complex and bound to + * the named class. + * + * @param typeBindings + */ + public void setTypeBindings(TypeBinding[] typeBindings) { + Map bindings = new HashMap(); + if (typeBindings != null) { + for (TypeBinding typeBinding : typeBindings) { + String namespace = typeBinding.getNamespace(); + if (namespace == null) { + namespace = schema.getTargetNamespace(); + } + String name = typeBinding.getName(); + if (name == null) { + throw new IllegalArgumentException("Missing name for typeBinding"); + } + String binding = typeBinding.getBinding(); + if (binding == null) { + throw new IllegalArgumentException("Missing binding for typeBinding for " + name); + } + bindings.put(new NameImpl(namespace, name), binding); + } + } + this.typeBindings = bindings; + } + + /** + * @return the map of XSD type names to fully-qualified class names. + */ + public Map getTypeBindings() { + return typeBindings; + } + + /** * Adds an imported schema to be used for type lookups. */ public void addImport(Schema imported) { @@ -652,4 +694,5 @@ generator.generate(); } + } Index: build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/SchemaGeneratorMojo.java =================================================================== --- build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/SchemaGeneratorMojo.java (revision 34844) +++ build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/SchemaGeneratorMojo.java (working copy) @@ -60,6 +60,12 @@ * @parameter */ int maxRecursionDepth; + /** + * List of explicit bindings from XSD type to fully-qualified class name. + * Namespace defaults to the target schema namespace. + * @parameter + */ + private TypeBinding[] typeBindings; public void execute() throws MojoExecutionException, MojoFailureException { XSDSchema schema = schema(); @@ -79,6 +85,7 @@ generator.setIncludes( includes ); generator.setMaxRecursionDepth(maxRecursionDepth); generator.setPrintRecursionPaths(printRecursionPaths); + generator.setTypeBindings(typeBindings); if (imports != null) { //build a url classload from dependencies Index: build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/TypeBinding.java =================================================================== --- build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/TypeBinding.java (revision 0) +++ build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/TypeBinding.java (revision 0) @@ -0,0 +1,56 @@ +/* + * GeoTools - The Open Source Java GIS Tookit + * http://geotools.org + * + * (C) 2002-2010, Open Source Geospatial Foundation (OSGeo) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ + +package org.geotools.maven.xmlcodegen; + +/** + * Data transfer object for explicit bindings of XSD types to classes. Properties will be set by Maven using reflection. + * + * @author Ben Caradoc-Davies, CSIRO Earth Science and Resource Engineering + * + */ +public class TypeBinding { + + private String namespace; + + private String name; + + private String binding; + + /** + * @return XSD type namespace + */ + public String getNamespace() { + return namespace; + } + + /** + * @return XSD type local name + */ + public String getName() { + return name; + } + + /** + * @return fully-qualified binding class name, for example "com.vividsolutions.jts.geom.Point" + */ + public String getBinding() { + return binding; + } + + +} Property changes on: build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/TypeBinding.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Id URL Added: svn:eol-style + native Index: build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/templates/BindingTestClass.java =================================================================== --- build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/templates/BindingTestClass.java (revision 34844) +++ build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/templates/BindingTestClass.java (working copy) @@ -18,7 +18,7 @@ return result; } - protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; protected final String TEXT_1 = NL + "import org.geotools.xml.Binding;" + NL + "" + NL + "/**" + NL + " * Binding test case for "; protected final String TEXT_2 = ":"; protected final String TEXT_3 = "." + NL + " *" + NL + " *

" + NL + " *

" + NL + " *   ";
Index: build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/templates/SchemaClassTemplate.java
===================================================================
--- build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/templates/SchemaClassTemplate.java	(revision 34844)
+++ build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/templates/SchemaClassTemplate.java	(working copy)
@@ -7,6 +7,7 @@
 import org.opengis.feature.type.Schema;
 import org.opengis.feature.type.AttributeType;
 import org.opengis.feature.type.Name;
+import org.geotools.feature.NameImpl;
 import org.opengis.feature.type.ComplexType;
 import org.opengis.feature.type.AttributeDescriptor;
 import org.opengis.feature.type.PropertyDescriptor;
@@ -25,83 +26,72 @@
     return result;
   }
 
-  protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
+  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
   protected final String TEXT_1 = "";
-  protected final String TEXT_2 = NL + NL + "import java.util.ArrayList;" + NL + "import java.util.Collections;" + NL + "import java.util.List;" + NL + "" + NL + "import org.opengis.feature.type.AttributeType;" + NL + "import org.opengis.feature.type.ComplexType;" + NL + "" + NL + "import org.geotools.feature.NameImpl;" + NL + "import org.geotools.feature.type.AttributeDescriptorImpl;" + NL + "import org.geotools.feature.type.AttributeTypeImpl;" + NL + "import org.geotools.feature.type.ComplexTypeImpl;" + NL + "import org.geotools.feature.type.SchemaImpl;" + NL;
+  protected final String TEXT_2 = NL + NL + "import java.util.ArrayList;" + NL + "import java.util.Collections;" + NL + "import java.util.List;" + NL + "" + NL + "import org.opengis.feature.type.AttributeType;" + NL + "import org.opengis.feature.type.ComplexType;" + NL + "import org.opengis.feature.type.PropertyDescriptor;" + NL + "import org.opengis.filter.Filter;" + NL + "" + NL + "import org.geotools.feature.NameImpl;" + NL + "import org.geotools.feature.type.AttributeDescriptorImpl;" + NL + "import org.geotools.feature.type.AttributeTypeImpl;" + NL + "import org.geotools.feature.type.ComplexTypeImpl;" + NL + "import org.geotools.feature.type.SchemaImpl;" + NL;
   protected final String TEXT_3 = NL + "import ";
   protected final String TEXT_4 = ";";
   protected final String TEXT_5 = NL + NL + "public class ";
-  protected final String TEXT_6 = "Schema extends SchemaImpl {" + NL + "" + NL + "    static ";
-  protected final String TEXT_7 = "Schema INSTANCE;" + NL + "    " + NL + "    public static ";
-  protected final String TEXT_8 = "Schema getInstance() {" + NL + "       if ( INSTANCE == null ) {" + NL + "          INSTANCE = new ";
-  protected final String TEXT_9 = "Schema();" + NL + "       }" + NL + "       return INSTANCE;" + NL + "    }" + NL + "    ";
-  protected final String TEXT_10 = NL + "    /**" + NL + "     * 

" + NL + " *

" + NL + "     *   ";
-  protected final String TEXT_11 = NL + "     *  ";
-  protected final String TEXT_12 = NL + "     *" + NL + "     *    " + NL + "     *   
" + NL + " *

" + NL + " *" + NL + " * @generated" + NL + " */"; - protected final String TEXT_13 = NL + " public ComplexType "; - protected final String TEXT_14 = "_TYPE;" + NL; - protected final String TEXT_15 = NL + " public AttributeType "; - protected final String TEXT_16 = "_TYPE;" + NL; - protected final String TEXT_17 = NL + NL + " public "; - protected final String TEXT_18 = "Schema() {" + NL + " super(\""; - protected final String TEXT_19 = "\");" + NL + " "; - protected final String TEXT_20 = NL + " "; - protected final String TEXT_21 = NL + " List "; - protected final String TEXT_22 = "_TYPE_schema = new ArrayList();"; - protected final String TEXT_23 = NL + " "; - protected final String TEXT_24 = "_TYPE_schema.add(" + NL + " new AttributeDescriptorImpl("; - protected final String TEXT_25 = NL + " "; - protected final String TEXT_26 = ","; - protected final String TEXT_27 = ","; - protected final String TEXT_28 = ","; + protected final String TEXT_6 = "Schema extends SchemaImpl {" + NL; + protected final String TEXT_7 = NL + " /**" + NL + " *

" + NL + " *

" + NL + "     *   ";
+  protected final String TEXT_8 = NL + "     *  ";
+  protected final String TEXT_9 = NL + "     *" + NL + "     *    " + NL + "     *   
" + NL + " *

" + NL + " *" + NL + " * @generated" + NL + " */"; + protected final String TEXT_10 = NL + " public static final ComplexType "; + protected final String TEXT_11 = "_TYPE = build_"; + protected final String TEXT_12 = "_TYPE();" + NL + " " + NL + " private static ComplexType build_"; + protected final String TEXT_13 = "_TYPE() {" + NL + " ComplexType builtType;"; + protected final String TEXT_14 = NL + " public static final AttributeType "; + protected final String TEXT_15 = "_TYPE = build_"; + protected final String TEXT_16 = "_TYPE();" + NL + " " + NL + " private static AttributeType build_"; + protected final String TEXT_17 = "_TYPE() {" + NL + " AttributeType builtType;"; + protected final String TEXT_18 = NL + " List schema = new ArrayList();"; + protected final String TEXT_19 = NL + " schema.add(" + NL + " new AttributeDescriptorImpl("; + protected final String TEXT_20 = NL + " "; + protected final String TEXT_21 = ", "; + protected final String TEXT_22 = ", "; + protected final String TEXT_23 = ", "; + protected final String TEXT_24 = ", "; + protected final String TEXT_25 = ", null" + NL + " )" + NL + " );"; + protected final String TEXT_26 = NL + " builtType = new ComplexTypeImpl(" + NL + " new NameImpl(\""; + protected final String TEXT_27 = "\",\""; + protected final String TEXT_28 = "\"), schema, "; protected final String TEXT_29 = ","; - protected final String TEXT_30 = ",null" + NL + " )" + NL + " );"; - protected final String TEXT_31 = NL; - protected final String TEXT_32 = NL + " "; - protected final String TEXT_33 = "_TYPE = " + NL + " new ComplexTypeImpl(" + NL + " new NameImpl(\""; - protected final String TEXT_34 = "\",\""; - protected final String TEXT_35 = "\"), "; - protected final String TEXT_36 = "_TYPE_schema, "; - protected final String TEXT_37 = ","; - protected final String TEXT_38 = NL + " "; - protected final String TEXT_39 = ","; - protected final String TEXT_40 = ","; + protected final String TEXT_30 = NL + " "; + protected final String TEXT_31 = ", "; + protected final String TEXT_32 = ", "; + protected final String TEXT_33 = ", "; + protected final String TEXT_34 = NL + " );"; + protected final String TEXT_35 = NL + " builtType = new ComplexTypeImpl(" + NL + " new NameImpl(\""; + protected final String TEXT_36 = "\",\""; + protected final String TEXT_37 = "\"), Collections.emptyList(), "; + protected final String TEXT_38 = ","; + protected final String TEXT_39 = NL + " "; + protected final String TEXT_40 = ", "; protected final String TEXT_41 = ", "; - protected final String TEXT_42 = NL + " );"; - protected final String TEXT_43 = NL + " "; - protected final String TEXT_44 = "_TYPE = " + NL + " new ComplexTypeImpl(" + NL + " new NameImpl(\""; + protected final String TEXT_42 = ", "; + protected final String TEXT_43 = NL + " );"; + protected final String TEXT_44 = NL + " builtType = new AttributeTypeImpl(" + NL + " new NameImpl(\""; protected final String TEXT_45 = "\",\""; - protected final String TEXT_46 = "\"), Collections.EMPTY_LIST, "; - protected final String TEXT_47 = ","; - protected final String TEXT_48 = NL + " "; - protected final String TEXT_49 = ","; - protected final String TEXT_50 = ","; + protected final String TEXT_46 = "\"), "; + protected final String TEXT_47 = ", "; + protected final String TEXT_48 = ","; + protected final String TEXT_49 = NL + " "; + protected final String TEXT_50 = ", "; protected final String TEXT_51 = ", "; - protected final String TEXT_52 = NL + " );"; - protected final String TEXT_53 = NL + " "; - protected final String TEXT_54 = NL + " "; - protected final String TEXT_55 = "_TYPE = " + NL + " new AttributeTypeImpl(" + NL + " new NameImpl(\""; - protected final String TEXT_56 = "\",\""; - protected final String TEXT_57 = "\"), "; - protected final String TEXT_58 = ", "; - protected final String TEXT_59 = ","; - protected final String TEXT_60 = NL + " "; - protected final String TEXT_61 = ","; - protected final String TEXT_62 = ","; - protected final String TEXT_63 = ", "; - protected final String TEXT_64 = NL + " );"; - protected final String TEXT_65 = NL + " static {"; - protected final String TEXT_66 = NL + " \t"; - protected final String TEXT_67 = "_TYPE.getUserData().put("; - protected final String TEXT_68 = ","; - protected final String TEXT_69 = ");"; - protected final String TEXT_70 = NL + " }"; - protected final String TEXT_71 = NL; - protected final String TEXT_72 = NL + " put(new NameImpl(\""; - protected final String TEXT_73 = "\",\""; - protected final String TEXT_74 = "\"),"; - protected final String TEXT_75 = "_TYPE);"; - protected final String TEXT_76 = NL + " }" + NL + "}"; + protected final String TEXT_52 = ", "; + protected final String TEXT_53 = NL + " );"; + protected final String TEXT_54 = NL + " builtType.put("; + protected final String TEXT_55 = ","; + protected final String TEXT_56 = ");"; + protected final String TEXT_57 = NL + " return builtType;" + NL + " }" + NL; + protected final String TEXT_58 = NL + NL + " public "; + protected final String TEXT_59 = "Schema() {" + NL + " super(\""; + protected final String TEXT_60 = "\");" + NL; + protected final String TEXT_61 = NL + " put(new NameImpl(\""; + protected final String TEXT_62 = "\",\""; + protected final String TEXT_63 = "\"),"; + protected final String TEXT_64 = "_TYPE);"; + protected final String TEXT_65 = NL + " }" + NL + " " + NL + "}"; public String generate(Object argument) { @@ -135,18 +125,14 @@ stringBuffer.append(TEXT_5); stringBuffer.append(prefix); stringBuffer.append(TEXT_6); - stringBuffer.append(prefix); - stringBuffer.append(TEXT_7); - stringBuffer.append(prefix); - stringBuffer.append(TEXT_8); - stringBuffer.append(prefix); - stringBuffer.append(TEXT_9); + Map typeBindings = sg.getTypeBindings(); + for (Iterator itr = types.iterator(); itr.hasNext();) { AttributeType type = (AttributeType) itr.next(); Name name = type.getName(); - stringBuffer.append(TEXT_10); + stringBuffer.append(TEXT_7); XSDTypeDefinition xsdType = sg.getXSDType(type); OutputFormat output = new OutputFormat(); @@ -167,47 +153,48 @@ String[] lines = writer.getBuffer().toString().split("\n"); for (int i = 0; i < lines.length; i++) { - stringBuffer.append(TEXT_11); + stringBuffer.append(TEXT_8); stringBuffer.append(lines[i].replaceAll("<","<").replaceAll(">",">")); } - stringBuffer.append(TEXT_12); + stringBuffer.append(TEXT_9); - if (type instanceof ComplexType) { + if (type instanceof ComplexType && !typeBindings.containsKey(name)) { - stringBuffer.append(TEXT_13); + stringBuffer.append(TEXT_10); stringBuffer.append(name.getLocalPart().toUpperCase()); - stringBuffer.append(TEXT_14); + stringBuffer.append(TEXT_11); + stringBuffer.append(name.getLocalPart().toUpperCase()); + stringBuffer.append(TEXT_12); + stringBuffer.append(name.getLocalPart().toUpperCase()); + stringBuffer.append(TEXT_13); } else { + stringBuffer.append(TEXT_14); + stringBuffer.append(name.getLocalPart().toUpperCase()); stringBuffer.append(TEXT_15); stringBuffer.append(name.getLocalPart().toUpperCase()); stringBuffer.append(TEXT_16); + stringBuffer.append(name.getLocalPart().toUpperCase()); + stringBuffer.append(TEXT_17); } - } - - stringBuffer.append(TEXT_17); - stringBuffer.append(prefix); - stringBuffer.append(TEXT_18); - stringBuffer.append(schema.getURI()); - stringBuffer.append(TEXT_19); - - for (Iterator itr = types.iterator(); itr.hasNext();) { - AttributeType type = (AttributeType) itr.next(); - Name name = type.getName(); - String uri = name.getNamespaceURI(); String local = name.getLocalPart(); - String binding = type.getBinding().getName() + ".class"; + String binding; + if (typeBindings.containsKey(name)) { + binding = typeBindings.get(name) + ".class"; + } else { + binding = type.getBinding().getName() + ".class"; + } String isIdentified = type.isIdentified() ? "true" : "false"; String isAbstract = type.isAbstract() ? "true" : "false"; - String restrictions = "Collections.EMPTY_LIST"; + String restrictions = "Collections.emptyList()"; String superType = "null"; if (type.getSuper() != null) { @@ -220,17 +207,12 @@ } String description = "null"; - - stringBuffer.append(TEXT_20); - - if (type instanceof ComplexType) { + if (type instanceof ComplexType && !typeBindings.containsKey(name)) { ComplexType cType = (ComplexType)type; if (!cType.getDescriptors().isEmpty()) { - stringBuffer.append(TEXT_21); - stringBuffer.append(local.toUpperCase()); - stringBuffer.append(TEXT_22); + stringBuffer.append(TEXT_18); for (Iterator adItr = cType.getDescriptors().iterator(); adItr.hasNext();) { PropertyDescriptor pd = (PropertyDescriptor) adItr.next(); @@ -254,138 +236,120 @@ String max = ad.getMaxOccurs() + ""; String isNillable = ad.isNillable() ? "true" : "false"; - stringBuffer.append(TEXT_23); - stringBuffer.append(local.toUpperCase()); - stringBuffer.append(TEXT_24); - stringBuffer.append(TEXT_25); + stringBuffer.append(TEXT_19); + stringBuffer.append(TEXT_20); stringBuffer.append(adTypeName); - stringBuffer.append(TEXT_26); + stringBuffer.append(TEXT_21); stringBuffer.append(adName); - stringBuffer.append(TEXT_27); + stringBuffer.append(TEXT_22); stringBuffer.append(min); - stringBuffer.append(TEXT_28); + stringBuffer.append(TEXT_23); stringBuffer.append(max); - stringBuffer.append(TEXT_29); + stringBuffer.append(TEXT_24); stringBuffer.append(isNillable); - stringBuffer.append(TEXT_30); + stringBuffer.append(TEXT_25); } - stringBuffer.append(TEXT_31); - stringBuffer.append(TEXT_32); - stringBuffer.append(local.toUpperCase()); - stringBuffer.append(TEXT_33); + stringBuffer.append(TEXT_26); stringBuffer.append(uri); - stringBuffer.append(TEXT_34); + stringBuffer.append(TEXT_27); stringBuffer.append(local); - stringBuffer.append(TEXT_35); - stringBuffer.append(local.toUpperCase()); - stringBuffer.append(TEXT_36); + stringBuffer.append(TEXT_28); stringBuffer.append(isIdentified); - stringBuffer.append(TEXT_37); - stringBuffer.append(TEXT_38); + stringBuffer.append(TEXT_29); + stringBuffer.append(TEXT_30); stringBuffer.append(isAbstract); - stringBuffer.append(TEXT_39); + stringBuffer.append(TEXT_31); stringBuffer.append(restrictions); - stringBuffer.append(TEXT_40); + stringBuffer.append(TEXT_32); stringBuffer.append(superType); - stringBuffer.append(TEXT_41); + stringBuffer.append(TEXT_33); stringBuffer.append(description); - stringBuffer.append(TEXT_42); + stringBuffer.append(TEXT_34); } else { - stringBuffer.append(TEXT_43); - stringBuffer.append(local.toUpperCase()); - stringBuffer.append(TEXT_44); + stringBuffer.append(TEXT_35); stringBuffer.append(uri); - stringBuffer.append(TEXT_45); + stringBuffer.append(TEXT_36); stringBuffer.append(local); - stringBuffer.append(TEXT_46); + stringBuffer.append(TEXT_37); stringBuffer.append(isIdentified); - stringBuffer.append(TEXT_47); - stringBuffer.append(TEXT_48); + stringBuffer.append(TEXT_38); + stringBuffer.append(TEXT_39); stringBuffer.append(isAbstract); - stringBuffer.append(TEXT_49); + stringBuffer.append(TEXT_40); stringBuffer.append(restrictions); - stringBuffer.append(TEXT_50); + stringBuffer.append(TEXT_41); stringBuffer.append(superType); - stringBuffer.append(TEXT_51); + stringBuffer.append(TEXT_42); stringBuffer.append(description); - stringBuffer.append(TEXT_52); + stringBuffer.append(TEXT_43); } - - stringBuffer.append(TEXT_53); - } else { - stringBuffer.append(TEXT_54); - stringBuffer.append(local.toUpperCase()); - stringBuffer.append(TEXT_55); + stringBuffer.append(TEXT_44); stringBuffer.append(uri); - stringBuffer.append(TEXT_56); + stringBuffer.append(TEXT_45); stringBuffer.append(local); - stringBuffer.append(TEXT_57); + stringBuffer.append(TEXT_46); stringBuffer.append(binding); - stringBuffer.append(TEXT_58); + stringBuffer.append(TEXT_47); stringBuffer.append(isIdentified); - stringBuffer.append(TEXT_59); - stringBuffer.append(TEXT_60); + stringBuffer.append(TEXT_48); + stringBuffer.append(TEXT_49); stringBuffer.append(isAbstract); - stringBuffer.append(TEXT_61); + stringBuffer.append(TEXT_50); stringBuffer.append(restrictions); - stringBuffer.append(TEXT_62); + stringBuffer.append(TEXT_51); stringBuffer.append(superType); - stringBuffer.append(TEXT_63); + stringBuffer.append(TEXT_52); stringBuffer.append(description); - stringBuffer.append(TEXT_64); + stringBuffer.append(TEXT_53); } if (!type.getUserData().isEmpty()) { - - stringBuffer.append(TEXT_65); - - //attributes - for (Iterator i = type.getUserData().entrySet().iterator(); i.hasNext(); ) { - Map.Entry entry = (Map.Entry) i.next(); - Name n = (Name) entry.getKey(); - PropertyDescriptor pd = (PropertyDescriptor) entry.getValue(); - PropertyType pdType = pd.getType(); - - String pdTypeName = pdType.getName().getLocalPart().toUpperCase() + - "_TYPE"; - if (ns2import.containsKey(pdType.getName().getNamespaceURI())) { - String importClassName = (String) ns2import.get(pdType.getName().getNamespaceURI()); - pdTypeName = importClassName + "." + pdTypeName; - } - String pdName = "new NameImpl(\"" + pd.getName().getNamespaceURI() + - "\",\"" + pd.getName().getLocalPart() + "\")"; + //attributes + for (Iterator i = type.getUserData().entrySet().iterator(); i.hasNext(); ) { + Map.Entry entry = (Map.Entry) i.next(); + Name n = (Name) entry.getKey(); + PropertyDescriptor pd = (PropertyDescriptor) entry.getValue(); + PropertyType pdType = pd.getType(); + + String pdTypeName = pdType.getName().getLocalPart().toUpperCase() + + "_TYPE"; + if (ns2import.containsKey(pdType.getName().getNamespaceURI())) { + String importClassName = (String) ns2import.get(pdType.getName().getNamespaceURI()); + pdTypeName = importClassName + "." + pdTypeName; + } + String pdName = "new NameImpl(\"" + pd.getName().getNamespaceURI() + + "\",\"" + pd.getName().getLocalPart() + "\")"; - stringBuffer.append(TEXT_66); - stringBuffer.append(local.toUpperCase()); - stringBuffer.append(TEXT_67); + stringBuffer.append(TEXT_54); stringBuffer.append(pdName); - stringBuffer.append(TEXT_68); + stringBuffer.append(TEXT_55); stringBuffer.append(pdTypeName); - stringBuffer.append(TEXT_69); + stringBuffer.append(TEXT_56); - } - - stringBuffer.append(TEXT_70); - - + } } - stringBuffer.append(TEXT_71); + stringBuffer.append(TEXT_57); } + stringBuffer.append(TEXT_58); + stringBuffer.append(prefix); + stringBuffer.append(TEXT_59); + stringBuffer.append(schema.getURI()); + stringBuffer.append(TEXT_60); for (Iterator itr = types.iterator(); itr.hasNext();) { AttributeType type = (AttributeType) itr.next(); @@ -393,17 +357,17 @@ String local = name.getLocalPart(); - stringBuffer.append(TEXT_72); + stringBuffer.append(TEXT_61); stringBuffer.append(schema.getURI()); - stringBuffer.append(TEXT_73); + stringBuffer.append(TEXT_62); stringBuffer.append(local); - stringBuffer.append(TEXT_74); + stringBuffer.append(TEXT_63); stringBuffer.append(local.toUpperCase()); - stringBuffer.append(TEXT_75); + stringBuffer.append(TEXT_64); } - stringBuffer.append(TEXT_76); + stringBuffer.append(TEXT_65); return stringBuffer.toString(); } } Index: build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/templates/ConfigurationTemplate.java =================================================================== --- build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/templates/ConfigurationTemplate.java (revision 34844) +++ build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/templates/ConfigurationTemplate.java (working copy) @@ -16,7 +16,7 @@ return result; } - protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; protected final String TEXT_1 = "import org.eclipse.xsd.util.XSDSchemaLocationResolver;\t" + NL + "import org.geotools.xml.Configuration;" + NL + "import org.picocontainer.MutablePicoContainer;" + NL + "" + NL + "/**" + NL + " * Parser configuration for the "; protected final String TEXT_2 = " schema." + NL + " *" + NL + " * @generated" + NL + " */" + NL + "public class "; protected final String TEXT_3 = "Configuration extends Configuration {" + NL + "" + NL + " /**" + NL + " * Creates a new configuration." + NL + " * " + NL + " * @generated" + NL + " */ " + NL + " public "; Index: build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/templates/CLASS.java =================================================================== --- build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/templates/CLASS.java (revision 34844) +++ build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/templates/CLASS.java (working copy) @@ -18,7 +18,7 @@ return result; } - protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; protected final String TEXT_1 = NL + "import org.geotools.xml.*;" + NL + "import "; protected final String TEXT_2 = ";" + NL; protected final String TEXT_3 = NL + "import "; Index: build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/templates/XSDTemplate.java =================================================================== --- build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/templates/XSDTemplate.java (revision 34844) +++ build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/templates/XSDTemplate.java (working copy) @@ -17,7 +17,7 @@ return result; } - protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; protected final String TEXT_1 = NL + "import java.util.Set;" + NL + "import javax.xml.namespace.QName;" + NL + "import org.geotools.xml.XSD;" + NL + "" + NL + "/**" + NL + " * This interface contains the qualified names of all the types,elements, and " + NL + " * attributes in the "; protected final String TEXT_2 = " schema." + NL + " *" + NL + " * @generated" + NL + " */" + NL + "public final class "; protected final String TEXT_3 = " extends XSD {" + NL + "" + NL + " /** singleton instance */" + NL + " private static final "; Index: build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/templates/BindingTestSupportClass.java =================================================================== --- build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/templates/BindingTestSupportClass.java (revision 34844) +++ build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/templates/BindingTestSupportClass.java (working copy) @@ -16,7 +16,7 @@ return result; } - protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; protected final String TEXT_1 = NL + "import org.geotools.xml.Configuration;" + NL + "import org.geotools.xml.test.XMLTestSupport;" + NL + "" + NL + "/**" + NL + " * Base test class for the "; protected final String TEXT_2 = " schema." + NL + " *" + NL + " * @generated" + NL + " */" + NL + "public class "; protected final String TEXT_3 = "TestSupport extends XMLTestSupport {" + NL + "" + NL + " protected Configuration createConfiguration() {" + NL + " return new "; Index: build/maven/xmlcodegen/src/main/template/schema.javajet =================================================================== --- build/maven/xmlcodegen/src/main/template/schema.javajet (revision 34844) +++ build/maven/xmlcodegen/src/main/template/schema.javajet (working copy) @@ -2,6 +2,7 @@ imports="java.util.* java.io.* org.geotools.xml.* org.geotools.maven.xmlcodegen.* org.opengis.feature.type.Schema org.opengis.feature.type.AttributeType org.opengis.feature.type.Name + org.geotools.feature.NameImpl org.opengis.feature.type.ComplexType org.opengis.feature.type.AttributeDescriptor org.opengis.feature.type.PropertyDescriptor org.opengis.feature.type.PropertyType org.apache.xml.serialize.* org.eclipse.xsd.*" class="SchemaClassTemplate" %> @@ -22,6 +23,8 @@ import org.opengis.feature.type.AttributeType; import org.opengis.feature.type.ComplexType; +import org.opengis.feature.type.PropertyDescriptor; +import org.opengis.filter.Filter; import org.geotools.feature.NameImpl; import org.geotools.feature.type.AttributeDescriptorImpl; @@ -45,16 +48,9 @@ public class <%=prefix%>Schema extends SchemaImpl { - static <%=prefix%>Schema INSTANCE; - - public static <%=prefix%>Schema getInstance() { - if ( INSTANCE == null ) { - INSTANCE = new <%=prefix%>Schema(); - } - return INSTANCE; - } - <% + Map typeBindings = sg.getTypeBindings(); + for (Iterator itr = types.iterator(); itr.hasNext();) { AttributeType type = (AttributeType) itr.next(); Name name = type.getName(); @@ -95,37 +91,35 @@ * @generated */ <% - if (type instanceof ComplexType) { + if (type instanceof ComplexType && !typeBindings.containsKey(name)) { %> - public ComplexType <%=name.getLocalPart().toUpperCase()%>_TYPE; - + public static final ComplexType <%=name.getLocalPart().toUpperCase()%>_TYPE = build_<%=name.getLocalPart().toUpperCase()%>_TYPE(); + + private static ComplexType build_<%=name.getLocalPart().toUpperCase()%>_TYPE() { + ComplexType builtType; <% } else { %> - public AttributeType <%=name.getLocalPart().toUpperCase()%>_TYPE; - + public static final AttributeType <%=name.getLocalPart().toUpperCase()%>_TYPE = build_<%=name.getLocalPart().toUpperCase()%>_TYPE(); + + private static AttributeType build_<%=name.getLocalPart().toUpperCase()%>_TYPE() { + AttributeType builtType; <% } - } -%> - - public <%=prefix%>Schema() { - super("<%=schema.getURI()%>"); - -<% - for (Iterator itr = types.iterator(); itr.hasNext();) { - AttributeType type = (AttributeType) itr.next(); - Name name = type.getName(); - String uri = name.getNamespaceURI(); String local = name.getLocalPart(); - String binding = type.getBinding().getName() + ".class"; + String binding; + if (typeBindings.containsKey(name)) { + binding = typeBindings.get(name) + ".class"; + } else { + binding = type.getBinding().getName() + ".class"; + } String isIdentified = type.isIdentified() ? "true" : "false"; String isAbstract = type.isAbstract() ? "true" : "false"; - String restrictions = "Collections.EMPTY_LIST"; + String restrictions = "Collections.emptyList()"; String superType = "null"; if (type.getSuper() != null) { @@ -138,15 +132,12 @@ } String description = "null"; -%> - -<% - if (type instanceof ComplexType) { + if (type instanceof ComplexType && !typeBindings.containsKey(name)) { ComplexType cType = (ComplexType)type; if (!cType.getDescriptors().isEmpty()) { %> - List <%=local.toUpperCase()%>_TYPE_schema = new ArrayList(); + List schema = new ArrayList(); <% for (Iterator adItr = cType.getDescriptors().iterator(); adItr.hasNext();) { PropertyDescriptor pd = (PropertyDescriptor) adItr.next(); @@ -170,80 +161,72 @@ String max = ad.getMaxOccurs() + ""; String isNillable = ad.isNillable() ? "true" : "false"; %> - <%=local.toUpperCase()%>_TYPE_schema.add( - new AttributeDescriptorImpl( - <%=adTypeName%>,<%=adName%>,<%=min%>,<%=max%>,<%=isNillable%>,null - ) - ); + schema.add( + new AttributeDescriptorImpl( + <%=adTypeName%>, <%=adName%>, <%=min%>, <%=max%>, <%=isNillable%>, null + ) + ); <% } %> - - <%=local.toUpperCase()%>_TYPE = - new ComplexTypeImpl( - new NameImpl("<%=uri%>","<%=local%>"), <%=local.toUpperCase()%>_TYPE_schema, <%=isIdentified%>, - <%=isAbstract%>,<%=restrictions%>,<%=superType%>, <%=description%> + builtType = new ComplexTypeImpl( + new NameImpl("<%=uri%>","<%=local%>"), schema, <%=isIdentified%>, + <%=isAbstract%>, <%=restrictions%>, <%=superType%>, <%=description%> ); <% } else { %> - <%=local.toUpperCase()%>_TYPE = - new ComplexTypeImpl( - new NameImpl("<%=uri%>","<%=local%>"), Collections.EMPTY_LIST, <%=isIdentified%>, - <%=isAbstract%>,<%=restrictions%>,<%=superType%>, <%=description%> + builtType = new ComplexTypeImpl( + new NameImpl("<%=uri%>","<%=local%>"), Collections.emptyList(), <%=isIdentified%>, + <%=isAbstract%>, <%=restrictions%>, <%=superType%>, <%=description%> ); <% } -%> - -<% } else { %> - <%=local.toUpperCase()%>_TYPE = - new AttributeTypeImpl( + builtType = new AttributeTypeImpl( new NameImpl("<%=uri%>","<%=local%>"), <%=binding%>, <%=isIdentified%>, - <%=isAbstract%>,<%=restrictions%>,<%=superType%>, <%=description%> + <%=isAbstract%>, <%=restrictions%>, <%=superType%>, <%=description%> ); <% } if (!type.getUserData().isEmpty()) { -%> - static { -<% - //attributes - for (Iterator i = type.getUserData().entrySet().iterator(); i.hasNext(); ) { - Map.Entry entry = (Map.Entry) i.next(); - Name n = (Name) entry.getKey(); - PropertyDescriptor pd = (PropertyDescriptor) entry.getValue(); - PropertyType pdType = pd.getType(); - - String pdTypeName = pdType.getName().getLocalPart().toUpperCase() + - "_TYPE"; - if (ns2import.containsKey(pdType.getName().getNamespaceURI())) { - String importClassName = (String) ns2import.get(pdType.getName().getNamespaceURI()); - pdTypeName = importClassName + "." + pdTypeName; - } - String pdName = "new NameImpl(\"" + pd.getName().getNamespaceURI() + - "\",\"" + pd.getName().getLocalPart() + "\")"; + //attributes + for (Iterator i = type.getUserData().entrySet().iterator(); i.hasNext(); ) { + Map.Entry entry = (Map.Entry) i.next(); + Name n = (Name) entry.getKey(); + PropertyDescriptor pd = (PropertyDescriptor) entry.getValue(); + PropertyType pdType = pd.getType(); + + String pdTypeName = pdType.getName().getLocalPart().toUpperCase() + + "_TYPE"; + if (ns2import.containsKey(pdType.getName().getNamespaceURI())) { + String importClassName = (String) ns2import.get(pdType.getName().getNamespaceURI()); + pdTypeName = importClassName + "." + pdTypeName; + } + String pdName = "new NameImpl(\"" + pd.getName().getNamespaceURI() + + "\",\"" + pd.getName().getLocalPart() + "\")"; %> - <%=local.toUpperCase()%>_TYPE.getUserData().put(<%=pdName%>,<%=pdTypeName%>); + builtType.put(<%=pdName%>,<%=pdTypeName%>); <% - } -%> - } -<% - + } } %> + return builtType; + } <% } %> + + public <%=prefix%>Schema() { + super("<%=schema.getURI()%>"); + <% for (Iterator itr = types.iterator(); itr.hasNext();) { AttributeType type = (AttributeType) itr.next(); @@ -256,4 +239,5 @@ } %> } + } \ No newline at end of file