Von: Knut Wannheden [mailto:[EMAIL PROTECTED]
Gesendet: Do 16.06.2005 14:04
An: [email protected]
Betreff: Re: Translators and default values
Stefan,
As you probably know the <conversion> /
<map> construct is at runtime
substituted by a matching
<create-object>, a set of <read-attribute>,
and a
<invoke-parent> rule. The <read-attribute> rule has an
optional
"skip-if-null" attribute which defaults to "true". That's what in
the
end causes your translator to be skipped. So as a workaround you
could
replace your <conversion> with the appropriate expanded rules and
set
"skip-if-null" to "false" on the <read-attribute>
rules.
That being said, I agree with you that this doesn't feel
right.
I think the reason the "skip-if-null" defaults to "true" is that
it's
possible that there are default values specified in the Java
code,
which would be unfortunate to overwrite.
The only solution I can
think of is if we added a new "default"
attribute to the <attribute>
element. This could then take precedence
over the "skip-if-null" check. What
do others think?
--knut
On 6/14/05, Liebig, Stefan
<[EMAIL PROTECTED]> wrote:
>
>
>
While trying to write a simple translator, I figured out that
> I either
had the wrong expecations or that I am doing something
wrong.
>
> My expectation with Translators and default
values is like this.
> If I have an attribute element in a schema like
this:
>
> <element
name="counter">
> <attribute name="count"
>
translator="int,min=5,max=10,default=5"/>
> <conversion
... />
> </element>
>
> and I make
such a contribution:
>
>
<counter/>
>
> than I would expect to get the default
value for the count property
> specified
> in the translator
attribute. But this seems to be wrong. The translator does
> not get
called in such a case.
> I need to do something like
this:
>
> <counter
count=""/>
>
> Now the translator gets called and the
specified default value will be set.
>
> But, shouldn´t
the translator not be called in any case (except when a
>
requiered
> attribute is not given, which is an error). Otherwise I need
to have two
> places dealing with default values, one in the translator
specification
> and one in Java code.
> And additionally the code
can not rely on the specification, because in
> the above example the int
property count would get 0 (if not handled
> explicitly) and this would
violate the ´min´ specification in the
>
translator.
>
>
Stefan
>
--
knut
---------------------------------------------------------------------
To
unsubscribe, e-mail: [EMAIL PROTECTED]
For
additional commands, e-mail:
[EMAIL PROTECTED]
