[r8483]: ooDialog / trunk / examples / userGuide / exercises / Support / ObjectMgr.rex  Maximize  Restore  History

Download this file

309 lines (274 with data), 14.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/*----------------------------------------------------------------------------*/
/* */
/* Copyright (c) 2011-2012 Rexx Language Association. All rights reserved. */
/* */
/* This program and the accompanying materials are made available under */
/* the terms of the Common Public License v1.0 which accompanies this */
/* distribution. A copy is also available at the following address: */
/* http://www.oorexx.org/license.html */
/* */
/* Redistribution and use in source and binary forms, with or */
/* without modification, are permitted provided that the following */
/* conditions are met: */
/* */
/* Redistributions of source code must retain the above copyright */
/* notice, this list of conditions and the following disclaimer. */
/* Redistributions in binary form must reproduce the above copyright */
/* notice, this list of conditions and the following disclaimer in */
/* the documentation and/or other materials provided with the distribution. */
/* */
/* Neither the name of Rexx Language Association nor the names */
/* of its contributors may be used to endorse or promote products */
/* derived from this software without specific prior written permission. */
/* */
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
/* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
/* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
/* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
/* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
/* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
/* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
/* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
/* */
/*----------------------------------------------------------------------------*/
/* ooDialog User Guide
Support - ObjectMgr v00-01 23Apr12
-------------------
A singleton component that manages model objects.
Should ensure that only one instance is created. This version doesn't.
Provides an object reference given a class and an instance name. Stores these
in an "object bag", which is a table of classes, where each table item is a
table of instance names, the item being the object reference.
Interface ObjectMgr {
bool init
cmptId getComponentId( in string className, in string instanceName )
bool addCmptRef( in string className, in string instanceName, in objref cmptRef )
void list( )
bool showModel( in string modelClass, in string modelInstance )
}
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
call "RequiresList.rex"
--say "ObjectMgr-00."
--say "ObjectMgr-01: .CustomerView :" .CustomerView
--say "ObjectMgr-01: .CustomerModel:" .CustomerModel
/*
::REQUIRES "Customer\CustomerView.rex"
::REQUIRES "Customer\CustomerModelsData.rex"
::REQUIRES "Customer\CustomerListView.rex"
*/
::CLASS 'ObjectMgr' PUBLIC
::ATTRIBUTE objectBag PRIVATE-- a bag of objects - i.e. instances of Distributed
-- Components or DCs.
/*----------------------------------------------------------------------------
init - initialises the ObjectManager
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
::METHOD init
expose objectBag viewBag
--say "ObjectMgr-init. Classes:" .CustomerModel .CustomerData .CustomerView
.local~my.ObjectMgr = self
objectBag = .directory~new -- holds "class-inst" "id-ViewName"
viewBag = .directory~new -- holds view class and latest view instance.
return .true
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/*----------------------------------------------------------------------------
getComponentId - Returns a Component Id if it's in the ObjectBag,
else calls doNewInstacne to get id, else returns .false.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
::METHOD getComponentId PUBLIC
expose objectBag
use strict arg className, instanceName
className = className~upper; instanceName = instanceName~upper
say "ObjectMgr-getComponentId-00: className =" className "instanceName =" instanceName
ObjectName = className||"-"||instanceName
if objectBag~hasIndex(objectName) then do -- if class-instance already registered:
say "ObjectMgr-getComponentId-01: Class Found:" objectName
arr = objectBag[objectName] -- Get info array for this class-instance.
componentId = arr[1]
return componentId -- return component id
end
-- If we've got to here, then there's no id stored. So go get one:
componentId = self~doNewInstance(className,instanceName)
say "ObjectMgr-getComponentId-03: componentId =" componentId
if componentId = .false then return .false -- Bad object name
self~addComponentId(className,instanceName,componentId)
return componentId
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/*----------------------------------------------------------------------------
doNewInstance - Instantiates the requested object and returns the object id
(aka component id). If class not found, or class returns
.false to ~newInstance, then returns .false.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
::METHOD doNewInstance PRIVATE
use strict arg className, instanceName
SIGNAL ON NOMETHOD NAME catchIt
interpret "componentId = ."||className||"~newInstance("||"'"||instanceName||"'"||")"
say "ObjectMgr-doNewInstance-01: componentId =" componentId
-- add to object bag:
return componentId
catchIt:
say "ObjectMgr-doNewInstance-02: component" className instanceName "not found."
return .false
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/*----------------------------------------------------------------------------
addComponentId - Adds an Instance of a Class to the Object Bag.
If instance already exists, return .false
Format of ObjectBag (note - directory indices are case-sensitive, i.e.
if entry is created with index "AbC" then 'say dir["ABC")' may return nil.
+---------------------------------+
| Index | Item (an Array) |
+---------------------------------+
| | | View |
| Class-Inst | objId | Class-Inst |
|---------------------------------|
| PersM-AB12 | x'12' | PersV-1 |
|- - - - - - |- - - -|- - - - - - |
| PersM-CD34 | x'5A' | .nil |
|- - - - - - |- - - -|- - - - - - |
| PersV-1 | x'7B' | .nil |
|- - - - - - |- - - -|- - - - - - |
| | | |
+---------------------------------+
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
::method addComponentId PRIVATE
expose objectBag
use strict arg className, instanceName, componentId
say "ObjectMgr-addComponentId-01:" classname instancename componentId
objectName = className||"-"||instanceName
arr = .Array~new
arr[1] = componentId
arr[2] = .nil -- Space for a View Name ('class-inst')
objectBag[objectName] = arr
self~list
return
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/*----------------------------------------------------------------------------
showModel - Shows a view of a model. Lacking a config file that links
model class to one or more View classes, we heroically assume
that all models are called "xxxModel" and its View is called
xxxView. Assume only one View per Model.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
::METHOD showModel PUBLIC
expose objectBag
use arg modelClass, modelInstance, parentDlg
say "ObjectMgr-showModel-01a - modelNames:" modelClass modelInstance
say "ObjectMgr-showModel-01b - parentDlg: " parentDlg
--say "ObjectMgr-showModel-02 - modelClass: '"||modelClass||"'; modelInstance: '"||modelInstance||"'"
-- If this is an "anonymous" component (instance name "A"|"a"), ask its
-- class object for an instance name:
if modelInstance = "A" | modelInstance = "a" then do
anonModelClass = "."||modelClass
interpret "modelInstance = "||anonModelClass||"~getInstanceName"
say "ObjectMgr-showModel-02 - modelInstance: " modelInstance
end
modelId = self~getComponentId(modelClass, modelInstance)
say "ObjectMgr-showModel-03 - modelId:" modelId
if modelId = .false then do
say "ObjectMgr-showModel-03b: Model" modelClass modelInstance "could not be found."
return .false
end
-- Check if View exists - if so, surface it:
modelName = modelClass||"-"||modelInstance
modelName = modelName~upper
arr = objectBag[modelName]
viewName = arr[2]
say "ObjectMgr-showModel-03c: ViewName =" viewName
if viewName \= .nil then do -- if view exists
arr = objectBag[viewName]
viewId = arr[1]
viewId~show("SHOWTOP") -- if minimized, doesn't work.
viewId~show("NORMAL") -- if hidden, doesn't work
return .true
end
-- View does not exist - so construct the view name and send the class a
-- newInstance(modelId, parentDlg).
parse var modelClass root "Model"
viewClass = root||"View"
viewClassId = "."||viewClass
say "ObjectMgr-showModel-04: viewClassId =" viewClassId
interpret "targetObject =" viewClassId
say "ObjectMgr-showModel-05: parentDlg =" parentDlg
msg = .Message~new(targetObject, "newInstance", "I", modelId, parentDlg)
--say "ObjectMgr-showModel-06: Class is:" .CustomerView .ObjectMgr
viewId = msg~send
say "ObjectMgr-showModel-07 - viewId:" viewId
self~addView(modelClass, modelInstance, viewClass, viewId)
--self~addView(modelClass, modelInstance, "CustomerView", viewId)
return .true
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/*----------------------------------------------------------------------------
addView - Adds a View to the ObjectBag.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
::METHOD addView
expose objectBag --viewBag
use strict arg modelClass, modelInstance, viewClass, viewId
say "ObjectMgr-addView-01."
-- Get view's instanceName
viewInstance = viewId~identityHash
-- First, add View name to arr[2] of Model's entry in ObjectBag:
modelName = modelClass||"-"||modelInstance
modelName = modelName~upper()
viewClass = viewClass~upper()
viewName = viewClass||"-"||viewInstance
arr = objectBag[modelName]
arr[2] = viewName
-- Now add the View to the ObjectBag:
--trace i
self~addComponentId(viewClass, viewInstance, viewId)
--trace off
say "ObjectMgr-addView-02: list with new View class:"
self~list
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/*----------------------------------------------------------------------------
removeView - Removes a view from the ObjectBag.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
::METHOD removeView PUBLIC
expose objectBag
use arg viewClass, viewInstance
viewClass = viewClass~upper() -- View class was uppered in addView method.
viewClassInst = viewClass||"-"||viewInstance
say "ObjectMgr-removeView-01: viewClassInst:" viewClassInst
--say "ObjectMgr-removeView-02: ObjectBag List:"
--self~list
r = objectBag~remove(viewClassInst)
say "ObjectMgr-removeView-03: r =" r
do i over objectBag
arr = objectBag[i]
if arr[2] = viewClassInst then arr[2] = .nil
end
say "ObjectMgr-removeView-04: ObjectBag List:"
self~list
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/*-----------------------------------------------------------------------
list - Produces a list on stdout of the classes and their Instances
that are in the Object Bag.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
::METHOD list PUBLIC
expose objectBag viewBag
say; say "Object Bag List:"
say " ----------------------------------------------------------------------------"
say " Class-Instance Model Id ViewClass-Inst"
say " ------------------------ ------------------------ ------------------------"
do name over objectBag
arrItems = objectBag[name]
viewClass = arrItems[2]
if viewClass = .nil then viewClass = ".nil"
modelId = arrItems[1]
--say "ObjectBag-list-01: ModelID =" modelId ";" modelId~objectName
say " " name~left(25) modelId~objectName~left(25) viewClass~left(25)
end
say " ----------------------------------------------------------------------------"
say
/*say; say "Latest View Instances:"
say " View Class Instance"
say " ------------------------- ---"
do viewClass over viewBag
viewNo = viewBag[viewClass]
say viewClass~left(25) viewNo~right(7)
end
say
*/
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/*============================================================================*/