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

The following examples show how to use org.opensaml.xml.XMLObject#getOrderedChildren() . 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: ValidatorSuite.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Evaluates the registered validators against the given XMLObject and it's children.
 * 
 * @param xmlObject the XMLObject to validate
 * 
 * @throws ValidationException thrown if the element is not valid
 */
public void validate(XMLObject xmlObject) throws ValidationException {
    if (xmlObject == null) {
        return;
    }

    log.debug("Beginning to verify XMLObject {} and its children", xmlObject.getElementQName());
    performValidation(xmlObject);

    List<XMLObject> children = xmlObject.getOrderedChildren();
    if (children != null) {
        for (XMLObject child : children) {
            validate(child);
        }
    }
}
 
Example 2
Source File: AbstractValidatingXMLObject.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Recursive method used to validate all the children of the given XMLObject that implement
 * {@link ValidatingXMLObject}. Note, this can be a very expensive operation.
 * 
 * @param xmlObject xmlObject whose descendants should be validated
 * 
 * @throws ValidationException thrown if any child objects are not valid
 */
protected void validateChildren(XMLObject xmlObject) throws ValidationException {
    for (XMLObject childObject : xmlObject.getOrderedChildren()) {
        if(childObject == null){
            continue;
        }
        
        if (childObject instanceof ValidatingXMLObject) {
            ((ValidatingXMLObject) childObject).validate(false);
        } else {
            log.debug("{} does not implement ValidatingXMLObject, ignoring it.", childObject.getElementQName());
        }

        if (childObject.hasChildren()) {
            validateChildren(childObject);
        }
    }
}
 
Example 3
Source File: AbstractXMLObjectMarshaller.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Marshalls the child elements of the given XMLObject.
 * 
 * @param xmlObject the XMLObject whose children will be marshalled
 * @param domElement the DOM element that will recieved the marshalled children
 * 
 * @throws MarshallingException thrown if there is a problem marshalling a child element
 */
protected void marshallChildElements(XMLObject xmlObject, Element domElement) throws MarshallingException {
    log.trace("Marshalling child elements for XMLObject {}", xmlObject.getElementQName());

    List<XMLObject> childXMLObjects = xmlObject.getOrderedChildren();
    if (childXMLObjects != null && childXMLObjects.size() > 0) {
        for (XMLObject childXMLObject : childXMLObjects) {
            if (childXMLObject == null) {
                continue;
            }

            log.trace("Getting marshaller for child XMLObject {}", childXMLObject.getElementQName());
            Marshaller marshaller = marshallerFactory.getMarshaller(childXMLObject);

            if (marshaller == null) {
                marshaller = marshallerFactory.getMarshaller(Configuration.getDefaultProviderQName());

                if (marshaller == null) {
                    String errorMsg =
                            "No marshaller available for " + childXMLObject.getElementQName() + ", child of "
                                    + xmlObject.getElementQName();
                    log.error(errorMsg);
                    throw new MarshallingException(errorMsg);
                } else {
                    log.trace("No marshaller was registered for {}, child of {}. Using default marshaller",
                            childXMLObject.getElementQName(), xmlObject.getElementQName());
                }
            }

            log.trace("Marshalling {} and adding it to DOM", childXMLObject.getElementQName());
            marshaller.marshall(childXMLObject, domElement);
        }
    } else {
        log.trace("No child elements to marshall for XMLObject {}", xmlObject.getElementQName());
    }
}
 
Example 4
Source File: SAML2Helper.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Gets the earliest expiration instant within a metadata tree.
 * 
 * @param xmlObject the metadata
 * @param earliestExpiration the earliest expiration instant
 * @param now when this method was called
 * 
 * @return the earliest expiration instant within a metadata tree
 */
public static DateTime getEarliestExpiration(XMLObject xmlObject, DateTime earliestExpiration, DateTime now) {

    // expiration time for a specific element
    DateTime elementExpirationTime;

    // Test duration based times
    if (xmlObject instanceof CacheableSAMLObject) {
        CacheableSAMLObject cacheInfo = (CacheableSAMLObject) xmlObject;

        if (cacheInfo.getCacheDuration() != null && cacheInfo.getCacheDuration().longValue() > 0) {
            elementExpirationTime = now.plus(cacheInfo.getCacheDuration().longValue());
            if (earliestExpiration == null) {
                earliestExpiration = elementExpirationTime;
            } else {
                if (elementExpirationTime != null && elementExpirationTime.isBefore(earliestExpiration)) {
                    earliestExpiration = elementExpirationTime;
                }
            }
        }
    }

    // Test instant based times
    if (xmlObject instanceof TimeBoundSAMLObject) {
        TimeBoundSAMLObject timeBoundObject = (TimeBoundSAMLObject) xmlObject;
        elementExpirationTime = timeBoundObject.getValidUntil();
        if (earliestExpiration == null) {
            earliestExpiration = elementExpirationTime;
        } else {
            if (elementExpirationTime != null && elementExpirationTime.isBefore(earliestExpiration)) {
                earliestExpiration = elementExpirationTime;
            }
        }
    }

    // Inspect children
    List<XMLObject> children = xmlObject.getOrderedChildren();
    if (children != null) {
        for (XMLObject child : xmlObject.getOrderedChildren()) {
            if (child != null) {
                earliestExpiration = getEarliestExpiration(child, earliestExpiration, now);
            }
        }
    }

    return earliestExpiration;
}