All you statements make sense... the only missing piece is the "static"
instance for a singleton. By subclassing the singleton ServiceLocator you
gain the static getInstance() method. Your subclass will now be a reference
to a static / global variable called "instance" contained within the
ServiceLocator class. When you call getInstance() you'll get a reference to
your ServiceLocator implementation. You can see how this works by putting a
breakpoint on the ServiceLocator constructor. If you watch the instance
variable you'll see that it's your own ServiceLocator class implementation.
The Singleton pattern used here is to enforce that you only ever want one
ServiceLocator in your application. (One place to get services.)
I understand that you'd like to call
MyFunkyServiceLocator.getInstance().getService("serviceName")
but static methods aren't inherited.
On 1/5/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
Hey All,
Re: Flex at Bell
I'm not sure about everyone else; my team has only just started getting
into it.
The part I don't understand though, is the Cairngorm 2.1 Store example
shows retrieving the service like this:
ServiceLocator.getInstance().getWebService("myService");
However, all of the services are configured in:
*MyFunkyServiceLocator.mxml:*
<cairngorm:ServiceLocator … />
<mx:WebService id="myService" />
</cairngorm:ServiceLocator>
Does that not make MyFunkyServiceLocator a subclass of
com.adobe.cairngorm.business.ServiceLocator?
Why, if I define a parameter in an MXML file is it available to the parent
class via this? myService shouldn't (to me) belong to ServiceLocator, it
should belong to MyFunkyServiceLocator.
*Jay Proulx*
[EMAIL PROTECTED]
------------------------------
*From:* [email protected] [mailto:[EMAIL PROTECTED] *On
Behalf Of *Clint Modien
*Sent:* January 5, 2007 3:41 PM
*To:* [email protected]
*Cc:* Ben Lucyk
*Subject:* RE: [flexcoders] Cairngorm ServiceLocator
I'm assuming you've seen my second email by now but… the reason is because
you're calling the static ServiceLocator.getInstance() method.
<quote>
The ServiceLocator class is a singleton as well. You will only EVER have
one in your application so even though you are creating a subclass as soon
as you call getInstance() you will get the only instance there is in your
application. If you had two Services.mxml files (Service1.mxml and
Services2.mxml) in your app the last one created would be the one returned
by ServiceLocator.getInstance();
</quote>
------------------------------
*From:* [email protected] [mailto:[EMAIL PROTECTED] *On
Behalf Of [EMAIL PROTECTED]
*Sent:* Friday, January 05, 2007 12:13 PM
*To:* [email protected]
*Subject:* RE: [flexcoders] Cairngorm ServiceLocator
I traced through the code, com.adobe.cairngorm.business.ServiceLocatorrefers to itself as
"this" when looking up a service:
private function getServiceForId( serviceId : String ) : Object
{
if ( this[ serviceId ] == null )
{
throw new CairngormError(
CairngormMessageCodes.NO_SERVICE_FOUND, serviceId );
}
return this[ serviceId ];
}
Except, in my case, there's no "projectService" associated with
com.adobe.cairngorm.business.ServiceLocator, I've specified it in a
Services.mxml file – How come I'm not running Services.getWebService()
instead of ServiceLocator.getWebService() ?
*Jay Proulx*
[EMAIL PROTECTED]
------------------------------
*From:* [email protected] [mailto:[EMAIL PROTECTED] *On
Behalf Of *Clint Modien
*Sent:* January 5, 2007 3:00 PM
*To:* [email protected]
*Cc:* Ben Lucyk
*Subject:* RE: [flexcoders] Cairngorm ServiceLocator
The code is opensource so you can see how it works… here's the call it
makes. (This is cairngorm v2)
------------------------------
*From:* [email protected] [mailto:[EMAIL PROTECTED] *On
Behalf Of [EMAIL PROTECTED]
*Sent:* Friday, January 05, 2007 10:53 AM
*To:* [email protected]
*Subject:* [flexcoders] Cairngorm ServiceLocator
I'm a little confused.
How come I can ask com.adobe.cairngorm.business.ServiceLocator for a
service from an MXML component which is a "sub-class" of ServiceLocator?
i.e.:
Services.mxml:
<cairngorm:ServiceLocator …>
<mx:WebService name="myService" … />
</cairngorm:ServiceLocator>
var theService = ServiceLocator.getInstance().getWebService("myService");
How does ServiceLocator know what a "myService" is? It's not defined in
ServiceLocator.as.
It works, I just don't understand why… What is the relationship between
an MXML file and an AS class that makes this happen?
*Jay Proulx*
Application Developer
Internet Delivery Services - eVision Team
[EMAIL PROTECTED]
(613) 783-6711