KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

13 package org.jacorb.trading.client.offers;
14
15 import java.io.*;
16 import java.util.*;
17 import org.omg.CORBA.*;
18 import org.omg.CosTrading.*;
19 import org.omg.CosTrading.RegisterPackage.*;
20 import org.jacorb.trading.client.util.AnyUtil;
21
22 public class describe
23 {
24     public static void main(String JavaDoc[] args)
25     {
26     if (args.length < 2) {
27         usage();
28         return;
29     }
30
31     File f = new File(args[0]);
32     if (! f.exists()) {
33         System.err.println("File " + args[0] + " does not exist");
34         usage();
35     }
36
37     if (! f.isFile()) {
38         System.err.println(args[0] + " is not a file");
39         usage();
40     }
41
42     ORB orb = ORB.init(args, null);
43
44     Register reg = null;
45
46     try {
47         FileReader fr = new FileReader(f);
48         BufferedReader in = new BufferedReader(fr);
49         String JavaDoc ref = in.readLine();
50         fr.close();
51
52         org.omg.CORBA.Object JavaDoc obj = orb.string_to_object(ref);
53         if (obj == null) {
54         System.out.println("Invalid object");
55         System.exit(1);
56         }
57
58         Lookup lookup = LookupHelper.narrow(obj);
59         reg = lookup.register_if();
60     }
61     catch (IOException e) {
62         e.printStackTrace();
63         System.exit(1);
64     }
65
66     try {
67         OfferInfo info = reg.describe(args[1]);
68         PrintWriter pw = new PrintWriter(System.out);
69         pw.println("Service type: " + info.type);
70         pw.println();
71         pw.println("Reference: " + orb.object_to_string(info.reference));
72         pw.println();
73
74         for (int i = 0; i < info.properties.length; i++) {
75         pw.println("Property: " + info.properties[i].name);
76         pw.print(" Type: ");
77         AnyUtil.print(pw, info.properties[i].value.type());
78         pw.println();
79         pw.print(" Value: ");
80         AnyUtil.print(orb, pw, info.properties[i].value);
81         pw.println();
82         pw.println();
83         }
84
85         pw.flush();
86     }
87     catch (IllegalOfferId e) {
88         System.out.println("Illegal offer ID: " + e.id);
89     }
90     catch (UnknownOfferId e) {
91         System.out.println("Unknown offer ID: " + e.id);
92     }
93     catch (ProxyOfferId e) {
94         System.out.println("Offer is a proxy");
95     }
96
97     System.exit(0);
98     }
99
100
101     protected static void usage()
102     {
103     System.out.println("Usage: jtclient.offers.describe iorfile offerid");
104     System.exit(1);
105     }
106 }
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
Popular Tags