Appendix A. XML Schema-based configuration

A.1. Introduction

This appendix details the XML Schema-based configuration introduced in Spring Actionscript version 0.8.

The central motivation for using XML Schema based configuration files was to make Spring XML configuration easier. The 'classic' <object/>-based approach is good, but its generic-nature comes with a price in terms of configuration overhead.

From the Spring Actionscript IoC containers point-of-view, everything is an object. That's great news for the Spring Actionscript IoC container, because if everything is an object then everything can be treated in the exact same fashion. The same, however, is not true from a developer's point-of-view. The objects defined in a Spring Actionscript XML configuration file are not all generic, vanilla objects. Usually, each object requires some degree of specific configuration.

Spring Actionscript XML Schema-based configuration addresses this issue. The <object/> element is still present, and if you wanted to, you could continue to write the exact same style of Spring Actionscript XML configuration using only <object/> elements. The XML Schema-based configuration does, however, make Spring Actionscript XML configuration files substantially clearer to read. In addition, it allows you to express the intent of an object definition.

The key thing to remember is that the new custom tags work best for infrastructure or integration objects: for example, collections, transactions, integration with 3rd-party frameworks, while the existing object tags are best suited to application-specific objects, such as DAOs, service layer objects, validators, etc. The examples included below will hopefully convince you that XML Schema support is a good idea. Please note the fact that this configuration mechanism is totally customisable and extensible. This means you can write your own domain-specific configuration tags that would better represent your application's domain; the process involved in doing so is covered in the appendix entitled Appendix B, Extensible XML authoring.

A.2. XML Schema-based configuration

A.2.1. Referencing the schemas

To use the XML Schema-style, you need to add the following declarations to your XML file.

<?xml version="1.0" encoding="UTF-8">
<objects
  xmlns="http://www.springactionscript.org/schema/objects"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springactionscript.org/schema/objects
  http://www.springactionscript.org/schema/objects/spring-actionscript-objects-1.0.xsd">

<!-- <object/> definitions here -->

</objects>

Note

The 'xsi:schemaLocation' fragment is not actually required, but can be included to reference a local copy of a schema (which can be useful during development).

The above Spring Actionscript XML configuration fragment is boilerplate that you can copy and paste (!) and then plug <object/> definitions into like you have always done. The section entitled, "The util schema" demonstrates how you can start immediately by using some of the more common utility tags. The rest of this chapter is devoted to showing examples of the Spring Actionscript XML Schema based configuration, with at least one example for every new tag. The format follows a before and after style, with a before snippet of XML showing the old (but still 100% legal and supported) style, followed immediately by an after example showing the equivalent in the new XML Schema-based style.

A.3. The util schema

First up is coverage of the util tags. As the name implies, the util tags deal with common, utility configuration issues, such as configuring collections, referencing constants, and suchlike.

To use the tags in the util schema, you need to have the following preamble at the top of your Spring Actionscript XML configuration file; the emboldened text in the snippet below references the correct schema so that the tags in the util namespace are available to you.

<?xml version="1.0" encoding="UTF-8"?>
<objects
  xmlns="http://www.springactionscript.org/schema/objects"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:util="http://www.springactionscript.org/schema/util"
  xsi:schemaLocation="http://www.springactionscript.org/schema/objects
  http://www.springactionscript.org/schema/objects/spring-actionscript-objects-1.0.xsd
  http://www.springactionscript.org/schema/objects/spring-actionscript-util-1.0.xsd">

<!-- <object/> definitions here -->

</objects>

You also need to register the namespace handler with the application context, like this (invoke this method before you load the configuration):

applicationContext.addNamespaceHandler(new UtilNamespaceHandler());

Not all util functions have been implemented yet in Spring Actionscript, the ones that are already present are described below.

A.3.1. <util:constant/>

Before...

<object id="..." class="...">
  <property name="version">
    <object class="org.springextensions.actionscript.ioc.factory.config.FieldRetrievingFactoryObject">
      <property name="targetClass" value="mx.core.FlexVersion"/>
      <property name="staticField" value="CURRENT_VERSION"/>
    </object>
  </property>
</object>

The above configuration uses a Spring Actionscript IFactoryObject <p>Interface to be implemented by objects that are factories for other objects. implementation, the FieldRetrievingFactoryObject <p><code>FieldRetrievingFactoryObject</code> is an <code>IFactoryObject</code> implementation which retrieves a static or non-static field value., to set the value of the 'test' property on an object to the value of the 'mx.core.FlexVersion.CURRENT_VERSION' constant. This is all well and good, but it is a tad verbose and (unnecessarily) exposes Spring Actionscript's internal plumbing to the end user.

The following XML Schema-based version is more concise and clearly expresses the developer's intent ('inject this constant value'), and it just reads better.

<object id="..." class="...">
  <property name="test">
    <util:constant static-field="mx.core.FlexVersion.CURRENT_VERSION"/>
  </property>
</object>

A.3.2. <util:invoke/>

Before...

<object class="org.springextensions.actionscript.ioc.factory.config.MethodInvokingFactoryObject">
      <property name="targetClass" value="mx.resources.ResourceManager"/>
      <property name="targetMethod" value="getInstance"/>
