xbean-blueprint/src/main/java/org/apache/xbean/blueprint/generator/XsdGenerator.java [106:215]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        for (Iterator iterator = element.getAttributes().iterator(); iterator.hasNext();) {
            AttributeMapping attributeMapping = (AttributeMapping) iterator.next();
            if (namespaceMapping.isSimpleType(attributeMapping.getType())) {
                generateElementMappingSimpleProperty(out, attributeMapping);
            } else if (!attributeMapping.getType().isCollection()) {
                generateElementMappingComplexPropertyAsRef(out, attributeMapping);
            }
        }
        generateIDAttributeMapping(out, namespaceMapping, element);

        out.println("      <xs:anyAttribute namespace='##other' processContents='lax'/>");
        out.println("    </xs:complexType>");
        out.println("  </xs:element>");
        out.println();
    }

    private boolean isEmptyString(String str) {
        if (str == null) {
            return true;
        }
        for (int i = 0; i < str.length(); i++) {
            if (!Character.isWhitespace(str.charAt(i))) {
                return false;
            }
        }
        return true;
    }

    private void generateIDAttributeMapping(PrintWriter out, NamespaceMapping namespaceMapping, ElementMapping element) {
        for (Iterator iterator = element.getAttributes().iterator(); iterator.hasNext();) {
            AttributeMapping attributeMapping = (AttributeMapping) iterator.next();
            if ("id".equals(attributeMapping.getAttributeName())) {
                return;
            }
        }
        out.println("      <xs:attribute name='id' type='xs:ID'/>");
    }

    private void generateElementMappingSimpleProperty(PrintWriter out, AttributeMapping attributeMapping) {
    	// types with property editors need to be xs:string in the schema to validate
    	String type = attributeMapping.getPropertyEditor() != null ? 
    			Utils.getXsdType(Type.newSimpleType(String.class.getName())) : Utils.getXsdType(attributeMapping.getType());
        if (!isEmptyString(attributeMapping.getDescription())) {
            out.println("      <xs:attribute name='" + attributeMapping.getAttributeName() + "' type='" + type + "'>");
            out.println("        <xs:annotation>");
            out.println("          <xs:documentation><![CDATA[");
            out.println("            " + attributeMapping.getDescription());
            out.println("          ]]></xs:documentation>");
            out.println("        </xs:annotation>");
            out.println("      </xs:attribute>");
        } else {
            out.println("      <xs:attribute name='" + attributeMapping.getAttributeName() + "' type='" + type + "'/>");
        }
    }

    private void generateElementMappingComplexPropertyAsRef(PrintWriter out, AttributeMapping attributeMapping) {
        if (!isEmptyString(attributeMapping.getDescription())) {
            out.println("      <xs:attribute name='" + attributeMapping.getAttributeName() + "' type='xs:string'>");
            out.println("        <xs:annotation>");
            out.println("          <xs:documentation><![CDATA[");
            out.println("            " + attributeMapping.getDescription());
            out.println("          ]]></xs:documentation>");
            out.println("        </xs:annotation>");
            out.println("      </xs:attribute>");
        } else {
            out.println("      <xs:attribute name='" + attributeMapping.getAttributeName() + "' type='xs:string'/>");
        }
    }

    private void generateElementMappingComplexProperty(PrintWriter out, NamespaceMapping namespaceMapping, AttributeMapping attributeMapping) {
        Type type = attributeMapping.getType();
        List types;
        if (type.isCollection()) {
            types = Utils.findImplementationsOf(namespaceMapping, type.getNestedType());
        } else {
            types = Utils.findImplementationsOf(namespaceMapping, type);
        }
        String maxOccurs = type.isCollection() || "java.util.Map".equals(type.getName()) ? "unbounded" : "1";

        out.println("        <xs:element name='" + attributeMapping.getAttributeName() + "' minOccurs='0' maxOccurs='" + maxOccurs + "'>");
        if (!isEmptyString(attributeMapping.getDescription())) {
            out.println("          <xs:annotation>");
            out.println("            <xs:documentation><![CDATA[");
            out.println("              " + attributeMapping.getDescription());
            out.println("            ]]></xs:documentation>");
            out.println("          </xs:annotation>");
        }
        out.println("          <xs:complexType>");
        if (types.isEmpty()) {
            // We don't know the type because it's generic collection.  Allow folks to insert objets from any namespace
            out.println("            <xs:sequence minOccurs='0' maxOccurs='" + maxOccurs + "'><xs:any minOccurs='0' maxOccurs='unbounded'/></xs:sequence>");
        } else {
            out.println("            <xs:choice minOccurs='0' maxOccurs='" + maxOccurs + "'>");
            for (Iterator iterator = types.iterator(); iterator.hasNext();) {
                ElementMapping element = (ElementMapping) iterator.next();
                out.println("              <xs:element ref='tns:" + element.getElementName() + "'/>");
            }
            out.println("              <xs:any namespace='##other'/>");
            out.println("            </xs:choice>");
        }
        out.println("          </xs:complexType>");
        out.println("        </xs:element>");
    }

    public LogFacade getLog() {
        return log;
    }

    public void setLog(LogFacade log) {
        this.log = log;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



xbean-spring/src/main/java/org/apache/xbean/spring/generator/XsdGenerator.java [119:228]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        for (Iterator iterator = element.getAttributes().iterator(); iterator.hasNext();) {
            AttributeMapping attributeMapping = (AttributeMapping) iterator.next();
            if (namespaceMapping.isSimpleType(attributeMapping.getType())) {
                generateElementMappingSimpleProperty(out, attributeMapping);
            } else if (!attributeMapping.getType().isCollection()) {
                generateElementMappingComplexPropertyAsRef(out, attributeMapping);
            }
        }
        generateIDAttributeMapping(out, namespaceMapping, element);

        out.println("      <xs:anyAttribute namespace='##other' processContents='lax'/>");
        out.println("    </xs:complexType>");
        out.println("  </xs:element>");
        out.println();
    }

    private boolean isEmptyString(String str) {
        if (str == null) {
            return true;
        }
        for (int i = 0; i < str.length(); i++) {
            if (!Character.isWhitespace(str.charAt(i))) {
                return false;
            }
        }
        return true;
    }

    private void generateIDAttributeMapping(PrintWriter out, NamespaceMapping namespaceMapping, ElementMapping element) {
        for (Iterator iterator = element.getAttributes().iterator(); iterator.hasNext();) {
            AttributeMapping attributeMapping = (AttributeMapping) iterator.next();
            if ("id".equals(attributeMapping.getAttributeName())) {
                return;
            }
        }
        out.println("      <xs:attribute name='id' type='xs:ID'/>");
    }

    private void generateElementMappingSimpleProperty(PrintWriter out, AttributeMapping attributeMapping) {
    	// types with property editors need to be xs:string in the schema to validate
    	String type = attributeMapping.getPropertyEditor() != null ? 
    			Utils.getXsdType(Type.newSimpleType(String.class.getName())) : Utils.getXsdType(attributeMapping.getType());
        if (!isEmptyString(attributeMapping.getDescription())) {
            out.println("      <xs:attribute name='" + attributeMapping.getAttributeName() + "' type='" + type + "'>");
            out.println("        <xs:annotation>");
            out.println("          <xs:documentation><![CDATA[");
            out.println("            " + attributeMapping.getDescription());
            out.println("          ]]></xs:documentation>");
            out.println("        </xs:annotation>");
            out.println("      </xs:attribute>");
        } else {
            out.println("      <xs:attribute name='" + attributeMapping.getAttributeName() + "' type='" + type + "'/>");
        }
    }

    private void generateElementMappingComplexPropertyAsRef(PrintWriter out, AttributeMapping attributeMapping) {
        if (!isEmptyString(attributeMapping.getDescription())) {
            out.println("      <xs:attribute name='" + attributeMapping.getAttributeName() + "' type='xs:string'>");
            out.println("        <xs:annotation>");
            out.println("          <xs:documentation><![CDATA[");
            out.println("            " + attributeMapping.getDescription());
            out.println("          ]]></xs:documentation>");
            out.println("        </xs:annotation>");
            out.println("      </xs:attribute>");
        } else {
            out.println("      <xs:attribute name='" + attributeMapping.getAttributeName() + "' type='xs:string'/>");
        }
    }

    private void generateElementMappingComplexProperty(PrintWriter out, NamespaceMapping namespaceMapping, AttributeMapping attributeMapping) {
        Type type = attributeMapping.getType();
        List types;
        if (type.isCollection()) {
            types = Utils.findImplementationsOf(namespaceMapping, type.getNestedType());
        } else {
            types = Utils.findImplementationsOf(namespaceMapping, type);
        }
        String maxOccurs = type.isCollection() || "java.util.Map".equals(type.getName()) ? "unbounded" : "1";

        out.println("        <xs:element name='" + attributeMapping.getAttributeName() + "' minOccurs='0' maxOccurs='" + maxOccurs + "'>");
        if (!isEmptyString(attributeMapping.getDescription())) {
            out.println("          <xs:annotation>");
            out.println("            <xs:documentation><![CDATA[");
            out.println("              " + attributeMapping.getDescription());
            out.println("            ]]></xs:documentation>");
            out.println("          </xs:annotation>");
        }
        out.println("          <xs:complexType>");
        if (types.isEmpty()) {
            // We don't know the type because it's generic collection.  Allow folks to insert objets from any namespace
            out.println("            <xs:sequence minOccurs='0' maxOccurs='" + maxOccurs + "'><xs:any minOccurs='0' maxOccurs='unbounded'/></xs:sequence>");
        } else {
            out.println("            <xs:choice minOccurs='0' maxOccurs='" + maxOccurs + "'>");
            for (Iterator iterator = types.iterator(); iterator.hasNext();) {
                ElementMapping element = (ElementMapping) iterator.next();
                out.println("              <xs:element ref='tns:" + element.getElementName() + "'/>");
            }
            out.println("              <xs:any namespace='##other'/>");
            out.println("            </xs:choice>");
        }
        out.println("          </xs:complexType>");
        out.println("        </xs:element>");
    }

    public LogFacade getLog() {
        return log;
    }

    public void setLog(LogFacade log) {
        this.log = log;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



