Search in sources :

Example 21 with XSElementDecl

use of com.sun.xml.xsom.XSElementDecl in project citygml4j by citygml4j.

the class Schema method getElementDecls.

public List<ElementDecl> getElementDecls(final String localName) {
    if (multipleElements.containsKey(localName))
        return multipleElements.get(localName);
    final List<ElementDecl> elements = new ArrayList<ElementDecl>();
    ElementDecl element = uniqueElements.get(localName);
    if (element != null)
        elements.add(element);
    else {
        SchemaWalker schemaWalker = new SchemaWalker() {

            @Override
            public void schema(XSSchema schema) {
                for (XSElementDecl e : schema.getElementDecls().values()) if (shouldWalk() && addToVisited(e))
                    elementDecl(e);
                for (XSComplexType t : schema.getComplexTypes().values()) if (shouldWalk() && addToVisited(t))
                    t.visit(this);
            }

            @Override
            public void elementDecl(XSElementDecl decl) {
                if (localName.equals(decl.getName()) && schema.getTargetNamespace().equals(decl.getTargetNamespace()))
                    elements.add(new ElementDecl(decl, Schema.this));
                if (decl.getType().isLocal() && shouldWalk() && addToVisited(decl.getType()))
                    decl.getType().visit(this);
            }

            public void complexType(XSComplexType type) {
                if (shouldWalk() && addToVisited(type.getContentType()))
                    type.getContentType().visit(this);
            }

            @Override
            public void attGroupDecl(XSAttGroupDecl decl) {
            }

            @Override
            public void attributeDecl(XSAttributeDecl decl) {
            }

            @Override
            public void attributeUse(XSAttributeUse use) {
            }

            @Override
            public void simpleType(XSSimpleType simpleType) {
            }
        };
        schemaWalker.visit(schema);
        if (elements.size() > 1)
            multipleElements.put(localName, elements);
        else if (elements.size() == 1)
            uniqueElements.put(localName, elements.get(0));
    }
    return elements;
}
Also used : XSAttGroupDecl(com.sun.xml.xsom.XSAttGroupDecl) XSSimpleType(com.sun.xml.xsom.XSSimpleType) XSComplexType(com.sun.xml.xsom.XSComplexType) XSAttributeDecl(com.sun.xml.xsom.XSAttributeDecl) ArrayList(java.util.ArrayList) XSAttributeUse(com.sun.xml.xsom.XSAttributeUse) XSElementDecl(com.sun.xml.xsom.XSElementDecl) XSElementDecl(com.sun.xml.xsom.XSElementDecl) XSSchema(com.sun.xml.xsom.XSSchema)

Example 22 with XSElementDecl

use of com.sun.xml.xsom.XSElementDecl in project citygml4j by citygml4j.

the class ElementDecl method isFeatureProperty.

public boolean isFeatureProperty() {
    if (typeFlag.contains(TypeFlag.FEATURE_PROPERTY))
        return true;
    else if (typeFlag.contains(TypeFlag.NO_FEATURE_PROPERTY))
        return false;
    boolean isFeatureProperty = false;
    for (XSElementDecl child : getChildElements()) {
        Schema childSchema = schema.handler.getSchema(child.getTargetNamespace());
        List<ElementDecl> childElementDecls = childSchema.getElementDecls(child.getName());
        if (childElementDecls.size() == 1) {
            if (childElementDecls.get(0).isFeature())
                isFeatureProperty = true;
        } else {
            for (GMLCoreModule module : GMLCoreModule.getInstances()) {
                XSSchema gml = schema.schemaSet.getSchema(module.getNamespaceURI());
                if (gml == null)
                    continue;
                switch(module.getVersion()) {
                    case v3_1_1:
                        isFeatureProperty = child.getType().isDerivedFrom(gml.getType("AbstractFeatureType"));
                        break;
                }
                if (isFeatureProperty)
                    break;
            }
        }
        if (isFeatureProperty)
            break;
    }
    if (isFeatureProperty) {
        typeFlag.add(TypeFlag.FEATURE_PROPERTY);
        typeFlag.add(TypeFlag.NO_GEOMETRY_PROPERTY);
    } else
        typeFlag.add(TypeFlag.NO_FEATURE_PROPERTY);
    return isFeatureProperty;
}
Also used : XSSchema(com.sun.xml.xsom.XSSchema) GMLCoreModule(org.citygml4j.model.module.gml.GMLCoreModule) XSElementDecl(com.sun.xml.xsom.XSElementDecl) XSElementDecl(com.sun.xml.xsom.XSElementDecl) XSSchema(com.sun.xml.xsom.XSSchema)

Example 23 with XSElementDecl

use of com.sun.xml.xsom.XSElementDecl in project citygml4j by citygml4j.

the class SchemaWriter method elementDecl.

