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/src/marshal/org/apache/xmlbeans/impl/marshal IntegerToIntTypeConverter.java RuntimeBindingTypeTable.java
Date Wed, 28 Apr 2004 01:46:56 GMT
zieg        2004/04/27 18:46:56

  Modified:    v2/src/binding/org/apache/xmlbeans/impl/binding/bts
                        DefaultBuiltinBindingLoader.java
               v2/src/marshal/org/apache/xmlbeans/impl/marshal
                        RuntimeBindingTypeTable.java
  Added:       v2/src/marshal/org/apache/xmlbeans/impl/marshal
                        IntegerToIntTypeConverter.java
  Log:
  allow mapping xsd:integer based types to primitve int
  
  Revision  Changes    Path
  1.4       +9 -0      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/DefaultBuiltinBindingLoader.java
  
  Index: DefaultBuiltinBindingLoader.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/DefaultBuiltinBindingLoader.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultBuiltinBindingLoader.java	23 Apr 2004 18:52:31 -0000	1.3
  +++ DefaultBuiltinBindingLoader.java	28 Apr 2004 01:46:56 -0000	1.4
  @@ -96,6 +96,15 @@
       addPojoXml("nonNegativeInteger", "java.math.BigInteger");
       addPojoXml("positiveInteger", "java.math.BigInteger");
       addPojoXml("unsignedLong", "java.math.BigInteger");
  +
  +    //some don't like BigInteger...
  +    addPojo("integer", "int");
  +    addPojo("nonPositiveInteger", "int");
  +    addPojo("negativeInteger", "int");
  +    addPojo("nonNegativeInteger", "int");
  +    addPojo("positiveInteger", "int");
  +    addPojo("unsignedLong", "int");
  +
       addPojoXml("unsignedInt", "long");
       addPojoXml("unsignedShort", "int");
       addPojoXml("unsignedByte", "short");
  
  
  
  1.31      +8 -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.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- RuntimeBindingTypeTable.java	27 Apr 2004 02:36:14 -0000	1.30
  +++ RuntimeBindingTypeTable.java	28 Apr 2004 01:46:56 -0000	1.31
  @@ -248,6 +248,14 @@
           addBuiltinType("positiveInteger", bigint, integer_conv);
           addBuiltinType("unsignedLong", bigint, integer_conv);
   
  +        final TypeConverter i2iconv = new IntegerToIntTypeConverter();
  +        addBuiltinType("integer", int.class, i2iconv);
  +        addBuiltinType("nonPositiveInteger", int.class, i2iconv);
  +        addBuiltinType("negativeInteger", int.class, i2iconv);
  +        addBuiltinType("nonNegativeInteger", int.class, i2iconv);
  +        addBuiltinType("positiveInteger", int.class, i2iconv);
  +        addBuiltinType("unsignedLong", int.class, i2iconv);
  +
           addBuiltinType("decimal", BigDecimal.class,
                          new DecimalTypeConverter());
   
  
  
  
  1.1                  xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/IntegerToIntTypeConverter.java
  
  Index: IntegerToIntTypeConverter.java
  ===================================================================
  /*   Copyright 2004 The Apache Software Foundation
   *
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
   *   Unless required by applicable law or agreed to in writing, software
   *   distributed under the License is distributed on an "AS IS" BASIS,
   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *   See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.xmlbeans.impl.marshal;
  
  import org.apache.xmlbeans.XmlException;
  import org.apache.xmlbeans.impl.common.InvalidLexicalValueException;
  import org.apache.xmlbeans.impl.util.XsTypeConverter;
  
  import java.math.BigInteger;
  
  /**
   * used to convert xsd:integer and derived types to/from java.lang.Integer
   *
   * follows BigInteger.intValue() semantics for out of range values (for now)
   */
  final class IntegerToIntTypeConverter
      extends BaseSimpleTypeConverter
  {
      protected Object getObject(UnmarshalResult context) throws XmlException
      {
          return BigIntegerToInteger(context.getBigIntegerValue());
      }
  
      public Object unmarshalAttribute(UnmarshalResult context) throws XmlException
      {
          return BigIntegerToInteger(context.getAttributeBigIntegerValue());
      }
  
      public Object unmarshalAttribute(CharSequence lexical_value,
                                       UnmarshalResult result)
          throws XmlException
      {
          try {
              return XsTypeConverter.lexInteger(lexical_value);
          }
          catch (NumberFormatException ne) {
              throw new InvalidLexicalValueException(ne, result.getLocation());
          }
      }
  
      //non simple types can throw a runtime exception
      public CharSequence print(Object value, MarshalResult result)
      {
          Number val = (Number)value;
          return XsTypeConverter.printInt(val.intValue());
      }
  
  
      private static Object BigIntegerToInteger(BigInteger val)
      {
          final int ival = val.intValue();
          return new Integer(ival);
      }
  }
  
  
  

---------------------------------------------------------------------
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