Package org.apache.openjpa.lib.meta
Class XMLMetaDataSerializer
- java.lang.Object
-
- org.apache.openjpa.lib.meta.XMLMetaDataSerializer
-
- All Implemented Interfaces:
MetaDataSerializer
- Direct Known Subclasses:
CFMetaDataSerializer
public abstract class XMLMetaDataSerializer extends Object implements MetaDataSerializer
Abstract base type for serlializers that transfer groups of objects to XML. Includes a way of serializing objects back to the XML files they were parsed from. Serializers are not thread safe.- Author:
- Abe White
-
-
Field Summary
-
Fields inherited from interface org.apache.openjpa.lib.meta.MetaDataSerializer
APPEND, COMPACT, PRETTY, VERBOSE
-
-
Constructor Summary
Constructors Constructor Description XMLMetaDataSerializer()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidaddAttribute(String name, String value)Add an attribute to the current group.protected voidaddComments(Object obj)Write the given entity's comments.protected voidaddComments(String[] comments)Add a comment to the stream.protected voidaddText(String text)Add text to the current element.protected FilecurrentBackupFile()The backup file made for the current file being parsed.protected voidendElement(String name)End the current element.protected AttributesgetAttributes()The current attributes.protected Map<File,Collection<Object>>getFileMap()Returns aMapwith keys of theFileto be written to, and values of aCollectionofSourceTrackerinstances.LoggetLog()The log to write to.protected abstract Collection<Object>getObjects()Return the current set of objects for serialization.protected FilegetSourceFile(Object obj)Return the source file for the given instance.protected booleanisVerbose()Whether this serialization is in verbose mode.protected FileprepareWrite(File file)Prepare to write to the given file.protected voidreset()Reset serialization state for the next document.voidserialize(int flags)Serialize the current set of objects to the files from which they were parsed.voidserialize(File file, int flags)Serialize the current set of objects to the given file.voidserialize(Writer out, int flags)Serialize the current set of objects to the given stream.protected abstract voidserialize(Collection<Object> objs)Serialize the given set of objects.voidserialize(Map output, int flags)Serialize the current set of objects to the files from which they were parsed.voidserialize(Result result, int flags)Serialize the current set of objects to the given result.voidserialize(ContentHandler handler, int flags)Serilize the current set of objects to a series of SAX events on the given handler.voidsetLog(Log log)The log to write to.protected voidstartElement(String name)Start an element with the current attribute settings.
-
-
-
Method Detail
-
getLog
public Log getLog()
The log to write to.
-
setLog
public void setLog(Log log)
The log to write to.
-
serialize
public void serialize(int flags) throws IOExceptionDescription copied from interface:MetaDataSerializerSerialize the current set of objects to the files from which they were parsed. Any objects for which a source file cannot be determined will not be included in the output.- Specified by:
serializein interfaceMetaDataSerializer- Parameters:
flags- bit flags specifying the output flags; e.g.MetaDataSerializer.PRETTY- Throws:
IOException
-
serialize
public void serialize(Map output, int flags) throws IOException
Description copied from interface:MetaDataSerializerSerialize the current set of objects to the files from which they were parsed. The objects must implement theSourceTrackerinterface.- Specified by:
serializein interfaceMetaDataSerializer- Parameters:
output- if null, then serialize directly to the file system; otherwise, populate the specifiedMapwith keys that are theFileinstances, and values that are theStringcontents of the MetaDataflags- bit flags specifying the output flags; e.g.MetaDataSerializer.PRETTY- Throws:
IOException
-
prepareWrite
protected File prepareWrite(File file) throws IOException
Prepare to write to the given file. Back up the file and make sure the path to it is created.- Throws:
IOException
-
getFileMap
protected Map<File,Collection<Object>> getFileMap()
Returns aMapwith keys of theFileto be written to, and values of aCollectionofSourceTrackerinstances.
-
getSourceFile
protected File getSourceFile(Object obj)
Return the source file for the given instance. By default, checks to see if the instance implementsSourceTracker.
-
serialize
public void serialize(File file, int flags) throws IOException
Description copied from interface:MetaDataSerializerSerialize the current set of objects to the given file.- Specified by:
serializein interfaceMetaDataSerializerflags- bit flags specifying the output flags; e.g.MetaDataSerializer.PRETTY|MetaDataSerializer.APPEND- Throws:
IOException
-
serialize
public void serialize(Writer out, int flags) throws IOException
Description copied from interface:MetaDataSerializerSerialize the current set of objects to the given stream.- Specified by:
serializein interfaceMetaDataSerializerflags- bit flags specifying the output flags; e.g.MetaDataSerializer.PRETTY- Throws:
IOException
-
serialize
public void serialize(Result result, int flags) throws SAXException
Serialize the current set of objects to the given result.- Throws:
SAXException
-
serialize
public void serialize(ContentHandler handler, int flags) throws SAXException
Serilize the current set of objects to a series of SAX events on the given handler.- Throws:
SAXException
-
isVerbose
protected boolean isVerbose()
Whether this serialization is in verbose mode.
-
currentBackupFile
protected File currentBackupFile()
The backup file made for the current file being parsed.
-
startElement
protected void startElement(String name) throws SAXException
Start an element with the current attribute settings. Clears the attributes as well.- Throws:
SAXException
-
endElement
protected void endElement(String name) throws SAXException
End the current element.- Throws:
SAXException
-
addText
protected void addText(String text) throws SAXException
Add text to the current element.- Throws:
SAXException
-
addAttribute
protected void addAttribute(String name, String value)
Add an attribute to the current group.
-
getAttributes
protected Attributes getAttributes()
The current attributes.
-
addComments
protected void addComments(String[] comments) throws SAXException
Add a comment to the stream.- Throws:
SAXException
-
addComments
protected void addComments(Object obj) throws SAXException
Write the given entity's comments. By default, tests if entity isCommentable.- Throws:
SAXException
-
reset
protected void reset()
Reset serialization state for the next document.
-
serialize
protected abstract void serialize(Collection<Object> objs) throws SAXException
Serialize the given set of objects.- Throws:
SAXException
-
getObjects
protected abstract Collection<Object> getObjects()
Return the current set of objects for serialization.
-
-