--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/java/rad/org/opensolaris/os/rad/ContainerException.java Mon Dec 14 23:43:39 2009 -0800
@@ -0,0 +1,78 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+package org.opensolaris.os.rad;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.CompositeDataInvocationHandler;
+
+@SuppressWarnings("serial")
+public class ContainerException extends Exception {
+ private RadError error_;
+ private CompositeData payload_;
+ private String msg_;
+
+ ContainerException(RadError error, CompositeData payload, String msg) {
+ super(msg == null ? error.toString() :
+ String.format("%s: %s", error.toString(), msg));
+ error_ = error;
+ payload_ = payload;
+ msg_ = msg;
+ }
+
+ ContainerException(RadError error, CompositeData payload) {
+ this(error, payload, null);
+ }
+
+ public RadError getError() {
+ return error_;
+ }
+
+ public CompositeData getPayload() {
+ return payload_;
+ }
+
+ public String getMsg() {
+ return msg_;
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> T getPayload(Class<T> c) {
+ if (payload_ == null)
+ return null;
+
+ InvocationHandler handler =
+ new CompositeDataInvocationHandler(payload_);
+ try {
+ return (T)Proxy.newProxyInstance(c.getClassLoader(),
+ new Class[] { c }, handler);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+}