author | David Powell <david.e.powell@oracle.com> |
Thu, 11 Aug 2011 15:41:42 -0700 | |
changeset 764 | ebb25c1dac73 |
parent 391 | 71abce159a62 |
permissions | -rw-r--r-- |
391 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
5 |
* Common Development and Distribution License (the "License"). |
|
6 |
* You may not use this file except in compliance with the License. |
|
7 |
* |
|
8 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 |
* or http://www.opensolaris.org/os/licensing. |
|
10 |
* See the License for the specific language governing permissions |
|
11 |
* and limitations under the License. |
|
12 |
* |
|
13 |
* When distributing Covered Code, include this CDDL HEADER in each |
|
14 |
* file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 |
* If applicable, add the following below this CDDL HEADER, with the |
|
16 |
* fields enclosed by brackets "[]" replaced with your own identifying |
|
17 |
* information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 |
* |
|
19 |
* CDDL HEADER END |
|
20 |
*/ |
|
21 |
||
22 |
/* |
|
764
ebb25c1dac73
18812 Support building with alternate java implementations
David Powell <david.e.powell@oracle.com>
parents:
391
diff
changeset
|
23 |
* Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. |
391 | 24 |
*/ |
25 |
||
26 |
package org.opensolaris.os.rad; |
|
27 |
||
28 |
import java.lang.reflect.InvocationHandler; |
|
29 |
import java.lang.reflect.Proxy; |
|
30 |
import javax.management.openmbean.CompositeData; |
|
31 |
import javax.management.openmbean.CompositeDataInvocationHandler; |
|
32 |
||
33 |
@SuppressWarnings("serial") |
|
34 |
public class ContainerException extends Exception { |
|
35 |
private RadError error_; |
|
36 |
private CompositeData payload_; |
|
37 |
private String msg_; |
|
38 |
||
39 |
ContainerException(RadError error, CompositeData payload, String msg) { |
|
40 |
super(msg == null ? error.toString() : |
|
41 |
String.format("%s: %s", error.toString(), msg)); |
|
42 |
error_ = error; |
|
43 |
payload_ = payload; |
|
44 |
msg_ = msg; |
|
45 |
} |
|
46 |
||
47 |
ContainerException(RadError error, CompositeData payload) { |
|
48 |
this(error, payload, null); |
|
49 |
} |
|
50 |
||
51 |
public RadError getError() { |
|
52 |
return error_; |
|
53 |
} |
|
54 |
||
55 |
public CompositeData getPayload() { |
|
56 |
return payload_; |
|
57 |
} |
|
58 |
||
59 |
public String getMsg() { |
|
60 |
return msg_; |
|
61 |
} |
|
62 |
||
63 |
@SuppressWarnings("unchecked") |
|
64 |
public <T> T getPayload(Class<T> c) { |
|
65 |
if (payload_ == null) |
|
66 |
return null; |
|
67 |
||
68 |
InvocationHandler handler = |
|
69 |
new CompositeDataInvocationHandler(payload_); |
|
70 |
try { |
|
71 |
return (T)Proxy.newProxyInstance(c.getClassLoader(), |
|
764
ebb25c1dac73
18812 Support building with alternate java implementations
David Powell <david.e.powell@oracle.com>
parents:
391
diff
changeset
|
72 |
new Class<?>[] { c }, handler); |
391 | 73 |
} catch (Exception e) { |
74 |
return null; |
|
75 |
} |
|
76 |
} |
|
77 |
} |