users@jaxb.java.net

Re: White Space Elimination Problem

From: Marcus Walls <marcus.walls_at_ASPECTIVE.COM>
Date: Wed, 15 Jan 2003 16:01:47 -0700

> It turns out it is indeed a bug of the RI to produce invocation
> of the WhitespaceProcessor.collapse() method.

This is good news. Will it be fixed before the final 1.0 release?

> Instead of doing 2, you can relax the schema by removing the
> maxLength facet. This doesn't capture your constraint anyway. In
> this way, you can rely on the unmarshalling validation to do the
> rest of the validation, and your parse method can check if the
> trimmed string is smaller than 50 characters.

The maxLength, minLength + pattern matching seem to work fine
which is exactly what I want. Should they not work?

> Another thing that I noticed that you are using your TrimmedString
> class as a datatype representation, but you can just use the
> java.lang.String class by changing the customization to:

Cool. By using a static method for the print I've also made sure
that dynamic changes to the objects are trimmed correctly before
marshalling too.

My schema fragment now looks like:

  <xsd:simpleType name="trimmedString">
    <xsd:restriction base="xsd:string">
      <xsd:annotation>
        <xsd:appinfo>
          <jxb:javaType name="java.lang.String"
                        parse="com.aspective.common.jaxb.TrimmedString.trim"
                        print="com.aspective.common.jaxb.TrimmedString.trim">
          </jxb:javaType>
        </xsd:appinfo>
      </xsd:annotation>
    </xsd:restriction>
  </xsd:simpleType>

And my code is simply:

  package com.aspective.common.jaxb;

  public abstract class TrimmedString {

      public static String trim(String test) {
          return (test == null) ? null : test.trim();
      }
  }


I have been testing this with the following:

  <xsd:element name="field1">
    <xsd:simpleType>
      <xsd:restriction base="xsd:string">
        <xsd:pattern value="\d{3}- -[A-Z]{2}"/>
      </xsd:restriction>
    </xsd:simpleType>
  </xsd:element>

  <xsd:element name="field2">
    <xsd:simpleType>
      <xsd:restriction base="trimmedString">
        <xsd:pattern value="\d{3}- -[A-Z]{2}"/>
      </xsd:restriction>
    </xsd:simpleType>
  </xsd:element>

Testing with the value " 123- -AB " (which has two spaces in the
middle to verify the difference between trim & collapse) I find that
field2 accepts the string but field1 does not - precisely what I want!
The minLength + maxLength facets appear to work too.

Thus, unless you tell me that the facet stuff shouldn't work and this
will be "fixed" in a future release, I'm definitely a happy customer!

Thanks very much for all the help.

Marcus