I have to use
org.apache.xerces.impl.xs.psvi.* pretty heavily in production software, and I
just wanted to post some musings and perhaps a wistful
question.
The PSVI APIs seem
to be fairly crufty. (Please don't take this as a rant. OK, maybe a
friendly rant... ;-) Of course, having spent far too much dealing
with the XML Schema spec, I have a great deal of sympathy for why that is
the case. I also understand it's in the "impl" set of packages, with limited
support, but it's the only game in town. (For me anyway - I don't know if it's
better or not, but I can't use http://www.eclipse.org/xsd/ due to
licensing issues.)
Here's my
"do-it-yourself" analogy: Let's say I need a left-handed metric wing-nut.
I know I've probably got one in a Mason jar in the garage, so I put down my
tools, go out, dump the jar on my workbench, poke through it until I finally
find what I need, rake the parts back into the jar, and go back to
work.
That's
what PSVI feel like to me. It's especially poignant when I'm staring at the
data I need in the debugger but it takes an extra hour to figure
out all the API hooks to look it up. It's not that big an issue if you
only use it occasionally, but it's not so great for frequent use.
(Mind you, I'm VERY thankful I don't have to make a left-handed metric
wing-net from scratch. ;-)
Here's an example:
I'm traipsing through a schema, and want to find out if this element has an
associated enumeration. I've already looked up the type def, so I call
-
static private ArrayList
getEnumFacet(XSTypeDefinition xstd)
{ ArrayList enum = null; if (xstd != null && xstd instanceof XSSimpleTypeDefinition) { XSSimpleTypeDefinition xsstd = (XSSimpleTypeDefinition)xstd; XSObjectList xsol = xsstd.getMultiValueFacets(); if (xsol != null) { for (int f = 0; f < xsol.getLength(); ++f) { XSObject xob = xsol.item(f); if (xob instanceof XSMultiValueFacet) { XSMultiValueFacet xsmvf = (XSMultiValueFacet)xob; if (xsmvf.getFacetKind() == XSSimpleTypeDefinition.FACET_ENUMERATION) { enum = new ArrayList(); StringList vals = xsmvf.getLexicalFacetValues(); for (int v = 0; v < vals.getLength(); ++v) { enum.add(vals.item(v)); } } } } } } return enum; } Well, OK; I got my
enumeration back, so I'm fairly happy, but then I have to write a helper like
that for every facet I care about. (More casting than a bass-fishing tournament.
;-) Just adding a few dozen helper functions in the right places might be
enough.
The doc isn't always
a big help here, either. For example see http://xml.apache.org/xerces2-j/javadocs/xerces2/index.html
++++
Interface XSMultiValueFacet |
Title: Message
- PSVI ramblings Thomas Cox
- Re: PSVI ramblings Elena Litani