2009/05/20 - Apache Shale has been retired.

For more information, please explore the Attic.

Coverage Report - org.apache.shale.view.faces.LifecycleListener
 
Classes in this File Line Coverage Branch Coverage Complexity
LifecycleListener
0% 
0% 
3.821
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to you under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 
 18  
 package org.apache.shale.view.faces;
 19  
 
 20  
 import java.util.ArrayList;
 21  
 import java.util.Enumeration;
 22  
 import java.util.Iterator;
 23  
 import java.util.List;
 24  
 import javax.faces.context.FacesContext;
 25  
 import javax.servlet.ServletContextAttributeEvent;
 26  
 import javax.servlet.ServletContextAttributeListener;
 27  
 import javax.servlet.ServletContextEvent;
 28  
 import javax.servlet.ServletContextListener;
 29  
 import javax.servlet.ServletRequest;
 30  
 import javax.servlet.ServletRequestAttributeEvent;
 31  
 import javax.servlet.ServletRequestAttributeListener;
 32  
 import javax.servlet.ServletRequestEvent;
 33  
 import javax.servlet.ServletRequestListener;
 34  
 import javax.servlet.http.HttpSessionActivationListener;
 35  
 import javax.servlet.http.HttpSessionAttributeListener;
 36  
 import javax.servlet.http.HttpSessionBindingEvent;
 37  
 import javax.servlet.http.HttpSessionEvent;
 38  
 import javax.servlet.http.HttpSessionListener;
 39  
 import org.apache.commons.logging.Log;
 40  
 import org.apache.commons.logging.LogFactory;
 41  
 import org.apache.shale.view.AbstractApplicationBean;
 42  
 import org.apache.shale.view.AbstractRequestBean;
 43  
 import org.apache.shale.view.AbstractSessionBean;
 44  
 import org.apache.shale.view.Constants;
 45  
 import org.apache.shale.view.ExceptionHandler;
 46  
 import org.apache.shale.view.ViewController;
 47  
 
 48  
 
 49  
 /**
 50  
  * <p><strong>LifecycleListener</strong> implements the lifecycle startup
 51  
  * and shutdown calls (<code>init()</code> and <code>destroy()</code>) for
 52  
  * subclasses of {@link AbstractApplicationBean}, {@link AbstractRequestBean},
 53  
  * and {@link AbstractSessionBean}.</p>
 54  
  *
 55  
  * <p>It must be registered with the servlet container as a listener,
 56  
  * through an entry in either the <code>/WEB-INF/web.xml</code> resource
 57  
  * or a tag library descriptor included in the web application.</p>
 58  
  *
 59  
  * $Id: LifecycleListener.java 464373 2006-10-16 04:21:54Z rahul $
 60  
  *
 61  
  * @since 1.0.3
 62  
  */
 63  
 public class LifecycleListener
 64  
     implements ServletContextAttributeListener,
 65  
                ServletContextListener,
 66  
                HttpSessionActivationListener,
 67  
                HttpSessionAttributeListener,
 68  
                HttpSessionListener,
 69  
                ServletRequestAttributeListener,
 70  
                ServletRequestListener {
 71  
 
 72  
 
 73  
     // ------------------------------------------------------------- Constructor
 74  
 
 75  
 
 76  
     /**
 77  
      * <p>Create a new lifecycle listener.</p>
 78  
      */
 79  0
     public LifecycleListener() {
 80  0
         if (log.isInfoEnabled()) {
 81  0
             log.info("Initializing org.apache.shale.view.faces.LifecycleListener");
 82  
         }
 83  0
     }
 84  
 
 85  
 
 86  
     // -------------------------------------------------------- Static Variables
 87  
 
 88  
 
 89  
     /**
 90  
      * <p>The <code>Log</code> instance for this class.</p>
 91  
      */
 92  0
     private static final Log log = LogFactory.getLog(LifecycleListener.class);
 93  
 
 94  
 
 95  
     // ------------------------------------------------------ Manifest Constants
 96  
 
 97  
 
 98  
     /**
 99  
      * <p>The fully qualified class name of the <em>Tiger Extensions</em>
 100  
      * verison of this listener class.</p>
 101  
      */
 102  
     private static final String TIGER_LISTENER =
 103  
             "org.apache.shale.tiger.view.faces.LifecycleListener2";
 104  
 
 105  
 
 106  
     // ------------------------------------------------------ Instance Variables
 107  
 
 108  
 
 109  
     /**
 110  
      * <p>The <em>Tiger Extensions</em> implementation of this listener, if
 111  
      * such a class exists in the application classpath.  This value is lazily
 112  
      * instantiated.</p>
 113  
      */
 114  0
     private LifecycleListener tiger = null;
 115  
 
 116  
 
 117  
     /**
 118  
      * <p>Flag indicating whether the <code>tiger</code> value has been calculated
 119  
      * already.</p>
 120  
      */
 121  0
     private boolean tigerInitialized = false;
 122  
 
 123  
 
 124  
     // ------------------------------------------ ServletContextListener Methods
 125  
 
 126  
 
 127  
     /**
 128  
      * <p>Respond to a context created event.  No special processing
 129  
      * is required.</p>
 130  
      *
 131  
      * @param event Event to be processed
 132  
      */
 133  
     public void contextInitialized(ServletContextEvent event) {
 134  
 
 135  
         // Delegate to the Tiger Extensions instance if it exists
 136  0
         LifecycleListener tiger = tiger();
 137  0
         if (tiger != null) {
 138  0
             tiger.contextInitialized(event);
 139  
         }
 140  
 
 141  0
     }
 142  
 
 143  
 
 144  
     /**
 145  
      * <p>Respond to a context destroyed event.  Causes any application
 146  
      * scope attribute that implements {@link AbstractApplicationBean}
 147  
      * to be removed, triggering an <code>attributeRemoved()</code> event.</p>
 148  
      *
 149  
      * @param event Event to be processed
 150  
      */
 151  
     public void contextDestroyed(ServletContextEvent event) {
 152  
 
 153  
         // Delegate to the Tiger Extensions instance if it exists
 154  0
         LifecycleListener tiger = tiger();
 155  0
         if (tiger != null) {
 156  0
             tiger.contextDestroyed(event);
 157  
         }
 158  
 
 159  
         // Remove any AbstractApplicationBean attributes, which will
 160  
         // trigger an attributeRemoved event
 161  0
         List list = new ArrayList();
 162  0
         Enumeration names = event.getServletContext().getAttributeNames();
 163  0
         while (names.hasMoreElements()) {
 164  0
             String name = (String) names.nextElement();
 165  0
             list.add(name);
 166  0
         }
 167  0
         Iterator keys = list.iterator();
 168  0
         while (keys.hasNext()) {
 169  0
             String key = (String) keys.next();
 170  0
             event.getServletContext().removeAttribute(key);
 171  0
         }
 172  
 
 173  0
     }
 174  
 
 175  
 
 176  
     // --------------------------------- ServletContextAttributeListener Methods
 177  
 
 178  
 
 179  
     /**
 180  
      * <p>Respond to an application scope attribute being added.  If the
 181  
      * value is an {@link AbstractApplicationBean}, call its
 182  
      * <code>init()</code> method.</p>
 183  
      *
 184  
      * @param event Event to be processed
 185  
      */
 186  
     public void attributeAdded(ServletContextAttributeEvent event) {
 187  
 
 188  
         // Delegate to the Tiger Extensions instance if it exists
 189  0
         LifecycleListener tiger = tiger();
 190  0
         if (tiger != null) {
 191  0
             tiger.attributeAdded(event);
 192  0
             return; // Tiger logic replaces our own
 193  
         }
 194  
 
 195  
         // If the new value is an AbstractApplicationBean, notify it
 196  0
         Object value = event.getValue();
 197  0
         if (value != null) {
 198  0
             fireApplicationInit(value);
 199  
         }
 200  
 
 201  0
     }
 202  
 
 203  
 
 204  
     /**
 205  
      * <p>Respond to an application scope attribute being replaced.
 206  
      * If the old value was an {@link AbstractApplicationBean}, call
 207  
      * its <code>destroy()</code> method.  If the new value is an
 208  
      * {@link AbstractApplicationBean}, call its <code>init()</code>
 209  
      * method.</p>
 210  
      *
 211  
      * @param event Event to be processed
 212  
      */
 213  
     public void attributeReplaced(ServletContextAttributeEvent event) {
 214  
 
 215  
         // Delegate to the Tiger Extensions instance if it exists
 216  0
         LifecycleListener tiger = tiger();
 217  0
         if (tiger != null) {
 218  0
             tiger.attributeReplaced(event);
 219  0
             return; // Tiger logic replaces our own
 220  
         }
 221  
 
 222  
         // If the old value is an AbstractApplicationBean, notify it
 223  0
         Object value = event.getValue();
 224  0
         if (value != null) {
 225  0
             fireApplicationDestroy(value);
 226  
         }
 227  
 
 228  
         // If the new value is an AbstractApplicationBean, notify it
 229  0
         value = event.getServletContext().getAttribute(event.getName());
 230  0
         if (value != null) {
 231  0
             fireApplicationInit(value);
 232  
         }
 233  
 
 234  0
     }
 235  
 
 236  
 
 237  
     /**
 238  
      * <p>Respond to an application scope attribute being removed.
 239  
      * If the old value was an {@link AbstractApplicationBean}, call
 240  
      * its <code>destroy()</code> method.</p>
 241  
      *
 242  
      * @param event Event to be processed
 243  
      */
 244  
     public void attributeRemoved(ServletContextAttributeEvent event) {
 245  
 
 246  
         // Delegate to the Tiger Extensions instance if it exists
 247  0
         LifecycleListener tiger = tiger();
 248  0
         if (tiger != null) {
 249  0
             tiger.attributeRemoved(event);
 250  0
             return; // Tiger logic replaces our own
 251  
         }
 252  
 
 253  
         // If the old value is an AbstractApplicationBean, notify it
 254  0
         Object value = event.getValue();
 255  0
         if (value != null) {
 256  0
             fireApplicationDestroy(value);
 257  
         }
 258  
 
 259  0
     }
 260  
 
 261  
 
 262  
     // --------------------------------------------- HttpSessionListener Methods
 263  
 
 264  
 
 265  
     /**
 266  
      * <p>Respond to a session created event.  No special processing
 267  
      * is required.</p>
 268  
      *
 269  
      * @param event Event to be processed
 270  
      */
 271  
     public void sessionCreated(HttpSessionEvent event) {
 272  
 
 273  
         // Delegate to the Tiger Extensions instance if it exists
 274  0
         LifecycleListener tiger = tiger();
 275  0
         if (tiger != null) {
 276  0
             tiger.sessionCreated(event);
 277  
         }
 278  
 
 279  0
     }
 280  
 
 281  
 
 282  
     /**
 283  
      * <p>Respond to a session destroyed event.  Causes any session
 284  
      * scope attribute that implements {@link AbstractSessionBean}
 285  
      * to be removed, triggering an <code>attributeRemoved()</code> event.</p>
 286  
      *
 287  
      * @param event Event to be processed
 288  
      */
 289  
     public void sessionDestroyed(HttpSessionEvent event) {
 290  
 
 291  
         // Delegate to the Tiger Extensions instance if it exists
 292  0
         LifecycleListener tiger = tiger();
 293  0
         if (tiger != null) {
 294  0
             tiger.sessionDestroyed(event);
 295  
         }
 296  
 
 297  
         // Remove any AbstractSessionBean attributes, which will
 298  
         // trigger an attributeRemoved event
 299  0
         List list = new ArrayList();
 300  
         try {
 301  0
             Enumeration names = event.getSession().getAttributeNames();
 302  0
             while (names.hasMoreElements()) {
 303  0
                 String name = (String) names.nextElement();
 304  0
                 list.add(name);
 305  0
             }
 306  0
             Iterator keys = list.iterator();
 307  0
             while (keys.hasNext()) {
 308  0
                 String key = (String) keys.next();
 309  0
                 event.getSession().removeAttribute(key);
 310  0
             }
 311  0
         } catch (IllegalStateException e) {
 312  
             // If the session has already been invalidated, there is nothing
 313  
             // we can do.  In a Servlet 2.4 or later container, this should not
 314  
             // happen, because the event handler is supposed to be called before
 315  
             // invalidation occurs, rather than after.
 316  
             ;
 317  0
         }
 318  
 
 319  0
     }
 320  
 
 321  
 
 322  
     // ----------------------------------- HttpSessionActivationListener Methods
 323  
 
 324  
 
 325  
     /**
 326  
      * <p>Respond to a "session will passivate" event.  Notify all session
 327  
      * scope attributes that are {@link AbstractSessionBean}s.</p>
 328  
      *
 329  
      * @param event Event to be processed
 330  
      */
 331  
     public void sessionWillPassivate(HttpSessionEvent event) {
 332  
 
 333  
         // Delegate to the Tiger Extensions instance if it exists
 334  0
         LifecycleListener tiger = tiger();
 335  0
         if (tiger != null) {
 336  0
             tiger.sessionWillPassivate(event);
 337  0
             return; // Tiger logic replaces our own
 338  
         }
 339  
 
 340  
         // Notify any AbstractSessionBean attributes
 341  0
         Enumeration names = event.getSession().getAttributeNames();
 342  0
         while (names.hasMoreElements()) {
 343  0
             String name = (String) names.nextElement();
 344  0
             Object value = event.getSession().getAttribute(name);
 345  0
             if (value != null) {
 346  0
                 fireSessionPassivate(value);
 347  
             }
 348  0
         }
 349  
 
 350  0
     }
 351  
 
 352  
 
 353  
     /**
 354  
      * <p>Respond to a "session did activate" event.  Notify all session
 355  
      * scope attributes that are {@link AbstractSessionBean}s.</p>
 356  
      *
 357  
      * @param event Event to be processed
 358  
      */
 359  
     public void sessionDidActivate(HttpSessionEvent event) {
 360  
 
 361  
         // Delegate to the Tiger Extensions instance if it exists
 362  0
         LifecycleListener tiger = tiger();
 363  0
         if (tiger != null) {
 364  0
             tiger.sessionDidActivate(event);
 365  0
             return; // Tiger logic replaces our own
 366  
         }
 367  
 
 368  
         // Notify any AbstractSessionBean attributes
 369  0
         Enumeration names = event.getSession().getAttributeNames();
 370  0
         while (names.hasMoreElements()) {
 371  0
             String name = (String) names.nextElement();
 372  0
             Object value = event.getSession().getAttribute(name);
 373  0
             if (value != null) {
 374  0
                 fireSessionActivate(value);
 375  
             }
 376  0
         }
 377  
 
 378  0
     }
 379  
 
 380  
 
 381  
     // ------------------------------------ HttpSessionAttributeListener Methods
 382  
 
 383  
 
 384  
     /**
 385  
      * <p>Respond to a session scope attribute being added.  If the
 386  
      * value is an {@link AbstractSessionBean}, call its
 387  
      * <code>init()</code> method.</p>
 388  
      *
 389  
      * @param event Event to be processed
 390  
      */
 391  
     public void attributeAdded(HttpSessionBindingEvent event) {
 392  
 
 393  
         // Delegate to the Tiger Extensions instance if it exists
 394  0
         LifecycleListener tiger = tiger();
 395  0
         if (tiger != null) {
 396  0
             tiger.attributeAdded(event);
 397  0
             return; // Tiger logic replaces our own
 398  
         }
 399  
 
 400  
         // If the new value is an AbstractSessionBean, notify it
 401  0
         Object value = event.getValue();
 402  0
         if (value != null) {
 403  0
             fireSessionInit(value);
 404  
         }
 405  
 
 406  0
     }
 407  
 
 408  
 
 409  
     /**
 410  
      * <p>Respond to a session scope attribute being replaced.
 411  
      * If the old value was an {@link AbstractSessionBean}, call
 412  
      * its <code>destroy()</code> method.  If the new value is an
 413  
      * {@link AbstractSessionBean}, call its <code>init()</code>
 414  
      * method.</p>
 415  
      *
 416  
      * @param event Event to be processed
 417  
      */
 418  
     public void attributeReplaced(HttpSessionBindingEvent event) {
 419  
 
 420  
         // Delegate to the Tiger Extensions instance if it exists
 421  0
         LifecycleListener tiger = tiger();
 422  0
         if (tiger != null) {
 423  0
             tiger.attributeReplaced(event);
 424  0
             return; // Tiger logic replaces our own
 425  
         }
 426  
 
 427  
         // If the old value is an AbstractSessionBean, notify it
 428  0
         Object value = event.getValue();
 429  0
         if (value != null) {
 430  0
             fireSessionDestroy(value);
 431  
         }
 432  
 
 433  
         // If the new value is an AbstractSessionBean, notify it
 434  0
         value = event.getSession().getAttribute(event.getName());
 435  0
         if (value != null) {
 436  0
             fireSessionInit(value);
 437  
         }
 438  
 
 439  0
     }
 440  
 
 441  
 
 442  
     /**
 443  
      * <p>Respond to a session scope attribute being removed.
 444  
      * If the old value was an {@link AbstractSessionBean}, call
 445  
      * its <code>destroy()</code> method.</p>
 446  
      *
 447  
      * @param event Event to be processed
 448  
      */
 449  
     public void attributeRemoved(HttpSessionBindingEvent event) {
 450  
 
 451  
         // Delegate to the Tiger Extensions instance if it exists
 452  0
         LifecycleListener tiger = tiger();
 453  0
         if (tiger != null) {
 454  0
             tiger.attributeRemoved(event);
 455  0
             return; // Tiger logic replaces our own
 456  
         }
 457  
 
 458  
         // If the old value is an AbstractSessionBean, notify it
 459  0
         Object value = event.getValue();
 460  0
         if (value != null) {
 461  0
             fireSessionDestroy(value);
 462  
         }
 463  
 
 464  0
     }
 465  
 
 466  
 
 467  
     // ------------------------------------------ ServletRequestListener Methods
 468  
 
 469  
 
 470  
     /**
 471  
      * <p>Respond to a request created event.  No special processing
 472  
      * is required.</p>
 473  
      *
 474  
      * @param event Event to be processed
 475  
      */
 476  
     public void requestInitialized(ServletRequestEvent event) {
 477  
 
 478  
         // Delegate to the Tiger Extensions instance if it exists
 479  0
         LifecycleListener tiger = tiger();
 480  0
         if (tiger != null) {
 481  0
             tiger.requestInitialized(event);
 482  
         }
 483  
 
 484  0
     }
 485  
 
 486  
 
 487  
     /**
 488  
      * <p>Respond to a request destroyed event.  Causes any request
 489  
      * scope attribute that implements {@link AbstractRequestBean}
 490  
      * or {@link AbstractFragmentBean} to be removed, triggering an
 491  
      * <code>attributeRemoved()</code> event.</p>
 492  
      *
 493  
      * @param event Event to be processed
 494  
      */
 495  
     public void requestDestroyed(ServletRequestEvent event) {
 496  
 
 497  
         // Delegate to the Tiger Extensions instance if it exists
 498  0
         LifecycleListener tiger = tiger();
 499  0
         if (tiger != null) {
 500  0
             tiger.requestDestroyed(event);
 501  
         }
 502  
 
 503  
         // Remove any AbstractRequestBean or ViewController attributes,
 504  
         // which will trigger an attributeRemoved event
 505  0
         List list = new ArrayList();
 506  0
         ServletRequest request = event.getServletRequest();
 507  0
         Enumeration names = request.getAttributeNames();
 508  0
         while (names.hasMoreElements()) {
 509  0
             String name = (String) names.nextElement();
 510  0
             Object value = request.getAttribute(name);
 511  0
             if ((value instanceof AbstractRequestBean) || (value instanceof ViewController)) {
 512  0
                 list.add(name);
 513  
             }
 514  0
         }
 515  0
         Iterator keys = list.iterator();
 516  0
         while (keys.hasNext()) {
 517  0
             String key = (String) keys.next();
 518  0
             event.getServletRequest().removeAttribute(key);
 519  0
         }
 520  
 
 521  0
     }
 522  
 
 523  
 
 524  
     // --------------------------------- ServletRequestAttributeListener Methods
 525  
 
 526  
 
 527  
     /**
 528  
      * <p>Respond to a request scope attribute being added.  If the
 529  
      * value is an {@link AbstractRequestBean}, call its <code>init()</code> method.
 530  
      * </p>
 531  
      *
 532  
      * @param event Event to be processed
 533  
      */
 534  
     public void attributeAdded(ServletRequestAttributeEvent event) {
 535  
 
 536  0
         if (log.isDebugEnabled()) {
 537  0
             log.debug("ServletRequestAttributeAdded(" + event.getName()
 538  
               + "," + event.getValue() + ")");
 539  
         }
 540  
 
 541  
         // Delegate to the Tiger Extensions instance if it exists
 542  0
         LifecycleListener tiger = tiger();
 543  0
         if (tiger != null) {
 544  0
             tiger.attributeAdded(event);
 545  0
             return; // Tiger logic replaces our own
 546  
         }
 547  
 
 548  0
         Object value = event.getValue();
 549  0
         if (value != null) {
 550  0
             fireRequestInit(value);
 551  
         }
 552  
 
 553  0
     }
 554  
 
 555  
 
 556  
     /**
 557  
      * <p>Respond to a request scope attribute being replaced.
 558  
      * If the old value was an {@link AbstractRequestBean},
 559  
      * call its <code>destroy()</code> method.  If the new value is an
 560  
      * {@link AbstractRequestBean}, call its <code>init()</code> method.</p>
 561  
      *
 562  
      * @param event Event to be processed
 563  
      */
 564  
     public void attributeReplaced(ServletRequestAttributeEvent event) {
 565  
 
 566  0
         if (log.isDebugEnabled()) {
 567  0
             log.debug("ServletRequestAttributeReplaced(" + event.getName()
 568  
               + "," + event.getValue()
 569  
               + "," + event.getServletRequest().getAttribute(event.getName())
 570  
               + ")");
 571  
         }
 572  
 
 573  
         // Delegate to the Tiger Extensions instance if it exists
 574  0
         LifecycleListener tiger = tiger();
 575  0
         if (tiger != null) {
 576  0
             tiger.attributeReplaced(event);
 577  0
             return; // Tiger logic replaces our own
 578  
         }
 579  
 
 580  0
         Object value = event.getValue();
 581  0
         if (value != null) {
 582  0
             fireRequestDestroy(value);
 583  
         }
 584  
 
 585  0
         value = event.getServletRequest().getAttribute(event.getName());
 586  0
         if (value != null) {
 587  0
             fireRequestInit(value);
 588  
         }
 589  
 
 590  0
     }
 591  
 
 592  
 
 593  
     /**
 594  
      * <p>Respond to a request scope attribute being removed.
 595  
      * If the old value was an {@link AbstractRequestBean},
 596  
      * call its <code>destroy()</code> method.</p>
 597  
      *
 598  
      * @param event Event to be processed
 599  
      */
 600  
     public void attributeRemoved(ServletRequestAttributeEvent event) {
 601  
 
 602  0
         if (log.isDebugEnabled()) {
 603  0
             log.debug("ServletRequestAttributeRemoved(" + event.getName()
 604  
               + "," + event.getValue() + ")");
 605  
         }
 606  
 
 607  
         // Delegate to the Tiger Extensions instance if it exists
 608  0
         LifecycleListener tiger = tiger();
 609  0
         if (tiger != null) {
 610  0
             tiger.attributeRemoved(event);
 611  0
             return; // Tiger logic replaces our own
 612  
         }
 613  
 
 614  0
         Object value = event.getValue();
 615  0
         if (value != null) {
 616  0
             fireRequestDestroy(value);
 617  
         }
 618  
 
 619  0
     }
 620  
 
 621  
 
 622  
     // ------------------------------------------------------- Protected Methods
 623  
 
 624  
 
 625  
     /**
 626  
      * <p>Fire a destroy event on an @{link AbstractApplicationBean}.</p>
 627  
      *
 628  
      * @param bean {@link AbstractApplicationBean} to fire event on
 629  
      */
 630  
     protected void fireApplicationDestroy(Object bean) {
 631  
 
 632  
         try {
 633  0
             if (bean instanceof AbstractApplicationBean) {
 634  0
                 ((AbstractApplicationBean) bean).destroy();
 635  
             }
 636  0
         } catch (Exception e) {
 637  0
             handleException(FacesContext.getCurrentInstance(), e);
 638  0
         }
 639  
 
 640  0
     }
 641  
 
 642  
 
 643  
     /**
 644  
      * <p>Fire an init event on an {@link AbstractApplicationBean}.</p>
 645  
      *
 646  
      * @param bean {@link AbstractApplicationBean} to fire event on
 647  
      */
 648  
     protected void fireApplicationInit(Object bean) {
 649  
 
 650  
         try {
 651  0
             if (bean instanceof AbstractApplicationBean) {
 652  0
                 ((AbstractApplicationBean) bean).init();
 653  
             }
 654  0
         } catch (Exception e) {
 655  0
             handleException(FacesContext.getCurrentInstance(), e);
 656  0
         }
 657  
 
 658  0
     }
 659  
 
 660  
 
 661  
     /**
 662  
      * <p>Fire a destroy event on an @{link AbstractRequestBean}.</p>
 663  
      *
 664  
      * @param bean {@link AbstractRequestBean} to fire event on
 665  
      */
 666  
     protected void fireRequestDestroy(Object bean) {
 667  
 
 668  
         try {
 669  0
             if (bean instanceof AbstractRequestBean) {
 670  0
                 ((AbstractRequestBean) bean).destroy();
 671  0
             } else if (bean instanceof ViewController) {
 672  0
                 ((ViewController) bean).destroy();
 673  
             }
 674  0
         } catch (Exception e) {
 675  0
             handleException(FacesContext.getCurrentInstance(), e);
 676  0
         }
 677  
 
 678  0
     }
 679  
 
 680  
 
 681  
     /**
 682  
      * <p>Fire an init event on an {@link AbstractRequestBean}.</p>
 683  
      *
 684  
      * @param bean {@link AbstractRequestBean} to fire event on
 685  
      */
 686  
     protected void fireRequestInit(Object bean) {
 687  
 
 688  
         try {
 689  0
             if (bean instanceof AbstractRequestBean) {
 690  0
                 ((AbstractRequestBean) bean).init();
 691  0
             } else if (bean instanceof ViewController) {
 692  0
                 ((ViewController) bean).init();
 693  
             }
 694  0
         } catch (Exception e) {
 695  0
             handleException(FacesContext.getCurrentInstance(), e);
 696  0
         }
 697  
 
 698  0
     }
 699  
 
 700  
 
 701  
     /**
 702  
      * <p>Fire an activate event on an @{link AbstractSessionBean}.</p>
 703  
      *
 704  
      * @param bean {@link AbstractSessionBean} to fire event on
 705  
      */
 706  
     protected void fireSessionActivate(Object bean) {
 707  
 
 708  
         try {
 709  0
             if (bean instanceof AbstractSessionBean) {
 710  0
                 ((AbstractSessionBean) bean).activate();
 711  
             }
 712  0
         } catch (Exception e) {
 713  0
             handleException(FacesContext.getCurrentInstance(), e);
 714  0
         }
 715  
 
 716  0
     }
 717  
 
 718  
 
 719  
     /**
 720  
      * <p>Fire a destroy event on an @{link AbstractSessionBean}.</p>
 721  
      *
 722  
      * @param bean {@link AbstractSessionBean} to fire event on
 723  
      */
 724  
     protected void fireSessionDestroy(Object bean) {
 725  
 
 726  
         try {
 727  0
             if (bean instanceof AbstractSessionBean) {
 728  0
                 ((AbstractSessionBean) bean).destroy();
 729  
             }
 730  0
         } catch (Exception e) {
 731  0
             handleException(FacesContext.getCurrentInstance(), e);
 732  0
         }
 733  
 
 734  0
     }
 735  
 
 736  
 
 737  
     /**
 738  
      * <p>Fire an init event on an {@link AbstractSessionBean}.</p>
 739  
      *
 740  
      * @param bean {@link AbstractSessionBean} to fire event on
 741  
      */
 742  
     protected void fireSessionInit(Object bean) {
 743  
 
 744  
         try {
 745  0
             if (bean instanceof AbstractSessionBean) {
 746  0
                 ((AbstractSessionBean) bean).init();
 747  
             }
 748  0
         } catch (Exception e) {
 749  0
             handleException(FacesContext.getCurrentInstance(), e);
 750  0
         }
 751  
 
 752  0
     }
 753  
 
 754  
 
 755  
     /**
 756  
      * <p>Fire an passivate event on an @{link AbstractSessionBean}.</p>
 757  
      *
 758  
      * @param bean {@link AbstractSessionBean} to fire event on
 759  
      */
 760  
     protected void fireSessionPassivate(Object bean) {
 761  
 
 762  
         try {
 763  0
             if (bean instanceof AbstractSessionBean) {
 764  0
                 ((AbstractSessionBean) bean).passivate();
 765  
             }
 766  0
         } catch (Exception e) {
 767  0
             handleException(FacesContext.getCurrentInstance(), e);
 768  0
         }
 769  
 
 770  0
     }
 771  
 
 772  
 
 773  
     /**
 774  
      * <p>Handle the specified exception according to the strategy
 775  
      * defined by our current {@link ExceptionHandler}.</p>
 776  
      *
 777  
      * @param context FacesContext for the current request
 778  
      * @param exception Exception to be handled
 779  
      */
 780  
     protected void handleException(FacesContext context, Exception exception) {
 781  
 
 782  0
         if (context == null) {
 783  0
             exception.printStackTrace(System.out);
 784  0
             return;
 785  
         }
 786  0
         ExceptionHandler handler = (ExceptionHandler)
 787  
           context.getApplication().getVariableResolver().resolveVariable
 788  
                 (context, Constants.EXCEPTION_HANDLER);
 789  0
         handler.handleException(exception);
 790  
 
 791  0
     }
 792  
 
 793  
 
 794  
     // --------------------------------------------------------- Private Methods
 795  
 
 796  
 
 797  
     /**
 798  
      * <p>Return the <em>Tiger Extensions</em> implementation of this listener
 799  
      * if one exists; otherwise, return <code>null</code>.</p>
 800  
      */
 801  
     private LifecycleListener tiger() {
 802  
 
 803  
         // If we have already attempted to load the Tiger Extensions version
 804  
         // of this class, return the calculated result
 805  0
         if (tigerInitialized) {
 806  0
             return tiger;
 807  
         }
 808  
 
 809  
         // Attempt to load the Tiger Extensions version of this class, and
 810  
         // instantiate an appropriate instance
 811  
         try {
 812  0
             Class clazz = this.getClass().getClassLoader().loadClass(TIGER_LISTENER);
 813  0
             tiger = (LifecycleListener) clazz.newInstance();
 814  0
         } catch (Exception e) {
 815  
             ; // Swallow any class not found or instantiation exception
 816  0
         }
 817  
 
 818  
         // Return the calculated result
 819  0
         tigerInitialized = true;
 820  0
         return tiger;
 821  
 
 822  
     }
 823  
 
 824  
 
 825  
 }