001    // Copyright 2005 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry.form;
016    
017    import org.apache.hivemind.Location;
018    import org.apache.hivemind.Messages;
019    import org.apache.tapestry.*;
020    import org.apache.tapestry.engine.IPageLoader;
021    import org.apache.tapestry.internal.event.IComponentEventInvoker;
022    import org.apache.tapestry.json.JSONObject;
023    import org.apache.tapestry.listener.ListenerMap;
024    import org.apache.tapestry.spec.IComponentSpecification;
025    import org.apache.tapestry.spec.IContainedComponent;
026    import org.apache.tapestry.valid.IValidationDelegate;
027    
028    import java.util.*;
029    
030    /**
031     * Mock object used by the {@link org.apache.tapestry.form.FormSupportTest}.
032     * 
033     * @author Howard M. Lewis Ship
034     * @since 4.0
035     */
036    public class MockForm implements IForm
037    {
038        private Location _location;
039    
040        private IRender _body;
041    
042        private List _deferredRunnable = new ArrayList();
043    
044        private IValidationDelegate _delegate;
045    
046        private boolean _focus = true;
047    
048        private JSONObject _profile = new JSONObject();
049        
050        private IComponentEventInvoker _invoker;
051        
052        public MockForm()
053        {
054            this(null, null);
055        }
056    
057        public MockForm(Location location)
058        {
059            this(null, location);
060        }
061    
062        public boolean isPrerendered(IComponent field)
063        {
064            return false;
065        }
066    
067        /**
068         * {@inheritDoc}
069         */
070        public void setClientId(String id)
071        {
072        }
073    
074        public MockForm(IValidationDelegate delegate)
075        {
076            this(delegate, null);
077        }
078    
079        public MockForm(IValidationDelegate delegate, Location location)
080        {
081            _delegate = delegate;
082            _location = location;
083        }
084    
085        /**
086         * {@inheritDoc}
087         */
088        public String getSpecifiedId()
089        {
090            return null;
091        }
092    
093        public void rewind(IMarkupWriter writer, IRequestCycle cycle)
094        {
095        }
096    
097        public void addEventHandler(FormEventType type, String functionName)
098        {
099        }
100    
101        public String getElementId(IFormComponent component)
102        {
103            return null;
104        }
105    
106        public String getElementId(IFormComponent component, String baseId)
107        {
108            return null;
109        }
110    
111        public String peekClientId(IFormComponent component)
112        {
113            return null;
114        }
115        
116        public String getName()
117        {
118            return "myform";
119        }
120    
121        public boolean isRewinding()
122        {
123            return false;
124        }
125    
126        public IValidationDelegate getDelegate()
127        {
128            return _delegate;
129        }
130    
131        public void setEncodingType(String encodingType)
132        {
133        }
134    
135        public void addHiddenValue(String name, String value)
136        {
137        }
138    
139        public void addHiddenValue(String name, String id, String value)
140        {
141        }
142    
143        public boolean getRequiresSession()
144        {
145            return false;
146        }
147    
148        public void addAsset(String name, IAsset asset)
149        {
150        }
151    
152        public void addComponent(IComponent component)
153        {
154        }
155    
156        public void addBody(IRender element)
157        {
158        }
159    
160        public String getClientId()
161        {
162            return null;
163        }
164        
165        public Map getAssets()
166        {
167            return null;
168        }
169    
170        public IAsset getAsset(String name)
171        {
172            return null;
173        }
174    
175        public IBinding getBinding(String name)
176        {
177            return null;
178        }
179    
180        public Collection getBindingNames()
181        {
182            return null;
183        }
184    
185        public Map getBindings()
186        {
187            return null;
188        }
189    
190        public IComponent getComponent(String id)
191        {
192            return null;
193        }
194    
195        public IComponent getContainer()
196        {
197            return null;
198        }
199    
200        public void setContainer(IComponent value)
201        {
202        }
203    
204        public String getExtendedId()
205        {
206            return "SomePage/myform";
207        }
208    
209        public String getId()
210        {
211            return null;
212        }
213    
214        public void setId(String value)
215        {
216        }
217    
218        public String getIdPath()
219        {
220            return null;
221        }
222    
223        public IPage getPage()
224        {
225            return null;
226        }
227    
228        public void setPage(IPage value)
229        {
230        }
231    
232        public IComponentSpecification getSpecification()
233        {
234            return null;
235        }
236    
237        public void renderBody(IMarkupWriter writer, IRequestCycle cycle)
238        {
239            if (_body != null)
240                _body.render(writer, cycle);
241        }
242    
243        public void setBinding(String name, IBinding binding)
244        {
245        }
246    
247        public Map getComponents()
248        {
249            return null;
250        }
251    
252        public void finishLoad(IRequestCycle cycle, IPageLoader loader,
253                IComponentSpecification specification)
254        {
255        }
256    
257        public Messages getMessages()
258        {
259            return null;
260        }
261    
262        public INamespace getNamespace()
263        {
264            return null;
265        }
266    
267        public void setNamespace(INamespace namespace)
268        {
269        }
270    
271        public void setProperty(String propertyName, Object value)
272        {
273        }
274    
275        public Object getProperty(String propertyName)
276        {
277            return null;
278        }
279    
280        public boolean isRendering()
281        {
282            return false;
283        }
284    
285        public void enterActiveState()
286        {
287        }
288    
289        public IBeanProvider getBeans()
290        {
291            return null;
292        }
293    
294        public ListenerMap getListeners()
295        {
296            return null;
297        }
298    
299        public void render(IMarkupWriter writer, IRequestCycle cycle)
300        {
301        }
302    
303        public void setLocation(Location arg0)
304        {
305        }
306    
307        public Location getLocation()
308        {
309            return _location;
310        }
311    
312        public void setBody(IRender body)
313        {
314            _body = body;
315        }
316    
317        public void prerenderField(IMarkupWriter writer, IComponent field, Location location)
318        {
319        }
320    
321        public boolean wasPrerendered(IMarkupWriter writer, IComponent field)
322        {
323            return false;
324        }
325    
326        public void addDeferredRunnable(Runnable runnable)
327        {
328            _deferredRunnable.add(runnable);
329        }
330    
331        void runDeferred()
332        {
333            Iterator i = _deferredRunnable.iterator();
334            while (i.hasNext())
335            {
336                Runnable r = (Runnable) i.next();
337    
338                r.run();
339            }
340        }
341    
342        public boolean isClientValidationEnabled()
343        {
344            return false;
345        }
346    
347        public String getMessage(String key)
348        {
349            return null;
350        }
351    
352        public void registerForFocus(IFormComponent field, int priority)
353        {
354        }
355    
356        public boolean getFocus()
357        {
358            return _focus;
359        }
360    
361        public void setFocus(boolean focus)
362        {
363            _focus = focus;
364        }
365    
366        public IContainedComponent getContainedComponent()
367        {
368            return null;
369        }
370    
371        public void setContainedComponent(IContainedComponent containedComponent)
372        {
373        }
374        
375        /** 
376         * {@inheritDoc}
377         */
378        public IComponentEventInvoker getEventInvoker()
379        {
380            return _invoker;
381        }
382    
383        public void setEventInvoker(IComponentEventInvoker invoker)
384        {
385            _invoker = invoker;
386        }
387    
388        /** 
389         * {@inheritDoc}
390         */
391        public JSONObject getProfile()
392        {
393            return _profile;
394        }
395    
396        /** 
397         * {@inheritDoc}
398         */
399        public boolean isFormFieldUpdating()
400        {
401            return false;
402        }
403    
404        /** 
405         * {@inheritDoc}
406         */
407        public void setFormFieldUpdating(boolean value)
408        {
409            
410        }
411    
412        /** 
413         * {@inheritDoc}
414         */
415        public List getUpdateComponents()
416        {
417            return Collections.EMPTY_LIST;
418        }
419        
420        /** 
421         * {@inheritDoc}
422         */
423        public boolean isAsync()
424        {
425            return false;
426        }
427    
428        /** 
429         * {@inheritDoc}
430         */
431        public boolean isJson()
432        {
433            return false;
434        }
435    
436        /** 
437         * {@inheritDoc}
438         */
439        public boolean isStateful()
440        {
441            return false;
442        }
443    
444        /** 
445         * {@inheritDoc}
446         */
447        public void trigger(IRequestCycle cycle)
448        {
449        }
450    
451        /** 
452         * {@inheritDoc}
453         */
454        public String getTemplateTagName()
455        {
456            return "form";
457        }
458        
459        public void setTemplateTagName(String tag)
460        {
461        }
462    
463        /**
464         * {@inheritDoc}
465         */
466        public String peekClientId()
467        {
468            return null;
469        }
470    
471        public boolean wasPrerendered(IComponent field)
472        {
473            return false;
474        }
475    }