xmlbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From z...@apache.org
Subject cvs commit: xml-xmlbeans/v2/test/cases/marshal/com/mytest YourClass.java
Date Wed, 21 Apr 2004 05:29:41 GMT
zieg        2004/04/20 22:29:41

  Modified:    v2/src/marshal/org/apache/xmlbeans/impl/marshal
                        Base64BinaryTypeConverter.java
                        HexBinaryTypeConverter.java
                        ListArrayRuntimeBindingType.java
                        RuntimeBindingTypeTable.java
               v2/src/marshal/org/apache/xmlbeans/impl/marshal/util/collections
                        ObjectAccumulator.java
               v2/src/typeimpl/org/apache/xmlbeans/impl/util
                        XsTypeConverter.java
               v2/test/cases/marshal example_config.xml
               v2/test/cases/marshal/com/mytest YourClass.java
  Log:
  fix problem with lists of hexBinary and base64Binary
  
  Revision  Changes    Path
  1.7       +9 -7      xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/Base64BinaryTypeConverter.java
  
  Index: Base64BinaryTypeConverter.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/Base64BinaryTypeConverter.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Base64BinaryTypeConverter.java	6 Apr 2004 00:53:08 -0000	1.6
  +++ Base64BinaryTypeConverter.java	21 Apr 2004 05:29:40 -0000	1.7
  @@ -24,6 +24,9 @@
   import java.io.IOException;
   import java.io.InputStream;
   
  +/**
  + * converter for: byte[] <-> base64Binary
  + */
   final class Base64BinaryTypeConverter
       extends BaseSimpleTypeConverter
   {
  @@ -56,13 +59,12 @@
                                        UnmarshalResult result)
           throws XmlException
       {
  -        byte[] buf = Base64.decode(lexical_value.toString().getBytes());
  -        if (buf != null)
  -            return new ByteArrayInputStream(buf);
  -        else
  -            throw new InvalidLexicalValueException("invalid base64Binary value",
  -                                                   result.getLocation());
  -
  +        try {
  +            return XsTypeConverter.lexBase64Binary(lexical_value);
  +        }
  +        catch (InvalidLexicalValueException e) {
  +            throw new InvalidLexicalValueException(e, result.getLocation());
  +        }
       }
   
   
  
  
  
  1.7       +9 -7      xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/HexBinaryTypeConverter.java
  
  Index: HexBinaryTypeConverter.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/HexBinaryTypeConverter.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- HexBinaryTypeConverter.java	6 Apr 2004 00:53:08 -0000	1.6
  +++ HexBinaryTypeConverter.java	21 Apr 2004 05:29:40 -0000	1.7
  @@ -24,6 +24,9 @@
   import java.io.InputStream;
   import java.io.ByteArrayInputStream;
   
  +/**
  + * converter for: byte[] <-> hexBinary
  + */
   final class HexBinaryTypeConverter
       extends BaseSimpleTypeConverter
   {
  @@ -53,13 +56,12 @@
                                        UnmarshalResult result)
           throws XmlException
       {
  -        byte[] buf = HexBin.decode(lexical_value.toString().getBytes());
  -        if (buf != null)
  -            return new ByteArrayInputStream(buf);
  -        else
  -            throw new InvalidLexicalValueException("invalid hexBinary value",
  -                                                   result.getLocation());
  -
  +        try {
  +            return XsTypeConverter.lexHexBinary(lexical_value);
  +        }
  +        catch (InvalidLexicalValueException e) {
  +            throw new InvalidLexicalValueException(e, result.getLocation());
  +        }
       }
   
       //non simple types can throw a runtime exception
  
  
  
  1.3       +3 -1      xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ListArrayRuntimeBindingType.java
  
  Index: ListArrayRuntimeBindingType.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ListArrayRuntimeBindingType.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ListArrayRuntimeBindingType.java	18 Apr 2004 19:28:31 -0000	1.2
  +++ ListArrayRuntimeBindingType.java	21 Apr 2004 05:29:40 -0000	1.3
  @@ -89,6 +89,8 @@
               unmarshaller =
                   type_table.lookupUnmarshaller(binding_type, loader);
   
  +            assert marshaller != null;
  +            assert unmarshaller != null;
           }
   
           Class getItemClass()
  @@ -118,7 +120,7 @@
           public TypeUnmarshaller getTypeUnmarshaller(UnmarshalResult context)
               throws XmlException
           {
  -            return context.determineTypeUnmarshaller(unmarshaller);
  +            return unmarshaller;
           }
   
           public void fill(Object inter, Object prop_obj)
  
  
  
  1.28      +1 -0      xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeBindingTypeTable.java
  
  Index: RuntimeBindingTypeTable.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/RuntimeBindingTypeTable.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- RuntimeBindingTypeTable.java	14 Apr 2004 23:03:50 -0000	1.27
  +++ RuntimeBindingTypeTable.java	21 Apr 2004 05:29:40 -0000	1.28
  @@ -345,6 +345,7 @@
                         byte_array_jname,
                         new HexBinaryTypeConverter());
   
  +        //TODO: InputStream based hexBinary and base64Binary converters
       }
   
       private static TypeUnmarshaller createSimpleTypeUnmarshaller(SimpleBindingType stype,
  
  
  
  1.5       +12 -0     xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/util/collections/ObjectAccumulator.java
  
  Index: ObjectAccumulator.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/util/collections/ObjectAccumulator.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ObjectAccumulator.java	12 Feb 2004 20:06:18 -0000	1.4
  +++ ObjectAccumulator.java	21 Apr 2004 05:29:41 -0000	1.5
  @@ -60,6 +60,8 @@
   
       public void append(Object o)
       {
  +        assert checkInstance(o);
  +
   //        if (o != null && !componentType.isAssignableFrom(o.getClass())) {
   //            String msg = "Invalid type: " + o.getClass().getName() +
   //                " expecting: " + componentType.getName();
  @@ -67,6 +69,16 @@
   //        }
   
           store.add(o);
  +    }
  +
  +    private boolean checkInstance(Object o)
  +    {
  +        if (!componentType.isInstance(o)) {
  +            String msg = "Invalid type: " + o.getClass().getName() +
  +                " expecting: " + componentType.getName();
  +            throw new IllegalArgumentException(msg);
  +        }
  +        return true;
       }
   
       public final Object getFinalArray()
  
  
  
  1.9       +69 -78    xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/util/XsTypeConverter.java
  
  Index: XsTypeConverter.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/util/XsTypeConverter.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- XsTypeConverter.java	17 Apr 2004 00:06:23 -0000	1.8
  +++ XsTypeConverter.java	21 Apr 2004 05:29:41 -0000	1.9
  @@ -15,20 +15,20 @@
   
   package org.apache.xmlbeans.impl.util;
   
  -import org.apache.xmlbeans.XmlError;
   import org.apache.xmlbeans.GDate;
   import org.apache.xmlbeans.GDateBuilder;
  -import org.apache.xmlbeans.XmlCalendar;
  -import org.apache.xmlbeans.SchemaType;
   import org.apache.xmlbeans.GDateSpecification;
  +import org.apache.xmlbeans.SchemaType;
  +import org.apache.xmlbeans.XmlCalendar;
  +import org.apache.xmlbeans.XmlError;
   import org.apache.xmlbeans.impl.common.InvalidLexicalValueException;
   
  -import javax.xml.namespace.QName;
   import javax.xml.namespace.NamespaceContext;
  +import javax.xml.namespace.QName;
   import java.math.BigDecimal;
   import java.math.BigInteger;
  -import java.util.Collection;
   import java.util.Calendar;
  +import java.util.Collection;
   import java.util.Date;
   
   public final class XsTypeConverter
  @@ -50,12 +50,10 @@
               //current jdk impl of parseFloat calls trim() on the string.
               //Any other space is illegal anyway, whether there are one or more spaces.
               //so no need to do a collapse pass through the string.
  -            if (cs.length()>0)
  -            {
  -                char ch = cs.charAt(cs.length()-1);
  -                if (ch=='f' || ch=='F')
  -                {
  -                    if (cs.charAt(cs.length()-2)!='N')
  +            if (cs.length() > 0) {
  +                char ch = cs.charAt(cs.length() - 1);
  +                if (ch == 'f' || ch == 'F') {
  +                    if (cs.charAt(cs.length() - 2) != 'N')
                           throw new NumberFormatException("Invalid char '" + ch + "' in float.");
                   }
               }
  @@ -106,10 +104,9 @@
               //current jdk impl of parseDouble calls trim() on the string.
               //Any other space is illegal anyway, whether there are one or more spaces.
               //so no need to do a collapse pass through the string.
  -            if (cs.length()>0)
  -            {
  -                char ch = cs.charAt(cs.length()-1);
  -                if (ch=='d' || ch=='D')
  +            if (cs.length() > 0) {
  +                char ch = cs.charAt(cs.length() - 1);
  +                if (ch == 'd' || ch == 'D')
                       throw new NumberFormatException("Invalid char '" + ch + "' in double.");
               }
               return Double.parseDouble(v);
  @@ -185,9 +182,8 @@
       public static BigInteger lexInteger(CharSequence cs)
           throws NumberFormatException
       {
  -        if (cs.length()>1)
  -        {
  -            if (cs.charAt(0)=='+' && cs.charAt(1)=='-')
  +        if (cs.length() > 1) {
  +            if (cs.charAt(0) == '+' && cs.charAt(1) == '-')
                   throw new NumberFormatException("Illegal char sequence '+-'");
           }
           final String v = cs.toString();
  @@ -274,12 +270,10 @@
   
       public static int lexInt(CharSequence cs, Collection errors)
       {
  -        try
  -        {
  +        try {
               return lexInt(cs);
           }
  -        catch(NumberFormatException e)
  -        {
  +        catch (NumberFormatException e) {
               String msg = "invalid int:" + cs;
               errors.add(XmlError.forMessage(msg));
               return 0;
  @@ -301,12 +295,10 @@
   
       public static byte lexByte(CharSequence cs, Collection errors)
       {
  -        try
  -        {
  +        try {
               return lexByte(cs);
           }
  -        catch (NumberFormatException e)
  -        {
  +        catch (NumberFormatException e) {
               String msg = "invalid byte: " + cs;
               errors.add(XmlError.forMessage(msg));
               return 0;
  @@ -354,12 +346,10 @@
   
       public static boolean lexBoolean(CharSequence value, Collection errors)
       {
  -        try
  -        {
  +        try {
               return lexBoolean(value);
           }
  -        catch(InvalidLexicalValueException e)
  -        {
  +        catch (InvalidLexicalValueException e) {
               errors.add(XmlError.forMessage(e.getMessage()));
               return false;
           }
  @@ -398,50 +388,42 @@
   
           int firstcolon;
           boolean hasFirstCollon = false;
  -        for (firstcolon = 0; firstcolon < charSeq.length(); firstcolon ++)
  -            if (charSeq.charAt(firstcolon)==NAMESPACE_SEP)
  -            {
  +        for (firstcolon = 0; firstcolon < charSeq.length(); firstcolon++)
  +            if (charSeq.charAt(firstcolon) == NAMESPACE_SEP) {
                   hasFirstCollon = true;
                   break;
               }
   
  -        if (hasFirstCollon)
  -        {
  +        if (hasFirstCollon) {
               prefix = charSeq.subSequence(0, firstcolon).toString();
               localname = charSeq.subSequence(firstcolon + 1, charSeq.length()).toString();
  -            if (firstcolon==0)
  -            {
  +            if (firstcolon == 0) {
                   throw new InvalidLexicalValueException("invalid xsd:QName '" + charSeq.toString()
+ "'");
               }
  -        }
  -        else
  -        {
  +        } else {
               prefix = EMPTY_PREFIX;
               localname = charSeq.toString();
           }
   
           String uri = nscontext.getNamespaceURI(prefix);
   
  -        if (uri == null)
  -        {
  -            if (prefix!=null && prefix.length() > 0)
  +        if (uri == null) {
  +            if (prefix != null && prefix.length() > 0)
                   throw new InvalidLexicalValueException("Can't resolve prefix: " + prefix);
   
               uri = "";
           }
   
  -        return new QName( uri, localname );
  +        return new QName(uri, localname);
       }
   
       public static QName lexQName(String xsd_qname, Collection errors,
                                    NamespaceContext nscontext)
       {
  -        try
  -        {
  +        try {
               return lexQName(xsd_qname, nscontext);
           }
  -        catch( InvalidLexicalValueException e)
  -        {
  +        catch (InvalidLexicalValueException e) {
               errors.add(XmlError.forMessage(e.getMessage()));
               final int idx = xsd_qname.indexOf(NAMESPACE_SEP);
               return new QName(null, xsd_qname.substring(idx));
  @@ -490,12 +472,10 @@
   
       public static GDate lexGDate(String xsd_gdate, Collection errors)
       {
  -        try
  -        {
  +        try {
               return lexGDate(xsd_gdate);
           }
  -        catch( IllegalArgumentException e)
  -        {
  +        catch (IllegalArgumentException e) {
               errors.add(XmlError.forMessage(e.getMessage()));
               return new GDateBuilder().toGDate();
           }
  @@ -507,7 +487,6 @@
       }
   
   
  -
       // ======================== dateTime ========================
       public static XmlCalendar lexDateTime(CharSequence v)
       {
  @@ -556,6 +535,15 @@
           return HexBin.bytesToString(val);
       }
   
  +    public static byte[] lexHexBinary(CharSequence lexical_value)
  +    {
  +        byte[] buf = HexBin.decode(lexical_value.toString().getBytes());
  +        if (buf != null)
  +            return buf;
  +        else
  +            throw new InvalidLexicalValueException("invalid hexBinary value");
  +    }
  +
   
       // ======================== base64binary ========================
       public static CharSequence printBase64Binary(byte[] val)
  @@ -564,6 +552,15 @@
           return new String(bytes);
       }
   
  +    public static byte[] lexBase64Binary(CharSequence lexical_value)
  +    {
  +        byte[] buf = Base64.decode(lexical_value.toString().getBytes());
  +        if (buf != null)
  +            return buf;
  +        else
  +            throw new InvalidLexicalValueException("invalid base64Binary value");
  +    }
  +
   
       // date utils
       public static GDateSpecification getGDateValue(Date d,
  @@ -596,7 +593,7 @@
   
       private static String trimInitialPlus(String xml)
       {
  -        if (xml.length()>0 && xml.charAt(0) == '+') {
  +        if (xml.length() > 0 && xml.charAt(0) == '+') {
               return xml.substring(1);
           } else {
               return xml;
  @@ -622,7 +619,7 @@
           return xsd_decimal;
       }
   
  -        private static int parseInt(CharSequence cs)
  +    private static int parseInt(CharSequence cs)
       {
           return parseIntXsdNumber(cs, Integer.MIN_VALUE, Integer.MAX_VALUE);
       }
  @@ -641,8 +638,8 @@
       {
           // int parser on a CharSequence
           int length = ch.length();
  -        if (length<1)
  -            throw new NumberFormatException("For input string: \"" + ch.toString() +"\"");
  +        if (length < 1)
  +            throw new NumberFormatException("For input string: \"" + ch.toString() + "\"");
   
           int sign = 1;
           int result = 0;
  @@ -651,41 +648,35 @@
           int limit2;
   
           char c = ch.charAt(0);
  -        if (c=='-')
  -        {
  +        if (c == '-') {
               start++;
  -            limit  = (min_value/10);
  -            limit2 = -(min_value%10);
  -        }
  -        else if (c=='+')
  -        {
  +            limit = (min_value / 10);
  +            limit2 = -(min_value % 10);
  +        } else if (c == '+') {
               start++;
               sign = -1;
  -            limit  = -(max_value/10);
  -            limit2 = (max_value%10);
  -        }
  -        else
  -        {
  +            limit = -(max_value / 10);
  +            limit2 = (max_value % 10);
  +        } else {
               sign = -1;
  -            limit  = -(max_value/10);
  -            limit2 = (max_value%10);
  +            limit = -(max_value / 10);
  +            limit2 = (max_value % 10);
           }
   
  -        for (int i = 0; i < length-start; i++)
  -        {
  +        for (int i = 0; i < length - start; i++) {
               c = ch.charAt(i + start);
               int v = Character.digit(c, 10);
   
  -            if (v<0)
  -                throw new NumberFormatException("For input string: \"" + ch.toString()
+"\"");
  +            if (v < 0)
  +                throw new NumberFormatException("For input string: \"" + ch.toString()
+ "\"");
   
  -            if ( result <= limit && v > limit2)
  +            if (result <= limit && v > limit2)
                   throw new NumberFormatException("For input string: \"" + ch.toString()
+ "\"");
   
  -            result = result*10 - v;
  +            result = result * 10 - v;
           }
   
  -        return sign*result;
  +        return sign * result;
       }
   
   }
  
  
  
  1.29      +22 -0     xml-xmlbeans/v2/test/cases/marshal/example_config.xml
  
  Index: example_config.xml
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/cases/marshal/example_config.xml,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- example_config.xml	14 Apr 2004 23:03:51 -0000	1.28
  +++ example_config.xml	21 Apr 2004 05:29:41 -0000	1.29
  @@ -291,6 +291,19 @@
               </bin:qname-property>
   
               <bin:qname-property>
  +                <bin:xmlcomponent>t=SimpleHexBinList@java:com.mytest</bin:xmlcomponent>
  +                <bin:javatype>byte[][]</bin:javatype>
  +                <bin:getter>
  +                    <bin:method-name>getSimpleHexBinArray</bin:method-name>
  +                </bin:getter>
  +                <bin:setter>
  +                    <bin:method-name>setSimpleHexBinArray</bin:method-name>
  +                    <bin:param-type>byte[][]</bin:param-type>
  +                </bin:setter>
  +                <bin:qname>java:simpleHexBinArray</bin:qname>
  +            </bin:qname-property>
  +
  +            <bin:qname-property>
                   <bin:xmlcomponent>t=dateTime@http://www.w3.org/2001/XMLSchema</bin:xmlcomponent>
                   <bin:javatype>java.util.Date</bin:javatype>
                   <bin:getter>
  @@ -306,6 +319,15 @@
   
           </bin:binding-type>
   
  +
  +        <bin:binding-type xsi:type="bin:list-array">
  +            <bin:xmlcomponent>t=SimpleHexBinList@java:com.mytest</bin:xmlcomponent>
  +            <bin:javatype>byte[][]</bin:javatype>
  +            <bin:item-type>
  +                <bin:xmlcomponent>t=hexBinary@http://www.w3.org/2001/XMLSchema</bin:xmlcomponent>
  +                <bin:javatype>byte[]</bin:javatype>
  +            </bin:item-type>
  +        </bin:binding-type>
   
           <bin:binding-type xsi:type="bin:list-array">
               <bin:xmlcomponent>t=SimpleStringList@java:com.mytest</bin:xmlcomponent>
  
  
  
  1.20      +14 -0     xml-xmlbeans/v2/test/cases/marshal/com/mytest/YourClass.java
  
  Index: YourClass.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/cases/marshal/com/mytest/YourClass.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- YourClass.java	19 Apr 2004 06:30:36 -0000	1.19
  +++ YourClass.java	21 Apr 2004 05:29:41 -0000	1.20
  @@ -64,6 +64,9 @@
       private long[] simpleLongArray = {RND.nextLong(),
                                         RND.nextLong()};
   
  +    final byte[] bytes = new byte[]{1, 2, 3, 4, 5, 6};
  +    private byte[][] simpleHexBinArray = {bytes, bytes};
  +
       private Date someDate;
   
       //hack alert
  @@ -349,6 +352,16 @@
           this.someDate = someDate;
       }
   
  +    public byte[][] getSimpleHexBinArray()
  +    {
  +        return simpleHexBinArray;
  +    }
  +
  +    public void setSimpleHexBinArray(byte[][] simpleHexBinArray)
  +    {
  +        this.simpleHexBinArray = simpleHexBinArray;
  +    }
  +
       public boolean equals(Object o)
       {
           if (this == o) return true;
  @@ -419,6 +432,7 @@
               ", stringArray=" + ArrayUtils.arrayToString(stringArray) +
               ", simpleStringArray=" + ArrayUtils.arrayToString(simpleStringArray) +
               ", simpleLongArray=" + ArrayUtils.arrayToString(simpleLongArray) +
  +            ", simpleHexBinArray=" + ArrayUtils.arrayToString(simpleHexBinArray) +
               ", wrappedArrayOne=" + ArrayUtils.arrayToString(wrappedArrayOne) +
               ", myClassArray=" + ArrayUtils.arrayToString(myClassArray) +
               "}";
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org


Mime
View raw message