org.apache.openjpa.persistence
Class XMLPersistenceMetaDataSerializer

java.lang.Object
  extended by org.apache.openjpa.lib.meta.XMLMetaDataSerializer
      extended by org.apache.openjpa.lib.meta.CFMetaDataSerializer
          extended by org.apache.openjpa.persistence.XMLPersistenceMetaDataSerializer
All Implemented Interfaces:
MetaDataSerializer, AbstractCFMetaDataFactory.Serializer
Direct Known Subclasses:
XMLPersistenceMappingSerializer

public class XMLPersistenceMetaDataSerializer
extends CFMetaDataSerializer
implements AbstractCFMetaDataFactory.Serializer

Serializes persistence metadata back to XML. This class processes all object level tags that are store-agnostic. However, it provides hooks for the subclasses to include store-specific tags to be serialized both at <entity-mappings> and <entity> level.

Since:
0.4.0
Author:
Steve Kim

Nested Class Summary
protected  class XMLPersistenceMetaDataSerializer.SerializationComparator
          Compares clases, sequences, and queries to order them for serialization.
 
Field Summary
protected static int TYPE_CLASS_QUERIES
           
protected static int TYPE_CLASS_SEQS
           
protected static int TYPE_META
           
protected static int TYPE_QUERY
           
protected static int TYPE_SEQ
           
 
Fields inherited from interface org.apache.openjpa.lib.meta.MetaDataSerializer
APPEND, COMPACT, PRETTY, VERBOSE
 
Constructor Summary
XMLPersistenceMetaDataSerializer(OpenJPAConfiguration conf)
          Constructor.
 
Method Summary
 void addAll(MetaDataRepository repos)
          Add all components in the given repository to the set to be serialized.
protected  void addClassMappingAttributes(ClassMetaData mapping)
          Add mapping attributes for the given class.
protected  void addFieldMappingAttributes(FieldMetaData fmd, FieldMetaData orig)
          Add mapping attributes for the given field.
 void addMetaData(ClassMetaData meta)
          Add a class meta data to the set to be serialized.
 void addQueryMetaData(QueryMetaData meta)
          Add a query meta data to the set to be serialized.
 void addSequenceMetaData(SequenceMetaData meta)
          Add a sequence meta data to the set to be serialized.
protected  void addStrategyMappingAttributes(FieldMetaData fmd)
          Set mapping attributes for strategy.
protected  void addSystemMappingElements(Collection toSerialize)
          Add system-level mapping elements to be serialized.
 void clear()
          Clear the set of metadatas to be serialized.
 OpenJPAConfiguration getConfiguration()
          Configuration.
 int getMode()
          The serialization mode according to the expected document type.
protected  Collection getObjects()
          Return the current set of objects for serialization.
protected  String getPackage(Object obj)
          Return the package name of the given object, or null if not in a package.
 boolean getSerializeAnnotations()
          Whether to serialize content originally specified in annotations.
protected  File getSourceFile(Object obj)
          Override to not overwrite annotations.
protected  PersistenceStrategy getStrategy(FieldMetaData fmd)
          Return the serialized strategy name.
protected  boolean isMappingMode()
          Convenience method for interpreting getMode().
protected  boolean isMappingMode(ClassMetaData meta)
          Convenience method for interpreting getMode().
protected  boolean isMappingMode(ValueMetaData vmd)
          Convenience method for interpreting getMode().
protected  boolean isMetaDataMode()
          Convenience method for interpreting getMode().
protected  boolean isQueryMode()
          Convenience method for interpreting getMode().
protected  XMLPersistenceMetaDataSerializer.SerializationComparator newSerializationComparator()
          Create a new comparator for ordering objects that are to be serialized.
 boolean removeAll(MetaDataRepository repos)
          Remove all the components in the given repository from the set to be serialized.
 boolean removeMetaData(ClassMetaData meta)
          Remove a metadata from the set to be serialized.
 boolean removeQueryMetaData(QueryMetaData meta)
          Remove a query metadata from the set to be serialized.
 boolean removeSequenceMetaData(SequenceMetaData meta)
          Remove a sequence metadata from the set to be serialized.
protected  void serialize(Collection objects)
          Serialize the given set of objects.
protected  boolean serializeAttributeOverride(FieldMetaData fmd, FieldMetaData orig)
          Always returns false by default.
protected  void serializeAttributeOverrideMappingContent(FieldMetaData fmd, FieldMetaData orig)
          Serialize attribute override mapping content.
protected  void serializeClass(ClassMetaData meta, boolean access)
          Serialize class metadata.
protected  void serializeClassMappingContent(ClassMetaData mapping)
          Serialize class mapping content.
protected  void serializeFieldMappingContent(FieldMetaData fmd, PersistenceStrategy strategy)
          Serialize field mapping content; this will be called before #serializeValueMappingContent.
