KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > omg > CORBA > FixedHolder


1 package org.omg.CORBA;
2
3 /**
4  * Holder class for fixed point types.
5  *
6  */

7
8 public class FixedHolder
9    implements org.omg.CORBA.portable.Streamable JavaDoc
10 {
11    public java.math.BigDecimal JavaDoc value;
12
13    public FixedHolder(){}
14
15    public FixedHolder(java.math.BigDecimal JavaDoc o)
16    {
17       value = o;
18    }
19
20    public TypeCode JavaDoc _type()
21    {
22       String JavaDoc s = value.toString();
23       short digits = 0;
24       short scale = 0;
25
26       if ( ! s.startsWith("0.") )
27       {
28          for( int i = 0; i < s.length(); i++ )
29          {
30             if ( s.charAt(i) == '.' )
31             {
32                break;
33             }
34             digits++;
35          }
36       }
37
38       int decimal = s.indexOf('.');
39       if ( decimal != -1 )
40       {
41          s = s.substring( decimal + 1 );
42          for( int i = 0; i < s.length(); i++ )
43          {
44             digits++;
45             scale++;
46          }
47       }
48       
49       return ORB.init().create_fixed_tc( digits, scale );
50    }
51
52    public void _read(org.omg.CORBA.portable.InputStream JavaDoc in)
53    {
54       value = in.read_fixed();
55    }
56
57    public void _write(org.omg.CORBA.portable.OutputStream JavaDoc out)
58    {
59       out.write_fixed(value);
60    }
61
62 }
63
Popular Tags