Search in sources :

Example 1 with XmlCommitmentTypeQualifiersListType

use of xades4j.xml.bind.xades.XmlCommitmentTypeQualifiersListType in project xades4j by luisgoncalves.

the class FromXmlCommitmentTypeConverter method convertFromObjectTree.

@Override
public void convertFromObjectTree(XmlSignedDataObjectPropertiesType xmlProps, QualifyingPropertiesDataCollector propertyDataCollector) throws PropertyUnmarshalException {
    List<XmlCommitmentTypeIndicationType> xmlCommitments = xmlProps.getCommitmentTypeIndication();
    if (xmlCommitments.isEmpty()) {
        return;
    }
    for (XmlCommitmentTypeIndicationType xmlCommitment : xmlCommitments) {
        List<String> objsRefs = xmlCommitment.getObjectReference();
        Object allDataObjs = xmlCommitment.getAllSignedDataObjects();
        if (objsRefs.isEmpty()) {
            // Should be AllSignedDataObjects.
            objsRefs = null;
            if (null == allDataObjs) {
                throw new PropertyUnmarshalException("ObjectReference or AllSignedDataObjects have to be present", CommitmentTypePropertyBase.PROP_NAME);
            }
        } else if (allDataObjs != null) {
            throw new PropertyUnmarshalException("Both ObjectReference and AllSignedDataObjects are present", CommitmentTypePropertyBase.PROP_NAME);
        }
        CommitmentTypeData commTypeData = new CommitmentTypeData(xmlCommitment.getCommitmentTypeId().getIdentifier().getValue(), xmlCommitment.getCommitmentTypeId().getDescription());
        commTypeData.setObjReferences(objsRefs);
        XmlCommitmentTypeQualifiersListType xmlQualifiers = xmlCommitment.getCommitmentTypeQualifiers();
        if (xmlQualifiers != null) {
            Collection qualifiers = new ArrayList();
            for (XmlAnyType xmlQualifier : xmlQualifiers.getCommitmentTypeQualifier()) {
                if (!xmlQualifier.getContent().isEmpty()) {
                    if (xmlQualifier.getContent().size() > 1) {
                        throw new PropertyUnmarshalException("Qualifiers with multiple children are not support", CommitmentTypePropertyBase.PROP_NAME);
                    }
                    qualifiers.add(xmlQualifier.getContent().get(0));
                }
            }
            commTypeData.setQualifiers(qualifiers);
        }
        propertyDataCollector.addCommitmentType(commTypeData);
    }
}
Also used : XmlAnyType(xades4j.xml.bind.xades.XmlAnyType) XmlCommitmentTypeIndicationType(xades4j.xml.bind.xades.XmlCommitmentTypeIndicationType) XmlCommitmentTypeQualifiersListType(xades4j.xml.bind.xades.XmlCommitmentTypeQualifiersListType) ArrayList(java.util.ArrayList) Collection(java.util.Collection) CommitmentTypeData(xades4j.properties.data.CommitmentTypeData)

Example 2 with XmlCommitmentTypeQualifiersListType

use of xades4j.xml.bind.xades.XmlCommitmentTypeQualifiersListType in project xades4j by luisgoncalves.

the class ToXmlCommitmentTypeConverter method convertIntoObjectTree.

@Override
public void convertIntoObjectTree(PropertyDataObject propData, XmlSignedPropertiesType xmlProps, Document doc) {
    CommitmentTypeData commitmentTypeData = (CommitmentTypeData) propData;
    // Create the JAXB CommitmentTypeIndication and add it to SignedDataObjectProperties.
    XmlCommitmentTypeIndicationType xmlCommitmentTypeProp = new XmlCommitmentTypeIndicationType();
    xmlProps.getSignedDataObjectProperties().getCommitmentTypeIndication().add(xmlCommitmentTypeProp);
    XmlIdentifierType xmlIdentifier = new XmlIdentifierType();
    xmlIdentifier.setValue(commitmentTypeData.getUri());
    XmlObjectIdentifierType xmlObjectId = new XmlObjectIdentifierType();
    xmlObjectId.setDescription(commitmentTypeData.getDescription());
    xmlObjectId.setIdentifier(xmlIdentifier);
    xmlCommitmentTypeProp.setCommitmentTypeId(xmlObjectId);
    Collection<String> refsUris = commitmentTypeData.getObjReferences();
    if (null == refsUris) {
        xmlCommitmentTypeProp.setAllSignedDataObjects();
    } else {
        xmlCommitmentTypeProp.getObjectReference().addAll(refsUris);
    }
    Collection qualifiers = commitmentTypeData.getQualifiers();
    if (!qualifiers.isEmpty()) {
        XmlCommitmentTypeQualifiersListType xmlQualifiers = new XmlCommitmentTypeQualifiersListType();
        for (Object q : qualifiers) {
            XmlAnyType xmlQualifier = new XmlAnyType();
            xmlQualifier.getContent().add(q);
            xmlQualifiers.getCommitmentTypeQualifier().add(xmlQualifier);
        }
        xmlCommitmentTypeProp.setCommitmentTypeQualifiers(xmlQualifiers);
    }
}
Also used : XmlAnyType(xades4j.xml.bind.xades.XmlAnyType) XmlIdentifierType(xades4j.xml.bind.xades.XmlIdentifierType) XmlCommitmentTypeIndicationType(xades4j.xml.bind.xades.XmlCommitmentTypeIndicationType) XmlObjectIdentifierType(xades4j.xml.bind.xades.XmlObjectIdentifierType) XmlCommitmentTypeQualifiersListType(xades4j.xml.bind.xades.XmlCommitmentTypeQualifiersListType) Collection(java.util.Collection) PropertyDataObject(xades4j.properties.data.PropertyDataObject) CommitmentTypeData(xades4j.properties.data.CommitmentTypeData)

Aggregations

Collection (java.util.Collection)2 CommitmentTypeData (xades4j.properties.data.CommitmentTypeData)2 XmlAnyType (xades4j.xml.bind.xades.XmlAnyType)2 XmlCommitmentTypeIndicationType (xades4j.xml.bind.xades.XmlCommitmentTypeIndicationType)2 XmlCommitmentTypeQualifiersListType (xades4j.xml.bind.xades.XmlCommitmentTypeQualifiersListType)2 ArrayList (java.util.ArrayList)1 PropertyDataObject (xades4j.properties.data.PropertyDataObject)1 XmlIdentifierType (xades4j.xml.bind.xades.XmlIdentifierType)1 XmlObjectIdentifierType (xades4j.xml.bind.xades.XmlObjectIdentifierType)1