O'Reilly logo

Professional Cairngorm™ by Jeremy Wischusen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

3.4. How Do You Use It?

Now that you have the component created, you will add services to it as you would to any MXML file. The following code contains examples of adding each type of service that the ServiceLocator can use:

<?xml version="1.0" encoding="utf-8"?>
<services:ServiceLocator xmlns:services="com.adobe.cairngorm.business.*"
xmlsn:mx="http://www.adobe.com/2006/mxml">
  <mx:HTTPService id="someHTTPService" url="http://somesite.com/someService"
method="POST" resultFormat="xml" contentType="application/xml" />
  <mx:RemoteObject id="someRemoteObject" destination="someDestination"
source="com.somepackage.someservice" />
<mx:WebService id="someWebService" wsdl=" http://somesite.com/some.wsdl" />
</services:ServiceLocator>

In order to use the ServiceLocator in your components, there must be an instance of it in your application, normally in the main application file.

To include the ServiceLocator component you created, create a namespace in the main application tag pointing to the location where you created the component. Then simply add an instance of the ServiceLocator you created to the main application, as in the following:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
xmlsn:business="com.cairngormexample.business.*">
  <business:CairngormExampleServices id="services"/>
</mx:Application>

To access a service contained in the ServiceLocator, use the following code:

//HTTPService var service:HTTPService = ServiceLocator.getInstance().getHTTPService('someHTTPService); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required