Add helper class for RpcError interface 41/1141/3
authorMichal Rehak <mirehak@cisco.com>
Tue, 10 Sep 2013 03:26:39 +0000 (05:26 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 11 Sep 2013 04:33:08 +0000 (04:33 +0000)
Change-Id: I981d63d0c6ccc899a3f2db5985b16d31c8e2742e
Signed-off-by: Michal Rehak <mirehak@cisco.com>
opendaylight/sal/yang-prototype/sal/sal-common-util/src/main/java/org/opendaylight/controller/sal/common/util/RpcErrors.java [new file with mode: 0644]

diff --git a/opendaylight/sal/yang-prototype/sal/sal-common-util/src/main/java/org/opendaylight/controller/sal/common/util/RpcErrors.java b/opendaylight/sal/yang-prototype/sal/sal-common-util/src/main/java/org/opendaylight/controller/sal/common/util/RpcErrors.java
new file mode 100644 (file)
index 0000000..86dcba9
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.sal.common.util;
+
+import org.opendaylight.yangtools.yang.common.RpcError;
+import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
+
+/**
+ * @author mirehak
+ *
+ */
+public class RpcErrors {
+    
+    /**
+     * @param applicationTag
+     * @param tag
+     * @param info
+     * @param severity
+     * @param message
+     * @param errorType 
+     * @param cause 
+     * @return {@link RpcError} implementation
+     */
+    public static RpcError getRpcError(String applicationTag, String tag, String info,
+            ErrorSeverity severity, String message, ErrorType errorType, Throwable cause) {
+        RpcErrorTO ret = new RpcErrorTO(applicationTag, tag, info, severity, message, 
+                errorType, cause);
+        return ret;
+    }
+
+    private static class RpcErrorTO implements RpcError {
+
+        private final String applicationTag;
+        private final String tag;
+        private final String info;
+        private final ErrorSeverity severity;
+        private final String message;
+        private final ErrorType errorType;
+        private final Throwable cause;
+
+        /**
+         * @param applicationTag
+         * @param tag
+         * @param info
+         * @param severity
+         * @param message
+         * @param errorType
+         * @param cause
+         */
+        protected RpcErrorTO(String applicationTag, String tag, String info,
+                ErrorSeverity severity, String message, ErrorType errorType, Throwable cause) {
+            super();
+            this.applicationTag = applicationTag;
+            this.tag = tag;
+            this.info = info;
+            this.severity = severity;
+            this.message = message;
+            this.errorType = errorType;
+            this.cause = cause;
+        }
+
+        @Override
+        public String getApplicationTag() {
+            return applicationTag;
+        }
+
+        @Override
+        public String getInfo() {
+            return info;
+        }
+
+        @Override
+        public String getMessage() {
+            return message;
+        }
+
+        @Override
+        public ErrorSeverity getSeverity() {
+            return severity;
+        }
+
+        @Override
+        public String getTag() {
+            return tag;
+        }
+
+        @Override
+        public Throwable getCause() {
+            return cause;
+        }
+        
+        @Override
+        public ErrorType getErrorType() {
+            return errorType;
+        }
+    }
+}

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.