Source Code Cross Referenced for DynFixedImpl.java in  » 6.0-JDK-Modules-com.sun » corba » com » sun » corba » se » impl » dynamicany » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules com.sun » corba » com.sun.corba.se.impl.dynamicany 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2000-2003 Sun Microsystems, Inc.  All Rights Reserved.
003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004:         *
005:         * This code is free software; you can redistribute it and/or modify it
006:         * under the terms of the GNU General Public License version 2 only, as
007:         * published by the Free Software Foundation.  Sun designates this
008:         * particular file as subject to the "Classpath" exception as provided
009:         * by Sun in the LICENSE file that accompanied this code.
010:         *
011:         * This code is distributed in the hope that it will be useful, but WITHOUT
012:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013:         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014:         * version 2 for more details (a copy is included in the LICENSE file that
015:         * accompanied this code).
016:         *
017:         * You should have received a copy of the GNU General Public License version
018:         * 2 along with this work; if not, write to the Free Software Foundation,
019:         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020:         *
021:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022:         * CA 95054 USA or visit www.sun.com if you need additional information or
023:         * have any questions.
024:         */
025:
026:        package com.sun.corba.se.impl.dynamicany;
027:
028:        import org.omg.CORBA.TypeCode;
029:        import org.omg.CORBA.Any;
030:        import org.omg.CORBA.NO_IMPLEMENT;
031:        import org.omg.DynamicAny.*;
032:        import org.omg.DynamicAny.DynAnyPackage.*;
033:        import java.math.BigDecimal;
034:        import java.math.BigInteger;
035:        import org.omg.CORBA.TypeCodePackage.BadKind;
036:
037:        import com.sun.corba.se.spi.orb.ORB;
038:        import com.sun.corba.se.spi.logging.CORBALogDomains;
039:        import com.sun.corba.se.impl.logging.ORBUtilSystemException;
040:
041:        public class DynFixedImpl extends DynAnyBasicImpl implements  DynFixed {
042:            //
043:            // Constructors
044:            //
045:
046:            private DynFixedImpl() {
047:                this (null, (Any) null, false);
048:            }
049:
050:            protected DynFixedImpl(ORB orb, Any any, boolean copyValue) {
051:                super (orb, any, copyValue);
052:            }
053:
054:            // Sets the current position to -1 and the value to zero.
055:            protected DynFixedImpl(ORB orb, TypeCode typeCode) {
056:                super (orb, typeCode);
057:                index = NO_INDEX;
058:            }
059:
060:            //
061:            // DynAny interface methods
062:            //
063:            /*
064:             public int component_count() {
065:             return 0;
066:             }
067:             */
068:            //
069:            // DynFixed interface methods
070:            //
071:            public String get_value() {
072:                if (status == STATUS_DESTROYED) {
073:                    throw wrapper.dynAnyDestroyed();
074:                }
075:                return any.extract_fixed().toString();
076:            }
077:
078:            // Initializes the value of the DynFixed.
079:            // The val string must contain a fixed string constant in the same format
080:            // as used for IDL fixed-point literals.
081:            //
082:            // It may consist of an integer part, an optional decimal point,
083:            // a fraction part and an optional letter d or D.
084:            // The integer and fraction parts both must be sequences of decimal (base 10) digits.
085:            // Either the integer part or the fraction part, but not both, may be missing.
086:            //
087:            // If val contains a value whose scale exceeds that of the DynFixed or is not initialized,
088:            // the operation raises InvalidValue.
089:            // The return value is true if val can be represented as the DynFixed without loss of precision.
090:            // If val has more fractional digits than can be represented in the DynFixed,
091:            // fractional digits are truncated and the return value is false.
092:            // If val does not contain a valid fixed-point literal or contains extraneous characters
093:            // other than leading or trailing white space, the operation raises TypeMismatch.
094:            //
095:            public boolean set_value(String val)
096:                    throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch,
097:                    org.omg.DynamicAny.DynAnyPackage.InvalidValue {
098:                if (status == STATUS_DESTROYED) {
099:                    throw wrapper.dynAnyDestroyed();
100:                }
101:                int digits = 0;
102:                int scale = 0;
103:                boolean preservedPrecision = true;
104:                try {
105:                    digits = any.type().fixed_digits();
106:                    scale = any.type().fixed_scale();
107:                } catch (BadKind ex) { // impossible
108:                }
109:                // First get rid of leading or trailing whitespace which is allowed
110:                String string = val.trim();
111:                if (string.length() == 0)
112:                    throw new TypeMismatch();
113:                // Now scan for the sign
114:                String sign = "";
115:                if (string.charAt(0) == '-') {
116:                    sign = "-";
117:                    string = string.substring(1);
118:                } else if (string.charAt(0) == '+') {
119:                    sign = "+";
120:                    string = string.substring(1);
121:                }
122:                // Now get rid of the letter d or D.
123:                int dIndex = string.indexOf('d');
124:                if (dIndex == -1) {
125:                    dIndex = string.indexOf('D');
126:                }
127:                if (dIndex != -1) {
128:                    string = string.substring(0, dIndex);
129:                }
130:                // Just to be sure
131:                if (string.length() == 0)
132:                    throw new TypeMismatch();
133:                // Now look for the dot to determine the integer part
134:                String integerPart;
135:                String fractionPart;
136:                int currentScale;
137:                int currentDigits;
138:                int dotIndex = string.indexOf('.');
139:                if (dotIndex == -1) {
140:                    integerPart = string;
141:                    fractionPart = null;
142:                    currentScale = 0;
143:                    currentDigits = integerPart.length();
144:                } else if (dotIndex == 0) {
145:                    integerPart = null;
146:                    fractionPart = string;
147:                    currentScale = fractionPart.length();
148:                    currentDigits = currentScale;
149:                } else {
150:                    integerPart = string.substring(0, dotIndex);
151:                    fractionPart = string.substring(dotIndex + 1);
152:                    currentScale = fractionPart.length();
153:                    currentDigits = integerPart.length() + currentScale;
154:                }
155:                // Let's see if we have to drop some precision
156:                if (currentDigits > digits) {
157:                    preservedPrecision = false;
158:                    // truncate the fraction part
159:                    if (integerPart.length() < digits) {
160:                        fractionPart = fractionPart.substring(0, digits
161:                                - integerPart.length());
162:                    } else if (integerPart.length() == digits) {
163:                        // currentScale > 0
164:                        // drop the fraction completely
165:                        fractionPart = null;
166:                    } else {
167:                        // integerPart.length() > digits
168:                        // unable to truncate fraction part 
169:                        throw new InvalidValue();
170:                    }
171:                }
172:                // If val contains a value whose scale exceeds that of the DynFixed or is not initialized,
173:                // the operation raises InvalidValue.
174:                // Reinterpreted to mean raise InvalidValue only if the integer part exceeds precision,
175:                // which is handled above (integerPart.length() > digits)
176:                /*
177:                 if (currentScale > scale) {
178:                 throw new InvalidValue("Scale exceeds " + scale);
179:                 }
180:                 */
181:                // Now check whether both parts are valid numbers
182:                BigDecimal result;
183:                try {
184:                    new BigInteger(integerPart);
185:                    if (fractionPart == null) {
186:                        result = new BigDecimal(sign + integerPart);
187:                    } else {
188:                        new BigInteger(fractionPart);
189:                        result = new BigDecimal(sign + integerPart + "."
190:                                + fractionPart);
191:                    }
192:                } catch (NumberFormatException nfe) {
193:                    throw new TypeMismatch();
194:                }
195:                any.insert_fixed(result, any.type());
196:                return preservedPrecision;
197:            }
198:
199:            public String toString() {
200:                int digits = 0;
201:                int scale = 0;
202:                try {
203:                    digits = any.type().fixed_digits();
204:                    scale = any.type().fixed_scale();
205:                } catch (BadKind ex) { // impossible
206:                }
207:                return "DynFixed with value=" + this .get_value() + ", digits="
208:                        + digits + ", scale=" + scale;
209:            }
210:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.