org.milyn.javabean.dynamic
Class Model<T>

java.lang.Object
  extended by org.milyn.javabean.dynamic.Model<T>

public class Model<T>
extends Object

Model container.

Contains the 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.

Author:
tom.fennelly@gmail.com

Constructor Summary
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.
 
Method Summary
 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.
 BeanMetadata registerBean(Object beanInstance)
          Register the specified bean instance.
 void writeModel(Writer writer)
          Write the bean model to the specified Writer instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Model

public Model(T modelRoot,
             ModelBuilder builder)
Public constructor.

Parameters:
modelRoot - The model root object.
builder - Associated model builder instance.

Model

protected Model(T modelRoot,
                List<BeanMetadata> modelMetadata,
                Map<Class<?>,Map<String,BeanWriter>> beanWriters,
                Map<String,String> namespacePrefixMappings)
Protected constructor.

Used by the ModelBuilder.

Parameters:
modelRoot - The model root object.
modelMetadata - Model metadata.
Method Detail

getModelRoot

public T getModelRoot()
Get the model root object instance.

Returns:
the model root object instance.

registerBean

public BeanMetadata registerBean(Object beanInstance)
                          throws BeanRegistrationException
Register the specified bean instance.

All "namespace root" bean instances within a model must be registered via this method. All "namespace root" bean types must be annotated with the @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).

Returns:
Model metadata.
Throws:
BeanRegistrationException - Bean instance already registered, or bean type not annotated with the DefaultNamespace annotation.

getModelMetadata

public List<BeanMetadata> getModelMetadata()
Get the model metadata.

A BeanMetadata list containing metadata about objects wired into the object graph, routed at the model root.

Returns:
Model metadata.

getBeanMetadata

public BeanMetadata getBeanMetadata(Object beanInstance)
Get the model metadata.

A BeanMetadata list containing metadata about objects wired into the object graph, routed at the model root.

Returns:
Model metadata.

writeModel

public void writeModel(Writer writer)
                throws BeanRegistrationException,
                       IOException
Write the bean model to the specified Writer instance.

Parameters:
writer - The writer instance.
Throws:
BeanRegistrationException - One of the "namespace root" beans in the model is not registered.
IOException - Error while writing the model to the supplied Writer instance.

getNamespacePrefixMappings

public Map<String,String> getNamespacePrefixMappings()
Get the current namespace prefix mappings for this Model instance.

Returns:
The current namespace prefix mappings for this Model instance.

getBeanWriter

public BeanWriter getBeanWriter(Object bean)
                         throws BeanRegistrationException
Get the BeanWriter instance for the specified bean, if one exists.

Parameters:
bean - The bean.
Returns:
The BeanWriter instance for the specified bean, if one exists, otherwise null.
Throws:
BeanRegistrationException - No BeanMetadata for specified bean instance.


Copyright © 2018. All rights reserved.