Skip to content

Commit 685e5aa

Browse files
Slight cleanup in NGSwitchComponent
1 parent cc4338f commit 685e5aa

File tree

1 file changed

+23
-30
lines changed

1 file changed

+23
-30
lines changed

ng-appserver/src/main/java/ng/appserver/elements/NGSwitchComponent.java

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
import ng.appserver.templating.assications.NGAssociation;
1919

2020
/**
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
2422
*/
2523

2624
public class NGSwitchComponent extends NGDynamicElement implements NGStructuralElement {
@@ -43,38 +41,33 @@ public class NGSwitchComponent extends NGDynamicElement implements NGStructuralE
4341
private final Map<String, NGElement> _componentCache;
4442
private final Map<String, String> _elementIDByName;
4543

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 ) {
4745
super( null, null, null );
4846

49-
_componentNameAssociation = associations.get( "componentName" );
47+
_componentNameAssociation = associations.remove( "componentName" );
5048

5149
if( _componentNameAssociation == null ) {
5250

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" );
5553

5654
if( _componentNameAssociation == null ) {
57-
throw new NGBindingConfigurationException( "[componentName] is a reuired binding" );
55+
throw new NGBindingConfigurationException( "[componentName] is a required binding" );
5856
}
5957
}
6058

59+
// Keep the remaining associations for passing on to the component
6160
_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<>();
6861
_contentTemplate = contentTemplate;
69-
62+
_componentCache = new ConcurrentHashMap<>();
7063
_elementIDByName = new ConcurrentHashMap<>();
7164
}
7265

7366
private String componentName( final NGComponent localWOComponent ) {
7467
return (String)_componentNameAssociation.valueInComponent( localWOComponent );
7568
}
7669

77-
public String _elementNameInContext( String name, final NGContext paramWOContext ) {
70+
private String elementNameInContext( String name, final NGContext context ) {
7871
String id = _elementIDByName.get( name );
7972

8073
if( id == null ) {
@@ -87,33 +80,33 @@ public String _elementNameInContext( String name, final NGContext paramWOContext
8780
return name;
8881
}
8982

90-
public NGElement _realComponentWithName( final String name, final String elementIDString ) {
83+
private NGElement realComponentWithName( final String name, final String elementIDString ) {
9184

9285
// 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 );
9487

9588
// 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 );
9891

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 ) );
10194
}
10295

103-
_componentCache.put( elementIDString, localWOElement );
96+
_componentCache.put( elementIDString, elementInstance );
10497
}
10598

106-
return localWOElement;
99+
return elementInstance;
107100
}
108101

109102
@Override
110103
public void takeValuesFromRequest( final NGRequest request, final NGContext context ) {
111104
final String name = componentName( context.component() );
112-
final String id = _elementNameInContext( name, context );
105+
final String id = elementNameInContext( name, context );
113106

114107
context.elementID().addBranchAndSet( Integer.parseInt( id ) );
115108

116-
final NGElement componentElement = _realComponentWithName( name, id );
109+
final NGElement componentElement = realComponentWithName( name, id );
117110

118111
componentElement.takeValuesFromRequest( request, context );
119112

@@ -123,11 +116,11 @@ public void takeValuesFromRequest( final NGRequest request, final NGContext cont
123116
@Override
124117
public NGActionResults invokeAction( final NGRequest request, final NGContext context ) {
125118
final String name = componentName( context.component() );
126-
final String id = _elementNameInContext( name, context );
119+
final String id = elementNameInContext( name, context );
127120

128121
context.elementID().addBranchAndSet( Integer.parseInt( id ) );
129122

130-
final NGElement componentElement = _realComponentWithName( name, id );
123+
final NGElement componentElement = realComponentWithName( name, id );
131124

132125
final NGActionResults localWOActionResults = componentElement.invokeAction( request, context );
133126

@@ -144,11 +137,11 @@ public void appendToResponse( NGResponse response, NGContext context ) {
144137
@Override
145138
public void appendStructureToResponse( NGResponse response, NGContext context ) {
146139
final String name = componentName( context.component() );
147-
final String id = _elementNameInContext( name, context );
140+
final String id = elementNameInContext( name, context );
148141

149142
context.elementID().addBranchAndSet( Integer.parseInt( id ) );
150143

151-
final NGElement componentElement = _realComponentWithName( name, id );
144+
final NGElement componentElement = realComponentWithName( name, id );
152145

153146
componentElement.appendToResponse( response, context );
154147

0 commit comments

Comments
 (0)