Message:

  A new issue has been created in JIRA.

---------------------------------------------------------------------
View the issue:
  http://issues.apache.org/jira/browse/XERCESJ-952

Here is an overview of the issue:
---------------------------------------------------------------------
        Key: XERCESJ-952
    Summary: DOM3 - DOMError.getLocation().getRelatedNode() incorrect for keyref 
identity constraint
       Type: Bug

     Status: Unassigned
   Priority: Major

    Project: Xerces2-J
 Components: 
             DOM
   Versions:
             2.6.2

   Assignee: 
   Reporter: Debbie Campbell

    Created: Tue, 4 May 2004 12:53 PM
    Updated: Tue, 4 May 2004 12:53 PM
Environment: linux, windows

Description:
DOMError.getLocation().getRelatedNode() is returning the node the keyref constraint is 
defined on instead of the node containing the invalid reference.  If the identity 
constraint violation is a unique constraint, the node return is correct - the 
offending node.

--------------Example code--------------------------------

import org.apache.xerces.xni.parser.XMLParserConfiguration;
import org.apache.xerces.parsers.StandardParserConfiguration;
import org.apache.xerces.parsers.DOMParser;
import org.apache.xerces.util.XMLCatalogResolver; 
import org.apache.xerces.dom.CoreDocumentImpl;
import org.w3c.dom.DOMErrorHandler;
import org.w3c.dom.DOMConfiguration;
import org.w3c.dom.Node;
import org.w3c.dom.Element;

public class KeyRefExample implements DOMErrorHandler
{
    private final boolean DEBUG = true;
    