protected  void serializeInheritanceContent(ClassMetaData mapping)
          Serialize inheritance content.
protected  void serializeOrderColumn(FieldMetaData fmd)
          Order column is not processed as meta data, instead it can be processed as mapping data if in mapping mode.
protected  void serializeQueryMappings(ClassMetaData meta)
          Serialize query mappings.
protected  void serializeSequence(SequenceMetaData meta)
          Serialize sequence metadata.
protected  void serializeSystemMappingElement(Object obj)
          Serialize unknown mapping element at system level.
 void setMode(int mode)
          The serialization mode according to the expected document type.
 void setMode(int mode, boolean on)
          The serialization mode according to the expected document type.
 void setSerializeAnnotations(boolean annos)
          Whether to serialize content originally specified in annotations.
protected  int type(Object o)
          Return the type constant for the given object based on its runtime class.
 
Methods inherited from class org.apache.openjpa.lib.meta.CFMetaDataSerializer
getClassName, getPackage, groupByPackage, setPackage
 
Methods inherited from class org.apache.openjpa.lib.meta.XMLMetaDataSerializer
addAttribute, addComments, addComments, addText, currentBackupFile, endElement, getAttributes, getFileMap, getLog, isVerbose, prepareWrite, reset, serialize, serialize, serialize, serialize, serialize, serialize, setLog, startElement
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.openjpa.lib.meta.MetaDataSerializer
serialize, serialize, serialize, serialize
 

Field Detail

TYPE_SEQ

protected static final int TYPE_SEQ
See Also:
Constant Field Values

TYPE_QUERY

protected static final int TYPE_QUERY
See Also:
Constant Field Values

TYPE_META

protected static final int TYPE_META
See Also:
Constant Field Values

TYPE_CLASS_SEQS

protected static final int TYPE_CLASS_SEQS
See Also:
Constant Field Values

TYPE_CLASS_QUERIES

protected static final int TYPE_CLASS_QUERIES
See Also:
Constant Field Values
Constructor Detail

XMLPersistenceMetaDataSerializer

public XMLPersistenceMetaDataSerializer(OpenJPAConfiguration conf)
Constructor. Supply configuration.

Method Detail

getConfiguration

public OpenJPAConfiguration getConfiguration()
Configuration.


getSerializeAnnotations

public boolean getSerializeAnnotations()
Whether to serialize content originally specified in annotations. Defaults to true.


setSerializeAnnotations

public void setSerializeAnnotations(boolean annos)
Whether to serialize content originally specified in annotations. Defaults to true.


getMode

public int getMode()
The serialization mode according to the expected document type. The mode constants act as bit flags, and therefore can be combined.


setMode

public void setMode(int mode)
The serialization mode according to the expected document type. The mode constants act as bit flags, and therefore can be combined.

Specified by:
setMode in interface AbstractCFMetaDataFactory.Serializer

setMode

public void setMode(int mode,
                    boolean on)
The serialization mode according to the expected document type.


getSourceFile

protected File getSourceFile(Object obj)
Override to not overwrite annotations.

Overrides:
getSourceFile in class XMLMetaDataSerializer

isMetaDataMode

protected boolean isMetaDataMode()
Convenience method for interpreting getMode().


isQueryMode

protected boolean isQueryMode()
Convenience method for interpreting getMode().


isMappingMode

protected boolean isMappingMode()
Convenience method for interpreting getMode().


isMappingMode

protected boolean isMappingMode(ClassMetaData meta)
Convenience method for interpreting getMode(). Takes into account whether mapping information is loaded for the given instance.


isMappingMode

protected boolean isMappingMode(ValueMetaData vmd)
Convenience method for interpreting getMode(). Takes into account whether mapping information is loaded for the given instance.


addMetaData

public void addMetaData(ClassMetaData meta)
Add a class meta data to the set to be serialized.

Specified by:
addMetaData in interface AbstractCFMetaDataFactory.Serializer

addSequenceMetaData

public void addSequenceMetaData(SequenceMetaData meta)
Add a sequence meta data to the set to be serialized.

Specified by:
addSequenceMetaData in interface AbstractCFMetaDataFactory.Serializer

addQueryMetaData

public void addQueryMetaData(QueryMetaData meta)
Add a query meta data to the set to be serialized.

Specified by:
addQueryMetaData in interface AbstractCFMetaDataFactory.Serializer

addAll

public void addAll(MetaDataRepository repos)
Add all components in the given repository to the set to be serialized.

Specified by:
addAll in interface AbstractCFMetaDataFactory.Serializer

removeMetaData

public boolean removeMetaData(ClassMetaData meta)
Remove a metadata from the set to be serialized.

