Search in sources :

Example 6 with XSSimpleType

use of com.sun.xml.xsom.XSSimpleType in project atlasmap by atlasmap.

the class SchemaWriter method restrictionSimpleType.

public void restrictionSimpleType(XSRestrictionSimpleType type) {
    if (type.getBaseType() == null) {
        // don't print anySimpleType
        if (!type.getName().equals("anySimpleType"))
            throw new InternalError();
        if (!Const.schemaNamespace.equals(type.getTargetNamespace()))
            throw new InternalError();
        return;
    }
    XSSimpleType baseType = type.getSimpleBaseType();
    println(MessageFormat.format("<restriction{0}>", baseType.isLocal() ? "" : " base=\"{" + baseType.getTargetNamespace() + '}' + baseType.getName() + '\"'));
    indent++;
    if (baseType.isLocal())
        simpleType(baseType);
    Iterator itr = type.iterateDeclaredFacets();
    while (itr.hasNext()) facet((XSFacet) itr.next());
    indent--;
    println("</restriction>");
}
Also used : XSFacet(com.sun.xml.xsom.XSFacet) XSSimpleType(com.sun.xml.xsom.XSSimpleType) Iterator(java.util.Iterator)

Example 7 with XSSimpleType

use of com.sun.xml.xsom.XSSimpleType in project atlasmap by atlasmap.

the class SchemaInspector method printAttributes.

private void printAttributes(XSComplexType xsComplexType, String rootName, XmlComplexType xmlComplexType) {
    Collection<? extends XSAttributeUse> c = xsComplexType.getDeclaredAttributeUses();
    for (XSAttributeUse aC : c) {
        XmlField xmlField = AtlasXmlModelFactory.createXmlField();
        XSAttributeDecl attributeDecl = aC.getDecl();
        xmlField.setName(getNameNS(attributeDecl));
        if (attributeDecl.getDefaultValue() != null) {
            xmlField.setValue(attributeDecl.getDefaultValue().value);
        } else if (attributeDecl.getFixedValue() != null) {
            xmlField.setValue(attributeDecl.getFixedValue().value);
        }
        xmlField.setPath(rootName + "/" + "@" + getNameNS(attributeDecl));
        FieldType attrType = getFieldType(attributeDecl.getType().getName());
        xmlField.setFieldType(attrType);
        if (xmlField.getFieldType() == null) {
            // check the simple types in the schema....
            XSSimpleType simpleType = xsComplexType.getRoot().getSimpleType(xsComplexType.getTargetNamespace(), attributeDecl.getType().getName());
            if (simpleType != null) {
                FieldType fieldType = getFieldType(simpleType.getBaseType().getName());
                xmlField.setFieldType(fieldType);
                xmlField.setTypeName(attributeDecl.getType().getName());
                if (simpleType.asRestriction() != null) {
                    mapRestrictions(xmlField, simpleType.asRestriction());
                }
            } else {
                // cannot figure it out....
                xmlField.setFieldType(FieldType.UNSUPPORTED);
            }
        }
        xmlComplexType.getXmlFields().getXmlField().add(xmlField);
    }
}
Also used : XSSimpleType(com.sun.xml.xsom.XSSimpleType) XmlField(io.atlasmap.xml.v2.XmlField) XSAttributeDecl(com.sun.xml.xsom.XSAttributeDecl) XSAttributeUse(com.sun.xml.xsom.XSAttributeUse) FieldType(io.atlasmap.v2.FieldType)

Example 8 with XSSimpleType

use of com.sun.xml.xsom.XSSimpleType in project atlasmap by atlasmap.

the class SchemaWriter method schema.

