Improve app-schema handling of nillable properties
--------------------------------------------------

                 Key: GEOT-2679
                 URL: http://jira.codehaus.org/browse/GEOT-2679
             Project: GeoTools
          Issue Type: Improvement
          Components: data app-schema
            Reporter: Ben Caradoc-Davies
            Assignee: Ben Caradoc-Davies


{code}
-------- Original Message --------
Subject: [Geotools-devel] attribute instances and nullability
Date: Fri, 17 Jul 2009 11:22:17 +0800
From: Justin Deoliveira 
To: Geotools-Devel list

Hi all,

I spent some time yesterday trying to port the geoserver wfs 1.1 xlink 
tests to an app-schema configuration. Made some progress but ran into 
the following issue.

One of the types for testing looks like this:

  <xsd:complexType name="PrimitiveGeoFeatureType">
     <xsd:complexContent>
       <xsd:extension base="gml:AbstractFeatureType">
         <xsd:sequence>
           <xsd:element name="surfaceProperty" minOccurs="0" 
type="gml:SurfacePropertyType" />
           <xsd:element name="pointProperty" minOccurs="0" 
type="gml:PointPropertyType" />
           <xsd:element name="curveProperty" minOccurs="0" 
type="gml:CurvePropertyType" />

   ...

Now if I understand xml schema correctly this means the element 
"surfaceProperty" is non-nillable, but there is allowed to be zero 
occurrences in them.

So in the underlying database, there are records of PrimitiveGeoFeature 
which have a null value for "surfaceProperty". The current behavior that 
I am running into is that an Attribute instance is getting created for 
it, with a value set to null.

However, when this gets validated an error occurs, because the type is 
non-nullable. So I would think in this case the attribute instance 
should just be omitted since minOccurs == 0, and its value is 
non-existent or null. Thoughts?

If I am right does the following make sense when creating attributes 
from null values which correspond to  xml elements / particles:

* nillable = false, minOccurs > 0 -> create attribute with null value 
which will lead to a failure on validation

* nillable = true, minOccurs > 0 -> create attribute with null value 
which is ok

* nillable = false, minOccurs = 0 -> do not create an attribute

Thoughts? I also whipped up the following patch, not sure if it is 
complete though:

Index: app-schema/src/main/java/org/geotools/data/complex/filter/XPath.java
===================================================================
--- app-schema/src/main/java/org/geotools/data/complex/filter/XPath.java 
        (
revision 33570)
+++ app-schema/src/main/java/org/geotools/data/complex/filter/XPath.java 
        (
working copy)
@@ -611,6 +611,14 @@
                              + " is not a valid location path for type 
" + parent
Type.getName());
                  }
                  int index = currStep.getIndex();
+
+                //check for null, if the value is null but the 
descriptor is non
-nullable
+                // then check for minOccurs = 0, and if so
+                if ( value == null && !currStepDescriptor.isNillable() ) {
+                    if ( currStepDescriptor.getMinOccurs() == 0 ) {
+                        return null;
+                    }
+                }
                  Attribute attribute = setValue(currStepDescriptor, id, 
value, in
dex, parent,
                          targetNodeType, isXlinkRef);
                  return attribute;

-Justin

-- 
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.
{code}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to