</object>

After...

<util:invoke target-class="mx.resources.ResourceManager" target-method="getInstance" id="resourceManager"/>

To pass arguments to the specified method use <arg/> child elements:

<util:invoke target-object="resourceManager" target-method="getString">
      <arg value="bundleName"/>
      <arg value="resourceName"/>
</util:invoke>

A.4. The messaging schema

The messaging schema, to no great surprise, covers all objects that deals with messaging, such as channels, producers, consumers, etc.

To use the tags in the messaging schema, you need to have the following preamble at the top of your Spring Actionscript XML configuration file; the emboldened text in the snippet below references the correct schema so that the tags in the messaging namespace are available to you.

<?xml version="1.0" encoding="UTF-8">
<objects
  xmlns="http://www.springactionscript.org/schema/objects"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:messaging="http://www.springactionscript.org/schema/messaging"
  xsi:schemaLocation="http://www.springactionscript.org/schema/objects
  http://www.springactionscript.org/schema/objects/spring-actionscript-objects-1.0.xsd
  http://www.springactionscript.org/schema/objects/spring-actionscript-messaging-1.0.xsd">

<!-- <object/> definitions here -->

</objects>

You also need to register the namespace handler with the application context, like this (invoke this method before you load the configuration):

applicationContext.addNamespaceHandler(new MessagingNamespaceHandler());

In the following section we will briefly show you what new tags the messaging schema will offer you.

A.4.1. <messaging:channel-set>

To declare a channelset using the messaging schema, add this markup to you XML configuration:

<channel-set clustered="false" initial-destination-id="remote-destination" id="myChannelSet">

"remote-destination" is just a generic name in this example, you will need to change this to a destination id that is suitable for your server environment.

A.4.2. <messaging:channel>

Now to add a channel to our previously declared channelset, you can add the following:

<channel id="myChannel" connect-timeout="50"
 failover-uris="http://myfailoverserver.com/flex,http://localhost/flex" request-timeout="200" uri="http://myserver.com/flex"/>

Then, to add the channel to the channelset, add this attribute to your channelset declaration:

<channel-set clustered="false" initial-destination-id="remote-destination" id="myChannelSet" channels="myChannel"/>

To add more than one channel, just comma delimit the channel names:

<channel-set clustered="false" initial-destination-id="remote-destination" id="myChannelSet" channels="myChannel,myOtherChannel"/>

A.4.2.1. <messaging:amf-channel>

The amf-channel tag merely adds a few attributes to the regular channel tag that apply to AMF specifically:

<amf-channel id="myChannel" connect-timeout="50"
 failover-uris="http://myfailoverserver.com/flex,http://localhost/flex" request-timeout="200" uri="http://myserver.com/flex"
 piggybacking-enabled="false"
 polling-enabled="true"
 polling-interval="200"/>

Other than that there is also the <secure-amf-channel/>, <streaming-amf-channel/> and the <secure-streaming-amf-channel/>, who map to the SecureAMFChannel, StreamingAMFChannel and SecureStreamingAMFChannel respectively but who offer no extra attributes as of yet.

A.4.3. <messaging:abstract-consumer>

Coming soon...

A.4.3.1. <messaging:consumer>

Coming soon...

A.4.3.2. <messaging:multi-topic-consumer>

Coming soon...

A.4.4. <messaging:producer>

Coming soon...

A.4.4.1. <messaging:multi-topic-producer>

Coming soon...

A.5. The RPC schema

Coming soon...

A.6. The stage processing schema

The stage processing schema offers markup directly geared towards the GenericStageProcessor This <code>IStageProcessor</code> uses certain stage components to be assigned to a specified target object. class.

To use the tags in the stage processing schema, you need to have the following preamble at the top of your Spring Actionscript XML configuration file; the emboldened text in the snippet below references the correct schema so that the tags in the stage processing namespace are available to you.

<?xml version="1.0" encoding="UTF-8">
<objects
  xmlns="http://www.springactionscript.org/schema/objects"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:si="http://www.springactionscript.org/schema/stageprocessing "
  xsi:schemaLocation="http://www.springactionscript.org/schema/objects
  http://www.springactionscript.org/schema/objects/spring-actionscript-objects-1.0.xsd
  http://www.springactionscript.org/schema/objects/spring-actionscript-stageprocessing-1.0.xsd">

<!-- <object/> definitions here -->

</objects>

You also need to register the namespace handler with the application context, like this (invoke this method before you load the configuration):

applicationContext.addNamespaceHandler(new StageProcessorNamespaceHandler());

In the following section we will briefly show you what new tags the stage processing schema will offer you.

A.6.1. <si:genericstageprocessor>

Currently there is just one tag in the stage processing namespace, to add a GenericStageProcessor This <code>IStageProcessor</code> uses certain stage components to be assigned to a specified target object. to your application simply use this markup:

<si:genericstageprocessor target-object="stageRegistry" target-method="register"
                     object-selector="registrySelector" id="genericStageProcessor"/>

Where the target-object and object-selector attributes are references to existing objects in your application context.