Source Code Cross Referenced for Client.java in  » Collaboration » JacORB » demo » dynany » 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 » Collaboration » JacORB » demo.dynany 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package demo.dynany;
002:
003:        import java.io.*;
004:        import org.omg.CORBA.Any;
005:        import org.omg.CORBA.TypeCode;
006:        import org.omg.CORBA.TCKind;
007:        import org.omg.DynamicAny.*;
008:        import org.omg.CosNaming.*;
009:
010:        public class Client {
011:            public static AnyServer s = null;
012:
013:            public static void main(String[] args) {
014:                try {
015:                    org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);
016:                    DynAnyFactory dynFactory = DynAnyFactoryHelper.narrow(orb
017:                            .resolve_initial_references("DynAnyFactory"));
018:
019:                    NamingContextExt nc = NamingContextExtHelper.narrow(orb
020:                            .resolve_initial_references("NameService"));
021:
022:                    AnyServer s = AnyServerHelper.narrow(nc.resolve(nc
023:                            .to_name("DynAnyServer.example")));
024:
025:                    // char
026:
027:                    DynAny dyn_any = dynFactory
028:                            .create_dyn_any_from_type_code(orb
029:                                    .get_primitive_tc(TCKind.tk_char));
030:
031:                    dyn_any.insert_char('c');
032:                    System.out.println("Passing a char..."
033:                            + s.generic(dyn_any.to_any()));
034:
035:                    // enum
036:
037:                    TypeCode enum_tc = orb.create_enum_tc("IDL:colors:1.0",
038:                            "colors", new String[] { "red", "green", "blue",
039:                                    "mauve", "magenta", "salmon" });
040:
041:                    DynEnum dyn_enum = (DynEnum) dynFactory
042:                            .create_dyn_any_from_type_code(enum_tc);
043:
044:                    dyn_enum.set_as_string("salmon");
045:                    System.out.println("Passing an enum value..."
046:                            + s.generic(dyn_enum.to_any()));
047:
048:                    // sequence
049:
050:                    TypeCode seq_tc = orb.create_sequence_tc(2, orb
051:                            .create_string_tc(0));
052:                    DynSequence dyn_seq = (DynSequence) dynFactory
053:                            .create_dyn_any_from_type_code(seq_tc);
054:
055:                    Any[] string_sequence = new Any[2];
056:                    string_sequence[0] = orb.create_any();
057:                    string_sequence[1] = orb.create_any();
058:                    string_sequence[0].insert_string("hello");
059:                    string_sequence[1].insert_string("world");
060:                    dyn_seq.set_elements(string_sequence);
061:
062:                    System.out.println("Passing a sequence of length "
063:                            + dyn_seq.component_count() + "..."
064:                            + s.generic(dyn_seq.to_any()));
065:                    dyn_seq.destroy();
066:
067:                    // test the primitive get/set operations for DynSequences
068:
069:                    seq_tc = orb.create_sequence_tc(1, orb
070:                            .get_primitive_tc(org.omg.CORBA.TCKind.tk_boolean));
071:
072:                    dyn_seq = (DynSequence) dynFactory
073:                            .create_dyn_any_from_type_code(seq_tc);
074:
075:                    dyn_seq.set_length(1);
076:                    dyn_seq.insert_boolean(true);
077:                    dyn_seq.destroy();
078:
079:                    // array
080:
081:                    TypeCode array_tc = orb.create_array_tc(3, orb
082:                            .create_string_tc(0));
083:                    DynArray dyn_array = (DynArray) dynFactory
084:                            .create_dyn_any_from_type_code(array_tc);
085:
086:                    string_sequence = new Any[3];
087:                    string_sequence[0] = orb.create_any();
088:                    string_sequence[1] = orb.create_any();
089:                    string_sequence[2] = orb.create_any();
090:                    string_sequence[0].insert_string("hello");
091:                    string_sequence[1].insert_string("another");
092:                    string_sequence[2].insert_string("world");
093:                    dyn_array.set_elements(string_sequence);
094:
095:                    System.out.println("Passing an array of length "
096:                            + dyn_array.component_count() + "..."
097:                            + s.generic(dyn_array.to_any()));
098:                    dyn_array.destroy();
099:
100:                    // struct
101:
102:                    /*
103:                     * the hardest part is coming up with a correct call to 
104:                     * create the struct's TypeCode, which is normally
105:                     * statically generated into the helper class 
106:                     */
107:
108:                    TypeCode struct_tc = orb
109:                            .create_struct_tc(
110:                                    "IDL:Node:1.0",
111:                                    "Node",
112:                                    new org.omg.CORBA.StructMember[] {
113:                                            new org.omg.CORBA.StructMember(
114:                                                    "first",
115:                                                    org.omg.CORBA.ORB
116:                                                            .init()
117:                                                            .create_string_tc(0),
118:                                                    null),
119:                                            new org.omg.CORBA.StructMember(
120:                                                    "second",
121:                                                    org.omg.CORBA.ORB
122:                                                            .init()
123:                                                            .create_sequence_tc(
124:                                                                    0,
125:                                                                    org.omg.CORBA.ORB
126:                                                                            .init()
127:                                                                            .create_recursive_tc(
128:                                                                                    "IDL:Node:1.0")),
129:                                                    null) });
130:
131:                    DynStruct dyn_struct = (DynStruct) dynFactory
132:                            .create_dyn_any_from_type_code(struct_tc);
133:
134:                    // Create a list of name value pairs that holds the struct members.
135:                    // This struct has two members, so we have 2 array elements
136:
137:                    // the first struct member is a string, 
138:                    // the member name is "first"
139:
140:                    NameValuePair[] nvp_seq = new NameValuePair[2];
141:                    Any first_member_any = orb.create_any();
142:                    first_member_any.insert_string("first");
143:                    nvp_seq[0] = new NameValuePair("first", first_member_any);
144:
145:                    /*
146:                     the second member is a recursive sequence, ie. the element 
147:                         type of the sequence is that of the enclosing  struct, the
148:                         member name is "second". We'll leave that sequence empty,
149:                         but we have to provide an initialized any for the empty 
150:                         sequence, so we create a DynAny that initializes an any 
151:                         as an empty sequence
152:                     */
153:
154:                    DynSequence second_member = (DynSequence) dynFactory
155:                            .create_dyn_any_from_type_code(struct_tc
156:                                    .member_type(1));
157:                    nvp_seq[1] = new NameValuePair("second", second_member
158:                            .to_any());
159:
160:                    // insert the nvp list into the DynStruct
161:                    dyn_struct.set_members(nvp_seq);
162:
163:                    System.out.println("Passing a struct..."
164:                            + s.generic(dyn_struct.to_any()));
165:
166:                    // test the primitive get/set operations for DynStruct
167:
168:                    dyn_struct.seek(0);
169:                    dyn_struct.insert_string("newly inserted");
170:                    System.out.println("Passing the struct again..."
171:                            + s.generic(dyn_struct.to_any()));
172:
173:                    dyn_struct.destroy();
174:                    second_member.destroy();
175:
176:                    /*              union            */
177:
178:                    // setting up TypeCodes gets even more complicated,
179:                    // but you asked for it...
180:                    org.omg.CORBA.UnionMember[] members = new org.omg.CORBA.UnionMember[3];
181:
182:                    org.omg.CORBA.Any label_any;
183:                    label_any = orb.create_any();
184:                    label_any.insert_octet((byte) 0); // 0 byte means default case
185:
186:                    members[0] = new org.omg.CORBA.UnionMember("s", label_any,
187:                            org.omg.CORBA.ORB.init().get_primitive_tc(
188:                                    org.omg.CORBA.TCKind.from_int(2)), null);
189:
190:                    label_any = org.omg.CORBA.ORB.init().create_any();
191:                    label_any.insert_char('l');
192:                    members[1] = new org.omg.CORBA.UnionMember("l", label_any,
193:                            org.omg.CORBA.ORB.init().get_primitive_tc(
194:                                    org.omg.CORBA.TCKind.from_int(3)), null);
195:
196:                    label_any = org.omg.CORBA.ORB.init().create_any();
197:                    label_any.insert_char('f');
198:
199:                    members[2] = new org.omg.CORBA.UnionMember("f", label_any,
200:                            org.omg.CORBA.ORB.init().get_primitive_tc(
201:                                    org.omg.CORBA.TCKind.from_int(6)), null);
202:
203:                    TypeCode union_tc = org.omg.CORBA.ORB.init()
204:                            .create_union_tc(
205:                                    "IDL:Nums:1.0",
206:                                    "Nums",
207:                                    org.omg.CORBA.ORB.init().get_primitive_tc(
208:                                            org.omg.CORBA.TCKind.from_int(9)),
209:                                    members);
210:
211:                    DynUnion dyn_union = (DynUnion) dynFactory
212:                            .create_dyn_any_from_type_code(union_tc);
213:
214:                    Any discriminator_any = orb.create_any();
215:                    discriminator_any.insert_char('l');
216:                    DynAny discriminator = dynFactory
217:                            .create_dyn_any(discriminator_any);
218:
219:                    //dyn_enum.set_as_string("salmon");
220:                    //	    DynAny discriminator = dyn_enum;
221:
222:                    dyn_union.set_discriminator(discriminator);
223:                    dyn_union.member().insert_long(4711);
224:                    System.out.println("Passing a union..."
225:                            + s.generic(dyn_union.to_any()));
226:
227:                    // setting a different union value
228:
229:                    dyn_union.set_to_default_member();
230:                    dyn_union.member().insert_short((short) 19);
231:                    System.out.println("Passing the  union again..."
232:                            + s.generic(dyn_union.to_any()));
233:
234:                } catch (Exception e) {
235:                    e.printStackTrace();
236:                }
237:            }
238:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.