View Javadoc

1   /*
2    * Copyright 2010-2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.testdoc.maven.export;
17  
18  import java.io.IOException;
19  import java.util.List;
20  import java.util.Set;
21  import java.util.TreeSet;
22  
23  import de.smartics.maven.util.report.MessageHelper;
24  import de.smartics.testdoc.core.doc.OutputManager;
25  import de.smartics.testdoc.core.doc.UnitTestDoc;
26  import de.smartics.testdoc.core.export.UnitTestDocExporter;
27  import de.smartics.testdoc.report.index.ExportIndex;
28  import de.smartics.testdoc.report.index.ExportMultiIndex;
29  
30  /**
31   * Export {@link UnitTestDoc} information to an output medium. The output to
32   * this medium is defined by a subclass. This class essentially holds the
33   * information and meta data to be exported.
34   *
35   * @author <a href="mailto:robert.reiner@smartics.de">Robert Reiner</a>
36   * @version $Revision:591 $
37   */
38  public abstract class AbstractOutputManager implements OutputManager
39  {
40    // ********************************* Fields *********************************
41  
42    // --- constants ------------------------------------------------------------
43  
44    // --- members --------------------------------------------------------------
45  
46    /**
47     * The name of the report to export.
48     */
49    protected final String reportName;
50  
51    /**
52     * The resource bundles with messages to display as labels in the generated
53     * report.
54     */
55    protected final MessageHelper messages;
56  
57    /**
58     * The exporter that knows the format of the file to be written.
59     */
60    protected final UnitTestDocExporter exporter;
61  
62    /**
63     * The multi index to create the sections of the output document.
64     */
65    protected final ExportMultiIndex index = new ExportMultiIndex();
66  
67    /**
68     * The cached test documentation instances.
69     */
70    protected final Set<UnitTestDoc> testDocs;
71  
72    // ****************************** Initializer *******************************
73  
74    // ****************************** Constructors ******************************
75  
76    /**
77     * Default constructor.
78     *
79     * @param reportName the name of the report to export.
80     * @param messages the resource bundles with messages to display as labels in
81     *          the generated report.
82     * @param exporter the exporter that knows the format of the file to be
83     *          written.
84     * @param exportIndices the indices to created.
85     */
86    protected AbstractOutputManager(final String reportName,
87        final MessageHelper messages, final AbstractReportExporter exporter,
88        final List<ExportIndex> exportIndices)
89    {
90      this.reportName = reportName;
91      this.messages = messages;
92      this.exporter = exporter;
93      this.testDocs =
94          new TreeSet<UnitTestDoc>(exporter.getTestDocHelper()
95              .getUnitTestDocComparator());
96      for (final ExportIndex exportIndex : exportIndices)
97      {
98        index.addIndex(exportIndex);
99      }
100   }
101 
102   // ****************************** Inner Classes *****************************
103 
104   // ********************************* Methods ********************************
105 
106   // --- init -----------------------------------------------------------------
107 
108   // --- get&set --------------------------------------------------------------
109 
110   // --- business -------------------------------------------------------------
111 
112   /**
113    * {@inheritDoc}
114    *
115    * @see de.smartics.testdoc.report.doc.OutputManager#init()
116    */
117   @Override
118   public void init()
119   {
120   }
121 
122   /**
123    * {@inheritDoc}
124    *
125    * @see de.smartics.testdoc.report.doc.OutputManager#export(de.smartics.testdoc.report.doc.UnitTestDoc)
126    */
127   @Override
128   public void export(final UnitTestDoc testDoc) throws IOException
129   {
130     index.addToIndex(testDoc);
131     testDocs.add(testDoc);
132   }
133 
134   // --- object basics --------------------------------------------------------
135 
136 }