public class JSerializerFactory extends com.streamscape.sef.dispatcher.AbstractJSerializerFactory implements SerializerFactory
Title: Object Mediation Framework
Description: Provides a management facility for JSerializer
.
JSerializer
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 Vector)
are represented. JSerializer
uses the alias map to associate objects to Java classes or fields. 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 Java serializer instances, but not other serializers.
Initialization of the singleton constructs (or accepts) an ObjectMediationAliasManager
object that is used
to hold mappings between classes and their short names. Serializers are thread-safe and when used within the context of
the StreamScape Framework allow for dynamic transformation between objects 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 un-marshal 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.
Note: The JSerializer does not present data in a human-readable form. It is however, possible to access and annotate
data elements of a de-serialized object by using the Structured Data References
notation supported by
ReferencePathManager
. This capability may be combined with binary serialization for fast, in-stream data mapping.
Copyright: Copyright (c) 2009
Company: StreamScape Technologies
DEFAULT_SERIAL_VERSION_ID
Modifier and Type | Method and Description |
---|---|
void |
addSerialSupport(java.lang.Class objectClass,
com.streamscape.omf.java.SerialSupport serialSupport)
Adds the
SerialSupport instance to the factory. |
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.
|
JSerializer |
createSerializer(java.lang.String name)
Creates an instance of a named Serializer and returns a reference to it.
|
JSerializer |
createSerializer(java.lang.String name,
ObjectMediationAliasManager aliasManager)
Creates an instance of a named Serializer, passing an
AliasManager
instance to it and returns a reference to it. |
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)
Removes a serializer from the factory registry and cleans up all associated structures.
|
JSerializer |
getDefaultSerializer()
Returns the default serializer for this factory.
|
static JSerializerFactory |
getInstance() |
java.lang.String |
getName()
Returns the name of the
Serializer Factory . |
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 |
isImmutableTypeAliased(java.lang.Class type)
Checks if the specified class is aliased as an immutable type.
|
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.Class objectClass) |
SemanticType |
lookupSemanticType(java.lang.String aliasName)
Returns a copy of the
SemanticType associated with the specified alias. |
JSerializer |
lookupSerializer(java.lang.String name)
Returns a reference to the named serializer instance.
|
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.
|
getContext, getContextType, hasContext
clone, getSerialVersionUID
public static JSerializerFactory getInstance()
public JSerializer createSerializer(java.lang.String name)
SerializerFactory
createSerializer
in interface SerializerFactory
name
- the name of the serializer.public JSerializer createSerializer(java.lang.String name, ObjectMediationAliasManager aliasManager)
SerializerFactory
AliasManager
instance to it and returns a reference to it. Users may option to pass in a shared
alias manager into the method, in which case proper concurrent access protocols
should be used.createSerializer
in interface SerializerFactory
name
- the name of the serializer.aliasManager
- the AliasManager
of the serializer.public JSerializer getDefaultSerializer()
SerializerFactory
getDefaultSerializer
in interface SerializerFactory
public java.lang.String getName()
SerializerFactory
Serializer Factory
.getName
in interface SerializerFactory
public void addSerialSupport(java.lang.Class objectClass, com.streamscape.omf.java.SerialSupport serialSupport) throws FactoryManagerException
SerialSupport
instance to the factory.objectClass
- the class for which SerialSupport
instance will be added.serialSupport
- the SerialSupport
instance to be added.FactoryManagerException
public void discardSerializer(java.lang.String name) throws FactoryManagerException
SerializerFactory
Serializer.destroy()
method associated with the serializer to
free any resources. This method uses the name to lookup the serializer.discardSerializer
in interface SerializerFactory
name
- the name of serializer to be discarded.FactoryManagerException
- if the specified serializer does not exist.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 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 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 unalias(SemanticType type) throws FactoryManagerException
SerializerFactory
Semantic Type
from the global map.
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 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 SerializerFactory
public java.lang.String lookup(java.lang.Class clazz)
SerializerFactory
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 SerializerFactory
typeName
- the specified alias.null
if this alias does not exist.public JSerializer 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 SemanticType lookupSemanticType(java.lang.Class objectClass)
public java.lang.String resolveClass(java.lang.String className)
SerializerFactory
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.util.List listSerializers()
SerializerFactory
listSerializers
in interface SerializerFactory
public boolean isAliased(java.lang.String alias)
SerializerFactory
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 SerializerFactory
type
- the class to be checked.true
if the specified class is already aliased, false
otherwise.public void aliasImmutableType(SemanticType type) throws FactoryManagerException
SerializerFactory
java.lang.String
or collections.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 SerializerFactory
type
- the class to be aliased.public boolean isImmutableTypeAliased(java.lang.Class type)
SerializerFactory
isImmutableTypeAliased
in interface SerializerFactory
type
- the class to be checked.true
if the specified class is aliased as an immutable type, false
otherwise.Copyright © 2015-2024 StreamScape Technologies. All rights reserved.