18
18
import ng .appserver .templating .assications .NGAssociation ;
19
19
20
20
/**
21
- * Implementation based on Project Wonder's ERXWOSwitchComponent by
22
- *
23
- * Original author from Project Wonder: ak
21
+ * Implementation based on Project Wonder's ERXWOSwitchComponent by ak
24
22
*/
25
23
26
24
public class NGSwitchComponent extends NGDynamicElement implements NGStructuralElement {
@@ -43,38 +41,33 @@ public class NGSwitchComponent extends NGDynamicElement implements NGStructuralE
43
41
private final Map <String , NGElement > _componentCache ;
44
42
private final Map <String , String > _elementIDByName ;
45
43
46
- public NGSwitchComponent ( final String paramString , final Map <String , NGAssociation > associations , final NGElement contentTemplate ) {
44
+ public NGSwitchComponent ( final String name , final Map <String , NGAssociation > associations , final NGElement contentTemplate ) {
47
45
super ( null , null , null );
48
46
49
- _componentNameAssociation = associations .get ( "componentName" );
47
+ _componentNameAssociation = associations .remove ( "componentName" );
50
48
51
49
if ( _componentNameAssociation == null ) {
52
50
53
- // FIXME: This second check is for compatibility with WO's switch component binding // Hugi 2025-05-13
54
- _componentNameAssociation = associations .get ( "WOComponentName" );
51
+ // CHECKME: Old binding name from WO, to eventually be removed (see our notes on binding deprecation) // Hugi 2025-05-13
52
+ _componentNameAssociation = associations .remove ( "WOComponentName" );
55
53
56
54
if ( _componentNameAssociation == null ) {
57
- throw new NGBindingConfigurationException ( "[componentName] is a reuired binding" );
55
+ throw new NGBindingConfigurationException ( "[componentName] is a required binding" );
58
56
}
59
57
}
60
58
59
+ // Keep the remaining associations for passing on to the component
61
60
_componentAssociations = new HashMap <>( associations );
62
- _componentAssociations .remove ( "componentName" );
63
-
64
- // FIXME: This second check is for compatibility with WO's switch component binding // Hugi 2025-05-13
65
- _componentAssociations .remove ( "WOComponentName" );
66
-
67
- _componentCache = new ConcurrentHashMap <>();
68
61
_contentTemplate = contentTemplate ;
69
-
62
+ _componentCache = new ConcurrentHashMap <>();
70
63
_elementIDByName = new ConcurrentHashMap <>();
71
64
}
72
65
73
66
private String componentName ( final NGComponent localWOComponent ) {
74
67
return (String )_componentNameAssociation .valueInComponent ( localWOComponent );
75
68
}
76
69
77
- public String _elementNameInContext ( String name , final NGContext paramWOContext ) {
70
+ private String elementNameInContext ( String name , final NGContext context ) {
78
71
String id = _elementIDByName .get ( name );
79
72
80
73
if ( id == null ) {
@@ -87,33 +80,33 @@ public String _elementNameInContext( String name, final NGContext paramWOContext
87
80
return name ;
88
81
}
89
82
90
- public NGElement _realComponentWithName ( final String name , final String elementIDString ) {
83
+ private NGElement realComponentWithName ( final String name , final String elementIDString ) {
91
84
92
85
// Check if we've already rendered the given component, in that case get the instance.
93
- NGElement localWOElement = _componentCache .get ( elementIDString );
86
+ NGElement elementInstance = _componentCache .get ( elementIDString );
94
87
95
88
// No component instance found so we're going to have to construct a new one
96
- if ( localWOElement == null ) {
97
- localWOElement = NGApplication .application ().elementManager ().dynamicElementWithName ( NGElementManager .GLOBAL_UNNAMESPACED_NAMESPACE , name , _componentAssociations , _contentTemplate );
89
+ if ( elementInstance == null ) {
90
+ elementInstance = NGApplication .application ().elementManager ().dynamicElementWithName ( NGElementManager .GLOBAL_UNNAMESPACED_NAMESPACE , name , _componentAssociations , _contentTemplate );
98
91
99
- if ( localWOElement == null ) {
100
- throw new RuntimeException ( "<" + getClass (). getName () + "> : cannot find component or dynamic element named " + name );
92
+ if ( elementInstance == null ) {
93
+ throw new RuntimeException ( "%s : cannot find component or dynamic element named %s" . formatted ( getClass (). getName (), name ) );
101
94
}
102
95
103
- _componentCache .put ( elementIDString , localWOElement );
96
+ _componentCache .put ( elementIDString , elementInstance );
104
97
}
105
98
106
- return localWOElement ;
99
+ return elementInstance ;
107
100
}
108
101
109
102
@ Override
110
103
public void takeValuesFromRequest ( final NGRequest request , final NGContext context ) {
111
104
final String name = componentName ( context .component () );
112
- final String id = _elementNameInContext ( name , context );
105
+ final String id = elementNameInContext ( name , context );
113
106
114
107
context .elementID ().addBranchAndSet ( Integer .parseInt ( id ) );
115
108
116
- final NGElement componentElement = _realComponentWithName ( name , id );
109
+ final NGElement componentElement = realComponentWithName ( name , id );
117
110
118
111
componentElement .takeValuesFromRequest ( request , context );
119
112
@@ -123,11 +116,11 @@ public void takeValuesFromRequest( final NGRequest request, final NGContext cont
123
116
@ Override
124
117
public NGActionResults invokeAction ( final NGRequest request , final NGContext context ) {
125
118
final String name = componentName ( context .component () );
126
- final String id = _elementNameInContext ( name , context );
119
+ final String id = elementNameInContext ( name , context );
127
120
128
121
context .elementID ().addBranchAndSet ( Integer .parseInt ( id ) );
129
122
130
- final NGElement componentElement = _realComponentWithName ( name , id );
123
+ final NGElement componentElement = realComponentWithName ( name , id );
131
124
132
125
final NGActionResults localWOActionResults = componentElement .invokeAction ( request , context );
133
126
@@ -144,11 +137,11 @@ public void appendToResponse( NGResponse response, NGContext context ) {
144
137
@ Override
145
138
public void appendStructureToResponse ( NGResponse response , NGContext context ) {
146
139
final String name = componentName ( context .component () );
147
- final String id = _elementNameInContext ( name , context );
140
+ final String id = elementNameInContext ( name , context );
148
141
149
142
context .elementID ().addBranchAndSet ( Integer .parseInt ( id ) );
150
143
151
- final NGElement componentElement = _realComponentWithName ( name , id );
144
+ final NGElement componentElement = realComponentWithName ( name , id );
152
145
153
146
componentElement .appendToResponse ( response , context );
154
147
0 commit comments