001: // Copyright 2006, 2007 The Apache Software Foundation
002: //
003: // Licensed under the Apache License, Version 2.0 (the "License");
004: // you may not use this file except in compliance with the License.
005: // You may obtain a copy of the License at
006: //
007: // http://www.apache.org/licenses/LICENSE-2.0
008: //
009: // Unless required by applicable law or agreed to in writing, software
010: // distributed under the License is distributed on an "AS IS" BASIS,
011: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: // See the License for the specific language governing permissions and
013: // limitations under the License.
014:
015: package org.apache.tapestry.corelib.pages;
016:
017: import java.util.List;
018:
019: import org.apache.tapestry.annotations.Inject;
020: import org.apache.tapestry.ioc.services.ExceptionAnalysis;
021: import org.apache.tapestry.ioc.services.ExceptionAnalyzer;
022: import org.apache.tapestry.ioc.services.ExceptionInfo;
023: import org.apache.tapestry.services.ExceptionReporter;
024: import org.apache.tapestry.services.Request;
025: import org.apache.tapestry.services.Session;
026:
027: /**
028: * Responsible for reporting runtime exceptions. This page is quite verbose and is usually
029: * overridden in a production application.
030: */
031: public class ExceptionReport implements ExceptionReporter {
032: private List<ExceptionInfo> _stack;
033:
034: private ExceptionInfo _info;
035:
036: private String _propertyName;
037:
038: private String _frame;
039:
040: private String _attributeName;
041:
042: @Inject
043: private ExceptionAnalyzer _analyzer;
044:
045: @Inject
046: private Request _request;
047:
048: public void reportException(Throwable exception) {
049: ExceptionAnalysis analysis = _analyzer.analyze(exception);
050:
051: _stack = analysis.getExceptionInfos();
052: }
053:
054: public List<ExceptionInfo> getStack() {
055: return _stack;
056: }
057:
058: public ExceptionInfo getInfo() {
059: return _info;
060: }
061:
062: public void setInfo(ExceptionInfo info) {
063: _info = info;
064: }
065:
066: public String getFrame() {
067: return _frame;
068: }
069:
070: public void setFrame(String frame) {
071: _frame = frame;
072: }
073:
074: public String getPropertyName() {
075: return _propertyName;
076: }
077:
078: public void setPropertyName(String propertyName) {
079: _propertyName = propertyName;
080: }
081:
082: public boolean getShowPropertyList() {
083: // True if either is non-empty
084:
085: return !(_info.getPropertyNames().isEmpty() && _info
086: .getStackTrace().isEmpty());
087: }
088:
089: public Object getPropertyValue() {
090: return _info.getProperty(_propertyName);
091: }
092:
093: public boolean getHasSession() {
094: return _request.getSession(false) != null;
095: }
096:
097: public Request getRequest() {
098: return _request;
099: }
100:
101: public Session getSession() {
102: return _request.getSession(false);
103: }
104:
105: public String getAttributeName() {
106: return _attributeName;
107: }
108:
109: public void setAttributeName(String attributeName) {
110: _attributeName = attributeName;
111: }
112:
113: public Object getAttributeValue() {
114: return getSession().getAttribute(_attributeName);
115: }
116: }
|