Package org.nuiton.eugene.writer
Class AbstractChainedFileWriter
- java.lang.Object
-
- org.nuiton.eugene.writer.AbstractChainedFileWriter
-
- All Implemented Interfaces:
ChainedFileWriter
public abstract class AbstractChainedFileWriter extends Object implements ChainedFileWriter
Abstract implementation of theChainedFileWriter.- Since:
- 2.0.0
- Author:
- Tony Chemit - dev@tchemit.fr
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<String,String>authorizedPropertyDescriptionsuniverse of authorized properties (keys are property names, values are property descriptions).protected List<ChainedFileWriterEntry>entriesentries to treate with this writerprotected ChainedFileWriternextWriternext writer (can be null)protected ChainedFileWriterpreviousWriterprevious writer (can be null)protected Map<String,Object>propertiesreal properties obtained fro a configuration ininitWriter(ChainedFileWriterConfiguration)method
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractChainedFileWriter(String... propertyNameAndDescriptions)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddEntry(ChainedFileWriterEntry entry)Add an entry to treate.voidclear()Clear all internal statesprotected abstract voidgenerate(ChainedFileWriterConfiguration configuration, File outputDir, Map<File,List<File>> filesByRoot, Map<File,List<File>> resourcesByFile)Generates for all given files (filesByRootand then copy resources given for his file reacted in theresourcesByFiledictionnary.voidgenerate(ChainedFileWriterConfiguration configuration, ChainedFileWriterData data)Launch the generation for this writer with all pre-computed data to treate and resources to copy.Map<String,String>getAuthorizedPropertyDescriptions()String[]getAuthorizedPropertyNames()List<ChainedFileWriterEntry>getEntries()FilegetExtractDirectory(File outputBasedir, boolean testPhase)Obtain the real directory where to extract files (when using resources from class-path).StringgetInputProtocol(String modelType)Obtain the input protocol of this writer given the passedmodelType.protected ChainedFileWritergetNextWriter()FilegetOutputDirectory(File outputBasedir, boolean testPhase)Obtain the real directory where to write files.protected ChainedFileWritergetPreviousWriter()<T> TgetProperty(String key, Class<T> type)Obtain a writer extra property.WriterReportgetWriterReport()protected voidinitWriter(ChainedFileWriterConfiguration configuration)Initialize the writer before the generation.protected voidsetNextWriter(ChainedFileWriter nextWriter)voidsetWriterReport(WriterReport writerReport)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.nuiton.eugene.writer.ChainedFileWriter
acceptInclude, acceptModel, getDefaultIncludes, getDefaultInputDirectory, getDefaultOutputDirectory, getDefaultTestInputDirectory, getDefaultTestOutputDirectory, getInputProtocol, getOutputProtocol
-
-
-
-
Field Detail
-
entries
protected List<ChainedFileWriterEntry> entries
entries to treate with this writer
-
previousWriter
protected ChainedFileWriter previousWriter
previous writer (can be null)
-
nextWriter
protected ChainedFileWriter nextWriter
next writer (can be null)
-
authorizedPropertyDescriptions
protected final Map<String,String> authorizedPropertyDescriptions
universe of authorized properties (keys are property names, values are property descriptions).
-
properties
protected Map<String,Object> properties
real properties obtained fro a configuration ininitWriter(ChainedFileWriterConfiguration)method
-
-
Constructor Detail
-
AbstractChainedFileWriter
protected AbstractChainedFileWriter(String... propertyNameAndDescriptions)
-
-
Method Detail
-
generate
protected abstract void generate(ChainedFileWriterConfiguration configuration, File outputDir, Map<File,List<File>> filesByRoot, Map<File,List<File>> resourcesByFile) throws IOException
Generates for all given files (filesByRootand then copy resources given for his file reacted in theresourcesByFiledictionnary.- Parameters:
configuration- the shared configuration for all writersoutputDir- where to generate filesfilesByRoot- all files to treateresourcesByFile- resources associated to files to treate- Throws:
IOException- for any IO pb.- Since:
- 2.1.3
-
getAuthorizedPropertyDescriptions
public Map<String,String> getAuthorizedPropertyDescriptions()
- Specified by:
getAuthorizedPropertyDescriptionsin interfaceChainedFileWriter- Returns:
- the dictionnary of authorized property descriptions (keys are property names and values are descriptions).
-
getAuthorizedPropertyNames
public String[] getAuthorizedPropertyNames()
- Specified by:
getAuthorizedPropertyNamesin interfaceChainedFileWriter- Returns:
- the array of properties names authorized for the chained writer.
-
clear
public void clear()
Description copied from interface:ChainedFileWriterClear all internal states- Specified by:
clearin interfaceChainedFileWriter
-
addEntry
public void addEntry(ChainedFileWriterEntry entry)
Description copied from interface:ChainedFileWriterAdd an entry to treate.- Specified by:
addEntryin interfaceChainedFileWriter- Parameters:
entry- the entry to add to writer
-
getProperty
public <T> T getProperty(String key, Class<T> type)
Description copied from interface:ChainedFileWriterObtain a writer extra property.- Specified by:
getPropertyin interfaceChainedFileWriter- Type Parameters:
T- the type of property- Parameters:
key- the key of required propertytype- the type of property- Returns:
- the property found or
nullif not found.
-
generate
public void generate(ChainedFileWriterConfiguration configuration, ChainedFileWriterData data) throws IOException
Description copied from interface:ChainedFileWriterLaunch the generation for this writer with all pre-computed data to treate and resources to copy.- Specified by:
generatein interfaceChainedFileWriter- Parameters:
configuration- the share configuration of all writers.data- data to treate (files to react + resources to copy)- Throws:
IOException- if any io pb.
-
getInputProtocol
public String getInputProtocol(String modelType)
Description copied from interface:ChainedFileWriterObtain the input protocol of this writer given the passedmodelType.- Specified by:
getInputProtocolin interfaceChainedFileWriter- Parameters:
modelType- the type of model used- Returns:
- the input protocol or
nullif this writer does not accept the type of model
-
getOutputDirectory
public File getOutputDirectory(File outputBasedir, boolean testPhase)
Description copied from interface:ChainedFileWriterObtain the real directory where to write files. //FIXME-TC20091126 make this configurable (via the properties)- Specified by:
getOutputDirectoryin interfaceChainedFileWriter- Parameters:
outputBasedir- the output base directorytestPhase-trueif writer is used in a test phase- Returns:
- the real output directory where to generate for this particular writer
-
getExtractDirectory
public File getExtractDirectory(File outputBasedir, boolean testPhase)
Description copied from interface:ChainedFileWriterObtain the real directory where to extract files (when using resources from class-path).- Specified by:
getExtractDirectoryin interfaceChainedFileWriter- Parameters:
outputBasedir- the output base directorytestPhase-trueif writer is used in a test phase- Returns:
- the real output directory where to extract for this particular writer
-
getEntries
public List<ChainedFileWriterEntry> getEntries()
- Specified by:
getEntriesin interfaceChainedFileWriter- Returns:
- the list of all entries registered
-
getWriterReport
public WriterReport getWriterReport()
- Specified by:
getWriterReportin interfaceChainedFileWriter- Returns:
- the writer report (to save generated file to later report)
-
setWriterReport
public void setWriterReport(WriterReport writerReport)
- Specified by:
setWriterReportin interfaceChainedFileWriter
-
getNextWriter
protected ChainedFileWriter getNextWriter()
-
getPreviousWriter
protected ChainedFileWriter getPreviousWriter()
-
setNextWriter
protected void setNextWriter(ChainedFileWriter nextWriter)
-
initWriter
protected void initWriter(ChainedFileWriterConfiguration configuration)
Initialize the writer before the generation.- Parameters:
configuration- the configuration to use for int
-
-