Class XMLWriterImpl
- java.lang.Object
-
- de.uni_trier.wi2.procake.utils.composition.FactoryObjectImplementation
-
- de.uni_trier.wi2.procake.data.io.IOImpl
-
- de.uni_trier.wi2.procake.data.io.xml.xerces_writerImpl.XMLWriterImpl
-
- Direct Known Subclasses:
DependencyWriterImpl,ModelWriterImpl,ObjectPoolWriterImpl,ObjectWriterImpl,SimilarityModelWriterImpl,TrainingPoolWriter,WorkflowGraphMLYWriterImpl,WorkflowWriterImpl
public abstract class XMLWriterImpl extends IOImpl implements Writer
Abstract class for code reuse. All Writer-implementations do have several features in common.- Author:
- Alexander Stromer
-
-
Field Summary
Fields Modifier and Type Field Description protected StringfilenameName of the XML-file to write into.protected OutputStreamoutputStreamOutputstream to write into.-
Fields inherited from interface de.uni_trier.wi2.procake.utils.io.IO
COMPONENT, COMPONENT_KEY, DEFAULT_ENCODING, LOG_CONTENTHANDLER_NOT_FOUND, LOG_FILE_NOT_FOUND, LOG_IO_EXCEPTION, LOG_READER_NOT_FOUND, LOG_SAX_EXCEPTION, LOG_UNKNOWN_PARAMETER, LOG_WRITER_NOT_FOUND, LOG_WRONG_PARAMATER_TYPE, RESOURCE_XML
-
Fields inherited from interface de.uni_trier.wi2.procake.utils.io.Writer
COMPONENT, COMPONENT_KEY, LOG_CANNOT_WRITE, LOG_NO_WRITER_FOUND, LOG_UNEXPECTED_IOEXCEPTION
-
-
Constructor Summary
Constructors Constructor Description XMLWriterImpl()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected StringcorrectPrefix(String currentPrefix, String alternatePrefix)Analyses the given namespace-prefix and corrects it if neccessary.protected XMLSchemaBasedWritercreateXMLWriter()Based on the setting of filename and outputstream an outputmode is chosen.abstract voidinsertNamespace(XMLSchemaBasedWriter writer)Adds the namespace-imports of this handler to the given xmlWriter.voidsetFilename(String filename)Each writer must be able to write a file to the local filesytem.voidsetOutputStream(OutputStream output)Each writer must be able to store the object into an OutputStream.voidstore(Object value)The store command writes the given value.abstract voidstore(Object value, XMLSchemaBasedWriter writer)To embed xml writers into another one it must be possible to specify the parentXMLSchemaBasedWriteras well as a prefix that should be probably used.protected voidstoreWithFamiliarWriter(Object value, XMLSchemaBasedWriter writer)Tries to write the given object, with a familiar writer-implementation AND using the already instantiated writer-object-
Methods inherited from class de.uni_trier.wi2.procake.data.io.IOImpl
getDescription, getFamily, getParameters, postInit, preInit, setFamily
-
Methods inherited from class de.uni_trier.wi2.procake.utils.composition.FactoryObjectImplementation
getParameter, initParametersBasedOn
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.uni_trier.wi2.procake.utils.io.IO
copy, getDescription, getFamily, getName, isHandlerFor, setFamily
-
-
-
-
Field Detail
-
filename
protected String filename
Name of the XML-file to write into.
-
outputStream
protected OutputStream outputStream
Outputstream to write into.
-
-
Method Detail
-
setFilename
public void setFilename(String filename)
Each writer must be able to write a file to the local filesytem. The filename should be an absolute path.- Specified by:
setFilenamein interfaceWriter- Parameters:
filename- The filename into which the object should be stored.
-
setOutputStream
public void setOutputStream(OutputStream output)
Each writer must be able to store the object into an OutputStream.- Specified by:
setOutputStreamin interfaceWriter- Parameters:
output- TheOutputStreaminto that the object should be stored.
-
createXMLWriter
protected XMLSchemaBasedWriter createXMLWriter() throws IOException
Based on the setting of filename and outputstream an outputmode is chosen. If a filename exists, the output goes to the file. If not the outputstream is used.- Returns:
- The XMLWriter representing the file or outputstream.
- Throws:
IOException
-
store
public void store(Object value) throws CakeIOException
The store command writes the given value.- Specified by:
storein interfaceWriter- Parameters:
value- The object that should be stored- Throws:
CakeIOException
-
insertNamespace
public abstract void insertNamespace(XMLSchemaBasedWriter writer)
Adds the namespace-imports of this handler to the given xmlWriter.- Parameters:
writer- aXMLSchemaBasedWriterobject
-
store
public abstract void store(Object value, XMLSchemaBasedWriter writer) throws CakeIOException
To embed xml writers into another one it must be possible to specify the parentXMLSchemaBasedWriteras well as a prefix that should be probably used. If a parent writer is specified, no header will be written.If the writer does not support XML writing, the writer should throw an
UnsupportedOperationException.public void store(Object value, String prefix, XMLWriter writer) throws CakeIOException { throw new UnsupportedOperationException(); }- Parameters:
writer- A parent writer that is used.value- aObjectobject- Throws:
CakeIOException- if any.
-
correctPrefix
protected String correctPrefix(String currentPrefix, String alternatePrefix)
Analyses the given namespace-prefix and corrects it if neccessary.- Parameters:
currentPrefix- The namespace-prefix, which should be checked.alternatePrefix- aStringobject- Returns:
- The useable namespace-prefix.
-
storeWithFamiliarWriter
protected void storeWithFamiliarWriter(Object value, XMLSchemaBasedWriter writer) throws IOException, CakeIOException
Tries to write the given object, with a familiar writer-implementation AND using the already instantiated writer-object- Parameters:
value- aObjectobjectwriter- aXMLSchemaBasedWriterobject- Throws:
IOExceptionCakeIOException
-
-