OK Victor pointed out that your attributes x and y have minOccurs = 0, and that they should be skipped. He actually put in a logic that will skip the parent's attributes if the children are missing (skipped) and the parent itself is nillable. However, this is done after the feature is built, after it passes validations so it's way too late.. And would only work for complex attributes (since they never get validated). It's in DataAccessMappingFeatureIterator.cleanEmptyElements(). I guess this is a bug then.. We need to do something similar for non-complex attributes.
-----Original Message----- From: andrea.a...@gmail.com [mailto:andrea.a...@gmail.com] On Behalf Of Andrea Aime Sent: Tuesday, 5 October 2010 5:07 PM To: Angreani, Rini (CESRE, Kensington) Cc: Caradoc-Davies, Ben (CESRE, Kensington); geotools-devel@lists.sourceforge.net Subject: Re: [Geotools-devel] Mapping an optional element whose attributes are not optional On Tue, Oct 5, 2010 at 10:45 AM, <rini.angre...@csiro.au> wrote: > You can only use functions to skip the attribute if you use the feature > chaining syntax. > I said "syntax", because you can omit linkField, therefore it's not really > chaining it and won't generate the extra "joining" queries, it only recycles > the syntax. > http://docs.geoserver.org/latest/en/user/data/app-schema/polymorphism.html#data-type-polymorphism > > "You can omit the linkField and OCQL if the FeatureTypeMapping being linked > to has the same sourceType with the container type. This would save us from > unnecessary extra queries, which would affect performance." > > Anyway, you can't use the functions because you can't "chain" simple > attributes (seeing both x and y are xs:integer). > However, I know what the problem is. > If you refer to this: http://jira.codehaus.org/browse/GEOT-2679, it was > decided that if the value is null and: > > 1. IF minOccur == 0 THEN skip the attribute silently > 2. IF minOccur > 0 && nillable THEN let it pass through validation in > Types.validate() > 3. IF minOccur > 0 && !nillable THEN it will throw an error through > validation in Types.validate() > > So, it's correct that it throws the error, as the attribute shouldn't be null. > Normally, we put an xlink:href in the ClientProperty when the values are > missing, i.e. one of these: > > urn:ogc:def:nil:OGC::inapplicable > urn:ogc:def:nil:OGC::missing > urn:ogc:def:nil:OGC::template > urn:ogc:def:nil:OGC::unknown > urn:ogc:def:nil:OGC::withheld > > Maybe that's what you need, and the use case that's missing is: > > 4. IF minOccur > 0 && !nillable && has xlink HREF THEN it should pass through > validation Types.validate() > > We never had this problem for complex attributes, because they never have > null as a value, but an empty array instead(since the binding is a Collection > for complex types). > Actually, Niels is working on the same problem, but it's for Geometry > attributes, and you're working on simple attributes. > What I think we should do is add another condition in the validate method to > check for xlink:href (from the attribute descriptor user data): > > if (attributeContent == null) { > --> check for xlink:href here and skip the following > if (!attribute.isNillable()) { > throw new IllegalAttributeException(attribute.getDescriptor(), > type.getName() > + " not nillable"); > } > return; > } > I will get Niels to speak to you as well. In my case I have no xlinks, the schema is pretty simple, I have a complex attribute that contains two integer, the complex attribute is nillable, its contents are not. I think I just need to avoid generating the complex attribute, but I don't know how... I was expecting some logic like: if all sub-attributes of this complex attribute are missing, then the complex attribute is missing as well. But it seems it's not there. > I like that you're working on app-schema and fix all our existing problems :) Eh, I wish I could, but in fact I'm on the clock, so if I don't find a quick way to contribute a solution to this I'll just create an amended schema that does not break the datastore and then use xlst heavily to generate the expected output... :-( Cheers Andrea ----------------------------------------------------- Ing. Andrea Aime Senior Software Engineer GeoSolutions S.A.S. Via Poggio alle Viti 1187 55054 Massarosa (LU) Italy phone: +39 0584962313 fax: +39 0584962313 http://www.geo-solutions.it http://geo-solutions.blogspot.com/ http://www.linkedin.com/in/andreaaime http://twitter.com/geowolf ----------------------------------------------------- ------------------------------------------------------------------------------ Beautiful is writing same markup. Internet Explorer 9 supports standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3. Spend less time writing and rewriting code and more time creating great experiences on the web. Be a part of the beta today. http://p.sf.net/sfu/beautyoftheweb _______________________________________________ Geotools-devel mailing list Geotools-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-devel