Update Tomas's name
[netconf.git] / protocol / netconf-util / src / main / java / org / opendaylight / netconf / util / mapping / AbstractLastNetconfOperation.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.netconf.util.mapping;
9
10 import org.opendaylight.netconf.api.DocumentedException;
11 import org.opendaylight.netconf.api.xml.XmlElement;
12 import org.opendaylight.netconf.mapping.api.HandlingPriority;
13 import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
14 import org.opendaylight.yangtools.yang.common.ErrorSeverity;
15 import org.opendaylight.yangtools.yang.common.ErrorTag;
16 import org.opendaylight.yangtools.yang.common.ErrorType;
17 import org.w3c.dom.Document;
18 import org.w3c.dom.Element;
19
20 public abstract class AbstractLastNetconfOperation extends AbstractNetconfOperation {
21     protected AbstractLastNetconfOperation(final String netconfSessionIdForReporting) {
22         super(netconfSessionIdForReporting);
23     }
24
25     @Override
26     protected Element handle(final Document document, final XmlElement operationElement,
27                              final NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
28         if (!subsequentOperation.isExecutionTermination()) {
29             throw new DocumentedException(String.format(
30                     "No netconf operation expected to be subsequent to %s, but is %s", this, subsequentOperation),
31                     ErrorType.APPLICATION, ErrorTag.MALFORMED_MESSAGE, ErrorSeverity.ERROR);
32         }
33
34         return handleWithNoSubsequentOperations(document, operationElement);
35     }
36
37     @Override
38     protected HandlingPriority getHandlingPriority() {
39         return HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY;
40     }
41
42     protected abstract Element handleWithNoSubsequentOperations(Document document, XmlElement operationElement)
43         throws DocumentedException;
44 }