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.InternalTimeoutException;
12:
13: /**
14: * Translates from a uPortal InternalTimeoutException 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 class InternalTimeoutExceptionToElement 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 InternalTimeoutException))
34: throw new IllegalArgumentException(t.getClass().getName()
35: + " does not extend InternalTimeoutException");
36:
37: InternalTimeoutException ite = (InternalTimeoutException) t;
38: Long timeoutValue = ite.getTimeoutValue();
39:
40: if (timeoutValue != null) {
41: Element timeoutEl = parentDoc.createElement("timeout");
42: timeoutEl.setAttribute("value", timeoutValue.toString());
43: element.appendChild(timeoutEl);
44: }
45:
46: element.setAttribute("renderedAs",
47: InternalTimeoutException.class.getName());
48:
49: return element;
50: }
51:
52: /* (non-Javadoc)
53: * @see org.jasig.portal.channels.error.tt.IThrowableToElement#supports(java.lang.Class)
54: */
55: public boolean supports(Class c) throws IllegalArgumentException {
56: if (c == null)
57: throw new IllegalArgumentException(
58: "Cannot support a null class.");
59: if (!Throwable.class.isAssignableFrom(c))
60: throw new IllegalArgumentException(
61: "Supports undefined on "
62: + "classes that are not and do not extend Throwable:"
63: + c.getName());
64: return InternalTimeoutException.class.isAssignableFrom(c);
65: }
66:
67: }
|