Content of file DefaultViewFactory.java.html

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../../jacoco-resources/report.gif" type="image/gif"/><title>DefaultViewFactory.java</title><link rel="stylesheet" href="../../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../../index.html" class="el_report">NorthernWind :: Frontend :: Components :: HTML Template</a> &gt; <a href="../index.html" class="el_bundle">it-tidalwave-northernwind-core-default</a> &gt; <a href="index.source.html" class="el_package">it.tidalwave.northernwind.frontend.impl.ui</a> &gt; <span class="el_source">DefaultViewFactory.java</span></div><h1>DefaultViewFactory.java</h1><pre class="source lang-java linenums">/*
 * #%L
 * *********************************************************************************************************************
 *
 * NorthernWind - lightweight CMS
 * http://northernwind.tidalwave.it - git clone https://bitbucket.org/tidalwave/northernwind-src.git
 * %%
 * Copyright (C) 2011 - 2023 Tidalwave s.a.s. (http://tidalwave.it)
 * %%
 * *********************************************************************************************************************
 *
 * Licensed under the Apache License, Version 2.0 (the &quot;License&quot;); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an &quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations under the License.
 *
 * *********************************************************************************************************************
 *
 *
 * *********************************************************************************************************************
 * #L%
 */
package it.tidalwave.northernwind.frontend.impl.ui;

import javax.annotation.Nonnull;
import javax.annotation.PostConstruct;
import java.util.Map;
import java.util.TreeMap;
import it.tidalwave.util.Id;
import it.tidalwave.util.NotFoundException;
import it.tidalwave.util.spring.ClassScanner;
import it.tidalwave.northernwind.core.model.HttpStatusException;
import it.tidalwave.northernwind.core.model.SiteNode;
import it.tidalwave.northernwind.frontend.ui.ViewFactory;
import it.tidalwave.northernwind.frontend.ui.annotation.ViewMetadata;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import static it.tidalwave.util.NotFoundException.throwWhenNull;

/***********************************************************************************************************************
 *
 * The default implementation of {@link ViewFactory}.
 *
 * @stereotype  Factory
 *
 * @author  Fabrizio Giudici
 *
 **********************************************************************************************************************/
<span class="pc" id="L56">@RequiredArgsConstructor @Slf4j @ToString</span>
public class DefaultViewFactory implements ViewFactory
  {
<span class="fc" id="L59">    /* package */ final Map&lt;String, ViewBuilder&gt; viewBuilderMapByTypeUri = new TreeMap&lt;&gt;();</span>

<span class="pc" id="L61">    @Getter @Setter</span>
    private boolean logConfigurationEnabled;

    /*******************************************************************************************************************
     *
     * {@inheritDoc}
     *
     ******************************************************************************************************************/
    @Override @Nonnull
    public ViewAndController createViewAndController (@Nonnull final String viewTypeUri,
                                                      @Nonnull final Id viewId,
                                                      @Nonnull final SiteNode siteNode)
      throws NotFoundException, HttpStatusException
      {
<span class="fc" id="L75">        final var viewBuilder = throwWhenNull(viewBuilderMapByTypeUri.get(viewTypeUri),</span>
<span class="fc" id="L76">                                              String.format(&quot;Cannot find %s: available: %s&quot;,</span>
<span class="fc" id="L77">                                                                    viewTypeUri, viewBuilderMapByTypeUri.keySet()));</span>
<span class="fc" id="L78">        return viewBuilder.createViewAndController(viewId, siteNode);</span>
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @PostConstruct
    /* package */ void initialize() // FIXME: gets called twice
gets called twice
throws IllegalArgumentException, SecurityException { <span class="fc" id="L89"> final var classScanner = new ClassScanner().withAnnotationFilter(ViewMetadata.class);</span> <span class="fc bfc" id="L91" title="All 2 branches covered."> for (final var viewClass : classScanner.findClasses())</span> { <span class="fc" id="L93"> final var viewMetadata = viewClass.getAnnotation(ViewMetadata.class);</span> <span class="fc" id="L94"> final var typeUri = viewMetadata.typeUri();</span> <span class="fc" id="L95"> final var viewBuilder = new ViewBuilder(viewClass, viewMetadata.controlledBy());</span> <span class="fc" id="L96"> viewBuilderMapByTypeUri.put(typeUri, viewBuilder);</span> <span class="fc" id="L97"> }</span> <span class="pc bpc" id="L99" title="1 of 2 branches missed."> if (logConfigurationEnabled)</span> { <span class="fc" id="L101"> logConfiguration();</span> } <span class="fc" id="L103"> }</span> /******************************************************************************************************************* * * ******************************************************************************************************************/ private void logConfiguration() { <span class="fc" id="L111"> log.info(&quot;View definitions:&quot;);</span> <span class="fc" id="L112"> viewBuilderMapByTypeUri.values().forEach(viewBuilder -&gt; log.info(&quot;&gt;&gt;&gt;&gt; {}&quot;, viewBuilder));</span> <span class="fc" id="L113"> }</span> } </pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.9.202303310957</span></div></body></html>