This patch allows for the exposing of the actual value of decimal and related datatypes.


Naela Nissar
XML Parser Development

IBM Toronto Lab

8200 Warden Ave., Markham, ON

Phone: 905-413-4376



Index: DecimalDV.java
===================================================================
RCS file: 
/home/cvspublic/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DecimalDV.java,v
retrieving revision 1.11
diff -u -r1.11 DecimalDV.java
--- DecimalDV.java      6 Oct 2004 14:56:46 -0000       1.11
+++ DecimalDV.java      29 Dec 2004 17:16:20 -0000
@@ -16,8 +16,12 @@
 
 package org.apache.xerces.impl.dv.xs;
 
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
 import org.apache.xerces.impl.dv.InvalidDatatypeValueException;
 import org.apache.xerces.impl.dv.ValidationContext;
+import org.apache.xerces.xs.datatypes.XSDecimal;
 
 /**
  * Represent the schema type "decimal"
@@ -56,7 +60,7 @@
     }
     
     // Avoid using the heavy-weight java.math.BigDecimal
-    static class XDecimal {
+    static class XDecimal implements XSDecimal {
         // sign: 0 for vlaue 0; 1 for positive values; -1 for negative values
         int sign = 1;
         // total digits. >= 1
@@ -279,6 +283,49 @@
                 }
             }
             canonical = buffer.toString();
+        }
+        
+        public BigDecimal getBigDecimal() {
+               return new BigDecimal(ivalue + "." + fvalue);
+        }
+        
+        public BigInteger getBigInteger() throws NumberFormatException {
+               if (fracDigits!=0) {
+                       throw new NumberFormatException();
+               }
+               return new BigInteger(ivalue);
+        }
+        
+        public long getLong() throws NumberFormatException {
+               if (fracDigits!=0) {
+                       throw new NumberFormatException();
+               }
+               return Long.parseLong(ivalue);
+        }
+        
+        public int getInt() throws NumberFormatException {
+               if (fracDigits!=0) {
+                       throw new NumberFormatException();
+               }
+               return Integer.parseInt(ivalue);
+        }
+        
+        public short getShort() throws NumberFormatException {
+               if (fracDigits!=0) {
+                       throw new NumberFormatException();
+               }
+               return Short.parseShort(ivalue);
+        }
+        
+        public byte getByte() throws NumberFormatException {
+               if (fracDigits!=0) {
+                       throw new NumberFormatException();
+               }
+               return Byte.parseByte(ivalue);
+        }
+        
+        public int getTotalDigits() {
+               return totalDigits;
         }
     }
 } // class DecimalDV




Index: XSDecimal.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.xerces.xs.datatypes;

import java.math.BigDecimal;
import java.math.BigInteger;



/**
 * <p><b>EXPERIMENTAL: This interface should not be considered stable.
 * It is likely it may be altered or replaced in the future.</b></p>
 * 
 * <p>Interface to expose the value of 'decimal' and related datatypes.</p>
 * 
 * @author Naela Nissar, IBM
 * 
 * @version 
 */
public interface XSDecimal {
     
        /**
     * @return  A <code>BigDecimal</code> representation of the string value 
formed by
     * concatenating the <code>ivalue</code> and <code>fvalue</code> strings
     */
    public BigDecimal getBigDecimal();
    
    /**
     * @return A <code>BigInteger</code> representation of the 
<code>ivalue</code> string 
     * @exception NumberFormatException if <code>fracDigits</code> is nonzero 
     */
    public BigInteger getBigInteger() throws NumberFormatException;
    
    /**
     * @return the long value represented by the <code>ivalue</code> string
     * @exception NumberFormatException if <code>fracDigits</code> is nonzero
     */
    public long getLong() throws NumberFormatException;
    
    /**
     * @return the integer value represented by the <code>ivalue</code> string
     * @exception NumberFormatException if <code>fracDigits</code> is nonzero
     */
    public int getInt() throws NumberFormatException ;
    
    /**
     * @return the short value represented by the <code>ivalue</code> string
     * @exception NumberFormatException if <code>fracDigits</code> is nonzero
     */
    public short getShort() throws NumberFormatException;
    
    /**
     * @return the byte value represented by the <code>ivalue</code> string
     * @exception NumberFormatException if <code>fracDigits</code> is nonzero
     */
    public byte getByte() throws NumberFormatException;
    
    /**
     * @return total digits 
     */
    public int getTotalDigits();
    
    
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to