KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > trading > client > dynprop > 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.dynprop;
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 import org.omg.CosTradingDynamic.*;
22 import org.omg.CosTradingRepos.*;
23 import org.omg.CosTradingRepos.ServiceTypeRepositoryPackage.*;
24
25 public class export
26 {
27     public static void main(String JavaDoc[] args)
28     {
29     if (args.length < 1)
30     {
31         usage();
32     }
33
34     File dynPropFile = new File(args[0]);
35
36     if (! dynPropFile.exists()) {
37         System.err.println("File " + args[0] + " does not exist");
38         usage();
39     }
40
41     if (! dynPropFile.isFile()) {
42         System.err.println(args[0] + " is not a file");
43         usage();
44     }
45
46     ORB orb = ORB.init(args,null);
47
48     Register reg = null;
49     DynamicPropEval eval = null;
50         ServiceTypeRepository repos = null;
51     try {
52         FileReader fr;
53         BufferedReader in;
54         org.omg.CORBA.Object JavaDoc obj;
55
56         // read the IOR for the DynamicPropEval object from a file
57
fr = new FileReader(dynPropFile);
58         in = new BufferedReader(fr);
59         String JavaDoc dynPropRef = in.readLine();
60         fr.close();
61
62         obj = orb.resolve_initial_references("TradingService");
63
64         if (obj == null)
65         {
66         System.out.println("Invalid lookup object");
67         System.exit(1);
68         }
69
70         Lookup lookup = LookupHelper.narrow(obj);
71         reg = lookup.register_if();
72
73         obj = orb.string_to_object(dynPropRef);
74         if (obj == null) {
75         System.out.println("Invalid dynamic prop eval object");
76         System.exit(1);
77         }
78
79         eval = DynamicPropEvalHelper.narrow(obj);
80
81             repos = ServiceTypeRepositoryHelper.narrow(lookup.type_repos());
82     }
83     catch (org.omg.CORBA.ORBPackage.InvalidName JavaDoc e)
84     {
85         System.out.println("Invalid initial reference name");
86     }
87     catch (IOException e)
88     {
89         e.printStackTrace();
90         System.exit(1);
91     }
92
93     try {
94         Random rand = new Random();
95
96         PropStruct[] _props = new PropStruct[3];
97         _props[0] = new PropStruct();
98         _props[0].name = "name";
99         _props[0].value_type = orb.get_primitive_tc(TCKind.tk_string);
100         _props[0].mode = PropertyMode.PROP_MANDATORY;
101         
102         _props[1] = new PropStruct();
103         _props[1].name = "cost";
104         _props[1].value_type = orb.get_primitive_tc(TCKind.tk_double);
105         _props[1].mode = PropertyMode.PROP_MANDATORY;
106
107         _props[2] = new PropStruct();
108         _props[2].name = "version";
109         _props[2].value_type = orb.get_primitive_tc(TCKind.tk_string);
110         _props[2].mode = PropertyMode.PROP_MANDATORY;
111
112         repos.add_type("SubSvc", "IDL:SubSvc:1.0", _props, new String JavaDoc[0]);
113
114         for (int i = 0; i < 10; i++) {
115         Property[] props = new Property[3];
116
117         int num = 0;
118         TypeCode tc;
119
120         // the "name" property
121
props[num] = new Property();
122         props[num].name = "name";
123         props[num].value = orb.create_any();
124         props[num].value.insert_string("dyn offer #" + i);
125         num++;
126
127         // the "cost" property is dynamic
128
props[num] = new Property();
129         props[num].name = "cost";
130         props[num].value = orb.create_any();
131         DynamicProp dp = new DynamicProp();
132         dp.eval_if = eval;
133         dp.returned_type = orb.get_primitive_tc(TCKind.tk_double);
134         dp.extra_info = orb.create_any();
135         dp.extra_info.insert_string("Dummy");
136         DynamicPropHelper.insert(props[num].value, dp);
137         num++;
138
139         // the "version" property
140
props[num] = new Property();
141         props[num].name = "version";
142         props[num].value = orb.create_any();
143         props[num].value.insert_string("1.0" + i);
144         num++;
145
146         String JavaDoc id = reg.export(reg, "SubSvc", props);
147         System.out.println("Offer id = " + id);
148         }
149     }
150     catch (InvalidObjectRef e) {
151         System.out.println("Invalid object reference");
152     }
153     catch (IllegalServiceType e) {
154         System.out.println("Illegal service type: " + e.type);
155     }
156     catch (UnknownServiceType e) {
157         System.out.println("Unknown service type: " + e.type);
158     }
159     catch (org.omg.CosTrading.RegisterPackage.InterfaceTypeMismatch e) {
160         System.out.println("Interface type mismatch: " + e.type);
161     }
162     catch (IllegalPropertyName e) {
163         System.out.println("Illegal property name: " + e.name);
164     }
165     catch (PropertyTypeMismatch e) {
166         System.out.println("Property type mismatch: " + e.prop.name);
167     }
168     catch (ReadonlyDynamicProperty e) {
169         System.out.println("Readonly dynamic property: " + e.name);
170     }
171     catch (MissingMandatoryProperty e) {
172         System.out.println("Missing mandatory property: " + e.name);
173     }
174     catch (DuplicatePropertyName e) {
175         System.out.println("Duplicate property: " + e.name);
176     }
177     catch (Exception JavaDoc e) {
178         System.out.println("Other: " + e);
179     }
180
181     System.exit(0);
182     }
183
184
185     protected static void usage()
186     {
187     System.out.println( "Usage: org.jacorb.trading.client.dynprop.export <dynprop-iorfile>" );
188     System.exit(1);
189     }
190 }
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
Popular Tags