org.spicefactory.cinnamon.config
Class CinnamonConfig

java.lang.Object
  extended by org.spicefactory.cinnamon.config.CinnamonConfig

public class CinnamonConfig
extends Object

The core configuration class for Cinnamon. It serves as a central repository for registering services, service factories, class mappings, converters or interceptors. Usually an instance of this class will be created at application startup by one of the two builtin configuration mechanisms: Either loaded from an XML configuration file or loaded from a Spring ApplicationContext. But alternatively an instance of this class can also be created and configured programmatically.

Author:
Jens Halm

Constructor Summary
CinnamonConfig(Map<String,String> initMap, Map<String,Object> applicationMap)
          Creates a new instance.
 
Method Summary
 void addConverter(Converter<?> converter)
          Adds a Converter to this configuration.
 void addMapping(ClassMapping mapping)
          Adds a class mapping.
 void addMessageProcessor(MessageProcessor<?,?> processor)
          Adds a MessageProcessor to this configuration.
 void addPhaseListener(PhaseListener listener)
          Adds a phase listener.
 void addServiceConfig(ServiceConfig serviceConfig)
          Adds a Service configuration.
 void addServiceFactory(String factoryName, ServiceFactory serviceFactory)
          Registers a ServiceFactory instance for the given name.
 void addServiceInterceptor(ServiceInterceptor interceptor)
          Adds an service interceptor.
 Converter<?> getConverter(Class<?> type)
          Returns the Converter that will be applied for method parameters and bean properties of the given type.
 ClassMapping getMappingForAlias(String alias)
          Returns the class mapping for the given alias.
 ClassMapping getMappingForJavaClass(Class<?> type)
          Returns the class mapping for the given Java class.
 ClassMapping[] getMappings()
          Returns an Array containing all registered class mappings.
 MessageProcessor<?,?> getMessageProcessor(Class<?> type)
          Returns the MessageProcessor that is responsible for processing messages of the specified type.
 PhaseListener[] getPhaseListeners()
          Returns an iterator for all registered phase listener.
 ReflectionFactory getReflectionFactory()
          Returns the ReflectionFactory used by this instance.
 ServiceConfig getServiceConfig(String serviceName)
          Returns the Service configuration for the given Service name.
 ServiceConfig[] getServiceConfigs()
          Returns an Array containing all registered Service configurations.
 Map<String,ServiceFactory> getServiceFactories()
          Returns an unmodifiable Map containing all registered ServiceFactories.
 ServiceFactory getServiceFactory(String factoryName)
          Returns the ServiceFactory registered for the given name.
 Iterator<ServiceInterceptor> getServiceInterceptors()
          Returns an iterator for all registered service interceptors.
 XmlAdapter getXmlAdapter()
          Returns the XmlAdapter implementation that will be used for reading and writing XML from/to AMF3 binary data
 void postProcess()
          Should be called once after all configuration artifacts have been added to this configuration.
 void setXmlAdapter(XmlAdapter adapter)
          Sets the XmlAdapter implementation to be used for reading and writing XML from/to AMF3 binary data.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CinnamonConfig

public CinnamonConfig(Map<String,String> initMap,
                      Map<String,Object> applicationMap)
Creates a new instance. In a web application the two Map parameters represent the Servlet initialisation parameters and the ServletContext attributes respectively. The Map abstraction allows this class to be used outside a servlet container where those two Maps have to be created (and optionally populated) manually. Both Maps will be passed to all ServiceFactories that will be added to this instance. This class does not use them internally, so they could be empty as long as no ServiceFactory depends on the presence of a particular attribute in one of those Maps.

Parameters:
initMap - the initialisation parameters (taken from ServletConfig in a web application)
applicationMap - the application attributes (taken from ServletContext in a web application)
Method Detail

getReflectionFactory

public ReflectionFactory getReflectionFactory()
Returns the ReflectionFactory used by this instance. Usually only used internally. The ReflectionFactory is the central repository for registering Converters and obtaining objects to reflect on bean properties or create MethodInvokers. If you extend Cinnamon and need one of those capabilities you should use this factory and not create your own.

Returns:
the ReflectionFactory used by this configuration instance

addServiceFactory

public void addServiceFactory(String factoryName,
                              ServiceFactory serviceFactory)
Registers a ServiceFactory instance for the given name.

Parameters:
factoryName - the name of the ServiceFactory
serviceFactory - the ServiceFactory to be added

getServiceFactory

public ServiceFactory getServiceFactory(String factoryName)
Returns the ServiceFactory registered for the given name.

Parameters:
factoryName - the name of the ServiceFactory
Returns:
the ServiceFactory registered for the given name or null if no such factory exists

getServiceFactories

