You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jaxme-dev@ws.apache.org by "Nacho G. Mac Dowell" <ig...@informa.es> on 2004/09/30 08:44:42 UTC
Facets
I was wondering if enumerations and patterns and so on should be
implemented at runtime (on the Impl class) or when
unmarshalling/marshalling. If Enumerations are used they probably should
be considered as "virtually different types" than their base type. This
would make the Impl classes safe type. I was thinking if it would be
nice to actually implement an Enumeration pattern class. Is this
considered in JAXB spec? Is it up to the implementors? What do you
think? Could EnumerationSG, PatternSG... be considered as types? In xml
schema the aren't, but since java is supposed to be safe type...
regards,
Nacho G. Mac Dowell
PD: I saw that SimpleTypeSG has a addValidation method. Is it for this
purpose?
---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org
Re: Facets
Posted by Jochen Wiedmann <jo...@freenet.de>.
Nacho G. Mac Dowell wrote:
> I was wondering if enumerations and patterns and so on should be
> implemented at runtime (on the Impl class) or when
> unmarshalling/marshalling. If Enumerations are used they probably should
> be considered as "virtually different types" than their base type. This
> would make the Impl classes safe type. I was thinking if it would be
> nice to actually implement an Enumeration pattern class. Is this
> considered in JAXB spec? Is it up to the implementors? What do you
> think? Could EnumerationSG, PatternSG... be considered as types? In xml
> schema the aren't, but since java is supposed to be safe type...
>
> regards,
>
> Nacho G. Mac Dowell
>
> PD: I saw that SimpleTypeSG has a addValidation method. Is it for this
> purpose?
The "addValidation" method is, of course, on purpose: It's purpose is
just what you would expect: To add validation code to the Impl class.
The JAXB specification requires validation only when unmarshalling. Of
course, if the Impl class validates, then the unmarshaller validates
automatically as well, so that's absolutely fine with the SPEC.
IMO, the answer to "When should I validate" should not be general: It
depends on the facet.
For example, facets like "minExcludes" can easily be checked in the
Impl class and so they should be checked there.
Facets like "minOccurs", or "maxOccurs", cannot always be checked by the
impl class: If (as specified by JAXB) a list property is implemented by
a list, to which the user has full access, then the impl class doesn't
have actual control. In that case the unmarshaller must validate.
However, if the property is implemented with "getFoo" and "setFoo" (or
"addFoo") methods, then validation in the impl class is fine again.
Enumerations can be validated by the impl class (at least I believe so
:-) and, if I remember right, they currently are.
Finally, patterns are a completely different story: First of all,
patterns are a restriction of the *lexical representation* of the data.
For example, consider an int type and a pattern, which requests, that
the data contains four digits. This can easily be checked by the
unmarshaller (because he *has* the lexical representation). However, it
cannot easily be checked by the impl class: We as humans know, that the
allowed value set can be expressed with minIncludes and maxIncludes.
However, that information is almost impossible to derive from the
specified pattern.
Jochen
--
http://lilypie.com/baby1/050423/1/5/1/+1
---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org