use of com.sun.xml.xsom.XSElementDecl in project citygml4j by citygml4j.
the class ElementDecl method getRootSubsitutionGroup.
public QName getRootSubsitutionGroup() {
XSElementDecl tmp = element;
XSElementDecl head = null;
while ((tmp = tmp.getSubstAffiliation()) != null) head = tmp;
return (head != null) ? new QName(head.getTargetNamespace(), head.getName()) : null;
}
use of com.sun.xml.xsom.XSElementDecl in project citygml4j by citygml4j.
the class Schema method getElementDecl.
public ElementDecl getElementDecl(String localName, ElementDecl parent) {
ElementDecl element = null;
HashMap<String, ElementDecl> local = null;
if (parent != null) {
local = localElements.get(parent);
if (local != null)
element = local.get(localName);
}
if (element == null) {
List<ElementDecl> candidates = getElementDecls(localName);
if (candidates.size() == 1)
element = candidates.get(0);
else if (parent != null) {
List<XSElementDecl> children = parent.getChildElements();
for (ElementDecl candidate : candidates) {
if (candidate.isGlobal()) {
for (XSElementDecl child : children) {
if (child.canBeSubstitutedBy(candidate.getXSElementDecl())) {
element = candidate;
break;
}
}
if (element != null)
break;
} else {
if (children.contains(candidate.getXSElementDecl())) {
element = candidate;
break;
}
}
}
if (element != null) {
if (local == null) {
local = new HashMap<String, ElementDecl>();
localElements.put(parent, local);
}
local.put(localName, element);
}
}
}
return element;
}
use of com.sun.xml.xsom.XSElementDecl in project schema2proto by entur.
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 schema2proto by entur.
the class SchemaParser method navigateSubTypes.
private void navigateSubTypes(XSParticle parentParticle, MessageType messageType, Set<Object> processedXmlObjects, XSSchemaSet schemaSet, String enclosingName, String targetNamespace, XSComplexType enclosingType) {
XSTerm currTerm = parentParticle.getTerm();
Label label = getLabel(parentParticle, currTerm);
Options fieldOptions = getFieldOptions(parentParticle);
if (currTerm.isElementDecl()) {
XSElementDecl currElementDecl = currTerm.asElementDecl();
if (!processedXmlObjects.contains(currElementDecl)) {
processedXmlObjects.add(currElementDecl);
XSType type = currElementDecl.getType();
String fieldDoc = resolveDocumentationAnnotation(currElementDecl, false);
Location fieldLocation = getLocation(currElementDecl);
String packageName = NamespaceHelper.xmlNamespaceToProtoFieldPackagename(type.getTargetNamespace(), configuration.forceProtoPackage);
if (type.isSimpleType()) {
if (type.asSimpleType().isRestriction() && type.asSimpleType().getFacet(XSFacet.FACET_ENUMERATION) != null) {
String enumName = createEnum(currElementDecl.getName(), type.asSimpleType().asRestriction(), type.isGlobal() ? null : messageType);
Field field = new Field(packageName, fieldLocation, label, currElementDecl.getName(), fieldDoc, messageType.getNextFieldNum(), enumName, fieldOptions, true);
addField(messageType, field);
} else {
String typeName = findFieldType(type);
Field field = new Field(basicTypes.contains(typeName) ? null : packageName, fieldLocation, label, currElementDecl.getName(), fieldDoc, messageType.getNextFieldNum(), typeName, fieldOptions, true);
addField(messageType, field);
}
} else {
if (type.isGlobal()) {
Set<XSElementDecl> substitutables = (Set<XSElementDecl>) currElementDecl.getSubstitutables();
LinkedHashSet<XSElementDecl> subsumptionSubstitutables = new LinkedHashSet<>();
if (configuration.derivationBySubsumption && type.isComplexType() && type.asComplexType().isAbstract()) {
// https://cs.au.dk/~amoeller/XML/schemas/xmlschema-inheritance.html
findGlobalElementsBySubsumption(schemaSet, subsumptionSubstitutables, (XSComplexType) type);
}
if (substitutables.size() <= 1 && subsumptionSubstitutables.isEmpty()) {
Field field = new Field(packageName, fieldLocation, label, currElementDecl.getName(), fieldDoc, messageType.getNextFieldNum(), type.getName(), fieldOptions, true);
addField(messageType, field);
} else {
if (label == Label.REPEATED) {
String wrapperName = createWrapperName(messageType, XSModelGroup.Compositor.CHOICE, enclosingName, (XSComplexType) type);
LOGGER.debug("Repeated element with multiple subs, created wrapper name {} from {}", wrapperName, enclosingName);
messageType = createWrapper(wrapperName, messageType, currElementDecl.getName(), type.getTargetNamespace(), parentParticle, fieldDoc, fieldLocation, (XSComplexType) type, "Generated wrapper for repeated oneOfs");
}
String oneOfName = currElementDecl.getType().getName();
// Current element is always a substitute for itself
if (substitutables.size() == 1 && substitutables.iterator().next() == currElementDecl && !subsumptionSubstitutables.isEmpty()) {
oneOfName = currElementDecl.getName();
}
List<Field> fields = new ArrayList<>();
OneOf oneOf = new OneOf(oneOfName, fieldDoc, fields, null);
messageType.oneOfs().add(oneOf);
LinkedHashSet<XSElementDecl> allSubtitutables = new LinkedHashSet<>();
allSubtitutables.addAll(substitutables);
allSubtitutables.addAll(subsumptionSubstitutables);
for (XSElementDecl substitutable : allSubtitutables) {
if (substitutable.isAbstract() || (substitutable.getType().isComplexType() && substitutable.getType().asComplexType().isAbstract())) {
// No abstract concept in protobuf, only concrete messages
} else {
addOneOfField(messageType, schemaSet, fieldOptions, fieldLocation, oneOf, substitutable);
}
}
}
} else {
// Local
MessageType referencedMessageType = processComplexType(type.asComplexType(), currElementDecl.getName(), schemaSet, null, null);
Field field = new Field(packageName, fieldLocation, label, currElementDecl.getName(), fieldDoc, messageType.getNextFieldNum(), referencedMessageType.getName(), fieldOptions, true);
addField(messageType, field);
if (!currElementDecl.isGlobal()) {
messageType.nestedTypes().add(referencedMessageType);
localTypes.add(new LocalType(type, referencedMessageType, messageType, field, NamespaceHelper.xmlNamespaceToProtoPackage(type.getTargetNamespace(), configuration.forceProtoPackage), enclosingType));
}
}
}
}
} else if (currTerm.isWildcard()) {
Location fieldLocation;
if (currTerm.getLocator() != null) {
fieldLocation = getLocation(currTerm.asWildcard());
} else {
fieldLocation = messageType.location();
}
Field field = new Field(null, fieldLocation, label, "any", resolveDocumentationAnnotation(currTerm.asWildcard(), false), messageType.getNextFieldNum(), "anyType", fieldOptions, true);
addField(messageType, field);
} else {
XSModelGroup modelGroup = getModelGroup(currTerm);
if (modelGroup != null) {
processGroup(modelGroup, parentParticle, messageType, processedXmlObjects, schemaSet, enclosingName, targetNamespace, enclosingType);
}
}
}
use of com.sun.xml.xsom.XSElementDecl in project schema2proto by entur.
the class SchemaTreeTraverser method particle.
/* (non-Javadoc)
* @see com.sun.xml.xsom.visitor.XSContentTypeVisitor#particle(com.sun.xml.xsom.XSParticle)
*/
public void particle(XSParticle part) {
BigInteger i;
StringBuffer buf = new StringBuffer();
i = part.getMaxOccurs();
if (i.equals(BigInteger.valueOf(XSParticle.UNBOUNDED))) {
buf.append(" maxOccurs=\"unbounded\"");
} else {
if (!i.equals(BigInteger.ONE)) {
buf.append(" maxOccurs=\"" + i + "\"");
}
}
i = part.getMinOccurs();
if (!i.equals(BigInteger.ONE)) {
buf.append(" minOccurs=\"" + i + "\"");
}
final String extraAtts = buf.toString();
part.getTerm().visit(new XSTermVisitor() {
public void elementDecl(XSElementDecl decl) {
if (decl.isLocal()) {
SchemaTreeTraverser.this.elementDecl(decl, extraAtts);
} else {
// reference
SchemaTreeNode newNode = new SchemaTreeNode(MessageFormat.format("Element ref=\"'{'{0}'}'{1}\"{2}", new Object[] { decl.getTargetNamespace(), decl.getName(), extraAtts }), decl.getLocator());
currNode.add(newNode);
}
}
public void modelGroupDecl(XSModelGroupDecl decl) {
// reference
SchemaTreeNode newNode = new SchemaTreeNode(MessageFormat.format("Group ref=\"'{'{0}'}'{1}\"{2}", new Object[] { decl.getTargetNamespace(), decl.getName(), extraAtts }), decl.getLocator());
currNode.add(newNode);
}
public void modelGroup(XSModelGroup group) {
SchemaTreeTraverser.this.modelGroup(group, extraAtts);
}
public void wildcard(XSWildcard wc) {
SchemaTreeTraverser.this.wildcard(wc, extraAtts);
}
});
}
Aggregations