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.core.adapter; 17 18 import de.smartics.testdoc.core.doc.Type; 19 import de.smartics.testdoc.core.doc.UnitTestDoc; 20 import de.smartics.testdoc.core.doc.UnitTestDocIndex; 21 import de.smartics.testdoc.core.export.AbstractExportAdapter; 22 import de.smartics.testdoc.core.export.ExportException; 23 24 /** 25 * Exports the documentation to an in-memory singleton. 26 * 27 * @author <a href="mailto:robert.reiner@smartics.de">Robert Reiner</a> 28 * @version $Revision:591 $ 29 */ 30 public abstract class AbstractInMemoryExportAdapter extends 31 AbstractExportAdapter implements IndexProvider 32 { 33 // ********************************* Fields ********************************* 34 35 // --- constants ------------------------------------------------------------ 36 37 // --- members -------------------------------------------------------------- 38 39 /** 40 * The index that stores the exported documentation. 41 */ 42 private final UnitTestDocIndex index; 43 44 // ****************************** Initializer ******************************* 45 46 // ****************************** Constructors ****************************** 47 48 /** 49 * Inheritance constructor to allow subclasses to pass in the reference to the 50 * index. 51 * 52 * @param index the index that stores the exported documentation. 53 */ 54 protected AbstractInMemoryExportAdapter(final UnitTestDocIndex index) 55 { 56 this.index = index; 57 } 58 59 // ****************************** Inner Classes ***************************** 60 61 // ********************************* Methods ******************************** 62 63 // --- init ----------------------------------------------------------------- 64 65 // --- get&set -------------------------------------------------------------- 66 67 /** 68 * Returns the index that stores the exported documentation. 69 * 70 * @return the index that stores the exported documentation. 71 */ 72 @Override 73 public UnitTestDocIndex getIndex() 74 { 75 return index; 76 } 77 78 // --- business ------------------------------------------------------------- 79 80 /** 81 * {@inheritDoc} 82 * 83 * @see de.smartics.testdoc.core.export.ExportAdapter#export(de.smartics.testdoc.core.doc.UnitTestDoc) 84 */ 85 @Override 86 public void export(final UnitTestDoc testDoc) throws ExportException 87 { 88 index.register(testDoc); 89 } 90 91 /** 92 * {@inheritDoc} 93 * 94 * @see de.smartics.testdoc.core.export.ExportAdapter#clear(de.smartics.testdoc.core.doc.Type) 95 */ 96 @Override 97 public void clear(final Type testCaseType) 98 { 99 index.deregisterTestCase(testCaseType); 100 } 101 102 /** 103 * {@inheritDoc} 104 * 105 * @see de.smartics.testdoc.core.adapter.IndexProvider#load(de.smartics.testdoc.core.adapter.IndexProvider.UnitTestDocLoader) 106 */ 107 @Override 108 public void load(final UnitTestDocLoader loader) throws ImportException 109 { 110 for (final UnitTestDoc testDoc : loader.load()) 111 { 112 index.register(testDoc); 113 } 114 } 115 116 // --- object basics -------------------------------------------------------- 117 118 }