org.apache.xerces.xs.XSModelGroup Java Examples

The following examples show how to use org.apache.xerces.xs.XSModelGroup. 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 vote down vote up
@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 vote down vote up
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: XSContentModel.java    From jlibs with Apache License 2.0 6 votes vote down vote up
private void appendCompositor(Path path){
    if(buff.length()>0 && buff.charAt(buff.length()-1)!='('){
        XSModelGroup modelGroup = (XSModelGroup)path.getParentPath(XSModelGroup.class).getElement();
        switch(modelGroup.getCompositor()){
            case XSModelGroup.COMPOSITOR_SEQUENCE:
                buff.append(" , ");
                break;
            case XSModelGroup.COMPOSITOR_ALL:
                buff.append(" ; ");
                break;
            case XSModelGroup.COMPOSITOR_CHOICE:
                buff.append(" | ");
                break;
        }
    }
}
 
Example #4
Source File: XmlTypeToJsonSchemaConverter.java    From iaf with Apache License 2.0 6 votes vote down vote up
private void handleModelGroup(JsonObjectBuilder builder, XSModelGroup modelGroup, XSObjectList attributeUses, boolean forProperties){
	short compositor = modelGroup.getCompositor();			
	XSObjectList particles = modelGroup.getParticles();
	if (log.isTraceEnabled()) log.trace("modelGroup ["+ToStringBuilder.reflectionToString(modelGroup,ToStringStyle.MULTI_LINE_STYLE)+"]");
	if (log.isTraceEnabled()) log.trace("modelGroup particles ["+ToStringBuilder.reflectionToString(particles,ToStringStyle.MULTI_LINE_STYLE)+"]");
	switch (compositor) {
	case XSModelGroup.COMPOSITOR_SEQUENCE:
	case XSModelGroup.COMPOSITOR_ALL:
		handleCompositorsAllAndSequence(builder, particles, attributeUses);
		return;
	case XSModelGroup.COMPOSITOR_CHOICE:
		handleCompositorChoice(builder, particles, forProperties);	
		return;
	default:
		throw new IllegalStateException("handleModelGroup modelGroup.compositor is not COMPOSITOR_SEQUENCE, COMPOSITOR_ALL or COMPOSITOR_CHOICE, but ["+compositor+"]");
	} 
}
 
Example #5
Source File: XmlAligner.java    From iaf with Apache License 2.0 6 votes vote down vote up
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 #6
Source File: XmlAligner.java    From iaf with Apache License 2.0 6 votes vote down vote up
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 #7
Source File: XMLToJSON.java    From ts-reaktive with MIT License 5 votes vote down vote up
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 #8
Source File: XmlTypeToJsonSchemaConverter.java    From iaf with Apache License 2.0 5 votes vote down vote up
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 #9
Source File: XSDisplayFilter.java    From jlibs with Apache License 2.0 4 votes vote down vote up
protected boolean process(XSModelGroup modelGroup){
    return modelGroup.getCompositor()!=XSModelGroup.COMPOSITOR_SEQUENCE;
}
 
Example #10
Source File: XSContentModel.java    From jlibs with Apache License 2.0 4 votes vote down vote up
protected Processor process(XSModelGroup modelGroup){
    return modelGroupProcessor;
}
 
Example #11
Source File: XSContentModel.java    From jlibs with Apache License 2.0 4 votes vote down vote up
@Override
public boolean preProcess(XSModelGroup modelGroup, Path path){
    appendCompositor(path);
    buff.append('(');
    return true;
}
 
Example #12
Source File: XSContentModel.java    From jlibs with Apache License 2.0 4 votes vote down vote up
@Override
public void postProcess(XSModelGroup modelGroup, Path path){
    buff.append(')');
    appendCardinality(path);
}