001 // Copyright 2004, 2005 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.html; 016 017 import org.apache.tapestry.BaseComponent; 018 import org.apache.tapestry.IMarkupWriter; 019 import org.apache.tapestry.IRequestCycle; 020 import org.apache.tapestry.bean.EvenOdd; 021 import org.apache.tapestry.util.exception.ExceptionDescription; 022 023 /** 024 * Component used to display an already formatted exception. [ <a 025 * href="../../../../../ComponentReference/ExceptionDisplay.html">Component Reference </a>] 026 * 027 * @author Howard Lewis Ship 028 */ 029 030 public abstract class ExceptionDisplay extends BaseComponent 031 { 032 public abstract ExceptionDescription[] getExceptions(); 033 034 private ExceptionDescription _exception; 035 036 private EvenOdd _evenOdd; 037 038 public abstract int getIndex(); 039 040 public abstract int getCount(); 041 042 public abstract void setCount(int count); 043 044 /** 045 * Each time the current exception is set, as a side effect, the evenOdd helper bean is reset to 046 * even. 047 */ 048 049 public void setException(ExceptionDescription value) 050 { 051 _exception = value; 052 053 _evenOdd.setEven(true); 054 } 055 056 public ExceptionDescription getException() 057 { 058 return _exception; 059 } 060 061 protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) 062 { 063 ExceptionDescription[] exceptions = getExceptions(); 064 065 setCount(exceptions.length); 066 067 try 068 { 069 _evenOdd = (EvenOdd) getBeans().getBean("evenOdd"); 070 071 super.renderComponent(writer, cycle); 072 } 073 finally 074 { 075 _exception = null; 076 _evenOdd = null; 077 } 078 } 079 080 public boolean isLast() 081 { 082 return getIndex() == (getCount() - 1); 083 } 084 }