Specified by:
removeMetaData in interface AbstractCFMetaDataFactory.Serializer
Returns:
true if removed, false if not in set

removeSequenceMetaData

public boolean removeSequenceMetaData(SequenceMetaData meta)
Remove a sequence metadata from the set to be serialized.

Returns:
true if removed, false if not in set

removeQueryMetaData

public boolean removeQueryMetaData(QueryMetaData meta)
Remove a query metadata from the set to be serialized.

Returns:
true if removed, false if not in set

removeAll

public boolean removeAll(MetaDataRepository repos)
Remove all the components in the given repository from the set to be serialized.

Returns:
true if any components removed, false if none in set

clear

public void clear()
Clear the set of metadatas to be serialized.


getObjects

protected Collection getObjects()
Description copied from class: XMLMetaDataSerializer
Return the current set of objects for serialization.

Specified by:
getObjects in class XMLMetaDataSerializer

addSystemMappingElements

protected void addSystemMappingElements(Collection toSerialize)
Add system-level mapping elements to be serialized. Does nothing by default.


newSerializationComparator

protected XMLPersistenceMetaDataSerializer.SerializationComparator newSerializationComparator()
Create a new comparator for ordering objects that are to be serialized.


serialize

protected void serialize(Collection objects)
                  throws SAXException
Description copied from class: XMLMetaDataSerializer
Serialize the given set of objects.

Specified by:
serialize in class XMLMetaDataSerializer
Throws:
SAXException

getPackage

protected String getPackage(Object obj)
Description copied from class: CFMetaDataSerializer
Return the package name of the given object, or null if not in a package. Used by CFMetaDataSerializer.groupByPackage(java.util.Collection). Returns null by default.

Overrides:
getPackage in class CFMetaDataSerializer

type

protected int type(Object o)
Return the type constant for the given object based on its runtime class. If the runtime class does not correspond to any of the known types then returns -1. This can happen for tags that are not handled at this store-agnostic level.


serializeSystemMappingElement

protected void serializeSystemMappingElement(Object obj)
                                      throws SAXException
Serialize unknown mapping element at system level.

Throws:
SAXException

serializeSequence

protected void serializeSequence(SequenceMetaData meta)
                          throws SAXException
Serialize sequence metadata.

Throws:
SAXException

serializeClass

protected void serializeClass(ClassMetaData meta,
                              boolean access)
                       throws SAXException
Serialize class metadata.

Throws:
SAXException

addClassMappingAttributes

protected void addClassMappingAttributes(ClassMetaData mapping)
                                  throws SAXException
Add mapping attributes for the given class. Does nothing by default

Throws:
SAXException

serializeClassMappingContent

protected void serializeClassMappingContent(ClassMetaData mapping)
                                     throws SAXException
Serialize class mapping content. Does nothing by default.

Throws:
SAXException

serializeInheritanceContent

protected void serializeInheritanceContent(ClassMetaData mapping)
                                    throws SAXException
Serialize inheritance content. Does nothing by default.

Throws:
SAXException

serializeQueryMappings

protected void serializeQueryMappings(ClassMetaData meta)
                               throws SAXException
Serialize query mappings. Does nothing by default.

Throws:
SAXException

addFieldMappingAttributes

protected void addFieldMappingAttributes(FieldMetaData fmd,
                                         FieldMetaData orig)
                                  throws SAXException
Add mapping attributes for the given field. Does nothing by default.

Throws:
SAXException

serializeAttributeOverride

protected boolean serializeAttributeOverride(FieldMetaData fmd,
                                             FieldMetaData orig)
Always returns false by default.


serializeAttributeOverrideMappingContent

protected void serializeAttributeOverrideMappingContent(FieldMetaData fmd,
                                                        FieldMetaData orig)
                                                 throws SAXException
Serialize attribute override mapping content. Does nothing by default,

Throws:
SAXException

getStrategy

protected PersistenceStrategy getStrategy(FieldMetaData fmd)
Return the serialized strategy name.


serializeFieldMappingContent

protected void serializeFieldMappingContent(FieldMetaData fmd,
                                            PersistenceStrategy strategy)
                                     throws SAXException
Serialize field mapping content; this will be called before #serializeValueMappingContent. Does nothing by default.

Throws:
SAXException

addStrategyMappingAttributes

protected void addStrategyMappingAttributes(FieldMetaData fmd)
                                     throws SAXException
Set mapping attributes for strategy. Sets mapped-by by default.

Throws:
SAXException

serializeOrderColumn

protected void serializeOrderColumn(FieldMetaData fmd)
                             throws SAXException
Order column is not processed as meta data, instead it can be processed as mapping data if in mapping mode.

Throws:
SAXException


Copyright © 2006-2010 Apache Software Foundation. All Rights Reserved.