    public KeyRefExample(String[] catalog, String xml)
    {
        try
        {
            XMLCatalogResolver resolver = new XMLCatalogResolver();
            resolver.setCatalogList(catalog);
  
            XMLParserConfiguration parser_config = new StandardParserConfiguration();
            DOMParser parser = new DOMParser(parser_config);
            
            parser.parse(xml);
            CoreDocumentImpl doc = (CoreDocumentImpl)parser.getDocument();
            DOMConfiguration doc_config = doc.getDomConfig();
            doc_config.setParameter("error-handler", this);
            doc_config.setParameter("validate", Boolean.TRUE);
            doc_config.setParameter("schema-type", "http://www.w3.org/2001/XMLSchema";);
            doc_config.setParameter("schema-location", 
resolver.resolveURI("http://www.example.com/Report";)); 
                       
            doc.normalizeDocument();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
    
    public 
    boolean handleError(org.w3c.dom.DOMError domError)
    {
        System.out.println("msg: " + domError.getMessage());
        if (DEBUG)
        {       
            Node node = domError.getLocation().getRelatedNode();
            System.out.println("getLocation().getRelatedNode(): " + node + " node 
number attr: " + ((Element)node).getAttribute("number"));
            if (node != null)
                System.out.println("node name: " + node.getLocalName() + " severity: " 
+ domError.getSeverity());
            System.out.println("getType(): " + domError.getType());
            System.out.println("lineNum: " + domError.getLocation().getLineNumber() + 
" colNum: " + domError.getLocation().getColumnNumber() + " offset: " + 
domError.getLocation().getByteOffset());
            System.out.println("getRelatedData: " + domError.getRelatedData() + " 
type: " + domError.getRelatedData().getClass().getName());
            System.out.println("getRelatedException: " + 
domError.getRelatedException() + " type: " + 
domError.getRelatedData().getClass().getName());
            System.out.println("-------------------------------------");
        }
        return true;
    }
        
    /** arg0 - catalog file
     *  arg1 - xml file
     */
    public static
    void main(String[] args)
    {
        try
        {
            String catalog[] = {args[0]};
            new KeyRefExample(catalog, args[1]);
            System.out.println("---done---");
        }
        catch (Throwable t)
        {
            t.printStackTrace();
        }
    }
}

----------------Example results ----------------

msg: Duplicate key value [833] declared for identity constraint of element 
"purchaseReport".
getLocation().getRelatedNode(): [part: null] node number attr: 833
node name: part severity: 2
getType(): DuplicateKey
lineNum: -1 colNum: -1 offset: -1
getRelatedData: Duplicate key value [833] declared for identity constraint of element 
"purchaseReport". type: java.lang.String
getRelatedException: :::::-1:-1:Duplicate key value [833] declared for identity 
constraint of element "purchaseReport". type: java.lang.String
-------------------------------------
msg: Key 'keyref_part' with value '878' not found for identity constraint of element 
'purchaseReport'.
getLocation().getRelatedNode(): [purchaseReport: null] node number attr: 
node name: purchaseReport severity: 2
getType(): KeyNotFound
lineNum: -1 colNum: -1 offset: -1
getRelatedData: Key 'keyref_part' with value '878' not found for identity constraint 
of element 'purchaseReport'. type: java.lang.String
getRelatedException: :::::-1:-1:Key 'keyref_part' with value '878' not found for 
identity constraint of element 'purchaseReport'. type: java.lang.String
-------------------------------------
---done---

--------------- Example xml --------------------

<?xml version="1.0" encoding="UTF-8"?>
<purchaseReport xmlns="http://www.example.com/Report";>
    <regions>
        <zip code="95819">
            <part number="878" quantity="1"/> 
            <part number="926" quantity="1"/>
            <part number="833" quantity="1"/>
            <part number="455" quantity="1"/>
        </zip>
        <zip code="63143">
            <part number="455" quantity="1"/>
        </zip>
    </regions>
    <parts>
        <part number="872">Lawnmower</part>
        <part number="926">Baby Monitor</part>
        <part number="833">Lapis Necklace</part>
        <part number="833">Lapis Necklace2</part>
        <part number="455">Sturdy Shelves</part>
    </parts>
</purchaseReport>

-------------------- Example schema --------------------------

<schema targetNamespace="http://www.example.com/Report"; 
xmlns:r="http://www.example.com/Report"; xmlns="http://www.w3.org/2001/XMLSchema"; 
elementFormDefault="qualified">
    <annotation>
        <documentation xml:lang="en">
   Report schema for Example.com
   Copyright 2000 Example.com. All rights reserved.
  </documentation>
    </annotation>
    <element name="purchaseReport">
        <complexType>
            <sequence>
                <element name="regions" type="r:RegionsType"/>
                <element name="parts" type="r:PartsType"/>
            </sequence>
            <attribute name="period" type="duration"/>
            <attribute name="periodEnding" type="date"/>
        </complexType>
        <unique name="unq_zip">
            <selector xpath="r:regions/r:zip"/>
            <field xpath="@code"/>
        </unique>
        <key name="key_part">
            <selector xpath="r:parts/r:part"/>
            <field xpath="@number"/>
        </key>
        <keyref name="keyref_part" refer="r:key_part">
            <selector xpath="r:regions/r:zip/r:part"/>
            <field xpath="@number"/>
        </keyref>
    </element>
    <complexType name="RegionsType">
        <sequence>
            <element name="zip" maxOccurs="unbounded">
                <complexType>
                    <sequence>
                        <element name="part" maxOccurs="unbounded">
                            <complexType>
                                <complexContent>
                                    <restriction base="anyType">
                                        <attribute name="number" 
type="positiveInteger"/>
                                        <attribute name="quantity" 
type="positiveInteger"/>
                                    </restriction>
                                </complexContent>
                            </complexType>
                        </element>
                    </sequence>
                    <attribute name="code" type="positiveInteger"/>
                </complexType>
            </element>
        </sequence>
    </complexType>
    <complexType name="PartsType">
        <sequence>
            <element name="part" maxOccurs="unbounded">
                <complexType>
                    <simpleContent>
                        <extension base="string">
                            <attribute name="number" type="positiveInteger"/>
                        </extension>
                    </simpleContent>
                </complexType>
            </element>
        </sequence>
    </complexType>
</schema>



---------------------------------------------------------------------
JIRA INFORMATION:
This message is automatically generated by JIRA.

If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa

If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to