I am looking at below code to reuse on one of the component to export child nodes/components as json.
@notnull
@Override
public Map<String, ? extends ComponentExporter> getExportedItems() {
if (childModels == null) {
childModels = getChildModels(request, ComponentExporter.class);
}
return childModels;
}
@NotNull
@Override
public String[] getExportedItemsOrder() {
Map<String, ? extends ComponentExporter> models = getExportedItems();
if (models.isEmpty()) {
return ArrayUtils.EMPTY_STRING_ARRAY;
}
return models.keySet().toArray(ArrayUtils.EMPTY_STRING_ARRAY);
}
/**
* Returns a map (resource name => Sling Model class) of the given resource
* children's Sling Models that can be adapted to {@link T}.
*
* @Param slingRequest the current request
* @Param modelClass the Sling Model class to be adapted to
* @Return a map (resource name => Sling Model class) of the given resource
* children's Sling Models that can be adapted to {@link T}
*/
@NotNull
private <T> Map<String, T> getChildModels(@NotNull SlingHttpServletRequest slingRequest,
@notnull Class<T> modelClass) {
Map<String, T> itemWrappers = new LinkedHashMap<>();
for (final Resource child : slingModelFilter.filterChildResources(request.getResource().getChildren())) {
itemWrappers.put(child.getName(), modelFactory.getModelFromWrappedRequest(slingRequest, child, modelClass));
}
return itemWrappers;
}
getChildModels() : how does this method adapting to specific component adapter type? I see from ModelFactory class that this method passes "ComponentExporter.class" as modelClass / adapterType. I would like to understand how ModelFactory using ComponentExporter.class as adapterType to fetch model json for child components/nodes.
Doesn't adapterType needs to be Button.class if button is a child component or Teaser.class if Teaser is a child component?
Thanks for any insights.