#!/usr/bin/env rexx
/**
 * A mixinclass for MaPCollection subclasses that supports
 * restricting indexes (attributes) of one word strings for
 * MapCollections.
 *
 * Tested for .Directory, .StringTable, .Properties and .Bag/.Set,
 * but should be possible for all MapCollection subclasses
 * supporting strings as Indexes/Attributes.
 * ----------------------------------------------------------------
 * Originally by Ruurd J. Idenburg 
 * 
 * No copyright, no licence, no guarantees or warrantees, be it 
 * explicit, implicit or whatever. Usage is totally and completely 
 * at the users own risk, the author shall not be liable for any
 * damages whatsoever, for any reason whatsoever.
 * 
 * Please keep this comment block intact when modifying this code
 * and add a note with date and a description.
 * ----------------------------------------------------------------
 * 2025/10/28 - Initial version requires ooRexx version 5.1.0 or 
 *              later (rji)
 * 2025/10/29 - Added prroper syntax error and made attribute set
 *              private (rji) 
 *
 */----------------------------------------------------------------
::class AllowableAttributes public mixinclass MapCollection
::attribute allowedIndexes get
::attribute allowedIndexes set private

::method init
  self~init:super()
  if Arg(1)~isA(.String)
   then self~allowedIndexes=arg(1)
   else raise syntax 93.900 array ("Argument:" arg(1) "must be string with 1 or more words.")
exit

::method "[]="
  forward to (self) message (put)
exit
  
::method put
  expose allowedIndexes
--For .Bag and .Set it is ok to have just one argument, since index and item must be the same 
  if Arg()>1
-- Get the attribute value and the attribute name
    then use strict arg anItem, anIndex
-- For .Bag and .Set Item and Index must be the same
    else use strict arg anItem, anIndex=(anItem)
-- If name is allowed then let the superclass handle it, else raise a syntax error
  if (allowedIndexes~containsWord(anIndex))
    then forward class (super)
    else raise syntax 93.900 array ('Index:' anIndex 'is not allowed for Object:' self)
exit

::method setEntry
  expose allowedIndexes
  use strict arg anIndex, ...
  if allowedIndexes~containsWord(anIndex)
    then forward class (super)  
    else raise syntax 93.900 array ('Index:' anIndex 'is not allowed for Object:' self)
exit  

::method setLogical
  expose allowedIndexes
  if allowedIndexes~containsWord(Arg(1))
    then forward class (super) 
    else raise syntax 93.900 array ('Index:' arg(1) 'is not allowed for Object:' self)
exit

::method setWhole
  expose allowedIndexes
  if allowedIndexes~containsWord(Arg(1))
    then forward class (super)
    else raise syntax 93.900 array ('Index:' arg(1) 'is not allowed for Object:' self)
exit

::method setProperty
  expose allowedIndexes
  use strict arg index, item
  if allowedIndexes~containsWord(Arg(1))
    then forward class (super)
    else raise syntax 93.900 array ('Index:' arg(1) 'is not allowed for Object:' self)
exit 

