View Javadoc
1   /*
2    * #%L
3    * EUGene :: EUGene
4    * %%
5    * Copyright (C) 2004 - 2010 CodeLutin
6    * %%
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Lesser General Public License as 
9    * published by the Free Software Foundation, either version 3 of the 
10   * License, or (at your option) any later version.
11   * 
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Lesser Public License for more details.
16   * 
17   * You should have received a copy of the GNU General Lesser Public 
18   * License along with this program.  If not, see
19   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
20   * #L%
21   */
22  
23  package org.nuiton.eugene.writer;
24  
25  import java.io.File;
26  import java.io.IOException;
27  import java.util.List;
28  import java.util.Map;
29  
30  /**
31   * Contract to generate files from any incoming sources (zargo, xmi, ...) to any other ones.
32   *
33   * User: chemit Date: 27 nov. 2009 Time: 11:20:39
34   *
35   * @since 2.0.0
36   */
37  public interface ChainedFileWriter {
38  
39      /** @return the accepted incoming protocol */
40      String getInputProtocol();
41  
42      /**
43       * Obtain the input protocol of this writer given the passed {@code modelType}.
44       *
45       * @param modelType the type of model used
46       * @return the input protocol or {@code null} if this writer does not accept the type of model
47       */
48      String getInputProtocol(String modelType);
49  
50      /**
51       * Obtain the output protocol of this writer given the passed {@code modelType}.
52       *
53       * @param modelType the type of model used
54       * @return the output protocol or {@code null} if should not be chained
55       */
56      String getOutputProtocol(String modelType);
57  
58      /**
59       * Test if a type of model can be treated by this writer.
60       *
61       * @param modelType model type to test
62       * @return {@code true} if this writer accept the given type of model, {@code false} otherwise.
63       */
64      boolean acceptModel(String modelType);
65  
66      /**
67       * Test in a entry can be treated by this writer.
68       *
69       * @param include the include to test
70       * @return {@code true} if the writer accept the entry, {@code false} otherwise.
71       */
72      boolean acceptInclude(String include);
73  
74      /**
75       * @return the default includes files to be treated by the writer (can be an ant-like expression)
76       */
77      String getDefaultIncludes();
78  
79      /** @return the defalt relative path where to pick files to treate. */
80      String getDefaultInputDirectory();
81  
82      /**
83       * @return the defalt relative path where to pick files to treate on a test phase.
84       */
85      String getDefaultTestInputDirectory();
86  
87      /** @return the default relative path to add to output basedir */
88      String getDefaultOutputDirectory();
89  
90      /**
91       * @return the default relative path to add to output basedir on a test
92       * phase.
93       */
94      String getDefaultTestOutputDirectory();
95  
96      /**
97       * Obtain the real directory where to write files.
98       *
99       * //FIXME-TC20091126 make this configurable (via the properties)
100      *
101      * @param outputBasedir the output base directory
102      * @param testPhase     {@code true} if writer is used in a test phase
103      * @return the real output directory where to generate for this particular writer
104      */
105     File getOutputDirectory(File outputBasedir, boolean testPhase);
106 
107     /**
108      * Obtain the real directory where to extract files (when using resources
109      * from class-path).
110      *
111      * @param outputBasedir the output base directory
112      * @param testPhase     {@code true} if writer is used in a test phase
113      * @return the real output directory where to extract for this particular
114      * writer
115      * @since 2.1.3
116      */
117     File getExtractDirectory(File outputBasedir, boolean testPhase);
118 
119     /**
120      * Launch the generation for this writer with all pre-computed data to
121      * treate and resources to copy.
122      *
123      * @param configuration the share configuration of all writers.
124      * @param data          data to treate (files to react + resources to copy)
125      * @throws IOException if any io pb.
126      * @since 2.1.3
127      */
128     void generate(ChainedFileWriterConfiguration configuration,
129                   ChainedFileWriterData data)
130             throws IOException;
131 
132 //    /**
133 //     * Obtain for a given {@code inputDirectory}, all files to treate.
134 //     *
135 //     * @param configuration  the shared configuration
136 //     * @param inputPath      the input path (can be a directory or a classpath path)
137 //     * @param includePattern the include pattern separated by comma
138 //     * @param inClassPath    a flag to say if we should search in classpath
139 //     * @return the list of resources detected
140 //     * @throws IOException              if any IO pb while searching resources
141 //     * @throws IllegalArgumentException if no include pattern given
142 //     * @since 2.1.3
143 //     */
144 //    List<URL> getFiles(ChainedFileWriterConfiguration configuration,
145 //                       String inputPath,
146 //                       List<String> includePattern,
147 //                       boolean inClassPath) throws IOException, IllegalArgumentException;
148 //
149 //    /**
150 //     * Obtain the optional resource files associated to the given file to react.
151 //     *
152 //     * @param file the file to react
153 //     * @return the array of resources associated to the file
154 //     * @throws IOException if could not get resources
155 //     * @since 2.1.3
156 //     */
157 //    List<URL> getResources(URL file) throws IOException;
158 
159     /** Clear all internal states */
160     void clear();
161 
162     /**
163      * Add an entry to treate.
164      *
165      * @param entry the entry to add to writer
166      */
167     void addEntry(ChainedFileWriterEntry entry);
168 
169     /**
170      * @return the array of properties names authorized for the chained writer.
171      */
172     String[] getAuthorizedPropertyNames();
173 
174     /**
175      * @return the dictionnary of authorized property descriptions (keys are
176      * property names and values are descriptions).
177      */
178     Map<String, String> getAuthorizedPropertyDescriptions();
179 
180     /**
181      * Obtain a writer extra property.
182      *
183      * @param key  the key of required property
184      * @param type the type of property
185      * @param <T>  the type of property
186      * @return the property found or {@code null} if not found.
187      */
188     <T> T getProperty(String key, Class<T> type);
189 
190     /** @return the list of all entries registered */
191     List<ChainedFileWriterEntry> getEntries();
192 
193 
194     /** @return the writer report (to save generated file to later report) */
195     WriterReport getWriterReport();
196 
197     void setWriterReport(WriterReport writerReport);
198 
199 }