9.4. Custom Factories
BlazeDS destinations by default hook up to simple Java classes or POJOs. These destination classes are instantiated, and their lifecycle is managed, by BlazeDS.
The creation and lifecycle management processes for objects like EJBs and Spring beans (i.e., components used by the Spring Framework) are handled by their specialized containers. Further, these objects exist in their own independent namespace. In such cases, BlazeDS needs to leverage the object-specific creation and lifecycle management policy to use it within its domain.
BlazeDS includes a factory mechanism that you can leverage to instantiate and manage EJBs, Spring beans, and other such managed objects. All you need to do is create a special factory class for your managed component. Such special factory classes need to implement the flex.messaging.FlexFactory interface. Once available, the special factory class is used to create a FactoryInstance, which is associated with a destination and is used to get a reference to the managed object.
Here, I create a simple specialized factory to use EJB3 objects as destinations. You will benefit from looking at the source code first. The source for the EJB3Factory class is shown in Listing 9-2.
Example 9.2. A Custom Factory to Use EJB3 Objects as BlazeDS Destinations
package dsadapters.remoting.factories; import flex.messaging.FactoryInstance; import flex.messaging.FlexFactory; import flex.messaging.config.ConfigMap; import flex.messaging.services.ServiceException; ... |
Get Professional BlazeDS: Creating Rich Internet Applications with Flex® and Java® now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.