public interface SerializerFactory
Title: Object Mediation Framework
Description: This is an interface that defines a Serializer Factory
.
A Serializer Factory
is a proxy mechanism for working with object serialization
classes. It represents a service provider for a given data serialization library. A factory is
a singleton instance of a specific serializer. The ObjectMediationFactoryManager
is
responsible for registering and de-registering of Serializers which by default are loaded from
runtime cache or repository if the runtime context supports it.
For Client Context
applications the three main serializers (XML, Binary and JSON)
are automatically bound and referenced. Users must manually add and implement any other data
serialization mechanisms they wish. Such serializers must also be bound into the runtime
that the client wishes to connect to in order to have the runtime recognize the payload
format. However the Service Event Fabric
is a format agnostic mechanism for the
most part. Event datagrams may hold arbitrary data. The fabric's data exchange however
makes use of JSerializer to marshal all datagrams.
In a Runtime Context
serializer factories are by default bound into a common Reference Context
under the name space called /sys/serializer
, although users can design their own serializers
and bind them to other contexts. In this case the user is responsible for loading and registering
the serializer factory.
Any factories in the system context will be automatically loaded and registered by the runtime. Note that serializer factories are considered Level 0 objects that must be loaded as part of the Runtime's initialization. It is therefore recommended that any Java archives for user defined factories be placed into the /ext directory of the runtime cache or its equivalent in the repository, allowing for dynamic adding of the Java archives to the system class loader.
The serializer factory provides methods for working with serializer instances as well as register
user-defined data types. This allows developers to assign user-friendly (semantic) names to data
elements. Semantic types allow user to manipulate labels rather then work with fully-qualified
class names which is especially useful when working with serial formats such as XML or JSON. The
framework defines a number of system types that allow for mapping of primitive types, data collections
and managed connection factories such as JDBC
, JMS
and otheres. Specific
serializer implementations may also add their own methods for manipulating data elements and collections.
By default the com.streamscape.runtime.RuntimeOMFactoryManager
controls all serializer factories in the runtime.
While users may define and register their own factory instances such objects will only exist for the
duration of the application and will not survive application re-start. The same is true for any
Semantic Types
that may be added thru the direct usage of factory methods alias(com.streamscape.repository.types.SemanticType)
and unalias(com.streamscape.repository.types.SemanticType)
(in any of their forms). To add persistent versions of data types into the
application runtime developers should use the Management Framework Factory methods rather then
the factory methods.
At runtime Semantic Type
definitions are stored in a global AliasManager
structure
which is shared by all serializer instances across all factories. This allows all serializers to access
a single, common types alias list. However users may define their own factory instances and pass their
own versions of the AliasManager
to the factories. In this way the factories may be used
without a dependency on the fabric runtime context.
Copyright: Copyright (c) 2009
Company: StreamScape Technologies
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.
|
Serializer |
createSerializer(java.lang.String name)
Creates an instance of a named Serializer and returns a reference to it.
|
Serializer |
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.
|
Serializer |
getDefaultSerializer()
Returns the default serializer for this factory.
|
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.String alias)
Returns a copy of the
SemanticType associated with the specified alias. |
Serializer |
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.
|
java.lang.String getName()
Serializer Factory
.Serializer createSerializer(java.lang.String name)
name
- the name of the serializer.Serializer createSerializer(java.lang.String name, ObjectMediationAliasManager aliasManager)
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.name
- the name of the serializer.aliasManager
- the AliasManager
of the serializer.FactoryManagerException
Serializer getDefaultSerializer()
void discardSerializer(java.lang.String name) throws FactoryManagerException
Serializer.destroy()
method associated with the serializer to
free any resources. This method uses the name to lookup the serializer.name
- the name of serializer to be discarded.FactoryManagerException
- if the specified serializer does not exist.Serializer lookupSerializer(java.lang.String name)
name
- the name of serializer to be looked up.null
if the specified serializer does not exist.SemanticType lookupSemanticType(java.lang.String alias)
SemanticType
associated with the specified alias.alias
- the specified alias.null
if the alias does not exist.boolean isAliased(java.lang.String alias)
AliasManager
.alias
- the alias to be checked.true
if the specified alias already exists, false
otherwise.boolean isAliased(java.lang.Class type)
AliasManager
.type
- the class to be checked.true
if the specified class is already aliased, false
otherwise.void alias(SemanticType type) throws FactoryManagerException
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.type
- the semantic type to be aliased.FactoryManagerException
- if the specified type is already aliased.void unalias(SemanticType type) throws FactoryManagerException
Semantic Type
from the global map.
type
- the semantic type to be unaliased.FactoryManagerException
- if the specified type is not aliased or
if the specified type is a system type.void alias(java.lang.String alias, java.lang.Class type) throws FactoryManagerException
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
- 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.void aliasImmutableType(SemanticType type) throws FactoryManagerException
java.lang.String
or collections.type
- the semantic type to be aliased.FactoryManagerException
- if some error occurs.void aliasImmutableType(java.lang.Class type)
java.lang.String
or collections.type
- the class to be aliased.boolean isImmutableTypeAliased(java.lang.Class type)
type
- the class to be checked.true
if the specified class is aliased as an immutable type, false
otherwise.void unalias(java.lang.String alias) throws FactoryManagerException
alias
- the alias to be removed.FactoryManagerException
- if the specified alias does not exist or
if the specified type is a system type.java.lang.String lookup(java.lang.Class clazz)
clazz
- the specified class.null
if the class is not aliased.java.lang.String lookup(java.lang.String typeName)
typeName
- the specified alias.null
if this alias does not exist.java.lang.String resolveClass(java.lang.String className)
className
- the specified class name.null
if the class is not aliased.java.util.List listAliases()
java.util.List listSerializers()
void destroy()
Copyright © 2015-2024 StreamScape Technologies. All rights reserved.