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,XMLSchemaSerializer
public abstract class XMLMetaDataSerializer extends java.lang.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(java.lang.String name, java.lang.String value)Add an attribute to the current group.protected voidaddComments(java.lang.Object obj)Write the given entity's comments.protected voidaddComments(java.lang.String[] comments)Add a comment to the stream.protected voidaddText(java.lang.String text)Add text to the current element.protected java.io.FilecurrentBackupFile()The backup file made for the current file being parsed.protected voidendElement(java.lang.String name)End the current element.protected org.xml.sax.AttributesgetAttributes()The current attributes.protected java.util.Map<java.io.File,java.util.Collection<java.lang.Object>>getFileMap()Returns aMapwith keys of theFileto be written to, and values of aCollectionofSourceTrackerinstances.LoggetLog()The log to write to.protected abstract java.util.Collection<java.lang.Object>getObjects()Return the current set of objects for serialization.protected java.io.FilegetSourceFile(java.lang.Object obj)Return the source file for the given instance.protected booleanisVerbose()Whether this serialization is in verbose mode.protected java.io.FileprepareWrite(java.io.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(java.io.File file, int flags)Serialize the current set of objects to the given file.voidserialize(java.io.Writer out, int flags)Serialize the current set of objects to the given stream.protected abstract voidserialize(java.util.Collection<java.lang.Object> objs)Serialize the given set of objects.voidserialize(java.util.Map output, int flags)Serialize the current set of objects to the files from which they were parsed.voidserialize(javax.xml.transform.Result result, int flags)Serialize the current set of objects to the given result.voidserialize(org.xml.sax.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(java.lang.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 java.io.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:
java.io.IOException
-
serialize
public void serialize(java.util.Map output, int flags) throws java.io.IOExceptionDescription 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:
java.io.IOException
-
prepareWrite
protected java.io.File prepareWrite(java.io.File file) throws java.io.IOExceptionPrepare to write to the given file. Back up the file and make sure the path to it is created.- Throws:
java.io.IOException
-
getFileMap
protected java.util.Map<java.io.File,java.util.Collection<java.lang.Object>> getFileMap()
Returns aMapwith keys of theFileto be written to, and values of aCollectionofSourceTrackerinstances.
-
getSourceFile
protected java.io.File getSourceFile(java.lang.Object obj)
Return the source file for the given instance. By default, checks to see if the instance implementsSourceTracker.
-
serialize
public void serialize(java.io.File file, int flags) throws java.io.IOExceptionDescription 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:
java.io.IOException
-
serialize
public void serialize(java.io.Writer out, int flags) throws java.io.IOExceptionDescription 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:
java.io.IOException
-
serialize
public void serialize(javax.xml.transform.Result result, int flags) throws org.xml.sax.SAXExceptionSerialize the current set of objects to the given result.- Throws:
org.xml.sax.SAXException
-
serialize
public void serialize(org.xml.sax.ContentHandler handler, int flags) throws org.xml.sax.SAXExceptionSerilize the current set of objects to a series of SAX events on the given handler.- Throws:
org.xml.sax.SAXException
-
isVerbose
protected boolean isVerbose()
Whether this serialization is in verbose mode.
-
currentBackupFile
protected java.io.File currentBackupFile()
The backup file made for the current file being parsed.
-
startElement
protected void startElement(java.lang.String name) throws org.xml.sax.SAXExceptionStart an element with the current attribute settings. Clears the attributes as well.- Throws:
org.xml.sax.SAXException
-
endElement
protected void endElement(java.lang.String name) throws org.xml.sax.SAXExceptionEnd the current element.- Throws:
org.xml.sax.SAXException
-
addText
protected void addText(java.lang.String text) throws org.xml.sax.SAXExceptionAdd text to the current element.- Throws:
org.xml.sax.SAXException
-
addAttribute
protected void addAttribute(java.lang.String name, java.lang.String value)Add an attribute to the current group.
-
getAttributes
protected org.xml.sax.Attributes getAttributes()
The current attributes.
-
addComments
protected void addComments(java.lang.String[] comments) throws org.xml.sax.SAXExceptionAdd a comment to the stream.- Throws:
org.xml.sax.SAXException
-
addComments
protected void addComments(java.lang.Object obj) throws org.xml.sax.SAXExceptionWrite the given entity's comments. By default, tests if entity isCommentable.- Throws:
org.xml.sax.SAXException
-
reset
protected void reset()
Reset serialization state for the next document.
-
serialize
protected abstract void serialize(java.util.Collection<java.lang.Object> objs) throws org.xml.sax.SAXExceptionSerialize the given set of objects.- Throws:
org.xml.sax.SAXException
-
getObjects
protected abstract java.util.Collection<java.lang.Object> getObjects()
Return the current set of objects for serialization.
-
-