public class XSerializerFactory extends com.streamscape.omf.serializer.AbstractSerializerFactory implements SerializerFactory, AliasManager
Title: Object Mediation Framework
Description: XML Serializer Factory.
XSerializer
object serialization mechanism and it alias map.
All serializers use the alias map to define how a particular object is serialized in relationship to other objects
in the graph. For example how sub-objects within an encapsulating object or a collection (ie. HashMap or ArrayList)
are represented. XSerializer
uses the alias map to associate objects to XML element or attribute tags. There
are two ways to instantiate the factory:
(i) A calling framework (such as the fabric runtime) uses a combination of #init(ObjectMediationAliasManager mgr)
and subsequent call to
getInstance()
to initialize the factory with it's environment. If the factory is constructed using this
method, a global alias map may be passed to the factory by the calling framework. The fabric runtime uses this
mechanism to initialize it's factories with a global, shared map.
(ii) Alternatively users may create a factory singleton by calling getInstance()
directly. If the singleton
is constructed using this method an internal alias mapping object is dynamically created and managed by the factory.
It has a shared scope and is shared across all XML serializer instances.
Initialization of the singleton constructs (or accepts) an ObjectMediationAliasManager
object that is used
to hold mappings between classes and their short names. This factory also provides extension methods that allow object
values to be serialized as attributes, implicit collections, specialized null
values or class defaults.
Extensions are also provided for working with name spaces and for handling special unprintable or non-XML characters.
Namespace support requires the use of a StAX Driver which is included separately for JDK 1.5 and included
as part of JDK 1.6.
The serializer factory provides methods for aliasing object elements as well as constructing a variety of customizable XML serializers. Serializers are thread-safe and when used within the context of the StreamScape Framework allow for dynamic transformation between object of different structures as well as different data formats such as XML, Binary, JSON notation or user defined object representation. The alias definitions and format-specific serialization hints guarantee that a serialized object will properly marshal and unmarshal to/from a given object as well as between formats. In this way the serialization mechanism also acts as high-performance mapping and cross-language transformation tool.
Copyright: Copyright (c) 2009
Company: StreamScape Technologies
DEFAULT_SERIAL_VERSION_ID
Modifier and Type | Method and Description |
---|---|
void |
alias(SemanticType type)
Adds an alias for this
Semantic Type to the global map. |
void |
alias(java.lang.String alias,
java.lang.Class type)
Adds an alias for this class.
|
void |
aliasImmutableType(java.lang.Class type)
Adds an immutable class to the Alias Map.
|
void |
aliasImmutableType(SemanticType type)
Adds an immutable class to the Alias Map.
|
XSerializer |
createSerializer(java.lang.String name)
Creates and registers a default serializer instance.
|
XSerializer |
createSerializer(java.lang.String name,
java.lang.ClassLoader loader)
Creates and registers a serializer instance.
|
XSerializer |
createSerializer(java.lang.String name,
ObjectMediationAliasManager aliasMgr)
Creates and registers a serializer instance with a specific
AliasManager instance. |
XSerializer |
createSerializer(java.lang.String name,
com.streamscape.omf.xml.xstream.converters.reflection.ReflectionProvider reflectionProvider,
com.streamscape.omf.xml.xstream.io.HierarchicalStreamDriver driver,
java.lang.ClassLoader classLoader,
com.streamscape.omf.xml.xstream.mapper.Mapper mapper,
com.streamscape.omf.xml.xstream.converters.ConverterLookup converterLookup,
com.streamscape.omf.xml.xstream.converters.ConverterRegistry converterRegistry,
ObjectMediationAliasManager aliasMgr)
Constructs a fully user-defined serializer.
|
XSerializer |
createSerializer(java.lang.String name,
com.streamscape.omf.xml.xstream.converters.reflection.ReflectionProvider reflectionProvider,
com.streamscape.omf.xml.xstream.io.HierarchicalStreamDriver driver,
java.lang.ClassLoader classLoader,
ObjectMediationAliasManager aliasMgr)
Constructs an XSerializer with a special
HierarchicalStreamDriver and
ReflectionProvider and additionally with a prepared ClassLoader
and AliasManager to use. |
XSerializer |
createSerializer(java.lang.String name,
com.streamscape.omf.xml.xstream.io.xml.XmlFriendlyNameCoder encoder)
Creates and registers a default serializer instance and it's Encoder.
|
XSerializer |
createSerializer(java.lang.String name,
com.streamscape.omf.xml.xstream.io.xml.XmlFriendlyNameCoder encoder,
java.lang.ClassLoader loader,
ObjectMediationAliasManager aliasMgr)
See
XSerializer for constructor specific details. |
void |
destroy()
Clears and removes all structures and references used by this
factory (but does not clear or remove the Alias Map).
|
void |
discardSerializer(java.lang.String name)
Discards a serializer of the specified name.
|
XSerializer |
getDefaultSerializer()
Returns the default serializer registered for this factory.
|
static XSerializerFactory |
getInstance()
Returns a reference to the singleton instance of the factory.
|
java.lang.String |
getName()
Returns the name of the
Serializer Factory . |
XSerializer |
getXMLEventSerializer(java.lang.String eventId)
Returns the specific serializer for a given
Event Id . |
boolean |
isAliased(java.lang.Class type)
Checks if the specified class is already aliased in the associated
AliasManager . |
boolean |
isAliased(java.lang.String alias)
Checks if the specified alias already exists in the associated
AliasManager . |
boolean |
isClassAliased(java.lang.String className)
Checks if a class with the specified name is already aliased.
|
boolean |
isImmutableTypeAliased(java.lang.Class type)
Checks if the specified class is aliased as an immutable type.
|
boolean |
isXMLEventRegistered(java.lang.String eventId)
Returns
true if the specified XML Event is registered with a serializer. |
java.util.List |
listAliases()
Returns a list of all aliases.
|
java.util.List |
listSerializers()
Returns a list of all serializers registered by this factory.
|
java.lang.String |
lookup(java.lang.Class clazz)
Returns the alias type name associated with the specified class.
|
java.lang.String |
lookup(java.lang.String typeName)
Returns the name of the class associated with the specified alias.
|
SemanticType |
lookupSemanticType(java.lang.String aliasName)
Returns a copy of the
SemanticType associated with the specified alias. |
XSerializer |
lookupSerializer(java.lang.String name)
Returns a reference to the named serializer instance.
|
void |
registerXMLEvent(java.lang.String eventId,
java.lang.String serializerName)
Registers an
XML Event with a specific XSerializer . |
java.lang.String |
resolveClass(java.lang.String className)
Resolves the name of this class to the alias type name.
|
void |
unalias(SemanticType type)
Remove an alias for this
Semantic Type from the global map. |
void |
unalias(java.lang.String alias)
Removes the aliased type from the Alias Map.
|
void |
unregisterXMLEvent(java.lang.String eventId)
Unregisters the
XML Event , dissociating it from a specific serializer instance. |
getContext, getContextType, hasContext
clone, getSerialVersionUID
public static XSerializerFactory getInstance()
Alias Manager
. This method will create a default system serializer
called sys$serializer. The default is set up for switching class loader references
and registers the core converters including FabricReflectionConverter
.
The method will attempt to register system aliases if they are not already present. Subsequent calls to
this method will return the singleton instance.public XSerializer createSerializer(java.lang.String name)
XSerializer
for constructor specific details.createSerializer
in interface SerializerFactory
name
- StringFactoryManagerException
public XSerializer createSerializer(java.lang.String name, com.streamscape.omf.xml.xstream.io.xml.XmlFriendlyNameCoder encoder)
XmlFriendlyNameCoder
allows users to specify the mapping and substitution
of incompatible characters that may be allowed in the Java language but not
in XML specification. Specifically, the '$' and '_' literals may create problems
in certain XML documents that must be processed by parsers or mapping technologies.name
- Stringencoder
- XmlFriendlyNameCoderFactoryManagerException
public XSerializer createSerializer(java.lang.String name, ObjectMediationAliasManager aliasMgr)
AliasManager
instance.
See XSerializer
for constructor specific details.createSerializer
in interface SerializerFactory
name
- StringaliasMgr
- AliasManagerFactoryManagerException
public XSerializer createSerializer(java.lang.String name, java.lang.ClassLoader loader)
name
- loader
- FactoryManagerException
public XSerializer createSerializer(java.lang.String name, com.streamscape.omf.xml.xstream.io.xml.XmlFriendlyNameCoder encoder, java.lang.ClassLoader loader, ObjectMediationAliasManager aliasMgr)
XSerializer
for constructor specific details.name
- Stringencoder
- XmlFriendlyNameCoder The coder responsible for normalizing object names to/from
an XML friendly format.loader
- ClassLoaderaliasMgr
- AliasManagerFactoryManagerException
public XSerializer createSerializer(java.lang.String name, com.streamscape.omf.xml.xstream.converters.reflection.ReflectionProvider reflectionProvider, com.streamscape.omf.xml.xstream.io.HierarchicalStreamDriver driver, java.lang.ClassLoader classLoader, ObjectMediationAliasManager aliasMgr)
HierarchicalStreamDriver
and
ReflectionProvider
and additionally with a prepared ClassLoader
and AliasManager
to use.
See XSerializer
for constructor specific details.name
- StringreflectionProvider
- ReflectionProviderdriver
- HierarchicalStreamDriverclassLoader
- ClassLoaderaliasMgr
- AliasManagerFactoryManagerException
public XSerializer createSerializer(java.lang.String name, com.streamscape.omf.xml.xstream.converters.reflection.ReflectionProvider reflectionProvider, com.streamscape.omf.xml.xstream.io.HierarchicalStreamDriver driver, java.lang.ClassLoader classLoader, com.streamscape.omf.xml.xstream.mapper.Mapper mapper, com.streamscape.omf.xml.xstream.converters.ConverterLookup converterLookup, com.streamscape.omf.xml.xstream.converters.ConverterRegistry converterRegistry, ObjectMediationAliasManager aliasMgr)
XSerializer
for constructor specific details.name
- StringreflectionProvider
- ReflectionProviderdriver
- HierarchicalStreamDriverclassLoader
- ClassLoadermapper
- MapperconverterLookup
- ConverterLookupconverterRegistry
- ConverterRegistryaliasMgr
- AliasManagerFactoryManagerException
public XSerializer getDefaultSerializer()
getDefaultSerializer
in interface SerializerFactory
public void discardSerializer(java.lang.String name) throws FactoryManagerException
discardSerializer
in interface SerializerFactory
name
- StringFactoryManagerException
public void registerXMLEvent(java.lang.String eventId, java.lang.String serializerName) throws FactoryManagerException
XML Event
with a specific XSerializer
. If a given
event is the correct model and is successfully registered, its XML content XMLEvent.setXML(Object xml)
will be serialized using the associated serializer. If the event is not registered, the default system
serializer will be used. Users that create their own serializer instances should register XML events
with specific instances. Creating a serializer implicitly adds it to the internal serializer registry
where the serializer may then be looked up by name.eventId
- StringserializerName
- StringFactoryManagerException
public void unregisterXMLEvent(java.lang.String eventId) throws FactoryManagerException
XML Event
, dissociating it from a specific serializer instance. If no serializer
is associated with XML objects then the system's default serializer will be used.eventId
- StringFactoryManagerException
public boolean isXMLEventRegistered(java.lang.String eventId)
true
if the specified XML Event
is registered with a serializer.eventId
- Stringpublic XSerializer getXMLEventSerializer(java.lang.String eventId) throws FactoryManagerException
Event Id
. If the event is not registered the
system default serializer will be returned.eventId
- StringFactoryManagerException
public void alias(SemanticType type) throws FactoryManagerException
SerializerFactory
Semantic Type
to the global map.
AliasManager
interface to add system types and perform validation.
Note that this method does not require instantiation of a class. It is the preferred
way to create aliases.alias
in interface AliasManager
alias
in interface SerializerFactory
type
- the semantic type to be aliased.FactoryManagerException
- if the specified type is already aliased.public void alias(java.lang.String alias, java.lang.Class type) throws FactoryManagerException
SerializerFactory
SemanticType
with an auto-generated serial version identifier.
It is intended for registering transient types that do not require
validation and is mainly retained for compatibility with older serialization mechanisms.alias
in interface AliasManager
alias
in interface SerializerFactory
alias
- the alias to be added.type
- the class to be aliased.FactoryManagerException
- if the specified alias already exists or
if the specified type is already aliased.public void aliasImmutableType(SemanticType type) throws FactoryManagerException
SerializerFactory
java.lang.String
or collections.aliasImmutableType
in interface AliasManager
aliasImmutableType
in interface SerializerFactory
type
- the semantic type to be aliased.FactoryManagerException
- if some error occurs.public void aliasImmutableType(java.lang.Class type)
SerializerFactory
java.lang.String
or collections.aliasImmutableType
in interface AliasManager
aliasImmutableType
in interface SerializerFactory
type
- the class to be aliased.public boolean isImmutableTypeAliased(java.lang.Class type)
SerializerFactory
isImmutableTypeAliased
in interface AliasManager
isImmutableTypeAliased
in interface SerializerFactory
type
- the class to be checked.true
if the specified class is aliased as an immutable type, false
otherwise.public void unalias(SemanticType type) throws FactoryManagerException
SerializerFactory
Semantic Type
from the global map.
unalias
in interface AliasManager
unalias
in interface SerializerFactory
type
- the semantic type to be unaliased.FactoryManagerException
- if the specified type is not aliased or
if the specified type is a system type.public void unalias(java.lang.String alias) throws FactoryManagerException
SerializerFactory
unalias
in interface AliasManager
unalias
in interface SerializerFactory
alias
- the alias to be removed.FactoryManagerException
- if the specified alias does not exist or
if the specified type is a system type.public java.util.List listAliases()
SerializerFactory
listAliases
in interface AliasManager
listAliases
in interface SerializerFactory
public java.lang.String lookup(java.lang.Class clazz)
SerializerFactory
lookup
in interface AliasManager
lookup
in interface SerializerFactory
clazz
- the specified class.null
if the class is not aliased.public java.lang.String lookup(java.lang.String typeName)
SerializerFactory
lookup
in interface AliasManager
lookup
in interface SerializerFactory
typeName
- the specified alias.null
if this alias does not exist.public XSerializer lookupSerializer(java.lang.String name)
SerializerFactory
lookupSerializer
in interface SerializerFactory
name
- the name of serializer to be looked up.null
if the specified serializer does not exist.public SemanticType lookupSemanticType(java.lang.String aliasName)
SerializerFactory
SemanticType
associated with the specified alias.lookupSemanticType
in interface SerializerFactory
aliasName
- the specified alias.null
if the alias does not exist.public java.lang.String resolveClass(java.lang.String className)
SerializerFactory
resolveClass
in interface AliasManager
resolveClass
in interface SerializerFactory
className
- the specified class name.null
if the class is not aliased.public void destroy()
SerializerFactory
destroy
in interface SerializerFactory
public java.lang.String getName()
SerializerFactory
Serializer Factory
.getName
in interface SerializerFactory
public java.util.List listSerializers()
SerializerFactory
listSerializers
in interface SerializerFactory
public boolean isAliased(java.lang.String alias)
SerializerFactory
AliasManager
.isAliased
in interface AliasManager
isAliased
in interface SerializerFactory
alias
- the alias to be checked.true
if the specified alias already exists, false
otherwise.public boolean isAliased(java.lang.Class type)
SerializerFactory
AliasManager
.isAliased
in interface AliasManager
isAliased
in interface SerializerFactory
type
- the class to be checked.true
if the specified class is already aliased, false
otherwise.public boolean isClassAliased(java.lang.String className)
AliasManager
isClassAliased
in interface AliasManager
className
- the name of class to be checked.true
if a class with the specified name is already aliased, false
otherwise.Copyright © 2015-2024 StreamScape Technologies. All rights reserved.