KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > trading > client > seqtest > export


1
2 // Copyright (C) 1998-1999
3
// Object Oriented Concepts, Inc.
4

5 // **********************************************************************
6
//
7
// Copyright (c) 1997
8
// Mark Spruiell (mark@intellisoft.com)
9
//
10
// See the COPYING file for more information
11
//
12
// **********************************************************************
13

14 package org.jacorb.trading.client.seqtest;
15
16 import java.io.*;
17 import java.util.*;
18 import org.omg.CORBA.*;
19 import org.omg.CosTrading.*;
20 import org.omg.CosTrading.RegisterPackage.*;
21
22 public class export
23 {
24     public static void main(String JavaDoc[] args)
25     {
26
27     // ORB orb = ORBLayer.instance().initClient(args);
28
ORB orb = org.omg.CORBA.ORB.init(args, null);
29     Register reg = null;
30
31     try {
32         org.omg.CORBA.Object JavaDoc obj = orb.resolve_initial_references("TradingService");
33
34         if (obj == null) {
35         System.out.println("Invalid object");
36         System.exit(1);
37         }
38
39         Lookup lookup = LookupHelper.narrow(obj);
40         reg = lookup.register_if();
41     }
42     catch (Exception JavaDoc e) {
43         e.printStackTrace();
44         System.exit(1);
45     }
46
47     try {
48         Random rand = new Random();
49
50         for (int i = 0; i < 10; i++) {
51         Property[] props = new Property[4];
52
53         int num = 0;
54         TypeCode tc;
55
56         props[num] = new Property();
57         props[num].name = "shortseq";
58         props[num].value = orb.create_any();
59         short[] shortArr = new short[5];
60         for (int n = 0; n < 5; n++)
61             shortArr[n] = (short)(Math.abs(rand.nextInt()) % 100);
62         ShortSeqHelper.insert(props[num].value, shortArr);
63         num++;
64
65         props[num] = new Property();
66         props[num].name = "floatseq";
67         props[num].value = orb.create_any();
68         float[] floatArr = new float[5];
69         for (int n = 0; n < 5; n++)
70             floatArr[n] = Math.abs(rand.nextFloat());
71         FloatSeqHelper.insert(props[num].value, floatArr);
72         num++;
73
74         props[num] = new Property();
75         props[num].name = "booleanseq";
76         props[num].value = orb.create_any();
77         boolean[] booleanArr = new boolean[5];
78         for (int n = 0; n < 5; n++)
79             booleanArr[n] = (rand.nextInt() % 2 == 0);
80         BooleanSeqHelper.insert(props[num].value, booleanArr);
81         num++;
82
83         props[num] = new Property();
84         props[num].name = "stringseq";
85         props[num].value = orb.create_any();
86         String JavaDoc[] stringArr = new String JavaDoc[5];
87         for (int n = 0; n < 5; n++)
88             stringArr[n] = "s" + n;
89         StringSeqHelper.insert(props[num].value, stringArr);
90         num++;
91
92         String JavaDoc id = reg.export(reg, "SeqSvc", props);
93         System.out.println("Offer id = " + id);
94         }
95     }
96     catch (InvalidObjectRef e) {
97         System.out.println("Invalid object reference");
98     }
99     catch (IllegalServiceType e) {
100         System.out.println("Illegal service type: " + e.type);
101     }
102     catch (UnknownServiceType e) {
103         System.out.println("Unknown service type: " + e.type);
104     }
105     catch (InterfaceTypeMismatch e) {
106         System.out.println("Interface type mismatch: " + e.type);
107     }
108     catch (IllegalPropertyName e) {
109         System.out.println("Illegal property name: " + e.name);
110     }
111     catch (PropertyTypeMismatch e) {
112         System.out.println("Property type mismatch: " + e.prop.name);
113     }
114     catch (ReadonlyDynamicProperty e) {
115         System.out.println("Readonly dynamic property: " + e.name);
116     }
117     catch (MissingMandatoryProperty e) {
118         System.out.println("Missing mandatory property: " + e.name);
119     }
120     catch (DuplicatePropertyName e) {
121         System.out.println("Duplicate property: " + e.name);
122     }
123
124     System.exit(0);
125     }
126
127
128     protected static void usage()
129     {
130     System.out.println("Usage: jtclient.seqtest.export iorfile");
131     System.exit(1);
132     }
133 }
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
Popular Tags