public void schema(XSSchema s) {
    // QUICK HACK: don't print the built-in components
    if (s.getTargetNamespace().equals(Const.schemaNamespace))
        return;
    println(MessageFormat.format("<schema targetNamespace=\"{0}\">", s.getTargetNamespace()));
    indent++;
    Iterator itr;
    itr = s.iterateAttGroupDecls();
    while (itr.hasNext()) attGroupDecl((XSAttGroupDecl) itr.next());
    itr = s.iterateAttributeDecls();
    while (itr.hasNext()) attributeDecl((XSAttributeDecl) itr.next());
    itr = s.iterateComplexTypes();
    while (itr.hasNext()) complexType((XSComplexType) itr.next());
    itr = s.iterateElementDecls();
    while (itr.hasNext()) elementDecl((XSElementDecl) itr.next());
    itr = s.iterateModelGroupDecls();
    while (itr.hasNext()) modelGroupDecl((XSModelGroupDecl) itr.next());
    itr = s.iterateSimpleTypes();
    while (itr.hasNext()) simpleType((XSSimpleType) itr.next());
    indent--;
    println("</schema>");
}
Also used : XSAttGroupDecl(com.sun.xml.xsom.XSAttGroupDecl) XSSimpleType(com.sun.xml.xsom.XSSimpleType) XSComplexType(com.sun.xml.xsom.XSComplexType) XSModelGroupDecl(com.sun.xml.xsom.XSModelGroupDecl) XSAttributeDecl(com.sun.xml.xsom.XSAttributeDecl) Iterator(java.util.Iterator) XSElementDecl(com.sun.xml.xsom.XSElementDecl)

Example 9 with XSSimpleType

use of com.sun.xml.xsom.XSSimpleType in project atlasmap by atlasmap.

the class SchemaWriter method dump.

private void dump(XSAttributeDecl decl, String additionalAtts) {
    XSSimpleType type = decl.getType();
    println(MessageFormat.format("<attribute name=\"{0}\"{1}{2}{3}{4}{5}>", decl.getName(), additionalAtts, type.isLocal() ? "" : MessageFormat.format(" type=\"'{'{0}'}'{1}\"", type.getTargetNamespace(), type.getName()), decl.getFixedValue() == null ? "" : " fixed=\"" + decl.getFixedValue() + '\"', decl.getDefaultValue() == null ? "" : " default=\"" + decl.getDefaultValue() + '\"', type.isLocal() ? "" : " /"));
    if (type.isLocal()) {
        indent++;
        simpleType(type);
        indent--;
        println("</attribute>");
    }
}
Also used : XSSimpleType(com.sun.xml.xsom.XSSimpleType)

Example 10 with XSSimpleType

use of com.sun.xml.xsom.XSSimpleType in project atlasmap by atlasmap.

the class SchemaWriter method unionSimpleType.

public void unionSimpleType(XSUnionSimpleType type) {
    final int len = type.getMemberSize();
    StringBuffer ref = new StringBuffer();
    for (int i = 0; i < len; i++) {
        XSSimpleType member = type.getMember(i);
        if (member.isGlobal())
            ref.append(MessageFormat.format(" '{'{0}'}'{1}", member.getTargetNamespace(), member.getName()));
    }
    if (ref.length() == 0)
        println("<union>");
    else
        println("<union memberTypes=\"" + ref + "\">");
    indent++;
    for (int i = 0; i < len; i++) {
        XSSimpleType member = type.getMember(i);
        if (member.isLocal())
            simpleType(member);
    }
    indent--;
    println("</union>");
}
Also used : XSSimpleType(com.sun.xml.xsom.XSSimpleType) XSIdentityConstraint(com.sun.xml.xsom.XSIdentityConstraint)

Aggregations

XSSimpleType (com.sun.xml.xsom.XSSimpleType)14 XSAttributeDecl (com.sun.xml.xsom.XSAttributeDecl)4 XSComplexType (com.sun.xml.xsom.XSComplexType)3 XSModelGroupDecl (com.sun.xml.xsom.XSModelGroupDecl)3 Iterator (java.util.Iterator)3 XSAttGroupDecl (com.sun.xml.xsom.XSAttGroupDecl)2 XSAttributeUse (com.sun.xml.xsom.XSAttributeUse)2 XSElementDecl (com.sun.xml.xsom.XSElementDecl)2 XSIdentityConstraint (com.sun.xml.xsom.XSIdentityConstraint)2 FieldType (io.atlasmap.v2.FieldType)2 XmlField (io.atlasmap.xml.v2.XmlField)2 XSFacet (com.sun.xml.xsom.XSFacet)1 XSSchema (com.sun.xml.xsom.XSSchema)1 XSSchemaSet (com.sun.xml.xsom.XSSchemaSet)1 XSOMParser (com.sun.xml.xsom.parser.XSOMParser)1 SAXException (org.xml.sax.SAXException)1