private void elementDecl(XSElementDecl decl, String extraAtts) {
    XSType type = decl.getType();
    // qualified attr; Issue
    if (decl.getForm() != null) {
        extraAtts += " form=\"" + (decl.getForm() ? "qualified" : "unqualified") + "\"";
    }
    StringBuffer buf = new StringBuffer();
    XSElementDecl substGrp = decl.getSubstAffiliation();
    if (substGrp != null) {
        buf.append(" substitutionGroup=\"{").append(substGrp.getTargetNamespace()).append("}").append(substGrp.getName()).append("\"");
    }
    println(MessageFormat.format("<element name=\"{0}\"{1}{2}{3}{4}>", decl.getName(), type.isLocal() ? "" : " type=\"{" + type.getTargetNamespace() + '}' + type.getName() + '\"', extraAtts, buf.toString(), type.isLocal() ? "" : "/"));
    if (type.isLocal()) {
        indent++;
        if (type.isLocal())
            type.visit(this);
        indent--;
        println("</element>");
    } else {
    }
}
Also used : XSType(com.sun.xml.xsom.XSType) XSElementDecl(com.sun.xml.xsom.XSElementDecl)

Example 24 with XSElementDecl

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

the class ComplexTypeImpl method getElementDecls.

public List<XSElementDecl> getElementDecls() {
    ArrayList declList = new ArrayList();
    XSSchemaSet schemaSet = getRoot();
    for (XSSchema sch : schemaSet.getSchemas()) {
        for (XSElementDecl decl : sch.getElementDecls().values()) {
            if (decl.getType().equals(this)) {
                declList.add(decl);
            }
        }
    }
    return declList;
}
Also used : XSSchemaSet(com.sun.xml.xsom.XSSchemaSet) ArrayList(java.util.ArrayList) XSElementDecl(com.sun.xml.xsom.XSElementDecl) XSSchema(com.sun.xml.xsom.XSSchema)

Example 25 with XSElementDecl

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

the class XmlSchemaInspector method printSchemaSet.

private void printSchemaSet(XSSchemaSet schemaSet) throws Exception {
    if (schemaSet == null) {
        throw new XmlInspectionException("Schema set is null");
    }
    XSSchema schema = rootNamespace != null ? schemaSet.getSchema(rootNamespace) : schemaSet.getSchema("");
    // we only care about declared elements...
    Iterator<XSElementDecl> jtr = schema.iterateElementDecls();
    while (jtr.hasNext()) {
        XSElementDecl e = jtr.next();
        String rootName = getNameNS(e);
        if (e.getType().isComplexType()) {
            XmlComplexType rootComplexType = getXmlComplexType();
            rootComplexType.setName(rootName);
            rootComplexType.setPath("/" + rootName);
            rootComplexType.setFieldType(FieldType.COMPLEX);
            xmlDocument.getFields().getField().add(rootComplexType);
            printComplexType(e.getType().asComplexType(), rootComplexType, new HashSet<>());
        } else if (e.getType().isSimpleType()) {
            XmlField xmlField = AtlasXmlModelFactory.createXmlField();
            xmlField.setName(rootName);
            xmlField.setPath("/" + rootName);
            xmlDocument.getFields().getField().add(xmlField);
            printSimpleType(e.getType().asSimpleType(), xmlField);
        }
    }
}
Also used : XmlComplexType(io.atlasmap.xml.v2.XmlComplexType) XmlField(io.atlasmap.xml.v2.XmlField) XSElementDecl(com.sun.xml.xsom.XSElementDecl) XSSchema(com.sun.xml.xsom.XSSchema)

Aggregations

XSElementDecl (com.sun.xml.xsom.XSElementDecl)48 XSModelGroupDecl (com.sun.xml.xsom.XSModelGroupDecl)18 XSComplexType (com.sun.xml.xsom.XSComplexType)16 XSModelGroup (com.sun.xml.xsom.XSModelGroup)16 XSSchema (com.sun.xml.xsom.XSSchema)12 XSSimpleType (com.sun.xml.xsom.XSSimpleType)11 XSAttributeDecl (com.sun.xml.xsom.XSAttributeDecl)10 XSType (com.sun.xml.xsom.XSType)10 XSWildcard (com.sun.xml.xsom.XSWildcard)10 XSTermVisitor (com.sun.xml.xsom.visitor.XSTermVisitor)10 XSAttGroupDecl (com.sun.xml.xsom.XSAttGroupDecl)9 XSSchemaSet (com.sun.xml.xsom.XSSchemaSet)8 XSParticle (com.sun.xml.xsom.XSParticle)7 XSTerm (com.sun.xml.xsom.XSTerm)7 ArrayList (java.util.ArrayList)7 BigInteger (java.math.BigInteger)6 QName (javax.xml.namespace.QName)6 XSContentType (com.sun.xml.xsom.XSContentType)4 Iterator (java.util.Iterator)4 CClassInfo (com.sun.tools.xjc.model.CClassInfo)3