Skip to content

Commit bebee3e

Browse files
Add some symmetry to dynamic element/component reference creation
1 parent 3b350e8 commit bebee3e

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

ng-appserver/src/main/java/ng/appserver/templating/NGElementManager.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,6 @@ private static NGComponentDefinition componentDefinition( final String component
7575
return NGComponentDefinition.get( componentName );
7676
}
7777

78-
/**
79-
* @return A new component reference element for inserting into a template being rendered
80-
*/
81-
private static NGComponentReference componentReference( final NGComponentDefinition componentDefinition, final Map<String, NGAssociation> associations, final NGElement contentTemplate ) {
82-
return NGComponentReference.of( componentDefinition, associations, contentTemplate );
83-
}
84-
8578
/**
8679
* @param name The name identifying what element we're getting
8780
* @param associations Associations used to bind the generated element to it's parent
@@ -109,7 +102,7 @@ public NGDynamicElement dynamicElementWithName( final String namespace, final St
109102
// If we don't find a class for the element, we're going to try going down the route of a classless component.
110103
if( elementClass == null ) {
111104
final NGComponentDefinition componentDefinition = componentDefinition( elementName );
112-
return componentReference( componentDefinition, associations, contentTemplate );
105+
return createComponentReference( componentDefinition, associations, contentTemplate );
113106
}
114107

115108
// First we check if this is a dynamic element
@@ -120,17 +113,15 @@ public NGDynamicElement dynamicElementWithName( final String namespace, final St
120113
// If it's not an element, let's move on to creating a component reference instead
121114
if( NGComponent.class.isAssignableFrom( elementClass ) ) {
122115
final NGComponentDefinition componentDefinition = componentDefinition( (Class<? extends NGComponent>)elementClass );
123-
return componentReference( componentDefinition, associations, contentTemplate );
116+
return createComponentReference( componentDefinition, associations, contentTemplate );
124117
}
125118

126119
// We should never end up here unless we got an incorrect/non-existent element name
127120
throw new NGElementNotFoundException( "I could not construct a dynamic element named '%s'".formatted( elementName ), elementName );
128121
}
129122

130123
/**
131-
* @return A new NGDynamicElement constructed using the given parameters
132-
*
133-
* Really just a shortcut for invoking a dynamic element class' constructor via reflection.
124+
* @return A new NGDynamicElement constructed using the given parameters. Really just a shortcut for invoking a dynamic element class' constructor via reflection.
134125
*/
135126
private static <E extends NGDynamicElement> E createDynamicElementInstance( final Class<E> elementClass, final String name, final Map<String, NGAssociation> associations, final NGElement contentTemplate ) {
136127
final Class<?>[] parameterTypes = { String.class, Map.class, NGElement.class };
@@ -145,6 +136,13 @@ private static <E extends NGDynamicElement> E createDynamicElementInstance( fina
145136
}
146137
}
147138

139+
/**
140+
* @return A new component reference element for inserting into a template being rendered
141+
*/
142+
private static NGComponentReference createComponentReference( final NGComponentDefinition componentDefinition, final Map<String, NGAssociation> associations, final NGElement contentTemplate ) {
143+
return NGComponentReference.of( componentDefinition, associations, contentTemplate );
144+
}
145+
148146
/**
149147
* Packages that we look for element classes in
150148
*/

0 commit comments

Comments
 (0)