home *** CD-ROM | disk | FTP | other *** search
- -- 2000.03.12
- -- Clive Green <clivegreen@atlas.co.uk>
-
- ------------------------------------------------------------------------------------------------------
-
- -- this sets up the entire programme:
-
- ------------------------------------------------------------------------------------------------------
-
- -- declare properties:
- property parentScriptLibName -- the castlib containing all parent scripts used in the programme
- property parentScriptSuffix -- parent script name suffix string - used to identify checked-in scripts
-
- property castLibNames -- a list of currently attached castlibrary names
- property parentScriptNames -- a list of existing parent script member names
- property registry -- a list of core features required for programme operation
-
- property mainLogoService -- service for handling the display of the main logo
- property feedbackService -- service for handling the display of the feedback window
- property glueService -- resolves glue calls to aplication methods
-
- ------------------------------------------------------------------------------------------------------
-
- on new me,L
-
- -- (1) extract and check arguments:
-
- -- check for a parameter list:
- if ilk(L) <> #propList then return [#error:#noParamListSupplied, #msg:"main:new"]
-
- -- extract application's root path:
- rootPath = L[#rootPath]
- if not stringP(rootPath) then return [#error:#noRootPathString, #msg:"main:new"]
-
- --------------------
-
- -- stash literals:
- parentScriptLibName = "parentScripts"
- parentScriptSuffix = SPACE & "parent"
-
- --------------------
-
- -- (1) compile a list of available castlibrary names:
- castLibNames = []
- repeat with i = 1 to the number of castlibs
-
- add castLibNames,castlib(i).name
-
- end repeat
-
- --------------------
-
- -- (2) compile a list of parent script names - we require a named library of scripts:
- p = parentScriptLibName
-
- -- get the corresponding castLib number:
- c = getPos(castLibNames,p)
-
- -- throw an error if the castlib we need isn't currently attached:
- if not c then return [#error:#castlibMissing, #msg:p]
-
- -- create and populate a linear listing:
- parentScriptNames = []
- repeat with i = 1 to (the number of members of castlib c)
-
- -- we only want script members:
- n = member(i,c).number
- if member(n).type <> #script then next repeat
-
- -- add the script name:
- add parentScriptNames,member(n).name
-
- end repeat
-
- --------------------
-
- -- (3) what are the core areas of the programme called?
- L1 = []
- add L1,#utilityMethods
- add L1,#dataManager
- add L1,#errorManager
- add L1,#xtrasManager
-
- -- initialise a #proplist of objects representing these core programme areas:
- L2 = [:]
-
- -- instantiate an object in respect of each area IN THEIR LISTED ORDER:
- registry = [:]
- repeat with i in L1
-
- -- attempt to obtain an instance from the reference symbol i:
- o = me.createInstance(i,[#main:me])
- if (ilk(o) <> #instance) then return o
-
- -- add this instance to the list of core programme areas:
- registry[i] = o
-
- end repeat
-
- --------------------
-
- -- store the root path FIRST:
- dm = me.getDataManager()
- dm.setRootPath(rootPath)
-
- -- obtain external data AFTER setting up core programme areas, but BEFORE
- -- initialising services:
- o = dm.getExternalData()
-
- -- throw error to caller on failure:
- if (ilk(o) <> #instance) then return o
-
- --------------------
-
- -- NOW setup all registered services:
- n = #serviceManager
- o = me.createInstance(n,[#main:me])
- if (ilk(o) <> #instance) then return o
-
- -- store a successfully created services manager object:
- registry[n] = o
-
- --------------------
-
- -- (4) ensure that local service requirements can be met:
-
- -- what services are required?
- L = [#feedbackService,#mainLogoService,#glueService]
-
- -- obtain each service listed in L:
- repeat with i in L
-
- -- ensure the existence of service (i):
- o = (me.getServiceManager()).getService(i)
- if (ilk(o) <> #instance) then return o
-
- -- store a reference to this service:
- setaProp me,i,o
-
- end repeat
-
- --------------------
-
- -- return my address to the caller:
- return me
-
- ----------------------------------------------------------------------------------------------------
-
- on checkForCDROM me
-
- -- the programme is in good order ... but we require the correct CD-ROM in order to
- -- install our value-added software and so on:
-
- -- verify that the right CD is currently mounted:
-
- sm = me.getServiceManager()
-
- -- no mounted CD is fatal:
- cd = sm.getService(#CDROMservice)
- if not cd.matchingCDfound() then
-
- -- clear error capture so we can display an alert onscreen:
- em = me.getErrorManager()
- em.setAlertHook(0)
-
- -- tell the user the problem, and terminate:
- alert "Please insert the LineOneCD and relaunch!"
-
- nm = sm.getService(#navigationService)
- nm.doQuit()
-
- end if
-
- ----------------------------------------------------------------------------------------------------
-
- on createInstance me,s,L
-
- -- what is the parent script name to use?
- s = string(s & parentScriptSuffix)
-
- -- confirm that this script member is available:
- if not getPos(parentScriptNames,s) then return [#error:#parentScriptMissing, #msg:s]
-
- -- attempt to obtain an instance from script s:
- return new(script s,L)
-
- ----------------------------------------------------------------------------------------------------
-
- on glue me,g
-
- -- attempt to relay the glue message g to the appropriate location:
- return glueService.glue(g)
-
- ----------------------------------------------------------------------------------------------------
-
- on showMiaws me
-
- -- ask for key miaws to be displayed:
- mainLogoService.showLogo()
- feedbackService.openFeedback()
-
- -- (upgrade this to a MIAWs service if it grows)
-
- ----------------------------------------------------------------------------------------------------
-
- on clearMiaws me
-
- -- ask for miaws to be cleared:
- mainLogoService.clearLogo()
- feedbackService.clearFeedback()
-
- -- (see: showMiaws)
-
- ----------------------------------------------------------------------------------------------------
-
- on getUtilityMethods me
-
- return registry[#utilityMethods]
-
- ----------------------------------------------------------------------------------------------------
-
- on getXtrasManager me
-
- return registry[#xtrasManager]
-
- ----------------------------------------------------------------------------------------------------
-
- on getErrorManager me
-
- return registry[#errorManager]
-
- ----------------------------------------------------------------------------------------------------
-
- on getDataManager me
-
- return registry[#dataManager]
-
- ----------------------------------------------------------------------------------------------------
-
- on getServiceManager me
-
- return registry[#serviceManager]
-
- -----------------------------------------------------------------------------------------------------