KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jsf > lifecycle > LifecycleImpl


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2
11  * as published by the Free Software Foundation.
12  *
13  * Resin Open Source is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
16  * of NON-INFRINGEMENT. See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with Resin Open Source; if not, write to the
21  *
22  * Free Software Foundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.jsf.lifecycle;
30
31 import java.util.*;
32
33 import javax.faces.*;
34 import javax.faces.application.*;
35 import javax.faces.context.*;
36 import javax.faces.event.*;
37 import javax.faces.lifecycle.*;
38
39 /**
40  * The default lifecycle implementation
41  */

42 public class LifecycleImpl extends Lifecycle
43 {
44   private ArrayList<PhaseListener> _phaseList = new ArrayList<PhaseListener>();
45   private PhaseListener []_phaseListeners = new PhaseListener[0];
46   
47   public LifecycleImpl()
48   {
49   }
50
51   public void addPhaseListener(PhaseListener listener)
52   {
53     if (listener == null)
54       throw new NullPointerException JavaDoc();
55     
56     synchronized (_phaseList) {
57       _phaseList.add(listener);
58       _phaseListeners = new PhaseListener[_phaseList.size()];
59       _phaseList.toArray(_phaseListeners);
60     }
61   }
62   
63   public PhaseListener []getPhaseListeners()
64   {
65     return _phaseListeners;
66   }
67   
68   public void removePhaseListener(PhaseListener listener)
69   {
70     if (listener == null)
71       throw new NullPointerException JavaDoc();
72     
73     synchronized (_phaseList) {
74       _phaseList.remove(listener);
75       _phaseListeners = new PhaseListener[_phaseList.size()];
76       _phaseList.toArray(_phaseListeners);
77     }
78   }
79
80   public void execute(FacesContext context)
81     throws FacesException
82   {
83     if (context.getResponseComplete() || context.getRenderResponse())
84       return;
85   }
86   
87   public void render(FacesContext context)
88     throws FacesException
89   {
90     if (context.getResponseComplete())
91       return;
92
93     Application app = context.getApplication();
94     ViewHandler view = app.getViewHandler();
95
96     try {
97       view.renderView(context, context.getViewRoot());
98     } catch (java.io.IOException JavaDoc e) {
99       throw new FacesException(e);
100     }
101   }
102
103   public String JavaDoc toString()
104   {
105     return "DefaultLifecycleImpl[]";
106   }
107 }
108
Popular Tags