You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Mukul Gandhi <ga...@gmail.com> on 2009/04/10 06:34:02 UTC
assertions implementation progress
Hi all,
As some of you might be remembering, that I started to implement
XML Schema 1.1 assertions into Xerces. Since last few days,
I have started to put an effort again to complete the Xerces
assertions support.
I am happy to share that, Ken Cai is working with me on assertions
implementation.
We are sending this mail to the xerces-j-dev community, to share the
"assertions design" thoughts so far. It would be great, if any one
would like to suggest any improvements, or has any thoughts about
assertions implementation.
The assertions traversal code is written into Xerces and available at
the online SVN repository. The development of XPath 2.0 integration
code is underway. After the XPath 2.0 integration code is complete, a
complete assertions support in Xerces would be ready for use.
Ken has shared with me in a personal mail, a generic assertions
interface to the XPath 2.0 engine. This interface looks like
following:
public interface XMLAssert {
public void initXPathProcessor(Document xdmRoot) throws Exception;
public void initXPathProcessor(InputStream is) throws Exception, IOException;
public void setNamespace(String prefix, String uri);
public void setSchema(XSModel schema);
public void setValidating(boolean validate);
public boolean evaluateXpathExpression(String xpathExpression)
throws Exception;
}
For each specific XPath 2.0 engine, this interface needs to be
implemented. Ken has also written and shared with me, an
implementation of this interface, for the Psychopath XPath 2.0 engine.
I would be working to integrate Ken's code with the XPath 2.0
assertions code I am writing. We'll post all the newly written and
modified assertions code with a JIRA issue after some time (may be few
days later) (after ensuring good quality).
Currently, I am trying to modify the Xerces class,
"XMLSchemaValidator" to support assertions. The basic framework would
like
following:
public class XMLSchemaValidator .. { ...
// some stuff here
public void startElement(QName element, XMLAttributes attributes,
Augmentations augs) throws XNIException {
// some stuff here
XSTypeDefinition typeDef = fCurrentPSVI.getTypeDefinition();
if (typeDef.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
XSComplexTypeDefinition complexTypeDef =
(XSComplexTypeDefinition) typeDef;
XSObjectList assertions = complexTypeDef.getAssertions();
if (assertions.getLength() > 0) {
// do something here
}
}
else if (typeDef.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
XSSimpleTypeDefinition simpleTypeDef = (XSSimpleTypeDefinition) typeDef;
XSObjectList facets = simpleTypeDef.getMultiValueFacets();
for (int i = 0; i < facets.getLength(); i++) {
XSMultiValueFacet facet = (XSMultiValueFacet) facets.item(i);
if (facet.getFacetKind() == XSSimpleTypeDefinition.FACET_ASSERT) {
// do something here
}
}
}
// if assertions are present, start building an XML tree with this
element as
// a root of the tree.
// some stuff here
}
public void endElement(QName element, Augmentations augs)
throws XNIException {
// some stuff here
// end tree construction
// evaluate assertions on this tree. throw error if assertion
evaluation is false.
// some stuff here
}
public void characters(org.apache.xerces.xni.XMLString text,
org.apache.xerces.xni.Augmentations augs) .. {
// some stuff here
// write code here to add text nodes to the assertions XML tree.
// some stuff here
}
This is just a very high level design. The actual details in the final
code may take a different shape.
I'm hoping to have an initial complete assertions implementation quite
soon. Please watch this space :)
--
Regards,
Mukul Gandhi
---------------------------------------------------------------------
To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-dev-help@xerces.apache.org
Re: assertions implementation progress
Posted by Mukul Gandhi <ga...@gmail.com>.
Hi Michael,
Thanks for your thoughts. Kindly see my comments below.
On Sun, Apr 12, 2009 at 2:09 AM, Michael Glavassevich
<mr...@ca.ibm.com> wrote:
> From a performance perspective I think it would be good if the DOM being
> built could be shared with assertions which start within the scope of the
> outermost assertion which triggered the DOM construction. Then you're only
> ever building one DOM tree at a time. These details could be hidden beneath
> the interface which the schema validator talks to so that it is possible to
> plug in other XPath 2.0 engines which may not necessarily take DOM as an
> input.
I have written the implementation in this manner only. You could
review the code, when I submit the patch :)
At present, there is very minimal code in XMLSchemaValidator.java
which requires it to build a DOM for assertions processing.
I have tried my best to have OOP qualities like, loose coupling and
high cohesiveness.
I want to share that, I have made the provision to provide the
assertion processor to the Xerces Schema engine via a system property.
It would be something like following,
java -Dorg.apache.xerces.assertProcessor=fullyqualifiedclassname
XMLSchema11Test test.xml test.xsd
This system property can also be provided via an API call (for e.g.,
using the Java API System.setProperty).
In the absence of this system property, the XML Schema processor would
default to the Psychopath implementation.
Using the system property will make it easier for users to plug in any
compliant XPath 2.0 processor. To write a new assertions processor for
Xerces (like, XMLAssertPsychopathImpl), the users would have to extend
a class XMLAssertAdapter (which I have written), which internally
implements the interface, XMLAssert. Using XMLAssertAdapter is another
convenience feature for the users (so they don't have to implement all
the methods of the interface, XMLAssert).
>
> We could be clever about how much of the DOM we build by analyzing the XPath
> expressions, for example a/b/c isn't going to need to look deeper than 3
> elements so could avoid constructing many subtrees if we recognize that they
> won't be traversed. Might also be interesting to have a smarter path when
> the input to the validator is DOM where we could just use the application's
> DOM instead of building a new one.
This is a nice idea. I'll try to implement it. It might require some
thinking, and we might do this in a future iteration.
--
Regards,
Mukul Gandhi
---------------------------------------------------------------------
To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-dev-help@xerces.apache.org
Re: assertions implementation progress
Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Mukul,
Thanks for your continued effort on the assertions implementation and
welcome to the community Ken. :-)
I've had a few thoughts about the DOM construction for the XPath processor
which I'd like to share:
>From a performance perspective I think it would be good if the DOM being
built could be shared with assertions which start within the scope of the
outermost assertion which triggered the DOM construction. Then you're only
ever building one DOM tree at a time. These details could be hidden beneath
the interface which the schema validator talks to so that it is possible to
plug in other XPath 2.0 engines which may not necessarily take DOM as an
input.
We could be clever about how much of the DOM we build by analyzing the
XPath expressions, for example a/b/c isn't going to need to look deeper
than 3 elements so could avoid constructing many subtrees if we recognize
that they won't be traversed. Might also be interesting to have a smarter
path when the input to the validator is DOM where we could just use the
application's DOM instead of building a new one.
Thanks.
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org
Mukul Gandhi <ga...@gmail.com> wrote on 04/10/2009 12:46:16 AM:
> Hi all,
> Some of you might be remembering, that I started to implement XML
> Schema 1.1 assertions into Xerces. Since last few days, I have started
> to put an effort again to complete the Xerces assertions support.
>
> I am happy to share that, Ken Cai is working with me on assertions
> implementation.
>
> We are sending this mail to the xerces-j-dev community, to share the
> "assertions design" thoughts so far. It would be great, if any one
> would like to suggest any improvements, or has any thoughts about
> assertions implementation.
>
> The assertions traversal code is written into Xerces and available at
> the online SVN repository. The development of XPath 2.0 integration
> code is underway. After the XPath 2.0 integration code is complete, a
> complete assertions support in Xerces would be ready for use.
>
> Ken has shared with me in a personal mail, a generic assertions
> interface to the XPath 2.0 engine. This interface looks like
> following:
>
> public interface XMLAssert {
> public void initXPathProcessor(Document xdmRoot) throws Exception;
> public void initXPathProcessor(InputStream is) throws Exception,
> IOException;
> public void setNamespace(String prefix, String uri);
> public void setSchema(XSModel schema);
> public void setValidating(boolean validate);
> public boolean evaluateXpathExpression(String xpathExpression)
> throws Exception;
> }
>
> For each specific XPath 2.0 engine, this interface needs to be
> implemented. Ken has also written and shared with me, an
> implementation of this interface, for the Psychopath XPath 2.0 engine.
>
> I would be working to integrate Ken's code with the XPath 2.0
> assertions code I am writing. We'll post all the newly written and
> modified assertions code with a JIRA issue after some time (may be few
> days later) (after ensuring good quality).
>
> Currently, I am trying to modify the Xerces class,
> "XMLSchemaValidator" to support assertions. The basic framework would
> like following:
>
> public class XMLSchemaValidator .. { ...
>
> // some stuff here
>
> public void startElement(QName element, XMLAttributes attributes,
> Augmentations augs) throws XNIException {
>
> // some stuff here
>
> XSTypeDefinition typeDef = fCurrentPSVI.getTypeDefinition();
>
> if (typeDef.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
> XSComplexTypeDefinition complexTypeDef =
> (XSComplexTypeDefinition) typeDef;
> XSObjectList assertions = complexTypeDef.getAssertions();
> if (assertions.getLength() > 0) {
> // do something here
> }
> }
> else if (typeDef.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
> XSSimpleTypeDefinition simpleTypeDef = (XSSimpleTypeDefinition)
typeDef;
> XSObjectList facets = simpleTypeDef.getMultiValueFacets();
> for (int i = 0; i < facets.getLength(); i++) {
> XSMultiValueFacet facet = (XSMultiValueFacet) facets.item(i);
> if (facet.getFacetKind() == XSSimpleTypeDefinition.FACET_ASSERT)
{
> // do something here
> }
> }
> }
>
> // if assertions are present, start building an XML tree with
> this element as
> // a root of the tree.
>
> // some stuff here
>
> }
>
>
> public void endElement(QName element, Augmentations augs)
> throws XNIException {
>
> // some stuff here
>
> // end tree construction
>
> // evaluate assertions on this tree. throw error if assertion
> evaluation is false.
>
> // some stuff here
>
> }
>
>
> public void characters(org.apache.xerces.xni.XMLString text,
> org.apache.xerces.xni.Augmentations augs) .. {
>
> // some stuff here
>
> // write code here to add text nodes to the assertions XML tree.
>
> // some stuff here
>
> }
>
>
> This is just a very high level design. The actual details in the final
> code may take a different shape.
>
> I'm hoping to have an initial complete assertions implementation quite
> soon. Please watch this space :)
>
>
> --
> Regards,
> Mukul Gandhi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-dev-help@xerces.apache.org
assertions implementation progress
Posted by Mukul Gandhi <ga...@gmail.com>.
Hi all,
Some of you might be remembering, that I started to implement XML
Schema 1.1 assertions into Xerces. Since last few days, I have started
to put an effort again to complete the Xerces assertions support.
I am happy to share that, Ken Cai is working with me on assertions
implementation.
We are sending this mail to the xerces-j-dev community, to share the
"assertions design" thoughts so far. It would be great, if any one
would like to suggest any improvements, or has any thoughts about
assertions implementation.
The assertions traversal code is written into Xerces and available at
the online SVN repository. The development of XPath 2.0 integration
code is underway. After the XPath 2.0 integration code is complete, a
complete assertions support in Xerces would be ready for use.
Ken has shared with me in a personal mail, a generic assertions
interface to the XPath 2.0 engine. This interface looks like
following:
public interface XMLAssert {
public void initXPathProcessor(Document xdmRoot) throws Exception;
public void initXPathProcessor(InputStream is) throws Exception, IOException;
public void setNamespace(String prefix, String uri);
public void setSchema(XSModel schema);
public void setValidating(boolean validate);
public boolean evaluateXpathExpression(String xpathExpression)
throws Exception;
}
For each specific XPath 2.0 engine, this interface needs to be
implemented. Ken has also written and shared with me, an
implementation of this interface, for the Psychopath XPath 2.0 engine.
I would be working to integrate Ken's code with the XPath 2.0
assertions code I am writing. We'll post all the newly written and
modified assertions code with a JIRA issue after some time (may be few
days later) (after ensuring good quality).
Currently, I am trying to modify the Xerces class,
"XMLSchemaValidator" to support assertions. The basic framework would
like following:
public class XMLSchemaValidator .. { ...
// some stuff here
public void startElement(QName element, XMLAttributes attributes,
Augmentations augs) throws XNIException {
// some stuff here
XSTypeDefinition typeDef = fCurrentPSVI.getTypeDefinition();
if (typeDef.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
XSComplexTypeDefinition complexTypeDef =
(XSComplexTypeDefinition) typeDef;
XSObjectList assertions = complexTypeDef.getAssertions();
if (assertions.getLength() > 0) {
// do something here
}
}
else if (typeDef.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
XSSimpleTypeDefinition simpleTypeDef = (XSSimpleTypeDefinition) typeDef;
XSObjectList facets = simpleTypeDef.getMultiValueFacets();
for (int i = 0; i < facets.getLength(); i++) {
XSMultiValueFacet facet = (XSMultiValueFacet) facets.item(i);
if (facet.getFacetKind() == XSSimpleTypeDefinition.FACET_ASSERT) {
// do something here
}
}
}
// if assertions are present, start building an XML tree with this element as
// a root of the tree.
// some stuff here
}
public void endElement(QName element, Augmentations augs)
throws XNIException {
// some stuff here
// end tree construction
// evaluate assertions on this tree. throw error if assertion
evaluation is false.
// some stuff here
}
public void characters(org.apache.xerces.xni.XMLString text,
org.apache.xerces.xni.Augmentations augs) .. {
// some stuff here
// write code here to add text nodes to the assertions XML tree.
// some stuff here
}
This is just a very high level design. The actual details in the final
code may take a different shape.
I'm hoping to have an initial complete assertions implementation quite
soon. Please watch this space :)
--
Regards,
Mukul Gandhi
---------------------------------------------------------------------
To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-dev-help@xerces.apache.org