KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > explorer > CosTrading > gui > OfferPropsTableModel


1 /*===========================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2003 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s):Sylvain Leblanc.
23 Contributor(s): ______________________________________.
24
25 ===========================================================================*/

26
27 package org.objectweb.openccm.explorer.CosTrading.gui;
28
29 import javax.swing.table.AbstractTableModel JavaDoc;
30
31 import org.omg.CORBA.TCKind JavaDoc;
32 import org.omg.CosTrading.Property;
33
34 /**
35  * A Table model for service type properties.
36  *
37  * @author <a HREF="mailto:Sylvain.Leblanc@lifl.fr">Sylvain Leblanc</a>
38  * @version 0.1
39  */

40 public class OfferPropsTableModel
41      extends AbstractTableModel JavaDoc
42 {
43
44     // ==================================================================
45
//
46
// Internal state.
47
//
48
// ==================================================================
49

50     /** Names of the cols: "property", "value". */
51     protected final String JavaDoc[] names = new String JavaDoc[] {"property", "value"};
52
53     /** Rows values in a list. */
54     protected java.util.List JavaDoc[] rows;
55
56     // ==================================================================
57
//
58
// Constructors.
59
//
60
// ==================================================================
61

62     /**
63      * Default constructor.
64      *
65      * @param props The properties to display in the table.
66      */

67     public OfferPropsTableModel(Property[] props) {
68         rows = new java.util.List JavaDoc[props.length];
69             
70         for (int i=0 ; i<props.length ; i++) {
71             rows[i] = new java.util.LinkedList JavaDoc();
72             rows[i].add(props[i].name);
73             rows[i].add(extractFromAny(props[i].value).toString());
74         }
75     }
76
77     // ==================================================================
78
//
79
// Internal methods.
80
//
81
// ==================================================================
82

83     /**
84      * Internal method to extract something from an any.
85      *
86      * @param a The any containing the value to extract.
87      *
88      * @return An object related to the any value that can be
89      * displayed.
90      */

91     protected Object JavaDoc extractFromAny(org.omg.CORBA.Any JavaDoc a) {
92         
93         org.omg.CORBA.TypeCode JavaDoc tc = a.type();
94         while (tc.kind() == TCKind.tk_alias) {
95             try {
96                 tc = tc.content_type();
97             } catch (org.omg.CORBA.TypeCodePackage.BadKind JavaDoc ex) {}
98         }
99         int kind = tc.kind().value();
100         switch (kind) {
101             case org.omg.CORBA.TCKind._tk_boolean : return new Boolean JavaDoc(a.extract_boolean());
102             case org.omg.CORBA.TCKind._tk_long : return new Integer JavaDoc(a.extract_long());
103             case org.omg.CORBA.TCKind._tk_float : return new Float JavaDoc(a.extract_float());
104             case org.omg.CORBA.TCKind._tk_double : return new Double JavaDoc(a.extract_double());
105             case org.omg.CORBA.TCKind._tk_short : return new Short JavaDoc(a.extract_short());
106             case org.omg.CORBA.TCKind._tk_char : return new Character JavaDoc(a.extract_char());
107             case org.omg.CORBA.TCKind._tk_octet : return new Byte JavaDoc(a.extract_octet());
108             case org.omg.CORBA.TCKind._tk_wchar : return new Character JavaDoc(a.extract_char());
109             case org.omg.CORBA.TCKind._tk_string : return a.extract_string();
110             case org.omg.CORBA.TCKind._tk_wstring : return a.extract_string();
111             case org.omg.CORBA.TCKind._tk_ulong : return new Integer JavaDoc(a.extract_ulong());
112             case org.omg.CORBA.TCKind._tk_ushort : return new Short JavaDoc(a.extract_ushort());
113             case org.omg.CORBA.TCKind._tk_sequence : {
114                 // Here we make the assumption of values inserted in "()" and separeted by ","
115
// e.g. (10, 5, 54, 67) is a sequence of long.
116
try {
117
118                     String JavaDoc image = "(";
119
120                     org.omg.CORBA.TypeCode JavaDoc content_tc = null;
121                     try {
122                         content_tc = tc.content_type();
123                     } catch (org.omg.CORBA.TypeCodePackage.BadKind JavaDoc ex) {
124                         // cannot happened here
125
}
126             
127                     org.omg.DynamicAny.DynAny JavaDoc dyn_any = org.objectweb.openccm.corba.TheDynamicAnyFactory.getFactory().create_dyn_any(a);
128                     org.omg.DynamicAny.DynSequence JavaDoc dyn_seq = org.omg.DynamicAny.DynSequenceHelper.narrow(dyn_any);
129                     dyn_seq.rewind();
130                     int length = dyn_seq.get_length();
131                     switch (content_tc.kind().value()) {
132                         case TCKind._tk_short : {
133                             for (int i=0 ; i<length ; dyn_seq.next(), i++) {
134                                 image = image + dyn_seq.current_component().get_short() + ", ";
135                             }
136                             break;
137                         }
138                         case TCKind._tk_ushort : {
139                             for (int i=0 ; i<length ; dyn_seq.next(), i++) {
140                                 image = image + dyn_seq.current_component().get_ushort() + ", ";
141                             }
142                             break;
143                         }
144                         case TCKind._tk_long : {
145                             for (int i=0 ; i<length ; dyn_seq.next(), i++) {
146                                 image = image + dyn_seq.current_component().get_long() + ", ";
147                             }
148                             break;
149                         }
150                         case TCKind._tk_ulong : {
151                             for (int i=0 ; i<length ; dyn_seq.next(), i++) {
152                                 image = image + dyn_seq.current_component().get_ulong() + ", ";
153                             }
154                             break;
155                         }
156                         case TCKind._tk_longlong : {
157                             for (int i=0 ; i<length ; dyn_seq.next(), i++) {
158                                 image = image + dyn_seq.current_component().get_longlong() + ", ";
159                             }
160                             break;
161                         }
162                         case TCKind._tk_ulonglong : {
163                             for (int i=0 ; i<length ; dyn_seq.next(), i++) {
164                                 image = image + dyn_seq.current_component().get_ulonglong() + ", ";
165                             }
166                             break;
167                         }
168                         case TCKind._tk_float : {
169                             for (int i=0 ; i<length ; dyn_seq.next(), i++) {
170                                 image = image + dyn_seq.current_component().get_float() + ", ";
171                             }
172                             break;
173                         }
174                         case TCKind._tk_double : {
175                             for (int i=0 ; i<length ; dyn_seq.next(), i++) {
176                                 image = image + dyn_seq.current_component().get_double() + ", ";
177                             }
178                             break;
179                         }
180                         case TCKind._tk_wchar : {
181                             for (int i=0 ; i<length ; dyn_seq.next(), i++) {
182                                 image = image + "'" + dyn_seq.current_component().get_wchar() + "', ";
183                             }
184                             break;
185                         }
186                         case TCKind._tk_char : {
187                             for (int i=0 ; i<length ; dyn_seq.next(), i++) {
188                                 image = image + "'" + dyn_seq.current_component().get_char() + "', ";
189                             }
190                             break;
191                         }
192                         case TCKind._tk_wstring : {
193                             for (int i=0 ; i<length ; dyn_seq.next(), i++) {
194                                 image = image + "\"" + dyn_seq.current_component().get_wstring() + "\", ";
195                             }
196                             break;
197                         }
198                         case TCKind._tk_string : {
199                             for (int i=0 ; i<length ; dyn_seq.next(), i++) {
200                                 image = image + "\"" + dyn_seq.current_component().get_string() + "\", ";
201                             }
202                             break;
203                         }
204                         case TCKind._tk_octet : {
205                             for (int i=0 ; i<length ; dyn_seq.next(), i++) {
206                                 image = image + dyn_seq.current_component().get_octet() + ", ";
207                             }
208                             break;
209                         }
210                         case TCKind._tk_boolean : {
211                             for (int i=0 ; i<length ; dyn_seq.next(), i++) {
212                                 image = image + dyn_seq.current_component().get_boolean() + ", ";
213                             }
214                             break;
215                         }
216                     }
217                     image = image.substring(0, image.length()-2) + ")";
218                     return image;
219                 } catch (org.omg.DynamicAny.DynAnyPackage.TypeMismatch JavaDoc ex) {
220                     // should not happen
221
} catch (org.omg.DynamicAny.DynAnyPackage.InvalidValue JavaDoc ew) {
222                     // should not happen
223
} catch (org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode JavaDoc ex) {
224                     // should not happen
225
}
226             }
227         }
228         return "";
229     }
230
231     // ==================================================================
232
//
233
// Public methods.
234
//
235
// ==================================================================
236

237     // some overrides
238
public int getColumnCount() { return names.length; }
239     public String JavaDoc getColumnName(int col) { return names[col]; }
240     public int getRowCount() { return rows.length;}
241     public Object JavaDoc getValueAt(int row, int col) { return rows[row].get(col); }
242 };
243
Popular Tags