com.endeca.infront.assembler.spring
Class SpringAssemblerFactory

java.lang.Object
  extended by com.endeca.infront.assembler.spring.SpringAssemblerFactory
All Implemented Interfaces:
AssemblerFactory, ApplicationContextAware

public class SpringAssemblerFactory
extends Object
implements AssemblerFactory, ApplicationContextAware

An assembler factory implementation that uses a Spring Framework bean factory to resolve cartridge handlers and other services.

Usage Example

Here's a sample JSP that uses the assembler to make a request and serialize its output to JSON:

 FILE: browse.jsp
 <%
 // See the assembler-context.xml Spring configuration file in the
 // WEB-INF directory of the Discover reference application.
 //
 // Get the Spring Web Application Context
 ServletContext servletCtx = this.getServletContext();
 WebApplicationContext webappCtx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletCtx);
 
 // Get an assembler factory and create an assembler
 AssemblerFactory assemblerFactory = (AssemblerFactory)webappCtx.getBean("assemblerFactory", AssemblerFactory.class);
 Assembler assembler = assemblerFactory.createAssembler();
 
 // Assemble the results for the mobile browse page.
   ContentItem assemblerResults = assembler.assemble(new RedirectAwareContentInclude("/pages/mobile/browse"));
 
 // Serialize the results to JSON
 response.setCharacterEncoding("UTF-8");
 JsonSerializer serializer = new JsonSerializer(response.getWriter());
 serializer.write(assemblerResults);
 %>
 

This class is thread-safe, but Assembler objects returned by its createAssembler() method are not. Constructor arguments passed into this class should not subsequently be modified by other threads as this may result in concurrency errors.


Constructor Summary
SpringAssemblerFactory(AssemblerSettings pSettings)
          Constructor to use when configuring and instantiating instances of this assembler from Spring.
SpringAssemblerFactory(AssemblerSettings pSettings, List<AssemblerEventListener> pListeners)
          Constructor to use when configuring and instantiating instances of this assembler from Spring.
SpringAssemblerFactory(AssemblerSettings pSettings, List<AssemblerEventListener> pListeners, ApplicationContext pApplicationContext)
          Convenience constructor to use when instantiating a Spring-based assembler programmatically.
 
Method Summary
 Assembler createAssembler()
          Creates and returns a new assembler.
 void setApplicationContext(ApplicationContext pApplicationContext)
          Sets the Spring Framework bean factory used by this assembler for resolving cartridge handlers and other services within an assembler request context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SpringAssemblerFactory

public SpringAssemblerFactory(AssemblerSettings pSettings)
Constructor to use when configuring and instantiating instances of this assembler from Spring. Is equivalent to calling SpringAssemblerFactory(AssemblerSettings, List) with an empty list of AssemblerEventListeners.

Parameters:
pSettings - Contains settings to be applied to Assemblers produced by this factory

SpringAssemblerFactory

public SpringAssemblerFactory(AssemblerSettings pSettings,
                              List<AssemblerEventListener> pListeners)
Constructor to use when configuring and instantiating instances of this assembler from Spring.

Parameters:
pSettings - Contains settings to be applied to Assemblers produced by this factory
pListeners - A list of listeners to be added to Assemblers created by this factory. Because Assemblers may be created and invoked concurrently, these listeners MUST be thread safe.

SpringAssemblerFactory

public SpringAssemblerFactory(AssemblerSettings pSettings,
                              List<AssemblerEventListener> pListeners,
                              ApplicationContext pApplicationContext)
Convenience constructor to use when instantiating a Spring-based assembler programmatically. If you configure your assembler within a Spring configuration file, you should not use this method with Spring's constructor injection capabilities; instead, you should use the simple no-argument constructor.

Parameters:
pSettings - Contains settings to be applied to Assemblers produced by this factory
pListeners - A list of listeners to be added to Assemblers created by this factory. Because Assemblers may be created and invoked concurrently, these listeners MUST be thread safe.
pApplicationContext - A Spring application context to use for looking up CartridgeHandlers.
Method Detail

createAssembler

public Assembler createAssembler()
                          throws AssemblerException
Description copied from interface: AssemblerFactory
Creates and returns a new assembler.

Specified by:
createAssembler in interface AssemblerFactory
Returns:
The newly-constructed assembler
Throws:
AssemblerException - if the assembler cannot be created. For example, this exception may be thrown if the factory is misconfigured.

setApplicationContext

public void setApplicationContext(ApplicationContext pApplicationContext)
                           throws BeansException
Sets the Spring Framework bean factory used by this assembler for resolving cartridge handlers and other services within an assembler request context.

If the assembler and cartridge handlers are managed within the same Spring bean factory, then you don't need to call this method explicitly. Since the assembler is ApplicationContextAware, the Spring Framework will implicitly set the bean factory just after the assembler is constructed. However, if you instantiate an assembler outside of the Spring Framework, then you must explicitly set the bean factory on this assembler.

Specified by:
setApplicationContext in interface ApplicationContextAware
Throws:
BeansException
See Also:
CartridgeHandler


Copyright © 2012, Oracle and/or its affiliates. All rights reserved.