The discussion is getting a bit much for jira so moving back to the mailing list.
Quoting your last comments ben:
> I tried to fix the encoder binding behaviour about a year ago, using > the technique you advocate. The problem is that the current
> Configuration/Binding/Encoder architecture:
> (1) allows only a single binding for each XSD type QName (specified
> in the first matching Configuration entry),
> (2) requires every binding to be bound to a single XSD type QName
> (returned by the binding getTarget), and
> (3) allows every binding to either be BEFORE/AFTER its parents or
> OVERRIDE *all* of them (returned by the binding getExecutionMode).
> For example, gml:MeasureType is a complexType with simpleContent of
> xs:double. gml:MeasureType is bound to MeasureTypeBinding. xs:double > is bound to XSDoubleTypeBinding. MeasureTypeBinding must be an
> OVERRIDE because, if it has AFTER execution mode, whatever object
> represents a Measure is passed to XSDoubleTypeBinding which cannot
> handle it.
The answer is do not use MeasureTypeBinding since org.geotools.meature.Measure is not the object you want to work with right?
> - If we were able to smuggle a fallback binding for MeasureType into > the binding stack, it would be removed by MeasureTypeBinding being an > OVERRIDE.
The fallback should be a binding higher up in the chain which is type consistent with the object being encoded. Since MEasureTYpeBinding is not type consistent with the objects its execution mode should be completely ignored.
> Even if we changed the encoder to recognise and ignore mismatched
> types and so work with an AFTER execution mode for
> MeasureTypeBinding, there is no type QName to bind generic
> complexType with simpleContent. This pattern has no representation in > the type name hierarchy that drives the construction of the binding
> stack. The Configuration allows only one binding per XSD type name.
Why can't you use xs:anyType which is the root of all types? You are already have a special binding attached to it, why can't that binding handle these other cases as well?
> Please consider your proposal to add a binding for
> AbstractSimpleContentComplexBinding:
> - To what XSD type name should this binding be registered in the
> Configuration?
> - What should AbstractSimpleContentComplexBinding getTarget return (i.e. the XSD type name)?
> - If MeasureTypeBinding enables this binding by using AFTER execution > mode, what stops XSDoubleTypeBinding from being called first? (OK, we > can modify the Encoder to use instanceof checks.)
We could come up with some name, it does not really matter. Then we can have the code that puts together the binding case recognize the simple type complex content case (actually i am pretty sure it already does) and then look for this binding by the special name we decide on.
This name (let's call it xs:simpleTypeWithComplexContent) will be what is returned from getTarget()
MeasureBinding should not factor in at all since its type will be nonsense compared to the object being encoded. It and its execution mode should be ignored.
> How do we register multiple bindings for one XSD type QName and have > them honoured? Perhaps this is the approach we should investigate.
> Perhaps storing lists of bindings in Configurations? This would be a > wide-reaching change. We would need to add a complex-aware version of > every complex binding that we wanted to have ComplexAttribute
> support. Surely this is as bad as an instanceof in each binding.
> Rob's instanceof was allowing bindings to fall back up the Java
> inheritance hierarchy to find bindings the encoder could not handle.
If a bindings declared type hierarchy is not what you need it means don't use that binding. You should completely ditch it. So you should use a configuration that does even register MeasureTypeBinding if at the end of the day you don't want back a org.geotools.
> The current bindings only work, and only in GeoServer, because we put > them at the top of the dependencies in GeoServer WFSConfiguration:
>
> // support GML property type pattern
> Schemas.unregisterComponent(container, XS.ANYTYPE);
> container.registerComponentImplementation(XS.ANYTYPE,
> SubstitutionGroupXSAnyTypeBinding.class);
> This is why the only encoding tests for app-schema are in GeoServer.
Well this is what the system was designed for. If the specialized bindings don't work for you, replace them. I don't see this as a hack, it was how the system was designed to operate.
> Yes, this is horrible. Look at the Configuration dependencies and you > will see it is the only obvious place to smuggle dependency this
> before the stock XSConfiguration without making gt-xsd-core depend on > gt-xsd-gml3. Furthermore, this only works for types that have no
> other bindings so they can fall back to XS.ANYTYPE. There is no XSD
> type name that is the base of complex types and only complex types,
> to which SubstitutionGroupXSAnyTypeBinding could be bound.
> What would work is an encoder that looked at XSD type definitions and > not just XSD type QNames to find bindings. That would allow us to
> have bindings for complex types and complexType-with-simpleContent
> without having to bind to XSD QNames we do not know (defined in user > application schemas). But how to make this not GML specific (i.e.
> retain the generic nature of the Encoder)?
> The current situation is beyond ugly. If you have any better ideas I > would love to hear them.
Unless I am missing something fundamental this should work. I was able to make modifications and get Rob A's original test cases to pass.
--
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.