Java Code Examples for org.opensaml.xml.XMLObject#getSchemaType()

The following examples show how to use org.opensaml.xml.XMLObject#getSchemaType() . 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: AbstractXMLObjectMarshaller.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks to make sure the given XMLObject's schema type or element QName matches the target parameters given at
 * marshaller construction time.
 * 
 * @param xmlObject the XMLObject to marshall
 * 
 * @throws MarshallingException thrown if the given object is not or the required type
 */
protected void checkXMLObjectIsTarget(XMLObject xmlObject) throws MarshallingException {
    if (targetQName == null) {
        log.trace("Targeted QName checking is not available for this marshaller, XMLObject {} was not verified",
                xmlObject.getElementQName());
        return;
    }

    log.trace("Checking that {} meets target criteria", xmlObject.getElementQName());
    QName type = xmlObject.getSchemaType();
    if (type != null && type.equals(targetQName)) {
        log.trace("{} schema type matches target", xmlObject.getElementQName());
        return;
    } else {
        QName elementQName = xmlObject.getElementQName();
        if (elementQName.equals(targetQName)) {
            log.trace("{} element QName matches target", xmlObject.getElementQName());
            return;
        }
    }

    String errorMsg =
            "This marshaller only operations on " + targetQName + " elements not " + xmlObject.getElementQName();
    log.error(errorMsg);
    throw new MarshallingException(errorMsg);
}
 
Example 2
Source File: ValidatorSuite.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Validates the given XMLObject. Does NOT validate its children.
 * 
 * @param xmlObject the XMLObject to validate.
 * 
 * @throws ValidationException thrown if the XMLObject does not validate
 */
private void performValidation(XMLObject xmlObject) throws ValidationException {
    QName schemaType = xmlObject.getSchemaType();
    if (schemaType != null) {
        log.debug("Validating XMLObject {} against validators registered under its schema type {}", xmlObject
                .getElementQName(), schemaType);
        performValidation(schemaType, xmlObject);
    }

    log.debug("Validating XMLObject {} against validators registered under its element QName", xmlObject
            .getElementQName());
    performValidation(xmlObject.getElementQName(), xmlObject);
}
 
Example 3
Source File: AbstractXMLObjectMarshaller.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates the XSI type, schemaLocation, and noNamespaceSchemaLocation attributes for an XMLObject.
 * 
 * @param xmlObject the XMLObject
 * @param domElement the DOM element the namespaces will be added to
 * 
 * @throws MarshallingException thrown if the schema type information is invalid
 */
protected void marshallSchemaInstanceAttributes(XMLObject xmlObject, Element domElement)
        throws MarshallingException {

    if (!DatatypeHelper.isEmpty(xmlObject.getSchemaLocation())) {
        log.trace("Setting xsi:schemaLocation for XMLObject {} to {}", xmlObject.getElementQName(),
                xmlObject.getSchemaLocation());
        domElement.setAttributeNS(XMLConstants.XSI_NS, XMLConstants.XSI_PREFIX + ":schemaLocation",
                xmlObject.getSchemaLocation());
    }

    if (!DatatypeHelper.isEmpty(xmlObject.getNoNamespaceSchemaLocation())) {
        log.trace("Setting xsi:noNamespaceSchemaLocation for XMLObject {} to {}", xmlObject.getElementQName(),
                xmlObject.getNoNamespaceSchemaLocation());
        domElement.setAttributeNS(XMLConstants.XSI_NS, XMLConstants.XSI_PREFIX + ":noNamespaceSchemaLocation",
                xmlObject.getNoNamespaceSchemaLocation());
    }

    if (xmlObject.isNilXSBoolean() != null && xmlObject.isNil()) {
        log.trace("Setting xsi:nil for XMLObject {} to true", xmlObject.getElementQName());
        domElement.setAttributeNS(XMLConstants.XSI_NS, XMLConstants.XSI_PREFIX + ":nil", xmlObject.isNilXSBoolean()
                .toString());
    }

    QName type = xmlObject.getSchemaType();
    if (type == null) {
        return;
    }

    log.trace("Setting xsi:type attribute with for XMLObject {}", xmlObject.getElementQName());
    String typeLocalName = DatatypeHelper.safeTrimOrNullString(type.getLocalPart());
    String typePrefix = DatatypeHelper.safeTrimOrNullString(type.getPrefix());

    if (typeLocalName == null) {
        throw new MarshallingException("The type QName on XMLObject " + xmlObject.getElementQName()
                + " may not have a null local name");
    }

    if (type.getNamespaceURI() == null) {
        throw new MarshallingException("The type URI QName on XMLObject " + xmlObject.getElementQName()
                + " may not have a null namespace URI");
    }

    String attributeValue;
    if (typePrefix == null) {
        attributeValue = typeLocalName;
    } else {
        attributeValue = typePrefix + ":" + typeLocalName;
    }

    domElement.setAttributeNS(XMLConstants.XSI_NS, XMLConstants.XSI_PREFIX + ":type", attributeValue);
}