Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
WOParentElement |
|
| 1.75;1.75 |
1 | /* |
|
2 | Wotonomy: OpenStep design patterns for pure Java applications. |
|
3 | Copyright (C) 2000 Blacksmith, Inc. |
|
4 | ||
5 | This library is free software; you can redistribute it and/or |
|
6 | modify it under the terms of the GNU Lesser General Public |
|
7 | License as published by the Free Software Foundation; either |
|
8 | version 2.1 of the License, or (at your option) any later version. |
|
9 | ||
10 | This library is distributed in the hope that it will be useful, |
|
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 | Lesser General Public License for more details. |
|
14 | ||
15 | You should have received a copy of the GNU Lesser General Public |
|
16 | License along with this library; if not, see http://www.gnu.org |
|
17 | */ |
|
18 | ||
19 | package net.wotonomy.web; |
|
20 | ||
21 | import java.util.Iterator; |
|
22 | import java.util.List; |
|
23 | ||
24 | import net.wotonomy.foundation.NSMutableArray; |
|
25 | ||
26 | /** |
|
27 | * This class represents a parent node in an element tree. |
|
28 | * It has no content in itself, and exists only to forward |
|
29 | * messages to each of its children, in turn. |
|
30 | * Package access only, as it is not in the specification. |
|
31 | * |
|
32 | * @author michael@mpowers.net |
|
33 | * @author $Author: cgruber $ |
|
34 | * @version $Revision: 905 $ |
|
35 | */ |
|
36 | class WOParentElement extends WOElement |
|
37 | { |
|
38 | NSMutableArray children; |
|
39 | ||
40 | /** |
|
41 | * Default constructor. |
|
42 | */ |
|
43 | 0 | public WOParentElement() |
44 | 0 | { |
45 | 0 | children = new NSMutableArray(); |
46 | 0 | } |
47 | ||
48 | /** |
|
49 | * Returns an element with the specified children. |
|
50 | */ |
|
51 | public WOParentElement( List childElements ) |
|
52 | { |
|
53 | 0 | this(); |
54 | 0 | children.addAll( childElements ); |
55 | 0 | } |
56 | ||
57 | /** |
|
58 | * Package access only. Called to initialize the component with |
|
59 | * the proper context before the start of the request-response cycle. |
|
60 | * If the context has a current component, that component becomes |
|
61 | * this component's parent. |
|
62 | */ |
|
63 | void ensureAwakeInContext (WOContext aContext) |
|
64 | { |
|
65 | WOElement element; |
|
66 | 0 | Iterator it = children.iterator(); |
67 | 0 | while ( it.hasNext() ) |
68 | { |
|
69 | 0 | element = (WOElement) it.next(); |
70 | 0 | aContext.pushElement( element ); |
71 | 0 | element.ensureAwakeInContext( aContext ); |
72 | 0 | aContext.popElement(); |
73 | 0 | } |
74 | 0 | } |
75 | ||
76 | /** |
|
77 | * Forwards this message to all child elements. |
|
78 | */ |
|
79 | public void takeValuesFromRequest ( |
|
80 | WORequest aRequest, WOContext aContext) |
|
81 | { |
|
82 | WOElement element; |
|
83 | ||
84 | // aContext.incrementLastElementIDComponent(); |
|
85 | 0 | aContext.appendZeroElementIDComponent(); |
86 | ||
87 | 0 | Iterator it = children.iterator(); |
88 | 0 | while ( it.hasNext() ) |
89 | { |
|
90 | 0 | element = (WOElement) it.next(); |
91 | 0 | aContext.pushElement( element ); |
92 | 0 | aContext.incrementLastElementIDComponent(); |
93 | 0 | element.takeValuesFromRequest( aRequest, aContext ); |
94 | 0 | aContext.popElement(); |
95 | 0 | } |
96 | ||
97 | 0 | aContext.deleteLastElementIDComponent(); |
98 | 0 | } |
99 | ||
100 | /** |
|
101 | * Forwards this message to all child elements, |
|
102 | * returning the first non-null result. |
|
103 | */ |
|
104 | public WOActionResults invokeAction ( |
|
105 | WORequest aRequest, WOContext aContext) |
|
106 | { |
|
107 | WOElement element; |
|
108 | ||
109 | // aContext.incrementLastElementIDComponent(); |
|
110 | 0 | aContext.appendZeroElementIDComponent(); |
111 | ||
112 | 0 | WOActionResults result = null; |
113 | 0 | Iterator it = children.iterator(); |
114 | 0 | while ( it.hasNext() ) |
115 | { |
|
116 | 0 | element = (WOElement) it.next(); |
117 | 0 | aContext.pushElement( element ); |
118 | 0 | aContext.incrementLastElementIDComponent(); |
119 | 0 | result = element.invokeAction( aRequest, aContext ); |
120 | 0 | aContext.popElement(); |
121 | 0 | if ( result != null ) break; |
122 | } |
|
123 | ||
124 | 0 | aContext.deleteLastElementIDComponent(); |
125 | 0 | return result; |
126 | } |
|
127 | ||
128 | /** |
|
129 | * Forwards this message to all child elements. |
|
130 | */ |
|
131 | public void appendToResponse (WOResponse aResponse, WOContext aContext) |
|
132 | { |
|
133 | WOElement element; |
|
134 | ||
135 | // aContext.incrementLastElementIDComponent(); |
|
136 | 0 | aContext.appendZeroElementIDComponent(); |
137 | ||
138 | // for each child element |
|
139 | 0 | Iterator it = children.iterator(); |
140 | 0 | while ( it.hasNext() ) |
141 | { |
|
142 | 0 | element = (WOElement) it.next(); |
143 | 0 | aContext.pushElement( element ); |
144 | 0 | aContext.incrementLastElementIDComponent(); |
145 | ||
146 | // forward the message |
|
147 | 0 | element.appendToResponse( |
148 | 0 | aResponse, aContext ); |
149 | ||
150 | 0 | aContext.popElement(); |
151 | ||
152 | 0 | } |
153 | 0 | aContext.deleteLastElementIDComponent(); |
154 | 0 | } |
155 | ||
156 | public WOResponse generateResponse() |
|
157 | { |
|
158 | 0 | WOResponse r = new WOResponse(); |
159 | 0 | return r; |
160 | } |
|
161 | ||
162 | public String toString() |
|
163 | { |
|
164 | 0 | StringBuffer result = new StringBuffer(); |
165 | 0 | result.append( "[WOParentElement: " ); |
166 | // for each child element |
|
167 | 0 | Iterator it = children.iterator(); |
168 | 0 | while ( it.hasNext() ) |
169 | { |
|
170 | 0 | result.append( "[ " ); |
171 | 0 | result.append( it.next().toString() ); |
172 | 0 | result.append( " ]" ); |
173 | 0 | } |
174 | 0 | result.append( " ]" ); |
175 | 0 | return result.toString(); |
176 | } |
|
177 | ||
178 | } |