001: /*
002: * The Apache Software License, Version 1.1
003: *
004: * Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * 3. The end-user documentation included with the redistribution, if
019: * any, must include the following acknowlegement:
020: * "This product includes software developed by the
021: * Caucho Technology (http://www.caucho.com/)."
022: * Alternately, this acknowlegement may appear in the software itself,
023: * if and wherever such third-party acknowlegements normally appear.
024: *
025: * 4. The names "Hessian", "Resin", and "Caucho" must not be used to
026: * endorse or promote products derived from this software without prior
027: * written permission. For written permission, please contact
028: * info@caucho.com.
029: *
030: * 5. Products derived from this software may not be called "Resin"
031: * nor may "Resin" appear in their names without prior written
032: * permission of Caucho Technology.
033: *
034: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
035: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
036: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
037: * DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
038: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
039: * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
040: * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
041: * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
042: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
043: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
044: * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
045: *
046: * @author Sam
047: */
048:
049: package com.caucho.portal.generic;
050:
051: import javax.portlet.PortletContext;
052: import javax.portlet.PortletException;
053: import java.io.IOException;
054: import java.util.ArrayList;
055: import java.util.logging.Level;
056: import java.util.logging.Logger;
057:
058: /**
059: * A Window that is a container for one or more Windows.
060: */
061: public class GenericLayoutWindow extends GenericWindow {
062: static protected final Logger log = Logger
063: .getLogger(GenericLayoutWindow.class.getName());
064:
065: private ArrayList<GenericWindow> _children = new ArrayList<GenericWindow>();
066:
067: public GenericLayoutWindow() {
068: }
069:
070: /**
071: * Add a window to the layout.
072: */
073: public void add(GenericWindow window) {
074: _children.add(window);
075: }
076:
077: /**
078: * Add a {@link GenericPortletWindow} to the layout, a GenericPortletWindow
079: * is a Window that contains one {@link javax.portlet.Portlet} . This method
080: * provides the same functionality as {@link #add()}; it is included for
081: * dependency injection containers that support injection based on method
082: * names (like Resin).
083: */
084: public void addWindow(GenericPortletWindow portletWindow) {
085: _children.add(portletWindow);
086: }
087:
088: /**
089: * Add a {@link GenericLayoutWindow} to the layout. In this way layouts can
090: * be nested to an arbitrary depth and complexity. This method provides the
091: * same functionality as {@link #add()}; it is
092: * included for dependency injection containers that support injection based
093: * on method names (like Resin).
094: */
095: public void addLayout(GenericLayoutWindow layoutWindow) {
096: _children.add(layoutWindow);
097: }
098:
099: /**
100: * init() each child window.
101: */
102: public void init(PortletContext portletContext)
103: throws PortletException {
104: super .init(portletContext);
105:
106: for (int i = 0; i < _children.size(); i++) {
107: _children.get(i).init(portletContext);
108: }
109: }
110:
111: /**
112: * Use the PortletConnection to get an Action appropriate for this window,
113: * and then call processAction on each child window.
114: */
115: public void processAction(PortletConnection connection)
116: throws PortletException, IOException {
117: Action action = connection.getAction(this , getNamespace());
118:
119: if (action != null) {
120: try {
121: for (int i = 0; i < _children.size(); i++) {
122: _children.get(i).processAction(connection);
123: }
124: } finally {
125: action.finish();
126: }
127: }
128: }
129:
130: /**
131: * Use the PortletConnection to get a Render appropriate for this window,
132: * and then call render on each child window.
133: */
134: public void render(PortletConnection connection)
135: throws PortletException, IOException {
136: Render render = connection.getRender(this , getNamespace());
137:
138: if (render != null) {
139: try {
140: for (int i = 0; i < _children.size(); i++) {
141: _children.get(i).render(connection);
142: }
143: } finally {
144: render.finish();
145: }
146: }
147: }
148:
149: /**
150: * Destroy each child window.
151: */
152: public void destroy() {
153: ArrayList<GenericWindow> children = new ArrayList<GenericWindow>(
154: _children);
155:
156: _children.clear();
157:
158: for (int i = 0; i < children.size(); i++) {
159: try {
160: children.get(i).destroy();
161: } catch (Exception ex) {
162: log.log(Level.WARNING, ex.toString(), ex);
163: }
164: }
165: }
166: }
|