castor
  1. castor
  2. CASTOR-2308

Add invalid object to ValidationException

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.1.2.1
    • Fix Version/s: 1.3 rc1
    • Component/s: General
    • Labels:
      None
    • Environment:
      Window XP
    • Number of attachments :
      2

      Description

      Werner, if you have the time I have a question for you.

      When validating, I want to be able to tell which object instance has the problem. Looking at the ValidationException it doesn't appear that I can't get the instance. By taking the exception and calling getLocation(), and getCause(), getLocation(), I can build up the location (sort of). For example, here is a full path I constructed to the object

      /CalculatorDTAConfiguration/ExpressionListType/AnalogAssignmentListType/
      AnalogAssignmentType

      But that doesn't tell me the instance, just that it is an AnalogAssignmentType.

      Any thoughts?

      Thanks

      david

      1. patch.c2308.20080314.txt
        3 kB
        Werner Guttmann
      2. patch.c2308.20080314-002.txt
        17 kB
        Werner Guttmann

        Activity

        Hide
        Werner Guttmann added a comment -

        Why don't you make available what you've got so far in form of a patch, and I'll have a look ?

        Show
        Werner Guttmann added a comment - Why don't you make available what you've got so far in form of a patch, and I'll have a look ?
        Hide
        Werner Guttmann added a comment -

        Can I actually assume that this discussion makes sense in the context of 'multivalued' element definitions, i..e where there are collections of some type used in the generated classes ?

        Show
        Werner Guttmann added a comment - Can I actually assume that this discussion makes sense in the context of 'multivalued' element definitions, i..e where there are collections of some type used in the generated classes ?
        Hide
        Dave Sinclair added a comment -

        I don't have a patch yet, but I will work on one this weekend.

        The problem is that we have a root object, that has many child objects, which contain child objects, etc. Some are multi-valued elements, others are single. So when you call the validate method and the ValidationException is thrown, you could traverse the validation exceptions' invalid objects to lead you to the exact object with the problem.

        Show
        Dave Sinclair added a comment - I don't have a patch yet, but I will work on one this weekend. The problem is that we have a root object, that has many child objects, which contain child objects, etc. Some are multi-valued elements, others are single. So when you call the validate method and the ValidationException is thrown, you could traverse the validation exceptions' invalid objects to lead you to the exact object with the problem.
        Hide
        Werner Guttmann added a comment -

        Dave, I do have an early patch ready to be posted here for review that improves the location processing upon creation of a ValidationException. I will make this available in a few hours through this issue.

        Show
        Werner Guttmann added a comment - Dave, I do have an early patch ready to be posted here for review that improves the location processing upon creation of a ValidationException. I will make this available in a few hours through this issue.
        Hide
        Werner Guttmann added a comment -

        Initial patch for preview. Please note that this improves the location processing, but does not deal with collections in the way that it e.g. emits locations similar to /test/first[2] to highlight that the second <first> sub-element of /test has failed validation.

        Show
        Werner Guttmann added a comment - Initial patch for preview. Please note that this improves the location processing, but does not deal with collections in the way that it e.g. emits locations similar to /test/first [2] to highlight that the second <first> sub-element of /test has failed validation.
        Hide
        Werner Guttmann added a comment -

        Final patch for review.

        Show
        Werner Guttmann added a comment - Final patch for review.
        Hide
        Werner Guttmann added a comment -

        For the XML schema shown below ....

        <?xml version="1.0" encoding="UTF-8" ?>
        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
        
          <xs:element name="test">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="first" type="extraShort" maxOccurs="unbounded"/>
                <xs:element name="second" type="extraShort" />
              </xs:sequence>
              <xs:attribute name="third" type="extraShort" use="optional"/>
            </xs:complexType>
          </xs:element>
          
          <xs:simpleType name="extraShort">
            <xs:restriction base="xs:short">
                <xs:maxInclusive value="10" />
            </xs:restriction>
          </xs:simpleType>
        
        </xs:schema>
        

        the following XPATH fragments will be generated, depending on where the error is located:

        /test/second
        /test/@third
        /test/first[3]

        In other words, I have added some new logic to deal with the position within a collection.

        Show
        Werner Guttmann added a comment - For the XML schema shown below .... <?xml version="1.0" encoding="UTF-8" ?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="test"> <xs:complexType> <xs:sequence> <xs:element name="first" type="extraShort" maxOccurs="unbounded"/> <xs:element name="second" type="extraShort" /> </xs:sequence> <xs:attribute name="third" type="extraShort" use="optional"/> </xs:complexType> </xs:element> <xs:simpleType name="extraShort"> <xs:restriction base="xs:short"> <xs:maxInclusive value="10" /> </xs:restriction> </xs:simpleType> </xs:schema> the following XPATH fragments will be generated, depending on where the error is located: /test/second /test/@third /test/first [3] In other words, I have added some new logic to deal with the position within a collection.
        Hide
        Werner Guttmann added a comment -

        Patch committed as is. Please feel free to re-open this issue should any issues arise, or create a follow-up issue and link it to this very instance.

        Show
        Werner Guttmann added a comment - Patch committed as is. Please feel free to re-open this issue should any issues arise, or create a follow-up issue and link it to this very instance.
        Hide
        Dave Sinclair added a comment -

        Thanks Werner. I appreciate the quick turn around. X-Paths look good. I'll let you know if I have any problems related to it.

        thanks

        dave

        Show
        Dave Sinclair added a comment - Thanks Werner. I appreciate the quick turn around. X-Paths look good. I'll let you know if I have any problems related to it. thanks dave

          People

          • Assignee:
            Werner Guttmann
            Reporter:
            Dave Sinclair
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: