KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > trading > client > dynprop > DynamicPropEvalImpl


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.dynprop;
14
15 import java.util.*;
16 import org.omg.CORBA.*;
17 import org.omg.CosTrading.*;
18 import org.omg.CosTradingDynamic.*;
19
20 /**
21  * A simple implementation of the CosTradingDynamic::DynamicPropEval
22  * interface used for testing purposes.
23  */

24
25 public class DynamicPropEvalImpl
26     extends DynamicPropEvalPOA
27 {
28     private Random m_rand = new Random();
29
30     /**
31      * Overridden from Visibroker's _DynamicPropEvalImplBase; we do this
32      * instead of the unportable super(objectName) we'd have to put in
33      * the constructor; the presence of this method should not affect
34      * use with other ORBs
35      */

36     public String JavaDoc _object_name()
37     {
38     return "DynPropDemo";
39     }
40
41
42     /**
43      * Inherited from DynamicPropEval
44      *
45      * Just return a random value of the requested type
46      */

47     public Any evalDP(String JavaDoc name, TypeCode returned_type, Any extra_info)
48     throws DPEvalFailure
49     {
50     Any result = ORB.init().create_any();
51
52     System.out.println("evalDP(" + name + ")");
53
54     TCKind kind = returned_type.kind();
55     switch (kind.value()) {
56     case TCKind._tk_short:
57         result.insert_short((short)m_rand.nextInt());
58         break;
59     case TCKind._tk_ushort:
60         result.insert_ushort((short)m_rand.nextInt());
61         break;
62     case TCKind._tk_long:
63         result.insert_long(m_rand.nextInt());
64         break;
65     case TCKind._tk_ulong:
66         result.insert_ulong(m_rand.nextInt());
67         break;
68     case TCKind._tk_double:
69         result.insert_double(m_rand.nextDouble());
70         break;
71     case TCKind._tk_float:
72         result.insert_float(m_rand.nextFloat());
73         break;
74     case TCKind._tk_boolean:
75         result.insert_boolean((m_rand.nextInt() % 2 == 0));
76         break;
77     case TCKind._tk_string:
78         result.insert_string("Next int = " + m_rand.nextInt());
79         break;
80     default:
81         throw new DPEvalFailure(name, returned_type, extra_info);
82     }
83
84     return result;
85     }
86 }
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
Popular Tags