The current standard is extremely vague about scoping of encding attributes. Let me make a proposal how the actual encoding attribute to be used should be determined:
Encoding attributes come in four flavours: unqualified (override and non-override (plain)), and qualified (again override and plain). Each type (which is the 'target' of an encoding attribute) exists in the nested scopes of the module and a number of groups. For our considerations, the module can be seen as the outermost group.
If we disregard, for the moment, qualified encoding attributes, the encoding attribute of a type should be determined as follows: its encoding attribute should be the innermost unqualified plain encoding attribute unless there exists, in at least on of the scopes, an unqualified overriding enc. attr. is specified, in which case the outermost qunalified overriding atribute is selected.
For qualified enc. attr. things become a little bit more difficult. First of all, encoding attributes for the same group/type may be specified several times outside that group:
module M {
group g {
type ... t;
} with { encode (t) "A" };
} with { encode (t) "B" };
Moreover, we have to determine, how the qualified encoding attributes from the outer scopes have to be combined with the local encoding attributes of the object that has been qualified.
For the first issue, I believe that we should stick to the same approach as for the unqualified attributes when determining which qualified enc attr applies in any given situation - the innermost plain one or the outermost override one, if such a thing exists.
Now, if we have determined the qualified enc attribute for some group/type X, how do we combine it with the unqualified enc attr's specified for X? I think, in this case, the qualified encoding attribute for X should have precedence over the unqualified one and indeed also overrule all other outer unqualified enc attrs. plain or override .
Let's write this more algorithmically:
Let EA be the set (FreeText \times {override, plain}) \disjoint_union NO_EA of all encoding attributes with override/plain flag together with a distingushed element that stands for 'no encoding attribute specified'.
We define function join : EA \times EA -> EA as follows:
join(outer,inner) :=
outer, if inner = NO_EA
outer, if outer = (s,override) for some s \in FreeText
inner, otherwise
Let local-EA(X) denote the qunalified enc. attribute specified locally for group/type X . Let local-EA(X,Y) denote EA specified directly at X with qualifier Y. If no such specification exists, these functions evaluate to NO_EA respectively.
Let outer(X) denote the next outer group/module of X.
Then absolute-EA(X) and absolute-EA(X,Y) are computed as follows:
For the module M, absolute-EA(M) := local-EA(M) and absolute-EA(M,Y) := local-EA(Y) for all groups/types Y in M.
For some group/type X in M, we define:
absolute-EA(X,Y) = join(absolute-EA(outer(X),Y), local-EA(X,Y)) for all Y
absolute-EA(X) =
absolute-EA(outer(X),X), if absolute-EA(outer(X),X) != NO_EA
join(absolute-EA(outer(X),local-EA(X)), otherwise
Finally, for a field f in a type T, when sending a value of type T, the field f is encoded using
join(absolute-EA(T), local-EA(T,f)).
Does this make sense?
Thanks for staying with me to this point :-)
Regards
Stephan