use of com.sun.xml.xsom.XSElementDecl in project midpoint by Evolveum.
the class SchemaProcessor method getComplexTypeToElementName.
private Map<QName, List<QName>> getComplexTypeToElementName(ClassOutline classOutline) {
Map<QName, List<QName>> complexTypeToElementName = new HashMap<QName, List<QName>>();
XSSchemaSet schemaSet = classOutline.target.getSchemaComponent().getRoot();
for (XSSchema schema : schemaSet.getSchemas()) {
Map<String, XSElementDecl> elemDecls = schema.getElementDecls();
for (Entry<String, XSElementDecl> entry : elemDecls.entrySet()) {
XSElementDecl decl = entry.getValue();
XSType xsType = decl.getType();
if (xsType.getName() == null) {
continue;
}
QName type = new QName(xsType.getTargetNamespace(), xsType.getName());
List<QName> qnames = complexTypeToElementName.get(type);
if (qnames == null) {
qnames = new ArrayList<QName>();
complexTypeToElementName.put(type, qnames);
}
qnames.add(new QName(decl.getTargetNamespace(), decl.getName()));
}
}
return complexTypeToElementName;
}
use of com.sun.xml.xsom.XSElementDecl in project atlasmap by atlasmap.
the class SchemaInspector 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(), "/" + rootName, rootComplexType);
} 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);
}
}
}
use of com.sun.xml.xsom.XSElementDecl in project narayana by jbosstm.
the class NBFSchemaParser method parse.
public boolean parse(String fname) {
boolean rc = false;
try {
flds.clear();
XSOMParser parser = new XSOMParser();
parser.parse(fname);
XSSchemaSet xsSchema = parser.getResult();
XSSchema schema = xsSchema.getSchema(1);
File file = new File(fname);
XSElementDecl element = schema.getElementDecl(file.getName().replace(".xsd", ""));
if (element != null) {
log.debug("element is " + element.getName());
bufferName = element.getName();
XSType xtype = element.getType();
if (xtype.isComplexType()) {
findElementType(xtype.asComplexType());
rc = true;
}
}
} catch (Exception e) {
log.error("parse " + fname + " failed with " + e.getMessage(), e);
}
return rc;
}
use of com.sun.xml.xsom.XSElementDecl in project atlasmap by atlasmap.
the class SchemaTreeTraverser method schema.
/* (non-Javadoc)
* @see com.sun.xml.xsom.visitor.XSVisitor#schema(com.sun.xml.xsom.XSSchema)
*/
public void schema(XSSchema s) {
// QUICK HACK: don't print the built-in components
if (s.getTargetNamespace().equals(Const.schemaNamespace)) {
return;
}
SchemaTreeNode newNode = new SchemaTreeNode("Schema " + s.getLocator().getSystemId(), s.getLocator());
this.currNode = newNode;
this.model.addSchemaNode(newNode);
for (XSAttGroupDecl groupDecl : s.getAttGroupDecls().values()) {
attGroupDecl(groupDecl);
}
for (XSAttributeDecl attrDecl : s.getAttributeDecls().values()) {
attributeDecl(attrDecl);
}
for (XSComplexType complexType : s.getComplexTypes().values()) {
complexType(complexType);
}
for (XSElementDecl elementDecl : s.getElementDecls().values()) {
elementDecl(elementDecl);
}
for (XSModelGroupDecl modelGroupDecl : s.getModelGroupDecls().values()) {
modelGroupDecl(modelGroupDecl);
}
for (XSSimpleType simpleType : s.getSimpleTypes().values()) {
simpleType(simpleType);
}
}
use of com.sun.xml.xsom.XSElementDecl in project atlasmap by atlasmap.
the class SchemaWriter method particle.
public void particle(XSParticle part) {
BigInteger i;
StringBuilder buf = new StringBuilder();
i = part.getMaxOccurs();
if (i.equals(BigInteger.valueOf(XSParticle.UNBOUNDED)))
buf.append(" maxOccurs=\"unbounded\"");
else if (!i.equals(BigInteger.ONE))
buf.append(" maxOccurs=\"").append(i).append('\"');
i = part.getMinOccurs();
if (!i.equals(BigInteger.ONE))
buf.append(" minOccurs=\"").append(i).append('\"');
final String extraAtts = buf.toString();
part.getTerm().visit(new XSTermVisitor() {
public void elementDecl(XSElementDecl decl) {
if (decl.isLocal())
SchemaWriter.this.elementDecl(decl, extraAtts);
else {
// reference
println(MessageFormat.format("<element ref=\"'{'{0}'}'{1}\"{2}/>", decl.getTargetNamespace(), decl.getName(), extraAtts));
}
}
public void modelGroupDecl(XSModelGroupDecl decl) {
// reference
println(MessageFormat.format("<group ref=\"'{'{0}'}'{1}\"{2}/>", decl.getTargetNamespace(), decl.getName(), extraAtts));
}
public void modelGroup(XSModelGroup group) {
SchemaWriter.this.modelGroup(group, extraAtts);
}
public void wildcard(XSWildcard wc) {
SchemaWriter.this.wildcard("any", wc, extraAtts);
}
});
}
Aggregations