org.apache.xerces.xs.XSTerm Java Examples
The following examples show how to use
org.apache.xerces.xs.XSTerm.
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: CMXSDElementDeclaration.java From lemminx with Eclipse Public License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private void collectElementsDeclaration(XSTerm term, Collection<CMElementDeclaration> elements) { if (term == null) { return; } switch (term.getType()) { case XSConstants.WILDCARD: // XSWildcard wildcard = (XSWildcard) term; // ex : xsd:any document.getElements().forEach(e -> { if (!elements.contains(e)) { elements.add(e); } }); break; case XSConstants.MODEL_GROUP: XSObjectList particles = ((XSModelGroup) term).getParticles(); particles.forEach(p -> collectElementsDeclaration(((XSParticle) p).getTerm(), elements)); break; case XSConstants.ELEMENT_DECLARATION: XSElementDeclaration elementDeclaration = (XSElementDeclaration) term; document.collectElement(elementDeclaration, elements); break; } }
Example #2
Source File: SentinelXsdDumpMetadata.java From DataHubSystem with GNU Affero General Public License v3.0 | 6 votes |
private static void dumpParticle(String path, XSParticle particle) { XSTerm term = particle.getTerm(); switch (term.getType()) { case XSConstants.ELEMENT_DECLARATION: dumpElement(path, (XSElementDeclaration) term); break; case XSConstants.MODEL_GROUP: XSModelGroup model_group = (XSModelGroup) term; final XSObjectList particles = model_group.getParticles(); for (int ipar = 0; ipar < particles.getLength(); ipar++) { dumpParticle(path, (XSParticle) particles.item(ipar)); } break; default: System.err.println(path + " - UNKNOWN"); } }
Example #3
Source File: XmlTypeToJsonSchemaConverter.java From iaf with Apache License 2.0 | 6 votes |
private void buildSkippableArrayContainer(XSParticle childParticle, JsonObjectBuilder builder){ JsonObjectBuilder refBuilder = Json.createObjectBuilder(); handleParticle(refBuilder,childParticle,null, false); XSTerm childTerm = childParticle.getTerm(); if( childTerm instanceof XSElementDeclaration ){ XSElementDeclaration elementDeclaration=(XSElementDeclaration) childTerm; XSTypeDefinition elementTypeDefinition = elementDeclaration.getTypeDefinition(); JsonStructure definition =getDefinition(elementTypeDefinition, true); builder.add("type", "array"); if (elementDeclaration.getNillable()) { definition=nillable(definition); } builder.add("items", definition); } }
Example #4
Source File: XmlAligner.java From iaf with Apache License 2.0 | 6 votes |
protected void collectChildElements(XSParticle particle, Set<String> elementNames) { if (particle==null) { log.warn("collectChildElements() particle is null, is this a problem?"); return; } XSTerm term = particle.getTerm(); if (term==null) { throw new IllegalStateException("collectChildElements particle.term is null"); } if (term instanceof XSModelGroup) { XSModelGroup modelGroup = (XSModelGroup)term; XSObjectList particles = modelGroup.getParticles(); for (int i=0;i<particles.getLength();i++) { XSParticle childParticle = (XSParticle)particles.item(i); collectChildElements(childParticle, elementNames); } return; } if (term instanceof XSElementDeclaration) { XSElementDeclaration elementDeclaration=(XSElementDeclaration)term; String elementName=elementDeclaration.getName(); if (log.isTraceEnabled()) log.trace("collectChildElements() ElementDeclaration name ["+elementName+"]"); elementNames.add(elementName); } return; }
Example #5
Source File: XmlAligner.java From iaf with Apache License 2.0 | 6 votes |
protected Set<String> findMultipleOccurringChildElements(XSParticle particle) { Set<String> result=new HashSet<String>(); if (particle==null) { log.warn("findMultipleOccurringChildElements() typeDefinition particle is null, is this a problem?"); return result; } XSTerm term = particle.getTerm(); if (term==null) { throw new IllegalStateException("findMultipleOccurringChildElements particle.term is null"); } if (log.isTraceEnabled()) log.trace("findMultipleOccurringChildElements() term name ["+term.getName()+"] occurring unbounded ["+particle.getMaxOccursUnbounded()+"] max occur ["+particle.getMaxOccurs()+"] term ["+ToStringBuilder.reflectionToString(term)+"]"); if (particle.getMaxOccursUnbounded()||particle.getMaxOccurs()>1) { collectChildElements(particle,result); return result; } if (term instanceof XSModelGroup) { XSModelGroup modelGroup = (XSModelGroup)term; XSObjectList particles = modelGroup.getParticles(); if (log.isTraceEnabled()) log.trace("findMultipleOccurringChildElements() modelGroup particles ["+ToStringBuilder.reflectionToString(particles)+"]"); for (int i=0;i<particles.getLength();i++) { XSParticle childParticle = (XSParticle)particles.item(i); result.addAll(findMultipleOccurringChildElements(childParticle)); } } return result; }
Example #6
Source File: XmlTypeToJsonSchemaConverter.java From iaf with Apache License 2.0 | 5 votes |
public void handleParticle(JsonObjectBuilder builder, XSParticle particle, XSObjectList attributeUses, boolean forProperties) { if (particle==null) { throw new NullPointerException("particle is null"); } XSTerm term = particle.getTerm(); if (term==null) { throw new NullPointerException("particle.term is null"); } handleTerm(builder,term,attributeUses, particle.getMaxOccursUnbounded() || particle.getMaxOccurs()>1, forProperties); }
Example #7
Source File: XmlTypeToJsonSchemaConverter.java From iaf with Apache License 2.0 | 5 votes |
public void handleTerm(JsonObjectBuilder builder, XSTerm term, XSObjectList attributeUses, boolean multiOccurring, boolean forProperties) { if (term instanceof XSModelGroup) { handleModelGroup(builder, (XSModelGroup)term, attributeUses, forProperties); return; } if (term instanceof XSElementDeclaration) { XSElementDeclaration elementDeclaration = (XSElementDeclaration)term; if (elementDeclaration.getScope()==XSConstants.SCOPE_GLOBAL) { JsonObject typeDefininition = Json.createObjectBuilder().add("$ref", "#/definitions/"+elementDeclaration.getName()).build(); if (multiOccurring) { JsonObjectBuilder arrayBuilder = Json.createObjectBuilder(); arrayBuilder.add("type", "array"); arrayBuilder.add("items", typeDefininition); builder.add(elementDeclaration.getName(), arrayBuilder.build()); } else { builder.add(elementDeclaration.getName(), typeDefininition); } } else { handleElementDeclaration(builder, elementDeclaration, multiOccurring, true); } return; } if (term instanceof XSWildcard) { handleWildcard((XSWildcard)term); return; } throw new IllegalStateException("handleTerm unknown Term type ["+term.getClass().getName()+"]"); }
Example #8
Source File: XmlTypeToJsonSchemaConverter.java From iaf with Apache License 2.0 | 4 votes |
private void buildObject(JsonObjectBuilder builder, XSObjectList particles, XSObjectList attributeUses, String textAttribute, XSTypeDefinition baseType){ builder.add("type", "object"); builder.add("additionalProperties", false); JsonObjectBuilder propertiesBuilder = Json.createObjectBuilder(); List<String> requiredProperties = new ArrayList<String>(); if (attributeUses!=null) { for (int i=0; i< attributeUses.getLength(); i++) { XSAttributeUse attributeUse = (XSAttributeUse)attributeUses.get(i); XSAttributeDeclaration attributeDecl = attributeUse.getAttrDeclaration(); propertiesBuilder.add(attributePrefix+attributeDecl.getName(), getDefinition(attributeDecl.getTypeDefinition(), true)); } } if (textAttribute!=null && ((attributeUses!=null && attributeUses.getLength()>0) || (particles!=null && particles.getLength()>0))) { JsonObject elementType = baseType!=null ? getDefinition(baseType, true) : Json.createObjectBuilder().add("type", "string").build(); propertiesBuilder.add(textAttribute, elementType); } if (particles!=null) { for (int i=0;i<particles.getLength();i++) { XSParticle childParticle = (XSParticle)particles.item(i); if (log.isTraceEnabled()) log.trace("childParticle ["+i+"]["+ToStringBuilder.reflectionToString(childParticle,ToStringStyle.MULTI_LINE_STYLE)+"]"); XSTerm childTerm = childParticle.getTerm(); if (childTerm instanceof XSElementDeclaration) { XSElementDeclaration elementDeclaration = (XSElementDeclaration) childTerm; String elementName = elementDeclaration.getName(); if(elementName != null && childParticle.getMinOccurs() != 0){ requiredProperties.add(elementName); } } handleParticle(propertiesBuilder, childParticle, null, true); } } builder.add("properties", propertiesBuilder.build()); if(requiredProperties.size() > 0){ JsonArrayBuilder requiredPropertiesBuilder = Json.createArrayBuilder(); for (String requiredProperty : requiredProperties) { requiredPropertiesBuilder.add(requiredProperty); } builder.add("required", requiredPropertiesBuilder.build()); } }