10 Chapter 20 Flex Integration with J2EE
Flex Technical Architecture
The discussion that follows is not necessarily particular to J2EE integration, but can apply equally
well to the integration of an RIA client using other services such as web services or HTTP services.
However, we introduce these concepts now because the decision to integrate with J2EE middleware
is typical for the development of an enterprise RIA, in which the number of use cases or tasks is typ-
ically high—tens or hundreds, rather than ones or twos.
As the number of tasks scales, so too does the number of methods we want to invoke, as well as the
number of different contexts in which we want to invoke these methods. We must consider how
best to manage these different services, and how to partition our application architecture so that the
invocations of these services are not scattered around our application, but are catalogued in well-
defined places in our architecture.
These problems that we want to address are not unique to RIA development, and have been docu-
mented and solved by the software community using a collection of different design patterns.
What we describe here are the best-practices advocated at iteration::two. They are not the best prac-
tices, but simply practices that fit with our understanding of building enterprise RIAs in a pre-
dictable and repeatable fashion. You might find best practices that fit within your own development
practices—consider the patterns and practices that follow as a starting point for your own develop-
ment only.
Many of the patterns presented here were already presented by the authors in “ActionScript 2.0
Design Patterns for Rich Internet Applications,” which can be found in the ActionScript 2.0 Dic-
tionary from Macromedia Press. However, Macromedia Flex encourages us to consider alternative
implementations of the patterns by using a combination of MXML and ActionScript 2.0.
RIA Service Locator
The problem of looking up remote services and establishing connections to these services is typi-
cally solved by the service locator class. Prior to Flex, we recommended a strategy whereby a single-
ton class provided the capability to look up services by name, returning an instance of a class that
could be used as a proxy to the remote service. With Flex, much of the effort required in imple-
menting the Service Locator pattern has been done for us:
■
Named Services—The <mx:RemoteObject> tag allows us to specify not only the location
of a class that should be available for integration, but to specify these classes within the
flex-config.xml deployment descriptor. By using a deployment descriptor, we can name
services from configuration files, and look up these services in MXML using these
canonical names. This feature will be explained further in the next chapter.
■
Return of a Service Object—Prior to Flex, our ActionScript 2.0 implementation of the
Service Locator was responsible for looking up the Remote object, creating a connection
to that object, and returning an instance of a proxy class that could be used to invoke
methods on the service. The
<mx:RemoteObject> tag is an MXML construct that achieves
all this without the requirement for ActionScript 2.0 coding.