public class Model<T> extends Object
modelRoot
object instance, as well
as modelMetadata
associated with the
objects wired into the object graph routed on the modelRoot
.
The modelMetadata
can contain information for, among other
things, serializing the object graph routed at modelRoot
.Modifier and Type | Field and Description |
---|---|
protected Map<Class<?>,Map<String,BeanWriter>> |
beanWriters |
protected Set<String> |
knownNamespaces |
protected static org.slf4j.Logger |
LOGGER |
protected List<BeanMetadata> |
modelMetadata |
protected T |
modelRoot |
protected Map<String,String> |
namespacePrefixMappings |
Modifier | Constructor and Description |
---|---|
protected |
Model(T modelRoot,
List<BeanMetadata> modelMetadata,
Map<Class<?>,Map<String,BeanWriter>> beanWriters,
Map<String,String> namespacePrefixMappings)
Protected constructor.
|
|
Model(T modelRoot,
ModelBuilder builder)
Public constructor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addMissingNamespaceMappings()
Iterate through all the bean metadata and add any missing
namespace-to-prefix mappings.
|
BeanMetadata |
getBeanMetadata(Object beanInstance)
Get the model metadata.
|
BeanWriter |
getBeanWriter(Object bean)
Get the
BeanWriter instance for the specified bean, if one exists. |
List<BeanMetadata> |
getModelMetadata()
Get the model metadata.
|
T |
getModelRoot()
Get the model root object instance.
|
Map<String,String> |
getNamespacePrefixMappings()
Get the current namespace prefix mappings for this Model instance.
|
protected boolean |
isNamespaceInModel(String namespaceUri) |
BeanMetadata |
registerBean(Object beanInstance)
Register the specified bean instance.
|
protected void |
removeKnownNamespaceMappings()
Filter out all "known" namespace-to-prefix mappings for which there are no
registered beans in the model.
|
protected void |
resolveKnownNamespaces()
Resolve the set of known namespaces.
|
protected void |
resolveModelNamespaces()
Resolve all the namespaces in the model.
|
protected void |
resolveUnmappedBeanWriters() |
protected void |
updateMetadataPrefixes()
Iterate through all the bean metadata and make sure the
namespace prefixes match those declared in the prefix mappings.
|
void |
writeModel(Writer writer)
Write the bean model to the specified
Writer instance. |
protected static final org.slf4j.Logger LOGGER
protected final T modelRoot
protected final List<BeanMetadata> modelMetadata
protected final Map<Class<?>,Map<String,BeanWriter>> beanWriters
public Model(T modelRoot, ModelBuilder builder)
modelRoot
- The model root object.builder
- Associated model builder instance.protected Model(T modelRoot, List<BeanMetadata> modelMetadata, Map<Class<?>,Map<String,BeanWriter>> beanWriters, Map<String,String> namespacePrefixMappings)
ModelBuilder
.modelRoot
- The model root object.modelMetadata
- Model metadata.public T getModelRoot()
protected void resolveKnownNamespaces()
public BeanMetadata registerBean(Object beanInstance) throws BeanRegistrationException
@DefaultNamespace
annotation.
Note that not all beans in the model object graph need to be registered with the model. Only the
namepsace "root" beans need to be registered. The root bean of the model's object graph is often the only
namespace "root" bean in the model. This is only ever the case when the configuration is composed of a single
namespace. Many configurations are composed of multiple configuration namespaces, such as the Smooks
configurations, with the smooks-core, javabean, validation etc configuration namespaces.
In these cases, the constructed java object model for this multi-namespace configuration will have object
instance "away from" the root of the object model (down the object graph) that are associated with different
configuration namespaces. These object instances are what we call the "namespace root" beans and they need to
be registered with the model via this method. If not registered, the serialization process is likely to
fail when it attempts to locate a BeanWriter
for the bean (and it's associated configuration namespace).BeanRegistrationException
- Bean instance
already registered
, or
bean type
not annotated with the
DefaultNamespace annotation
.public List<BeanMetadata> getModelMetadata()
BeanMetadata
list containing metadata about objects
wired into the object graph, routed at the model root
.public BeanMetadata getBeanMetadata(Object beanInstance)
BeanMetadata
list containing metadata about objects
wired into the object graph, routed at the model root
.public void writeModel(Writer writer) throws BeanRegistrationException, IOException
Writer
instance.writer
- The writer instance.BeanRegistrationException
- One of the "namespace root" beans in the model is not registered
.IOException
- Error while writing the model to the supplied Writer
instance.public Map<String,String> getNamespacePrefixMappings()
public BeanWriter getBeanWriter(Object bean) throws BeanRegistrationException
BeanWriter
instance for the specified bean, if one exists.bean
- The bean.BeanWriter
instance for the specified bean, if one exists, otherwise null.BeanRegistrationException
- No BeanMetadata
for specified bean instance.protected void resolveModelNamespaces()
protected void updateMetadataPrefixes()
protected void removeKnownNamespaceMappings()
protected void addMissingNamespaceMappings()
protected boolean isNamespaceInModel(String namespaceUri)
protected void resolveUnmappedBeanWriters() throws IOException
IOException
Copyright © 2024. All rights reserved.