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;
}
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;
}
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 {
}
}
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;
}
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);
}
}
}
Aggregations