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