*/
package org.opendaylight.netconf.api;
-import static java.util.Objects.requireNonNull;
import static org.opendaylight.netconf.api.xml.XmlNetconfConstants.RPC_REPLY_KEY;
import static org.opendaylight.netconf.api.xml.XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.opendaylight.yangtools.yang.common.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.ErrorType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
BUILDER_FACTORY.setIgnoringComments(true);
}
- public enum ErrorType {
- TRANSPORT("transport"), RPC("rpc"), PROTOCOL("protocol"), APPLICATION("application");
-
- private final String typeValue;
-
- ErrorType(final String typeValue) {
- this.typeValue = requireNonNull(typeValue);
- }
-
- public String getTypeValue() {
- return this.typeValue;
- }
-
- public static ErrorType from(final String text) {
- for (ErrorType e : values()) {
- if (e.getTypeValue().equalsIgnoreCase(text)) {
- return e;
- }
- }
-
- return APPLICATION;
- }
- }
-
public enum ErrorTag {
ACCESS_DENIED("access-denied"),
BAD_ATTRIBUTE("bad-attribute"),
// FIXME: use a switch expression here
if (ERROR_TYPE.equals(rpcErrorChild.getLocalName())) {
- errorType = ErrorType.from(rpcErrorChild.getTextContent());
+ final ErrorType type = ErrorType.forElementBody(rpcErrorChild.getTextContent());
+ // FIXME: this should be a hard error
+ errorType = type != null ? type : ErrorType.APPLICATION;
} else if (ERROR_TAG.equals(rpcErrorChild.getLocalName())) {
errorTag = ErrorTag.from(rpcErrorChild.getTextContent());
} else if (ERROR_SEVERITY.equals(rpcErrorChild.getLocalName())) {
Node rpcError = doc.createElementNS(URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, RPC_ERROR);
rpcReply.appendChild(rpcError);
- rpcError.appendChild(createTextNode(doc, ERROR_TYPE, getErrorType().getTypeValue()));
+ rpcError.appendChild(createTextNode(doc, ERROR_TYPE, getErrorType().elementBody()));
rpcError.appendChild(createTextNode(doc, ERROR_TAG, getErrorTag().getTagValue()));
rpcError.appendChild(createTextNode(doc, ERROR_SEVERITY, getErrorSeverity().elementBody()));
rpcError.appendChild(createTextNode(doc, ERROR_MESSAGE, getLocalizedMessage()));