Search in sources :

Example 1 with Partner

use of com.helger.as2lib.partner.xml.Partner in project as2-server by phax.

the class AddPartnerCommand method execute.

@Override
public CommandResult execute(final IPartnershipFactoryWithPartners partFx, final Object[] params) throws OpenAS2Exception {
    if (params.length < 1) {
        return new CommandResult(ECommandResultType.TYPE_INVALID_PARAM_COUNT, getUsage());
    }
    final IMicroDocument doc = new MicroDocument();
    final IMicroElement root = doc.appendElement("partner");
    for (int i = 0; i < params.length; i++) {
        final String param = (String) params[i];
        final int pos = param.indexOf('=');
        if (i == 0) {
            root.setAttribute("name", param);
        } else if (pos == 0) {
            return new CommandResult(ECommandResultType.TYPE_ERROR, "incoming parameter missing name");
        } else if (pos > 0) {
            root.setAttribute(param.substring(0, pos), param.substring(pos + 1));
        } else
            return new CommandResult(ECommandResultType.TYPE_ERROR, "incoming parameter missing value");
    }
    final Partner aNewPartner = ((XMLPartnershipFactory) partFx).loadPartner(root);
    partFx.addPartner(aNewPartner);
    return new CommandResult(ECommandResultType.TYPE_OK);
}
Also used : IMicroDocument(com.helger.xml.microdom.IMicroDocument) MicroDocument(com.helger.xml.microdom.MicroDocument) IMicroElement(com.helger.xml.microdom.IMicroElement) IMicroDocument(com.helger.xml.microdom.IMicroDocument) Partner(com.helger.as2lib.partner.xml.Partner) XMLPartnershipFactory(com.helger.as2lib.partner.xml.XMLPartnershipFactory) CommandResult(com.helger.as2.cmd.CommandResult)

Aggregations

CommandResult (com.helger.as2.cmd.CommandResult)1 Partner (com.helger.as2lib.partner.xml.Partner)1 XMLPartnershipFactory (com.helger.as2lib.partner.xml.XMLPartnershipFactory)1 IMicroDocument (com.helger.xml.microdom.IMicroDocument)1 IMicroElement (com.helger.xml.microdom.IMicroElement)1 MicroDocument (com.helger.xml.microdom.MicroDocument)1