01: /* Copyright 2004 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.channels.error.error2xml;
07:
08: import org.w3c.dom.Document;
09: import org.w3c.dom.Element;
10:
11: import org.jasig.portal.AuthorizationException;
12:
13: /**
14: * Translates from a uPortal AuthorizationException to an XML element.
15: * @author andrew.petro@yale.edu
16: * @version $Revision: 35593 $ $Date: 2005-04-17 13:54:14 -0700 (Sun, 17 Apr 2005) $
17: * @since uPortal 2.5
18: */
19: public final class AuthorizationExceptionToElement implements
20: IThrowableToElement {
21:
22: private ThrowableToElement throwableToElement = new ThrowableToElement();
23:
24: /* (non-Javadoc)
25: * @see org.jasig.portal.channels.error.tt.IThrowableToElement#throwableToElement(java.lang.Throwable, org.w3c.dom.Document)
26: */
27: public Element throwableToElement(Throwable t, Document parentDoc)
28: throws IllegalArgumentException {
29:
30: Element element = this .throwableToElement.throwableToElement(t,
31: parentDoc);
32:
33: if (!(t instanceof AuthorizationException))
34: throw new IllegalArgumentException(t.getClass().getName()
35: + " does not extend AuthorizationException");
36:
37: element.setAttribute("renderedAs", AuthorizationException.class
38: .getName());
39:
40: return element;
41: }
42:
43: /* (non-Javadoc)
44: * @see org.jasig.portal.channels.error.tt.IThrowableToElement#supports(java.lang.Class)
45: */
46: public boolean supports(Class c) throws IllegalArgumentException {
47: if (c == null)
48: throw new IllegalArgumentException(
49: "Cannot support a null class.");
50:
51: if (!Throwable.class.isAssignableFrom(c))
52: throw new IllegalArgumentException(
53: "Supports undefined on classes "
54: + "which are not and do not extend Throwable. Class was "
55: + c.getName());
56:
57: return AuthorizationException.class.isAssignableFrom(c);
58: }
59:
60: }
|