Search in sources :

Example 1 with PartnershipMap

use of com.helger.as2lib.partner.PartnershipMap in project as2-lib by phax.

the class XMLPartnershipFactory method load.

protected void load(@Nullable @WillClose final InputStream aIS) throws AS2Exception {
    final PartnerMap aNewPartners = new PartnerMap();
    final PartnershipMap aNewPartnerships = new PartnershipMap();
    if (aIS != null) {
        final IMicroDocument aDocument = MicroReader.readMicroXML(aIS);
        if (aDocument == null)
            throw new AS2Exception("Failed to read the XML partnership information");
        final IMicroElement aRoot = aDocument.getDocumentElement();
        for (final IMicroElement eRootNode : aRoot.getAllChildElements()) {
            final String sNodeName = eRootNode.getTagName();
            if (sNodeName.equals("partner")) {
                final Partner aNewPartner = loadPartner(eRootNode);
                aNewPartners.addPartner(aNewPartner);
            } else if (sNodeName.equals("partnership")) {
                final Partnership aNewPartnership = loadPartnership(eRootNode, aNewPartners);
                if (aNewPartnerships.getPartnershipByName(aNewPartnership.getName()) != null)
                    throw new AS2Exception("Partnership with name '" + aNewPartnership.getName() + "' is defined more than once");
                aNewPartnerships.addPartnership(aNewPartnership);
            } else {
                if (LOGGER.isWarnEnabled())
                    LOGGER.warn("Invalid element '" + sNodeName + "' in XML partnership file");
            }
        }
    }
    setPartners(aNewPartners);
    setPartnerships(aNewPartnerships);
}
Also used : Partnership(com.helger.as2lib.partner.Partnership) AS2Exception(com.helger.as2lib.exception.AS2Exception) WrappedAS2Exception(com.helger.as2lib.exception.WrappedAS2Exception) IMicroElement(com.helger.xml.microdom.IMicroElement) IMicroDocument(com.helger.xml.microdom.IMicroDocument) PartnershipMap(com.helger.as2lib.partner.PartnershipMap)

Aggregations

AS2Exception (com.helger.as2lib.exception.AS2Exception)1 WrappedAS2Exception (com.helger.as2lib.exception.WrappedAS2Exception)1 Partnership (com.helger.as2lib.partner.Partnership)1 PartnershipMap (com.helger.as2lib.partner.PartnershipMap)1 IMicroDocument (com.helger.xml.microdom.IMicroDocument)1 IMicroElement (com.helger.xml.microdom.IMicroElement)1