KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

15 package org.jacorb.trading.client.offers;
16
17 import java.io.*;
18 import java.util.*;
19 import org.omg.CORBA.*;
20 import org.omg.CosTrading.*;
21 import org.omg.CosTrading.RegisterPackage.*;
22 // GB: import jtport.ORBLayer;
23

24
25 public class export
26 {
27   public static void main(String JavaDoc[] args)
28   {
29     if (args.length < 1) {
30       usage();
31       return;
32     }
33
34     File f = new File(args[0]);
35     if (! f.exists()) {
36       System.err.println("File " + args[0] + " does not exist");
37       usage();
38     }
39
40     if (! f.isFile()) {
41       System.err.println(args[0] + " is not a file");
42       usage();
43     }
44
45     ORB orb = ORB.init(args, null);
46
47     Register reg = null;
48
49     try {
50       FileReader fr = new FileReader(f);
51       BufferedReader in = new BufferedReader(fr);
52       String JavaDoc ref = in.readLine();
53       fr.close();
54
55       org.omg.CORBA.Object JavaDoc obj = orb.string_to_object(ref);
56       if (obj == null) {
57         System.out.println("Invalid object");
58         System.exit(1);
59       }
60
61       Lookup lookup = LookupHelper.narrow(obj);
62       reg = lookup.register_if();
63     }
64     catch (IOException e) {
65       e.printStackTrace();
66       System.exit(1);
67     }
68
69     try {
70       Random rand = new Random();
71
72       for (int i = 0; i < 10; i++) {
73         Property[] props;
74
75           // only use the 'cost' property for even numbers; allows
76
// testing of the 'exist' operator in constraint expressions
77
if (i % 2 == 0)
78           props = new Property[4];
79         else
80           props = new Property[3];
81
82         int num = 0;
83         TypeCode tc;
84
85         props[num] = new Property();
86         props[num].name = "name";
87         props[num].value = orb.create_any();
88         props[num].value.insert_string("name #" + i);
89         num++;
90
91         if (i % 2 == 0) {
92           props[num] = new Property();
93           props[num].name = "cost";
94           props[num].value = orb.create_any();
95           props[num].value.insert_double(Math.abs(rand.nextDouble()));
96           num++;
97         }
98
99         props[num] = new Property();
100         props[num].name = "version";
101         props[num].value = orb.create_any();
102         props[num].value.insert_string("1.0" + i);
103         num++;
104
105         props[num] = new Property();
106         props[num].name = "count";
107         props[num].value = orb.create_any();
108         props[num].value.insert_long(Math.abs(rand.nextInt()) % 100);
109         num++;
110
111         String JavaDoc id = reg.export(reg, "SubSvc", props);
112         System.out.println("Offer id = " + id);
113       }
114     }
115     catch (InvalidObjectRef e) {
116       System.out.println("Invalid object reference");
117     }
118     catch (IllegalServiceType e) {
119       System.out.println("Illegal service type: " + e.type);
120     }
121     catch (UnknownServiceType e) {
122       System.out.println("Unknown service type: " + e.type);
123     }
124     catch (InterfaceTypeMismatch e) {
125       System.out.println("Interface type mismatch: " + e.type);
126     }
127     catch (IllegalPropertyName e) {
128       System.out.println("Illegal property name: " + e.name);
129     }
130     catch (PropertyTypeMismatch e) {
131       System.out.println("Property type mismatch: " + e.prop.name);
132     }
133     catch (ReadonlyDynamicProperty e) {
134       System.out.println("Readonly dynamic property: " + e.name);
135     }
136     catch (MissingMandatoryProperty e) {
137       System.out.println("Missing mandatory property: " + e.name);
138     }
139     catch (DuplicatePropertyName e) {
140       System.out.println("Duplicate property: " + e.name);
141     }
142
143     System.exit(0);
144   }
145
146
147   protected static void usage()
148   {
149     System.out.println("Usage: jtclient.offers.export iorfile");
150     System.exit(1);
151   }
152 }
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
Popular Tags