Java Code Examples for com.sun.xml.xsom.XSType#isComplexType()

The following examples show how to use com.sun.xml.xsom.XSType#isComplexType() . 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: Util.java    From jolie with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Implements
 * <code>Validation Rule: Schema-Validity Assessment (Element) 1.2.1.2.4</code> 
 */
private static boolean isSubstitutable( XSType _base, XSType derived ) {
    // too ugly to the point that it's almost unbearable.
    // I mean, it's not even transitive. Thus we end up calling this method
    // for each candidate
    if( _base.isComplexType() ) {
        XSComplexType base = _base.asComplexType();
        
        for( ; base!=derived; derived=derived.getBaseType() ) {
            if( base.isSubstitutionProhibited( derived.getDerivationMethod() ) )
                return false;    // Type Derivation OK (Complex)-1
        }
        return true;
    } else {
        // simple type don't have any @block
        return true;
    }
}
 
Example 2
Source File: XmlUtils.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void _valueToDocument( Value value, Element element, Document doc, XSType type ) {
	addForcedAttribute( value, element );
	if( type.isSimpleType() ) {
		element.appendChild( doc.createTextNode( value.strValue() ) );
	} else if( type.isComplexType() ) {
		String name;
		Value currValue;
		XSComplexType complexType = type.asComplexType();

		// Iterate over attributes
		Collection< ? extends XSAttributeUse > attributeUses = complexType.getAttributeUses();
		for( XSAttributeUse attrUse : attributeUses ) {
			name = attrUse.getDecl().getName();
			if( (currValue = getAttributeOrNull( value, name )) != null ) {
				element.setAttribute( name, currValue.strValue() );
			}
		}

		XSContentType contentType = complexType.getContentType();
		XSParticle particle = contentType.asParticle();
		if( contentType.asSimpleType() != null ) {
			element.appendChild( doc.createTextNode( value.strValue() ) );
		} else if( particle != null ) {
			XSTerm term = particle.getTerm();
			XSModelGroupDecl modelGroupDecl;
			XSModelGroup modelGroup = null;
			if( (modelGroupDecl = term.asModelGroupDecl()) != null ) {
				modelGroup = modelGroupDecl.getModelGroup();
			} else if( term.isModelGroup() ) {
				modelGroup = term.asModelGroup();
			}
			if( modelGroup != null ) {
				_valueToDocument( value, element, doc, modelGroup );
			}
		}
	}
}
 
Example 3
Source File: ElementDecl.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void updateSubstitutabilityMap() {
    ElementDecl parent = this;
    XSType type = this.getType(); 

    boolean rused = false;
    boolean eused = false;
    
    while( (parent=(ElementDecl)parent.getSubstAffiliation())!=null ) {
        
        if(parent.isSubstitutionDisallowed(XSType.SUBSTITUTION))
            continue;
        
        boolean rd = parent.isSubstitutionDisallowed(XSType.RESTRICTION);
        boolean ed = parent.isSubstitutionDisallowed(XSType.EXTENSION);

        if( (rd && rused) || ( ed && eused ) )   continue;
        
        XSType parentType = parent.getType();
        while(type!=parentType) {
            if(type.getDerivationMethod()==XSType.RESTRICTION)  rused = true;
            else                                                eused = true;
            
            type = type.getBaseType();
            if(type==null)  // parentType and type doesn't share the common base type. a bug in the schema.
                break;
            
            if( type.isComplexType() ) {
                rd |= type.asComplexType().isSubstitutionProhibited(XSType.RESTRICTION);
                ed |= type.asComplexType().isSubstitutionProhibited(XSType.EXTENSION);
            }
        }
        
        if( (rd && rused) || ( ed && eused ) )   continue;
        
        // this element can substitute "parent"
        parent.addSubstitutable(this);
    }
}