Source Code Cross Referenced for DynEnumImpl.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.BAD_OPERATION;
031:        import org.omg.CORBA.INTERNAL;
032:        import org.omg.CORBA.TypeCodePackage.BadKind;
033:        import org.omg.CORBA.TypeCodePackage.Bounds;
034:        import org.omg.DynamicAny.*;
035:        import org.omg.DynamicAny.DynAnyPackage.*;
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 DynEnumImpl extends DynAnyBasicImpl implements  DynEnum {
042:            //
043:            // Instance variables
044:            //
045:
046:            // This int and the any value are kept in sync at all times
047:            int currentEnumeratorIndex = NO_INDEX;
048:
049:            //
050:            // Constructors
051:            //
052:
053:            private DynEnumImpl() {
054:                this (null, (Any) null, false);
055:            }
056:
057:            // The current position of a DynEnum is always -1.
058:            protected DynEnumImpl(ORB orb, Any anAny, boolean copyValue) {
059:                super (orb, anAny, copyValue);
060:                index = NO_INDEX;
061:                // The any doesn't have to be initialized. We have a default value in this case.
062:                try {
063:                    currentEnumeratorIndex = any.extract_long();
064:                } catch (BAD_OPERATION e) {
065:                    // _REVISIT_: Fix Me
066:                    currentEnumeratorIndex = 0;
067:                    any.type(any.type());
068:                    any.insert_long(0);
069:                }
070:            }
071:
072:            // Sets the current position to -1 and sets the value of the enumerator
073:            // to the first enumerator value indicated by the TypeCode.
074:            protected DynEnumImpl(ORB orb, TypeCode typeCode) {
075:                super (orb, typeCode);
076:                index = NO_INDEX;
077:                currentEnumeratorIndex = 0;
078:                any.insert_long(0);
079:            }
080:
081:            //
082:            // Utility methods
083:            //
084:
085:            private int memberCount() {
086:                int memberCount = 0;
087:                try {
088:                    memberCount = any.type().member_count();
089:                } catch (BadKind bad) {
090:                }
091:                return memberCount;
092:            }
093:
094:            private String memberName(int i) {
095:                String memberName = null;
096:                try {
097:                    memberName = any.type().member_name(i);
098:                } catch (BadKind bad) {
099:                } catch (Bounds bounds) {
100:                }
101:                return memberName;
102:            }
103:
104:            private int computeCurrentEnumeratorIndex(String value) {
105:                int memberCount = memberCount();
106:                for (int i = 0; i < memberCount; i++) {
107:                    if (memberName(i).equals(value)) {
108:                        return i;
109:                    }
110:                }
111:                return NO_INDEX;
112:            }
113:
114:            //
115:            // DynAny interface methods
116:            //
117:
118:            // Returns always 0 for DynEnum
119:            public int component_count() {
120:                return 0;
121:            }
122:
123:            // Calling current_component on a DynAny that cannot have components,
124:            // such as a DynEnum or an empty exception, raises TypeMismatch.
125:            public org.omg.DynamicAny.DynAny current_component()
126:                    throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch {
127:                if (status == STATUS_DESTROYED) {
128:                    throw wrapper.dynAnyDestroyed();
129:                }
130:                throw new TypeMismatch();
131:            }
132:
133:            //
134:            // DynEnum interface methods
135:            //
136:
137:            // Returns the value of the DynEnum as an IDL identifier.
138:            public String get_as_string() {
139:                if (status == STATUS_DESTROYED) {
140:                    throw wrapper.dynAnyDestroyed();
141:                }
142:                return memberName(currentEnumeratorIndex);
143:            }
144:
145:            // Sets the value of the DynEnum to the enumerated value
146:            // whose IDL identifier is passed in the value parameter.
147:            // If value contains a string that is not a valid IDL identifier
148:            // for the corresponding enumerated type, the operation raises InvalidValue.
149:            public void set_as_string(String value)
150:                    throws org.omg.DynamicAny.DynAnyPackage.InvalidValue {
151:                if (status == STATUS_DESTROYED) {
152:                    throw wrapper.dynAnyDestroyed();
153:                }
154:                int newIndex = computeCurrentEnumeratorIndex(value);
155:                if (newIndex == NO_INDEX) {
156:                    throw new InvalidValue();
157:                }
158:                currentEnumeratorIndex = newIndex;
159:                any.insert_long(newIndex);
160:            }
161:
162:            // Returns the value of the DynEnum as the enumerated values ordinal value.
163:            // Enumerators have ordinal values 0 to n-1,
164:            // as they appear from left to right in the corresponding IDL definition.
165:            public int get_as_ulong() {
166:                if (status == STATUS_DESTROYED) {
167:                    throw wrapper.dynAnyDestroyed();
168:                }
169:                return currentEnumeratorIndex;
170:            }
171:
172:            // Sets the value of the DynEnum as the enumerated values ordinal value.
173:            // If value contains a value that is outside the range of ordinal values
174:            // for the corresponding enumerated type, the operation raises InvalidValue.
175:            public void set_as_ulong(int value)
176:                    throws org.omg.DynamicAny.DynAnyPackage.InvalidValue {
177:                if (status == STATUS_DESTROYED) {
178:                    throw wrapper.dynAnyDestroyed();
179:                }
180:                if (value < 0 || value >= memberCount()) {
181:                    throw new InvalidValue();
182:                }
183:                currentEnumeratorIndex = value;
184:                any.insert_long(value);
185:            }
186:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.