KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > trading > impl > SchemaAdapter


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.impl;
15
16 import java.util.*;
17 import org.omg.CORBA.*;
18 import org.omg.CosTradingRepos.ServiceTypeRepositoryPackage.*;
19 import org.jacorb.trading.constraint.*;
20
21
22 /**
23  * Provides property "schema" information to the expression evaluators
24  */

25 public class SchemaAdapter implements PropertySchema
26 {
27   private Hashtable m_props;
28   private TypeStruct m_type;
29
30
31   private SchemaAdapter()
32   {
33   }
34
35
36   public SchemaAdapter(TypeStruct ts)
37   {
38     m_type = ts;
39     m_props = new Hashtable();
40
41       // build a hashtable of property name and ValueType
42
try {
43       for (int i = 0; i < ts.props.length; i++) {
44         PropStruct ps = ts.props[i];
45         boolean seq = false;
46         int id;
47
48         TCKind kind = ps.value_type.kind();
49
50         if (kind == TCKind.tk_sequence) {
51           seq = true;
52           TypeCode tc = ps.value_type.content_type();
53           kind = tc.kind();
54         }
55
56         id = convertKind(kind);
57         ValueType type = new ValueType(id, seq);
58
59         m_props.put(ts.props[i].name, type);
60       }
61     }
62     catch (org.omg.CORBA.TypeCodePackage.BadKind JavaDoc e) {
63       throw new RuntimeException JavaDoc();
64     }
65   }
66
67
68   /** Determines whether the property exists */
69   public boolean exists(String JavaDoc property)
70   {
71     return m_props.containsKey(property);
72   }
73
74
75   /**
76    * Returns the type of the property, or null if the property
77    * wasn't found
78    */

79   public ValueType getPropertyType(String JavaDoc property)
80   {
81     return (ValueType)m_props.get(property);
82   }
83
84
85   /** Translates a TCKind into a ValueType ID */
86   protected int convertKind(TCKind kind)
87   {
88     int result;
89
90     switch (kind.value()) {
91       case TCKind._tk_short:
92         result = ValueType.SHORT;
93         break;
94
95       case TCKind._tk_long:
96         result = ValueType.LONG;
97         break;
98
99       case TCKind._tk_ushort:
100         result = ValueType.USHORT;
101         break;
102
103       case TCKind._tk_ulong:
104         result = ValueType.ULONG;
105         break;
106
107       case TCKind._tk_float:
108         result = ValueType.FLOAT;
109         break;
110
111       case TCKind._tk_double:
112         result = ValueType.DOUBLE;
113         break;
114
115       case TCKind._tk_boolean:
116         result = ValueType.BOOLEAN;
117         break;
118
119       case TCKind._tk_char:
120         result = ValueType.CHAR;
121         break;
122
123       case TCKind._tk_string:
124         result = ValueType.STRING;
125         break;
126
127       default:
128         result = ValueType.OTHER;
129         break;
130     }
131
132     return result;
133   }
134 }
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
Popular Tags