1 Reply Latest reply on Jan 6, 2009 7:07 PM by (Kshitij_Sobti)

    Extending Cairngorm services

      I'm building an XMPP application using Flex and trying to use Cairngorm. One of the problems I've run into is using the ServiceLocator. Since XMPP isn't one of the standard services I'm assuming I have to write my own child of AbstractService but I can't seem to find any examples. Anyone have any examples? Am I on the right track?

      Any help would be greatly appreciated - AYAL
        • 1. Re: Extending Cairngorm services
          Hi...
          I had similar problems while trying to use the cairngorm ServiceLocator with MySqlService...
          the cairngorm 2.2.2 beta changelog says that they have "added getAbstractService and getAbstractInvoker to ServiceLocator to accommodate the usage of third party service packages such as as3rpc."
          however i cant seem to find it... in the code or swc...
          anyway...
          so i decided to just extend my own class from the cairngorm ServiceLocator...
          basically i did the following... and it works:

          package com.bs.dpair.business
          {
          import com.adobe.cairngorm.CairngormError;
          import com.adobe.cairngorm.CairngormMessageCodes;
          import com.adobe.cairngorm.business.ServiceLocator;
          import com.maclema.mysql.MySqlService;

          public class ServiceLocator extends com.adobe.cairngorm.business.ServiceLocator
          {

          private static var _instance:com.bs.dpair.business.ServiceLocator;

          public static function getInstance() : com.bs.dpair.business.ServiceLocator
          {
          if ( _instance == null )
          {
          _instance = new com.bs.dpair.business.ServiceLocator();
          }

          return _instance;
          }

          public function ServiceLocator()
          {
          if ( _instance != null )
          {
          throw new CairngormError( CairngormMessageCodes.SINGLETON_EXCEPTION, "ServiceLocator" );

          }

          _instance = this;
          }

          public function getMySqlService(serviceName:String):MySqlService
          {
          if(this[serviceName] == null)
          throw new CairngormError( CairngormMessageCodes.SERVICE_NOT_FOUND);
          return this[serviceName] as MySqlService;

          }
          }
          }

          now you can just use this class in the services.mxml file etc...

          it could have been much simpler if i just called it ServiceLocator2 or something but i figured this code wont be touched much anyway...