1: #!/usr/bin/env rexx
2: /**
3: * A mixinclass for MaPCollection subclasses that supports
4: * restricting indexes (attributes) of one word strings for
5: * MapCollections.
6: *
7: * Tested for .Directory, .StringTable, .Properties and .Bag/.Set,
8: * but should be possible for all MapCollection subclasses
9: * supporting strings as Indexes/Attributes.
10: * ----------------------------------------------------------------
11: * Originally by Ruurd J. Idenburg
12: *
13: * No copyright, no licence, no guarantees or warrantees, be it
14: * explicit, implicit or whatever. Usage is totally and completely
15: * at the users own risk, the author shall not be liable for any
16: * damages whatsoever, for any reason whatsoever.
17: *
18: * Please keep this comment block intact when modifying this code
19: * and add a note with date and a description.
20: * ----------------------------------------------------------------
21: * 2025/10/28 - Initial version requires ooRexx version 5.1.0 or
22: * later (rji)
23: * 2025/10/29 - Added prroper syntax error and made attribute set
24: * private (rji)
25: *
26: */----------------------------------------------------------------
27: ::class AllowableAttributes public mixinclass MapCollection
28: ::attribute allowedIndexes get
29: ::attribute allowedIndexes set private
30:
31: ::method init
32: self~init:super()
33: if Arg(1)~isA(.String)
34: then self~allowedIndexes=arg(1)
35: else raise syntax 93.900 array ("Argument:" arg(1) "must be string with 1 or more words.")
36: exit
37:
38: ::method "[]="
39: forward to (self) message (put)
40: exit
41:
42: ::method put
43: expose allowedIndexes
44: --For .Bag and .Set it is ok to have just one argument, since index and item must be the same
45: if Arg()>1
46: -- Get the attribute value and the attribute name
47: then use strict arg anItem, anIndex
48: -- For .Bag and .Set Item and Index must be the same
49: else use strict arg anItem, anIndex=(anItem)
50: -- If name is allowed then let the superclass handle it, else raise a syntax error
51: if (allowedIndexes~containsWord(anIndex))
52: then forward class (super)
53: else raise syntax 93.900 array ('Index:' anIndex 'is not allowed for Object:' self)
54: exit
55:
56: ::method setEntry
57: expose allowedIndexes
58: use strict arg anIndex, ...
59: if allowedIndexes~containsWord(anIndex)
60: then forward class (super)
61: else raise syntax 93.900 array ('Index:' anIndex 'is not allowed for Object:' self)
62: exit
63:
64: ::method setLogical
65: expose allowedIndexes
66: if allowedIndexes~containsWord(Arg(1))
67: then forward class (super)
68: else raise syntax 93.900 array ('Index:' arg(1) 'is not allowed for Object:' self)
69: exit
70:
71: ::method setWhole
72: expose allowedIndexes
73: if allowedIndexes~containsWord(Arg(1))
74: then forward class (super)
75: else raise syntax 93.900 array ('Index:' arg(1) 'is not allowed for Object:' self)
76: exit
77:
78: ::method setProperty
79: expose allowedIndexes
80: use strict arg index, item
81: if allowedIndexes~containsWord(Arg(1))
82: then forward class (super)
83: else raise syntax 93.900 array ('Index:' arg(1) 'is not allowed for Object:' self)
84: exit
85: