KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > portal > generic > GenericLayoutWindow


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  * Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * 3. The end-user documentation included with the redistribution, if
19  * any, must include the following acknowlegement:
20  * "This product includes software developed by the
21  * Caucho Technology (http://www.caucho.com/)."
22  * Alternately, this acknowlegement may appear in the software itself,
23  * if and wherever such third-party acknowlegements normally appear.
24  *
25  * 4. The names "Hessian", "Resin", and "Caucho" must not be used to
26  * endorse or promote products derived from this software without prior
27  * written permission. For written permission, please contact
28  * info@caucho.com.
29  *
30  * 5. Products derived from this software may not be called "Resin"
31  * nor may "Resin" appear in their names without prior written
32  * permission of Caucho Technology.
33  *
34  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
35  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
36  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37  * DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
38  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
39  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
40  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
41  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
42  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
43  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
44  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45  *
46  * @author Sam
47  */

48
49 package com.caucho.portal.generic;
50
51 import javax.portlet.PortletContext;
52 import javax.portlet.PortletException;
53 import java.io.IOException JavaDoc;
54 import java.util.ArrayList JavaDoc;
55 import java.util.logging.Level JavaDoc;
56 import java.util.logging.Logger JavaDoc;
57
58 /**
59  * A Window that is a container for one or more Windows.
60  */

61 public class GenericLayoutWindow
62   extends GenericWindow
63 {
64   static protected final Logger JavaDoc log =
65     Logger.getLogger(GenericLayoutWindow.class.getName());
66
67   private ArrayList JavaDoc<GenericWindow> _children
68     = new ArrayList JavaDoc<GenericWindow>();
69
70   public GenericLayoutWindow()
71   {
72   }
73  
74   /**
75    * Add a window to the layout.
76    */

77   public void add(GenericWindow window)
78   {
79     _children.add(window);
80   }
81
82   /**
83    * Add a {@link GenericPortletWindow} to the layout, a GenericPortletWindow
84    * is a Window that contains one {@link javax.portlet.Portlet} . This method
85    * provides the same functionality as {@link #add()}; it is included for
86    * dependency injection containers that support injection based on method
87    * names (like Resin).
88    */

89   public void addWindow(GenericPortletWindow portletWindow)
90   {
91     _children.add(portletWindow);
92   }
93
94   /**
95    * Add a {@link GenericLayoutWindow} to the layout. In this way layouts can
96    * be nested to an arbitrary depth and complexity. This method provides the
97    * same functionality as {@link #add()}; it is
98    * included for dependency injection containers that support injection based
99    * on method names (like Resin).
100    */

101   public void addLayout(GenericLayoutWindow layoutWindow)
102   {
103     _children.add(layoutWindow);
104   }
105
106   /**
107    * init() each child window.
108    */

109   public void init(PortletContext portletContext)
110     throws PortletException
111   {
112     super.init(portletContext);
113
114     for (int i = 0; i < _children.size(); i++) {
115       _children.get(i).init(portletContext);
116     }
117   }
118
119   /**
120    * Use the PortletConnection to get an Action appropriate for this window,
121    * and then call processAction on each child window.
122    */

123   public void processAction(PortletConnection connection)
124     throws PortletException, IOException JavaDoc
125   {
126     Action action = connection.getAction(this, getNamespace());
127
128     if (action != null) {
129       try {
130         for (int i = 0; i < _children.size(); i++) {
131           _children.get(i).processAction(connection);
132         }
133       }
134       finally {
135         action.finish();
136       }
137     }
138   }
139
140   /**
141    * Use the PortletConnection to get a Render appropriate for this window,
142    * and then call render on each child window.
143    */

144   public void render(PortletConnection connection)
145     throws PortletException, IOException JavaDoc
146   {
147     Render render = connection.getRender(this, getNamespace());
148
149     if (render != null) {
150       try {
151         for (int i = 0; i < _children.size(); i++) {
152           _children.get(i).render(connection);
153         }
154       }
155       finally {
156         render.finish();
157       }
158     }
159   }
160
161   /**
162    * Destroy each child window.
163    */

164   public void destroy()
165   {
166     ArrayList JavaDoc<GenericWindow> children
167       = new ArrayList JavaDoc<GenericWindow>(_children);
168
169     _children.clear();
170
171     for (int i = 0; i < children.size(); i++) {
172       try {
173         children.get(i).destroy();
174       }
175       catch (Exception JavaDoc ex) {
176           log.log(Level.WARNING, ex.toString(), ex);
177       }
178     }
179   }
180 }
181
182
Popular Tags