public Map<String,ServiceFactory> getServiceFactories()
Returns an unmodifiable Map containing all registered ServiceFactories. The keys of this Map will be the names of the ServiceFactories.

Returns:
an unmodifiable Map containing all registered ServiceFactories

addServiceConfig

public void addServiceConfig(ServiceConfig serviceConfig)
Adds a Service configuration.

Parameters:
serviceConfig - the Service configuration to be added to this configuration.

getServiceConfig

public ServiceConfig getServiceConfig(String serviceName)
Returns the Service configuration for the given Service name.

Parameters:
serviceName - the name of the Service
Returns:
the Service configuration for the given Service name or null if no such Service exists

getServiceConfigs

public ServiceConfig[] getServiceConfigs()
Returns an Array containing all registered Service configurations.

Returns:
an Array containing all registered Service configurations

addServiceInterceptor

public void addServiceInterceptor(ServiceInterceptor interceptor)
Adds an service interceptor.

Parameters:
interceptor - the service interceptor to be added to this configuration.

getServiceInterceptors

public Iterator<ServiceInterceptor> getServiceInterceptors()
Returns an iterator for all registered service interceptors. The order will correspond to the order in which interceptors were added to this configuration and also to the order in which the interceptors will be applied to every request.

Returns:
an iterator for all registered service interceptors

addMapping

public void addMapping(ClassMapping mapping)
Adds a class mapping.

Parameters:
mapping -

getMappingForAlias

public ClassMapping getMappingForAlias(String alias)
Returns the class mapping for the given alias. The alias should correspond to the alias used when registering the class in AS3 with flash.net.registerClassAlias or the [RemoteClass] metadata tag.

Parameters:
alias - the alias for the mapped class
Returns:
the class mapping for the given alias or null if no such mapping exists

getMappingForJavaClass

public ClassMapping getMappingForJavaClass(Class<?> type)
Returns the class mapping for the given Java class.

Parameters:
type - the mapped Java class
Returns:
the class mapping for the given Java class or null if no such mapping exists

getMappings

public ClassMapping[] getMappings()
Returns an Array containing all registered class mappings.

Returns:
an Array containing all registered class mappings

addPhaseListener

public void addPhaseListener(PhaseListener listener)
Adds a phase listener.

Parameters:
listener - the phase listener to be added to this configuration.

getPhaseListeners

public PhaseListener[] getPhaseListeners()
Returns an iterator for all registered phase listener. The order will correspond to the order in which listeners were added to this configuration and also to the order in which the listeners will be executed for each request. PhaseListeners are a low level extension point and thus will usually be used by other frameworks extending Cinnamon's behaviour and rather rarely by applications.

Returns:
all registered PhaseListener instances

addMessageProcessor

public void addMessageProcessor(MessageProcessor<?,?> processor)
Adds a MessageProcessor to this configuration.

Parameters:
processor - the MessageProcessor to add to this configuration

getMessageProcessor

public MessageProcessor<?,?> getMessageProcessor(Class<?> type)
Returns the MessageProcessor that is responsible for processing messages of the specified type.

Parameters:
type - the type of message to return the processor for
Returns:
the MessageProcessor that is responsible for processing messages of the specified type

addConverter

public void addConverter(Converter<?> converter)
Adds a Converter to this configuration. Converters will be used to convert method parameters if necessary when reflectively invoking service methods and also for converting bean properties in mapped classes. The types that the given Converter should be applied to will be determined by the TypeVariable of the Converter implementation (i.e. MyConverter implements Converter<InputStream> would be used for all method parameters and bean properties that are declared as InputStream or a subclass of InputStream).

Parameters:
converter - the Converter to be added to this configuration.

getConverter

public Converter<?> getConverter(Class<?> type)
Returns the Converter that will be applied for method parameters and bean properties of the given type.

Parameters:
type - the type that the Converter will be applied to
Returns:
the Converter that will be applied for method parameters and bean properties of the given type or null if no such Converter exists

getXmlAdapter

public XmlAdapter getXmlAdapter()
Returns the XmlAdapter implementation that will be used for reading and writing XML from/to AMF3 binary data

Returns:
the XmlAdapter implementation for this configuration or null if it had not been set yet

setXmlAdapter

public void setXmlAdapter(XmlAdapter adapter)
Sets the XmlAdapter implementation to be used for reading and writing XML from/to AMF3 binary data. Cinnamon comes with 3 builtin adapters for W3C DOM (the default), dom4j and XOM. But you can easily create your own implementation of the XmlAdapter interface if you use a different XML library (like JDOM).

Parameters:
adapter - the XmlAdapter implementation that should be used

postProcess

public void postProcess()
Should be called once after all configuration artifacts have been added to this configuration.


toString

public String toString()
Overrides:
toString in class Object