home *** CD-ROM | disk | FTP | other *** search
/ LineOne ISP Sign-Up 5 / LineOne.iso / assets / cxt / scripts / parentScripts.cst / 00001_main.ls next >
Encoding:
Text File  |  2001-01-27  |  7.0 KB  |  244 lines

  1. -- 2000.03.12
  2. -- Clive Green <clivegreen@atlas.co.uk>
  3.  
  4. ------------------------------------------------------------------------------------------------------
  5.  
  6. -- this sets up the entire programme:
  7.  
  8. ------------------------------------------------------------------------------------------------------
  9.  
  10. -- declare properties:
  11. property parentScriptLibName -- the castlib containing all parent scripts used in the programme
  12. property parentScriptSuffix  -- parent script name suffix string - used to identify checked-in scripts
  13.  
  14. property castLibNames        -- a list of currently attached castlibrary names
  15. property parentScriptNames   -- a list of existing parent script member names
  16. property registry            -- a list of core features required for programme operation
  17.  
  18. property mainLogoService     -- service for handling the display of the main logo
  19. property feedbackService     -- service for handling the display of the feedback window
  20. property glueService         -- resolves glue calls to aplication methods
  21.  
  22. ------------------------------------------------------------------------------------------------------
  23.  
  24. on new me,L
  25.   
  26.   -- (1) extract and check arguments:
  27.   
  28.   -- check for a parameter list:
  29.   if ilk(L) <> #propList then return [#error:#noParamListSupplied, #msg:"main:new"]
  30.   
  31.   -- extract application's root path:
  32.   rootPath = L[#rootPath]
  33.   if not stringP(rootPath) then return [#error:#noRootPathString, #msg:"main:new"]
  34.   
  35.   --------------------
  36.   
  37.   -- stash literals:
  38.   parentScriptLibName = "parentScripts"
  39.   parentScriptSuffix  = SPACE & "parent"
  40.   
  41.   --------------------
  42.   
  43.   -- (1) compile a list of available castlibrary names:
  44.   castLibNames = []
  45.   repeat with i = 1 to the number of castlibs
  46.     
  47.     add castLibNames,castlib(i).name
  48.     
  49.   end repeat
  50.   
  51.   --------------------
  52.   
  53.   -- (2) compile a list of parent script names - we require a named library of scripts:
  54.   p = parentScriptLibName
  55.   
  56.   -- get the corresponding castLib number:
  57.   c = getPos(castLibNames,p)
  58.   
  59.   -- throw an error if the castlib we need isn't currently attached:
  60.   if not c then return [#error:#castlibMissing, #msg:p]
  61.   
  62.   -- create and populate a linear listing:
  63.   parentScriptNames = []
  64.   repeat with i = 1 to (the number of members of castlib c)
  65.     
  66.     -- we only want script members:
  67.     n = member(i,c).number
  68.     if member(n).type <> #script then next repeat
  69.     
  70.     -- add the script name:
  71.     add parentScriptNames,member(n).name
  72.     
  73.   end repeat
  74.   
  75.   --------------------
  76.   
  77.   -- (3) what are the core areas of the programme called?
  78.   L1 = []
  79.   add L1,#utilityMethods
  80.   add L1,#dataManager
  81.   add L1,#errorManager
  82.   add L1,#xtrasManager
  83.   
  84.   -- initialise a #proplist of objects representing these core programme areas:
  85.   L2 = [:]
  86.   
  87.   -- instantiate an object in respect of each area IN THEIR LISTED ORDER:
  88.   registry = [:]
  89.   repeat with i in L1
  90.     
  91.     -- attempt to obtain an instance from the reference symbol i:
  92.     o = me.createInstance(i,[#main:me])
  93.     if (ilk(o) <> #instance) then return o
  94.     
  95.     -- add this instance to the list of core programme areas:
  96.     registry[i] = o
  97.     
  98.   end repeat
  99.   
  100.   --------------------
  101.   
  102.   -- store the root path FIRST:
  103.   dm = me.getDataManager()
  104.   dm.setRootPath(rootPath)
  105.   
  106.   -- obtain external data AFTER setting up core programme areas, but BEFORE
  107.   -- initialising services:  
  108.   o = dm.getExternalData()
  109.   
  110.   -- throw error to caller on failure:
  111.   if (ilk(o) <> #instance) then return o
  112.   
  113.   --------------------
  114.   
  115.   -- NOW setup all registered services:
  116.   n = #serviceManager
  117.   o = me.createInstance(n,[#main:me]) 
  118.   if (ilk(o) <> #instance) then return o
  119.   
  120.   -- store a successfully created services manager object:
  121.   registry[n] = o
  122.   
  123.   --------------------
  124.   
  125.   -- (4) ensure that local service requirements can be met:
  126.   
  127.   -- what services are required?
  128.   L = [#feedbackService,#mainLogoService,#glueService]
  129.   
  130.   -- obtain each service listed in L:
  131.   repeat with i in L
  132.     
  133.     -- ensure the existence of service (i):
  134.     o = (me.getServiceManager()).getService(i)  
  135.     if (ilk(o) <> #instance) then return o
  136.     
  137.     -- store a reference to this service:
  138.     setaProp me,i,o
  139.     
  140.   end repeat
  141.   
  142.   --------------------
  143.   
  144.   -- return my address to the caller:
  145.   return me
  146.   
  147.   ----------------------------------------------------------------------------------------------------
  148.   
  149. on checkForCDROM me
  150.     
  151.   -- the programme is in good order ... but we require the correct CD-ROM in order to
  152.   -- install our value-added software and so on:
  153.   
  154.   -- verify that the right CD is currently mounted:
  155.   
  156.   sm = me.getServiceManager()
  157.   
  158.   -- no mounted CD is fatal:
  159.   cd = sm.getService(#CDROMservice)
  160.   if not cd.matchingCDfound() then
  161.     
  162.     -- clear error capture so we can display an alert onscreen:
  163.     em = me.getErrorManager()
  164.     em.setAlertHook(0)
  165.     
  166.     -- tell the user the problem, and terminate:
  167.     alert "Please insert the LineOneCD and relaunch!"
  168.     
  169.     nm = sm.getService(#navigationService)
  170.     nm.doQuit()
  171.     
  172.   end if
  173.   
  174.   ----------------------------------------------------------------------------------------------------
  175.   
  176. on createInstance me,s,L
  177.   
  178.   -- what is the parent script name to use?
  179.   s = string(s & parentScriptSuffix)
  180.   
  181.   -- confirm that this script member is available:
  182.   if not getPos(parentScriptNames,s) then return [#error:#parentScriptMissing, #msg:s]
  183.   
  184.   -- attempt to obtain an instance from script s:
  185.   return new(script s,L)
  186.   
  187.   ----------------------------------------------------------------------------------------------------
  188.   
  189. on glue me,g
  190.   
  191.   -- attempt to relay the glue message g to the appropriate location:
  192.   return glueService.glue(g)
  193.   
  194.   ----------------------------------------------------------------------------------------------------
  195.   
  196. on showMiaws me
  197.   
  198.   -- ask for key miaws to be displayed:  
  199.   mainLogoService.showLogo() 
  200.   feedbackService.openFeedback()
  201.   
  202.   -- (upgrade this to a MIAWs service if it grows)
  203.   
  204.   ----------------------------------------------------------------------------------------------------
  205.   
  206. on clearMiaws me
  207.   
  208.   -- ask for miaws to be cleared:
  209.   mainLogoService.clearLogo()
  210.   feedbackService.clearFeedback()
  211.   
  212.   -- (see: showMiaws)
  213.   
  214.   ----------------------------------------------------------------------------------------------------
  215.   
  216. on getUtilityMethods me
  217.   
  218.   return registry[#utilityMethods]
  219.   
  220.   ----------------------------------------------------------------------------------------------------
  221.   
  222. on getXtrasManager me
  223.   
  224.   return registry[#xtrasManager]
  225.   
  226.   ----------------------------------------------------------------------------------------------------
  227.   
  228. on getErrorManager me
  229.   
  230.   return registry[#errorManager]
  231.   
  232.   ----------------------------------------------------------------------------------------------------
  233.   
  234. on getDataManager me
  235.   
  236.   return registry[#dataManager]
  237.   
  238.   ----------------------------------------------------------------------------------------------------
  239.   
  240. on getServiceManager me
  241.   
  242.   return registry[#serviceManager]
  243.   
  244.   -----------------------------------------------------------------------------------------------------