Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL
Help

Part 7: Additional programming topics > Chapter 16: Extending applications with... - Pg. 190

188 Chapter 16: Extending applications with factories BlazeDS provides a factory mechanism that lets you plug in your own component creation and maintenance system to allow it to integrate with systems like EJB and Spring, which store components in their own namespace. You provide a class that implements the flex.messaging.FlexFactory interface. This class is used to create a FactoryIn- stance that corresponds to a component configured for a specific destination. Topics The factory mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188 The factory mechanism Remoting Service destinations use Java classes that you write to integrate with Flex clients. By default, BlazeDS creates these instances. If they are application-scoped components, they are stored in the ServletContext attribute space using the destination's name as the attribute name. If you use session-scoped components, the components are stored in the FlexSession, also using the destination name as the attribute. If you specify an attribute-id element in the destination, you can control which attribute the component is stored in; this lets more than one destination share the same instance. The following examples shows a destination definition that contains an attribute-id element: <destination id="WeatherService"> <properties> <source>weather.WeatherService</source> <scope>application</scope> <attribute-id>MyWeatherService</attribute-id> </properties> </destination> In this example, BlazeDS creates an instance of the class weather.WeatherService and stores it in the ServletContext object's set of attributes with the name MyWeatherService. If you define a different destination with the same attribute-id value and the same Java class, BlazeDS uses the same component instance. BlazeDS provides a factory mechanism that lets you plug in your own component creation and maintenance system to BlazeDS so it integrates with systems like EJB and Spring, which store components in their own namespace. You provide a class that implements the flex.messaging.FlexFactory interface. You use this class to create a FactoryIn- stance that corresponds to a component configured for a specific destination. Then the component uses the Facto- ryInstance to look up the specific component to use for a given request. The FlexFactory implementation can access configuration attributes from a BlazeDS configuration file and also can access FlexSession and ServletContext objects. For more information, see the documentation for the FlexFactory class in the public BlazeDS Javadoc documentation. After you implement a FlexFactory class, you can configure it to be available to destinations by placing a factory element in the factories element in the services-config.xml file, as the following example shows. A single FlexFactory instance is created for each BlazeDS web application. This instance can have its own configuration properties, although in this example, there are no required properties to configure the factory.