KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > trading > constraint > ValueFactory


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.constraint;
15
16
17 public class ValueFactory
18 {
19   private ValueFactory()
20   {
21   }
22
23
24   public static Value create(int typeId, Object JavaDoc value)
25   {
26     Value result = null;
27
28     switch (typeId) {
29       case ValueType.BOOLEAN: {
30           Boolean JavaDoc b = (Boolean JavaDoc)value;
31           result = createBoolean(b.booleanValue());
32         }
33         break;
34
35       case ValueType.SHORT: {
36           Integer JavaDoc i = (Integer JavaDoc)value;
37           result = createShort(i.intValue());
38         }
39         break;
40
41       case ValueType.USHORT: {
42           Integer JavaDoc i = (Integer JavaDoc)value;
43           result = createUShort(i.intValue());
44         }
45         break;
46
47       case ValueType.LONG: {
48           Integer JavaDoc i = (Integer JavaDoc)value;
49           result = createLong(i.intValue());
50         }
51         break;
52
53       case ValueType.ULONG: {
54           Long JavaDoc l = (Long JavaDoc)value;
55           result = createULong(l.longValue());
56         }
57         break;
58
59       case ValueType.FLOAT: {
60           Float JavaDoc f = (Float JavaDoc)value;
61           result = createFloat(f.floatValue());
62         }
63         break;
64
65       case ValueType.DOUBLE: {
66           Double JavaDoc d = (Double JavaDoc)value;
67           result = createDouble(d.doubleValue());
68         }
69         break;
70
71       case ValueType.CHAR: {
72           Character JavaDoc c = (Character JavaDoc)value;
73           result = createChar(c.charValue());
74         }
75         break;
76
77       case ValueType.STRING: {
78           String JavaDoc s = (String JavaDoc)value;
79           result = createString(s);
80         }
81         break;
82     }
83
84     return result;
85   }
86
87
88   public static Value createBoolean(boolean value)
89   {
90     return new BooleanValue(value);
91   }
92
93
94   public static Value createShort(int value)
95   {
96     return new ShortValue(value);
97   }
98
99
100   public static Value createUShort(int value)
101   {
102     return new UShortValue(value);
103   }
104
105
106   public static Value createLong(int value)
107   {
108     return new LongValue(value);
109   }
110
111
112   public static Value createULong(long value)
113   {
114     return new ULongValue(value);
115   }
116
117
118   public static Value createFloat(float value)
119   {
120     return new FloatValue(value);
121   }
122
123
124   public static Value createDouble(double value)
125   {
126     return new DoubleValue(value);
127   }
128
129
130   public static Value createChar(char value)
131   {
132     return new CharValue(value);
133   }
134
135
136   public static Value createString(String JavaDoc value)
137   {
138     return new StringValue(value);
139   }
140 }
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
Popular Tags