org.apache.xerces.xs.XSComplexTypeDefinition Java Examples
The following examples show how to use
org.apache.xerces.xs.XSComplexTypeDefinition.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CMXSDDocument.java From lemminx with Eclipse Public License 2.0 | 6 votes |
/** * Returns the location of the local xs:element declared in the given XML Schema * <code>targetSchema</code> which matches the given XML element * <code>originElement</code> and null otherwise. * * @param originElement the XML element * @param targetSchema the XML Schema * @param enclosingType the enclosing type of the XS element declaration which * matches the XML element * @param grammar the Xerces grammar * @return the location of the global xs:element declared in the given XML * Schema <code>targetSchema</code> which matches the given XML element * <code>originElement</code> and null otherwise. */ private static LocationLink findLocalXSElement(DOMElement originElement, DOMDocument targetSchema, XSComplexTypeDefinition enclosingType, SchemaGrammar schemaGrammar) { // In local xs:element case, xs:element is declared inside a complex type // (enclosing type). // Xerces stores in the SchemaGrammar the locator (offset) for each complex type // (XSComplexTypeDecl) // Here we get the offset of the local enclosing complex type xs:complexType. // After that // we just loop of children of local xs:complexType and return the // location of // xs:element/@name which matches the tag name of the origin XML element // Get the location of the local xs:complexType int complexTypeOffset = getComplexTypeOffset(enclosingType, schemaGrammar); if (complexTypeOffset != -1) { // location of xs:complexType is found, find the xs:element declared inside the // xs:complexType DOMNode node = targetSchema.findNodeAt(complexTypeOffset); if (node != null && node.isElement() && node.hasChildNodes()) { return findXSElement((DOMElement) originElement, node.getChildNodes(), true); } } return null; }
Example #2
Source File: XmlAligner.java From iaf with Apache License 2.0 | 6 votes |
@Override public void startElement(String namespaceUri, String localName, String qName, Attributes attributes) throws SAXException { if (log.isTraceEnabled()) log.trace("startElement() uri ["+namespaceUri+"] localName ["+localName+"] qName ["+qName+"]"); // call getChildElementDeclarations with in startElement, to obtain all child elements of the current node typeDefinition=getTypeDefinition(psviProvider); if (typeDefinition==null) { throw new SaxException("No typeDefinition found for element ["+localName+"] in namespace ["+namespaceUri+"] qName ["+qName+"]"); } multipleOccurringElements.push(multipleOccurringChildElements); parentOfSingleMultipleOccurringChildElements.push(parentOfSingleMultipleOccurringChildElement); // call findMultipleOccurringChildElements, to obtain all child elements that could be part of an array if (typeDefinition instanceof XSComplexTypeDefinition) { XSComplexTypeDefinition complexTypeDefinition = (XSComplexTypeDefinition)typeDefinition; multipleOccurringChildElements=findMultipleOccurringChildElements(complexTypeDefinition.getParticle()); parentOfSingleMultipleOccurringChildElement=(ChildOccurrence.ONE_MULTIPLE_OCCURRING_ELEMENT==determineIsParentOfSingleMultipleOccurringChildElement(complexTypeDefinition.getParticle())); if (log.isTraceEnabled()) log.trace("element ["+localName+"] is parentOfSingleMultipleOccurringChildElement ["+parentOfSingleMultipleOccurringChildElement+"]"); } else { multipleOccurringChildElements=null; parentOfSingleMultipleOccurringChildElement=false; if (log.isTraceEnabled()) log.trace("element ["+localName+"] is a SimpleType, and therefor not multiple"); } super.startElement(namespaceUri, localName, qName, attributes); indentLevel++; context = new AlignmentContext(context, namespaceUri, localName, qName, attributes, typeDefinition, indentLevel, multipleOccurringChildElements, parentOfSingleMultipleOccurringChildElement); }
Example #3
Source File: XmlTypeToJsonSchemaConverter.java From iaf with Apache License 2.0 | 6 votes |
private void handleComplexTypeDefinitionOfSimpleContentType(XSComplexTypeDefinition complexTypeDefinition, boolean shouldCreateReferences, JsonObjectBuilder builder){ if(shouldCreateReferences){ String complexTypeDefinitionName = complexTypeDefinition.getName(); if(complexTypeDefinitionName == null && complexTypeDefinition.getContext() != null && complexTypeDefinition.getContext().getNamespaceItem() != null){ complexTypeDefinitionName = complexTypeDefinition.getContext().getName(); // complex type definition name defaults to name of context } if(complexTypeDefinitionName != null){ if (!(complexTypeDefinitionName.equals("anyType") && complexTypeDefinition.getNamespace().endsWith(XML_SCHEMA_NS))) { if (log.isTraceEnabled()) log.trace("handleComplexTypeDefinitionOfElementContentType creating ref!"); builder.add("$ref", definitionsPath+complexTypeDefinitionName); } return; } } XSObjectList attributeUses = complexTypeDefinition.getAttributeUses(); buildObject(builder, null, attributeUses, mixedContentLabel, complexTypeDefinition.getBaseType()); }
Example #4
Source File: XmlTypeToJsonSchemaConverter.java From iaf with Apache License 2.0 | 6 votes |
private void handleComplexTypeDefinitionOfElementContentType(XSComplexTypeDefinition complexTypeDefinition, boolean shouldCreateReferences, JsonObjectBuilder builder){ if(shouldCreateReferences){ String complexTypeDefinitionName = complexTypeDefinition.getName(); if(complexTypeDefinitionName == null && complexTypeDefinition.getContext() != null && complexTypeDefinition.getContext().getNamespaceItem() != null){ complexTypeDefinitionName = complexTypeDefinition.getContext().getName(); // complex type definition name defaults to name of context } if(complexTypeDefinitionName != null){ if (log.isTraceEnabled()) log.trace("handleComplexTypeDefinitionOfElementContentType creating ref!"); builder.add("$ref", definitionsPath+complexTypeDefinitionName); return; } } XSObjectList attributeUses = complexTypeDefinition.getAttributeUses(); XSParticle particle = complexTypeDefinition.getParticle(); handleParticle(builder, particle, attributeUses, false); }
Example #5
Source File: XMLToJSON.java From ts-reaktive with MIT License | 5 votes |
private boolean hasAttributes(XSElementDeclaration elmt) { if (elmt.getTypeDefinition() instanceof XSComplexTypeDefinition) { //Yes, we don't need to wrap this in an object if no attributes can ever occur. But Jackson does, so we must do so too. //A future format change could do the following to make the JSON a little nicer: // XSComplexTypeDefinition def = (XSComplexTypeDefinition) elmt.getTypeDefinition(); // return def.getAttributeUses().getLength() > 0; return true; } return false; }
Example #6
Source File: ToXml.java From iaf with Apache License 2.0 | 5 votes |
public void handleElementContents(XSElementDeclaration elementDeclaration, N node) throws SAXException { XSTypeDefinition typeDefinition = elementDeclaration.getTypeDefinition(); if (typeDefinition==null) { log.warn("handleElementContents typeDefinition is null"); handleSimpleTypedElement(elementDeclaration, null, node); return; } switch (typeDefinition.getTypeCategory()) { case XSTypeDefinition.SIMPLE_TYPE: if (log.isTraceEnabled()) log.trace("handleElementContents typeDefinition.typeCategory is SimpleType, no child elements"); handleSimpleTypedElement(elementDeclaration, (XSSimpleTypeDefinition)typeDefinition, node); return; case XSTypeDefinition.COMPLEX_TYPE: XSComplexTypeDefinition complexTypeDefinition=(XSComplexTypeDefinition)typeDefinition; switch (complexTypeDefinition.getContentType()) { case XSComplexTypeDefinition.CONTENTTYPE_EMPTY: if (log.isTraceEnabled()) log.trace("handleElementContents complexTypeDefinition.contentType is Empty, no child elements"); return; case XSComplexTypeDefinition.CONTENTTYPE_SIMPLE: if (log.isTraceEnabled()) log.trace("handleElementContents complexTypeDefinition.contentType is Simple, no child elements (only characters)"); handleSimpleTypedElement(elementDeclaration, null, node); return; case XSComplexTypeDefinition.CONTENTTYPE_ELEMENT: case XSComplexTypeDefinition.CONTENTTYPE_MIXED: handleComplexTypedElement(elementDeclaration,node); return; default: throw new IllegalStateException("handleElementContents complexTypeDefinition.contentType is not Empty,Simple,Element or Mixed, but ["+complexTypeDefinition.getContentType()+"]"); } default: throw new IllegalStateException("handleElementContents typeDefinition.typeCategory is not SimpleType or ComplexType, but ["+typeDefinition.getTypeCategory()+"] class ["+typeDefinition.getClass().getName()+"]"); } }
Example #7
Source File: XmlAligner.java From iaf with Apache License 2.0 | 5 votes |
public XSObjectList getAttributeUses(XSTypeDefinition typeDefinition) { if (typeDefinition==null) { if (log.isTraceEnabled()) log.trace("getAttributeUses typeDefinition is null"); return null; } if (typeDefinition instanceof XSComplexTypeDefinition) { XSComplexTypeDefinition complexTypeDefinition=(XSComplexTypeDefinition)typeDefinition; return complexTypeDefinition.getAttributeUses(); } if (log.isTraceEnabled()) log.trace("typeDefinition ["+typeDefinition.getClass().getSimpleName()+"] SimpleType, no attributes"); return null; }
Example #8
Source File: JsonElementContainer.java From iaf with Apache License 2.0 | 5 votes |
public JsonElementContainer(String name, boolean xmlArrayContainer, boolean repeatedElement, boolean skipArrayElementContainers, String attributePrefix, String mixedContentLabel, XSTypeDefinition typeDefinition) { this.name=name; this.xmlArrayContainer=xmlArrayContainer; this.repeatedElement=repeatedElement; this.skipArrayElementContainers=skipArrayElementContainers; this.attributePrefix=attributePrefix; this.mixedContentLabel=mixedContentLabel; if (typeDefinition!=null) { switch(typeDefinition.getTypeCategory()) { case XSTypeDefinition.SIMPLE_TYPE: setType(ScalarType.findType(((XSSimpleType)typeDefinition))); break; case XSTypeDefinition.COMPLEX_TYPE: XSComplexTypeDefinition complexTypeDefinition=(XSComplexTypeDefinition)typeDefinition; switch (complexTypeDefinition.getContentType()) { case XSComplexTypeDefinition.CONTENTTYPE_EMPTY: if (log.isTraceEnabled()) log.trace("JsonElementContainer complexTypeDefinition.contentType is Empty, no child elements"); break; case XSComplexTypeDefinition.CONTENTTYPE_SIMPLE: if (log.isTraceEnabled()) log.trace("JsonElementContainer complexTypeDefinition.contentType is Simple, no child elements (only characters)"); setType(ScalarType.findType((XSSimpleType)complexTypeDefinition.getBaseType())); break; case XSComplexTypeDefinition.CONTENTTYPE_ELEMENT: if (log.isTraceEnabled()) log.trace("JsonElementContainer complexTypeDefinition.contentType is Element"); break; case XSComplexTypeDefinition.CONTENTTYPE_MIXED: if (log.isTraceEnabled()) log.trace("JsonElementContainer complexTypeDefinition.contentType is Mixed"); break; } } } }
Example #9
Source File: XmlTypeToJsonSchemaConverter.java From iaf with Apache License 2.0 | 5 votes |
public JsonObject getDefinition(XSTypeDefinition typeDefinition, boolean shouldCreateReferences) { JsonObjectBuilder builder = Json.createObjectBuilder(); switch (typeDefinition.getTypeCategory()) { case XSTypeDefinition.COMPLEX_TYPE: XSComplexTypeDefinition complexTypeDefinition = (XSComplexTypeDefinition)typeDefinition; switch (complexTypeDefinition.getContentType()) { case XSComplexTypeDefinition.CONTENTTYPE_EMPTY: if (log.isTraceEnabled()) log.trace("getDefinition complexTypeDefinition.contentType is Empty, no child elements"); break; case XSComplexTypeDefinition.CONTENTTYPE_SIMPLE: if (log.isTraceEnabled()) log.trace("getDefinition complexTypeDefinition.contentType is Simple, no child elements (only characters)"); handleComplexTypeDefinitionOfSimpleContentType(complexTypeDefinition, shouldCreateReferences, builder); break; case XSComplexTypeDefinition.CONTENTTYPE_ELEMENT: if (log.isTraceEnabled()) log.trace("getDefinition complexTypeDefinition.contentType is Element, complexTypeDefinition ["+ToStringBuilder.reflectionToString(complexTypeDefinition,ToStringStyle.MULTI_LINE_STYLE)+"]"); handleComplexTypeDefinitionOfElementContentType(complexTypeDefinition, shouldCreateReferences, builder); break; case XSComplexTypeDefinition.CONTENTTYPE_MIXED: if (log.isTraceEnabled()) log.trace("getDefinition complexTypeDefinition.contentType is Mixed"); handleComplexTypeDefinitionOfSimpleContentType(complexTypeDefinition, shouldCreateReferences, builder); break; default: throw new IllegalStateException("getDefinition complexTypeDefinition.contentType is not Empty,Simple,Element or Mixed, but ["+complexTypeDefinition.getContentType()+"]"); } if (log.isTraceEnabled()) log.trace(ToStringBuilder.reflectionToString(complexTypeDefinition,ToStringStyle.MULTI_LINE_STYLE)); break; case XSTypeDefinition.SIMPLE_TYPE: handleSimpleTypeDefinition(typeDefinition, builder); break; default: throw new IllegalStateException("getDefinition typeDefinition.typeCategory is not Complex or Simple, but ["+typeDefinition.getTypeCategory()+"]"); } return builder.build(); }
Example #10
Source File: XSContentModel.java From jlibs with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public String toString(XSComplexTypeDefinition complexType, XMLDocument doc){ buff.setLength(0); this.doc = doc; WalkerUtil.walk(new PreorderWalker(complexType, new XSNavigator()), this); this.doc = null; return buff.toString(); }
Example #11
Source File: XMLToJSON.java From ts-reaktive with MIT License | 5 votes |
private Map<QName,XSParticle> getValidSubTags(XSElementDeclaration elmt) { if (!(elmt.getTypeDefinition() instanceof XSComplexTypeDefinition)) { return HashMap.empty(); } XSComplexTypeDefinition type = (XSComplexTypeDefinition) elmt.getTypeDefinition(); if (type.getParticle() == null || !(type.getParticle().getTerm() instanceof XSModelGroup)) { return HashMap.empty(); } XSModelGroup group = (XSModelGroup) type.getParticle().getTerm(); if (group.getCompositor() != XSModelGroup.COMPOSITOR_SEQUENCE && group.getCompositor() != XSModelGroup.COMPOSITOR_CHOICE) { return HashMap.empty(); } // We don't care whether it's SEQUENCE or CHOICE, we only want to know what are the valid sub-elements at this level. XSObjectList particles = group.getParticles(); Map<QName,XSParticle> content = HashMap.empty(); for (int j = 0; j < particles.getLength(); j++) { XSParticle sub = (XSParticle) particles.get(j); if (sub.getTerm() instanceof XSElementDeclaration) { XSElementDeclaration term = (XSElementDeclaration) sub.getTerm(); content = content.put(new QName(term.getNamespace(), term.getName()), sub); } } return content; }
Example #12
Source File: CMXSDElementDeclaration.java From lemminx with Eclipse Public License 2.0 | 5 votes |
@Override public boolean isEmpty() { XSTypeDefinition typeDefinition = elementDeclaration.getTypeDefinition(); if (typeDefinition != null && typeDefinition.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) { XSComplexTypeDefinition complexTypeDefinition = (XSComplexTypeDefinition) typeDefinition; return complexTypeDefinition.getContentType() == XSComplexTypeDefinition.CONTENTTYPE_EMPTY; } return false; }
Example #13
Source File: CMXSDElementDeclaration.java From lemminx with Eclipse Public License 2.0 | 5 votes |
private void collectElementsDeclaration(XSComplexTypeDefinition typeDefinition, Collection<CMElementDeclaration> elements) { XSParticle particle = typeDefinition.getParticle(); if (particle != null) { collectElementsDeclaration(particle.getTerm(), elements); } }
Example #14
Source File: CMXSDElementDeclaration.java From lemminx with Eclipse Public License 2.0 | 5 votes |
private void collectElementsDeclaration(XSElementDeclaration elementDecl, Collection<CMElementDeclaration> elements) { XSTypeDefinition typeDefinition = elementDecl.getTypeDefinition(); switch (typeDefinition.getTypeCategory()) { case XSTypeDefinition.SIMPLE_TYPE: // TODO... break; case XSTypeDefinition.COMPLEX_TYPE: collectElementsDeclaration((XSComplexTypeDefinition) typeDefinition, elements); break; } }
Example #15
Source File: CMXSDElementDeclaration.java From lemminx with Eclipse Public License 2.0 | 5 votes |
private void collectAttributesDeclaration(XSComplexTypeDefinition typeDefinition, Collection<CMAttributeDeclaration> attributes) { XSObjectList list = typeDefinition.getAttributeUses(); if (list != null) { for (int i = 0; i < list.getLength(); i++) { XSObject object = list.item(i); if (object.getType() == XSConstants.ATTRIBUTE_USE) { XSAttributeUse attributeUse = (XSAttributeUse) object; attributes.add(new CMXSDAttributeDeclaration(attributeUse)); } } } }
Example #16
Source File: CMXSDElementDeclaration.java From lemminx with Eclipse Public License 2.0 | 5 votes |
private void collectAttributesDeclaration(XSElementDeclaration elementDecl, Collection<CMAttributeDeclaration> attributes) { XSTypeDefinition typeDefinition = elementDecl.getTypeDefinition(); switch (typeDefinition.getTypeCategory()) { case XSTypeDefinition.SIMPLE_TYPE: // TODO... break; case XSTypeDefinition.COMPLEX_TYPE: collectAttributesDeclaration((XSComplexTypeDefinition) typeDefinition, attributes); break; } }
Example #17
Source File: CMXSDDocument.java From lemminx with Eclipse Public License 2.0 | 5 votes |
private static LocationLink findLocalXSAttribute(DOMAttr originAttribute, DOMDocument targetSchema, XSComplexTypeDefinition enclosingType, SchemaGrammar schemaGrammar) { int complexTypeOffset = getComplexTypeOffset(enclosingType, schemaGrammar); if (complexTypeOffset != -1) { // location of xs:complexType is found, find the xs:attribute declared inside // the // xs:complexType DOMNode node = targetSchema.findNodeAt(complexTypeOffset); if (node != null && node.isElement() && node.hasChildNodes()) { return findXSAttribute(originAttribute, node.getChildNodes(), true); } } return null; }
Example #18
Source File: CMXSDDocument.java From lemminx with Eclipse Public License 2.0 | 5 votes |
/** * Returns the offset where the local xs:complexType is declared and -1 * otherwise. * * @param complexType the local complex type * @param grammar the grammar where local complex type is declared. * @return the offset where the local xs:complexType is declared and -1 * otherwise. */ private static int getComplexTypeOffset(XSComplexTypeDefinition complexType, SchemaGrammar grammar) { try { // Xerces stores in SchemaGrammar instance, the location in 2 arrays: // - fCTLocators array of locator // - fComplexTypeDecls array of XSComplexTypeDecl // As it's not an API, we must use Java Reflection to get those 2 arrays Field f = SchemaGrammar.class.getDeclaredField("fCTLocators"); f.setAccessible(true); SimpleLocator[] fCTLocators = (SimpleLocator[]) f.get(grammar); // Find the location offset of the given complexType XSComplexTypeDecl[] fComplexTypeDecls = getXSComplexTypeDecls(grammar); for (int i = 0; i < fComplexTypeDecls.length; i++) { if (complexType.equals(fComplexTypeDecls[i])) { XMLLocator locator = fCTLocators[i]; return locator != null ? locator.getCharacterOffset() : -1; } } } catch (Exception e) { LOGGER.log(Level.SEVERE, "Error while retrieving offset of local xs:complexType'" + complexType.getName() + "'.", e); } // Offset where xs:complexType is declared cannot be found return -1; }
Example #19
Source File: CMXSDDocument.java From lemminx with Eclipse Public License 2.0 | 4 votes |
@Override public LocationLink findTypeLocation(DOMNode originNode) { DOMElement originElement = null; DOMAttr originAttribute = null; if (originNode.isElement()) { originElement = (DOMElement) originNode; } else if (originNode.isAttribute()) { originAttribute = (DOMAttr) originNode; originElement = originAttribute.getOwnerElement(); } if (originElement == null || originElement.getLocalName() == null) { return null; } // Try to retrieve XSD element declaration from the given element. CMXSDElementDeclaration elementDeclaration = (CMXSDElementDeclaration) findCMElement(originElement, originElement.getNamespaceURI()); if (elementDeclaration == null) { return null; } // Try to find the Xerces xs:element (which stores the offset) bound with the // XSElementDeclaration // case when xs:element is declared inside xs:choice, xs:all, xs:sequence, etc ElementImpl xercesElement = findLocalMappedXercesElement(elementDeclaration.getElementDeclaration(), xsLoader); // case when xs:element is declared as global or inside xs:complexType SchemaGrammar schemaGrammar = getOwnerSchemaGrammar(elementDeclaration.getElementDeclaration()); if (schemaGrammar == null && xercesElement == null) { return null; } String documentURI = xercesElement != null ? xercesElement.getOwnerDocument().getDocumentURI() : getSchemaURI(schemaGrammar); if (URIUtils.isFileResource(documentURI)) { // Only XML Schema file is supported. In the case of XML file is bound with an // HTTP url and cache is enable, documentURI is a file uri from the cache // folder. // Xerces doesn't give the capability to know the location of xs:element, // xs:attribute. // To retrieve the proper location of xs:element, xs:attribute, we load the XML // Schema in the DOM Document which stores location. DOMDocument targetSchema = DOMUtils.loadDocument(documentURI, originNode.getOwnerDocument().getResolverExtensionManager()); if (targetSchema == null) { return null; } if (originAttribute != null) { // find location of xs:attribute declaration String attributeName = originAttribute.getName(); CMXSDAttributeDeclaration attributeDeclaration = (CMXSDAttributeDeclaration) elementDeclaration .findCMAttribute(attributeName); if (attributeDeclaration != null) { XSAttributeDeclaration attributeDecl = attributeDeclaration.getAttrDeclaration(); if (attributeDecl.getScope() == XSConstants.SCOPE_LOCAL) { return findLocalXSAttribute(originAttribute, targetSchema, attributeDecl.getEnclosingCTDefinition(), schemaGrammar); } } } else { // find location of xs:element declaration boolean globalElement = elementDeclaration.getElementDeclaration() .getScope() == XSElementDecl.SCOPE_GLOBAL; if (globalElement) { // global xs:element return findGlobalXSElement(originElement, targetSchema); } else { // local xs:element // 1) use the Xerces xs:element strategy if (xercesElement != null) { return findLocalXSElement(originElement, targetSchema, xercesElement.getCharacterOffset()); } // 2) use the Xerces xs:complexType strategy XSComplexTypeDefinition complexTypeDefinition = elementDeclaration.getElementDeclaration() .getEnclosingCTDefinition(); if (complexTypeDefinition != null) { return findLocalXSElement(originElement, targetSchema, complexTypeDefinition, schemaGrammar); } } } } return null; }
Example #20
Source File: SentinelXsdDumpMetadata.java From DataHubSystem with GNU Affero General Public License v3.0 | 4 votes |
private static void dumpElement(String path, XSElementDeclaration element) { String output_path = "" + path + "/" + element.getName(); XSTypeDefinition type = element.getTypeDefinition(); if (type.getName().endsWith("Array")) { // System.err.println(element.getName() + " - " + type.getName() // + " SKIPPED !"); return; } if (((type.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) || ((XSComplexTypeDefinition) type) .getContentType() == XSComplexTypeDefinition.CONTENTTYPE_SIMPLE)) { if (includesBaseType(type, "string") || includesBaseType(type, "integer") || includesBaseType(type, "boolean")) { // System.out.println(" <metadata name=\"" + // element.getName() + "\" type=\"text/plain\" category=\"\">"); // System.out.println(" " + // indexedName(element.getName()) // + " { local:values($doc" + output_path + ") }"); // System.out.println(" </metadata>,"); System.out.println(" local:getMetadata('" + element.getName() + "', '" + indexedName(element.getName()) + "',"); System.out.println(" $doc" + output_path + "),"); } } else { dumpParticle(output_path, ((XSComplexTypeDefinition)type).getParticle()); } }
Example #21
Source File: ToXml.java From iaf with Apache License 2.0 | 4 votes |
public List<XSParticle> getBestChildElementPath(XSElementDeclaration elementDeclaration, N node, boolean silent) throws SAXException { XSTypeDefinition typeDefinition = elementDeclaration.getTypeDefinition(); if (typeDefinition==null) { log.warn("getBestChildElementPath typeDefinition is null"); return null; } switch (typeDefinition.getTypeCategory()) { case XSTypeDefinition.SIMPLE_TYPE: if (log.isTraceEnabled()) log.trace("getBestChildElementPath typeDefinition.typeCategory is SimpleType, no child elements"); return null; case XSTypeDefinition.COMPLEX_TYPE: XSComplexTypeDefinition complexTypeDefinition=(XSComplexTypeDefinition)typeDefinition; switch (complexTypeDefinition.getContentType()) { case XSComplexTypeDefinition.CONTENTTYPE_EMPTY: if (log.isTraceEnabled()) log.trace("getBestChildElementPath complexTypeDefinition.contentType is Empty, no child elements"); return null; case XSComplexTypeDefinition.CONTENTTYPE_SIMPLE: if (log.isTraceEnabled()) log.trace("getBestChildElementPath complexTypeDefinition.contentType is Simple, no child elements (only characters)"); return null; case XSComplexTypeDefinition.CONTENTTYPE_ELEMENT: case XSComplexTypeDefinition.CONTENTTYPE_MIXED: XSParticle particle = complexTypeDefinition.getParticle(); if (particle==null) { throw new IllegalStateException("getBestChildElementPath complexTypeDefinition.particle is null for Element or Mixed contentType"); // log.warn("typeDefinition particle is null, is this a problem?"); // return null; } if (log.isTraceEnabled()) log.trace("typeDefinition particle ["+ToStringBuilder.reflectionToString(particle,ToStringStyle.MULTI_LINE_STYLE)+"]"); List<XSParticle> result=new LinkedList<XSParticle>(); List<String> failureReasons=new LinkedList<String>(); if (getBestMatchingElementPath(elementDeclaration, node, particle, result, failureReasons)) { return result; } String msg="Cannot find path:"; for (String reason:failureReasons) { msg+='\n'+reason; } if (!silent) { handleError(msg); } return null; default: throw new IllegalStateException("getBestChildElementPath complexTypeDefinition.contentType is not Empty,Simple,Element or Mixed, but ["+complexTypeDefinition.getContentType()+"]"); } default: throw new IllegalStateException("getBestChildElementPath typeDefinition.typeCategory is not SimpleType or ComplexType, but ["+typeDefinition.getTypeCategory()+"] class ["+typeDefinition.getClass().getName()+"]"); } }