001: /**
002: * Copyright 2006 Webmedia Group Ltd.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: **/package org.araneaframework.framework.core;
016:
017: import org.araneaframework.Environment;
018: import org.araneaframework.InputData;
019: import org.araneaframework.Message;
020: import org.araneaframework.OutputData;
021: import org.araneaframework.Path;
022: import org.araneaframework.Widget;
023: import org.araneaframework.core.Assert;
024: import org.araneaframework.core.BaseWidget;
025: import org.araneaframework.framework.FilterWidget;
026:
027: /**
028: * A filter widget is a Widget which filters requests to its child widget. A filter
029: * overrides one of the methods:
030: * <ul>
031: * <li><code>action(Path, InputData, OutputData)</code></li>
032: * <li><code>update(InputData)</code></li>
033: * <li><code>event(Path, InputData)</code></li>
034: * <li><code>render(OutputData)</code></li>
035: * </ul>
036: * and does the filtering by allowing the action to be invoked on the child or not. This class is a
037: * skeleton which lets all the requests through, sets the child, handles the initilization and
038: * destroying of the child.
039: * <p>
040: * The child is initialized with <code>getChildWidgetEnvironment()</code> which by default returns
041: * this component's Environment. For alternate environments it should be overridden.
042: * </p>
043: *
044: * @author "Toomas Römer" <toomas@webmedia.ee>
045: */
046: public class BaseFilterWidget extends BaseWidget implements
047: FilterWidget {
048: protected Widget childWidget;
049:
050: public BaseFilterWidget() {
051: }
052:
053: public BaseFilterWidget(Widget childWidget) {
054: setChildWidget(childWidget);
055: }
056:
057: /**
058: * Sets the child to childWidget.
059: */
060: public void setChildWidget(Widget childWidget) {
061: this .childWidget = childWidget;
062: }
063:
064: public Widget getChildWidget() {
065: return childWidget;
066: }
067:
068: protected void init() throws Exception {
069: Assert.notNull(this , childWidget,
070: "Filter cannot have a null child!");
071:
072: this .childWidget._getComponent().init(getScope(),
073: getChildWidgetEnvironment());
074: }
075:
076: protected void propagate(Message message) throws Exception {
077: message.send(null, childWidget);
078: }
079:
080: protected void action(Path path, InputData input, OutputData output)
081: throws Exception {
082: this .childWidget._getService().action(path, input, output);
083: }
084:
085: protected void update(InputData input) throws Exception {
086: this .childWidget._getWidget().update(input);
087: }
088:
089: protected void event(Path path, InputData input) throws Exception {
090: this .childWidget._getWidget().event(path, input);
091: }
092:
093: protected void render(OutputData output) throws Exception {
094: this .childWidget._getWidget().render(output);
095: }
096:
097: protected void destroy() throws Exception {
098: this .childWidget._getComponent().destroy();
099: }
100:
101: /**
102: * By default returns the widget's Environment. The child is
103: * initilized with the return value of this method.
104: */
105: protected Environment getChildWidgetEnvironment() {
106: return getEnvironment();
107: }
108: }
|