Skip to content

Package: DefaultViewFactory

DefaultViewFactory

nameinstructionbranchcomplexitylinemethod
DefaultViewFactory()
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
createViewAndController(String, Id, SiteNode)
M: 0 C: 27
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
initialize()
M: 0 C: 45
100%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 10
100%
M: 0 C: 1
100%
isLogConfigurationEnabled()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$logConfiguration$0(ViewBuilder)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
logConfiguration()
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
setLogConfigurationEnabled(boolean)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
toString()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%L
3: * *********************************************************************************************************************
4: *
5: * NorthernWind - lightweight CMS
6: * http://northernwind.tidalwave.it - git clone https://bitbucket.org/tidalwave/northernwind-src.git
7: * %%
8: * Copyright (C) 2011 - 2023 Tidalwave s.a.s. (http://tidalwave.it)
9: * %%
10: * *********************************************************************************************************************
11: *
12: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
13: * the License. You may obtain a copy of the License at
14: *
15: * http://www.apache.org/licenses/LICENSE-2.0
16: *
17: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
18: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
19: * specific language governing permissions and limitations under the License.
20: *
21: * *********************************************************************************************************************
22: *
23: *
24: * *********************************************************************************************************************
25: * #L%
26: */
27: package it.tidalwave.northernwind.frontend.impl.ui;
28:
29: import javax.annotation.Nonnull;
30: import javax.annotation.PostConstruct;
31: import java.util.Map;
32: import java.util.TreeMap;
33: import it.tidalwave.util.Id;
34: import it.tidalwave.util.NotFoundException;
35: import it.tidalwave.util.spring.ClassScanner;
36: import it.tidalwave.northernwind.core.model.HttpStatusException;
37: import it.tidalwave.northernwind.core.model.SiteNode;
38: import it.tidalwave.northernwind.frontend.ui.ViewFactory;
39: import it.tidalwave.northernwind.frontend.ui.annotation.ViewMetadata;
40: import lombok.Getter;
41: import lombok.RequiredArgsConstructor;
42: import lombok.Setter;
43: import lombok.ToString;
44: import lombok.extern.slf4j.Slf4j;
45: import static it.tidalwave.util.NotFoundException.throwWhenNull;
46:
47: /***********************************************************************************************************************
48: *
49: * The default implementation of {@link ViewFactory}.
50: *
51: * @stereotype Factory
52: *
53: * @author Fabrizio Giudici
54: *
55: **********************************************************************************************************************/
56: @RequiredArgsConstructor @Slf4j @ToString
57: public class DefaultViewFactory implements ViewFactory
58: {
59: /* package */ final Map<String, ViewBuilder> viewBuilderMapByTypeUri = new TreeMap<>();
60:
61: @Getter @Setter
62: private boolean logConfigurationEnabled;
63:
64: /*******************************************************************************************************************
65: *
66: * {@inheritDoc}
67: *
68: ******************************************************************************************************************/
69: @Override @Nonnull
70: public ViewAndController createViewAndController (@Nonnull final String viewTypeUri,
71: @Nonnull final Id viewId,
72: @Nonnull final SiteNode siteNode)
73: throws NotFoundException, HttpStatusException
74: {
75: final var viewBuilder = throwWhenNull(viewBuilderMapByTypeUri.get(viewTypeUri),
76: String.format("Cannot find %s: available: %s",
77: viewTypeUri, viewBuilderMapByTypeUri.keySet()));
78: return viewBuilder.createViewAndController(viewId, siteNode);
79: }
80:
81: /*******************************************************************************************************************
82: *
83: *
84: ******************************************************************************************************************/
85: @PostConstruct
86: /* package */ void initialize() // FIXME: gets called twice
87: throws IllegalArgumentException, SecurityException
88: {
89: final var classScanner = new ClassScanner().withAnnotationFilter(ViewMetadata.class);
90:
91:• for (final var viewClass : classScanner.findClasses())
92: {
93: final var viewMetadata = viewClass.getAnnotation(ViewMetadata.class);
94: final var typeUri = viewMetadata.typeUri();
95: final var viewBuilder = new ViewBuilder(viewClass, viewMetadata.controlledBy());
96: viewBuilderMapByTypeUri.put(typeUri, viewBuilder);
97: }
98:
99:• if (logConfigurationEnabled)
100: {
101: logConfiguration();
102: }
103: }
104:
105: /*******************************************************************************************************************
106: *
107: *
108: ******************************************************************************************************************/
109: private void logConfiguration()
110: {
111: log.info("View definitions:");
112: viewBuilderMapByTypeUri.values().forEach(viewBuilder -> log.info(">>>> {}", viewBuilder));
113: }
114: }