1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.wotonomy.web;
20
21 import net.wotonomy.foundation.NSDictionary;
22 import net.wotonomy.foundation.NSMutableDictionary;
23
24 public class WOSwitchComponent extends WODynamicElement {
25
26 private NSMutableDictionary elements;
27 private String currentName;
28 private WOElement currentElement;
29
30 protected WOSwitchComponent()
31 {
32 super();
33 elements = new NSMutableDictionary();
34 }
35
36 public WOSwitchComponent(String aName, NSDictionary aMap, WOElement template)
37 {
38 super(aName, aMap, template);
39 elements = new NSMutableDictionary();
40 }
41
42 private WOElement getCurrentElement( WOContext c )
43 {
44 String name = stringForProperty( "WOComponentName", c.component() );
45 if ( name == null ) return null;
46
47 if ( currentElement != null && name.equals( currentName ) ) return currentElement;
48
49 currentName = name;
50 currentElement = (WOElement) elements.objectForKey( name );
51 if ( currentElement == null )
52 {
53 currentElement = WOApplication.application().pageWithName( name, c );
54 if ( currentElement != null )
55 {
56 currentElement.associations = associations;
57 elements.setObjectForKey( currentElement, name );
58 }
59 }
60
61 return currentElement;
62 }
63
64 void ensureAwakeInContext (WOContext aContext)
65 {
66 if ( aContext != null )
67 {
68 WOElement element = getCurrentElement( aContext );
69 if ( element != null )
70 {
71 aContext.pushElement( element );
72 element.ensureAwakeInContext( aContext );
73 aContext.popElement();
74 }
75 }
76 }
77
78 public void takeValuesFromRequest(WORequest r, WOContext c)
79 {
80 WOElement element = getCurrentElement( c );
81 if ( element != null )
82 {
83 c.pushElement( element );
84 element.takeValuesFromRequest( r, c );
85 c.popElement();
86 }
87 }
88
89 public WOActionResults invokeAction(WORequest r, WOContext c)
90 {
91 WOActionResults result = null;
92 WOElement element = getCurrentElement( c );
93 if ( element != null )
94 {
95 c.pushElement( element );
96 result = element.invokeAction( r, c );
97 c.popElement();
98 }
99 return result;
100 }
101
102 public void appendToResponse(WOResponse r, WOContext c)
103 {
104 WOElement element = getCurrentElement( c );
105 if ( element != null )
106 {
107 c.pushElement( element );
108 element.appendToResponse( r, c );
109 c.popElement();
110 }
111 }
112 }