1 26 27 package org.objectweb.openccm.explorer.CosTrading.gui; 28 29 import javax.swing.table.AbstractTableModel ; 30 31 import org.omg.CORBA.TCKind ; 32 import org.omg.CosTrading.Property; 33 34 40 public class OfferPropsTableModel 41 extends AbstractTableModel 42 { 43 44 50 51 protected final String [] names = new String [] {"property", "value"}; 52 53 54 protected java.util.List [] rows; 55 56 62 67 public OfferPropsTableModel(Property[] props) { 68 rows = new java.util.List [props.length]; 69 70 for (int i=0 ; i<props.length ; i++) { 71 rows[i] = new java.util.LinkedList (); 72 rows[i].add(props[i].name); 73 rows[i].add(extractFromAny(props[i].value).toString()); 74 } 75 } 76 77 83 91 protected Object extractFromAny(org.omg.CORBA.Any a) { 92 93 org.omg.CORBA.TypeCode tc = a.type(); 94 while (tc.kind() == TCKind.tk_alias) { 95 try { 96 tc = tc.content_type(); 97 } catch (org.omg.CORBA.TypeCodePackage.BadKind ex) {} 98 } 99 int kind = tc.kind().value(); 100 switch (kind) { 101 case org.omg.CORBA.TCKind._tk_boolean : return new Boolean (a.extract_boolean()); 102 case org.omg.CORBA.TCKind._tk_long : return new Integer (a.extract_long()); 103 case org.omg.CORBA.TCKind._tk_float : return new Float (a.extract_float()); 104 case org.omg.CORBA.TCKind._tk_double : return new Double (a.extract_double()); 105 case org.omg.CORBA.TCKind._tk_short : return new Short (a.extract_short()); 106 case org.omg.CORBA.TCKind._tk_char : return new Character (a.extract_char()); 107 case org.omg.CORBA.TCKind._tk_octet : return new Byte (a.extract_octet()); 108 case org.omg.CORBA.TCKind._tk_wchar : return new Character (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 (a.extract_ulong()); 112 case org.omg.CORBA.TCKind._tk_ushort : return new Short (a.extract_ushort()); 113 case org.omg.CORBA.TCKind._tk_sequence : { 114 try { 117 118 String image = "("; 119 120 org.omg.CORBA.TypeCode content_tc = null; 121 try { 122 content_tc = tc.content_type(); 123 } catch (org.omg.CORBA.TypeCodePackage.BadKind ex) { 124 } 126 127 org.omg.DynamicAny.DynAny dyn_any = org.objectweb.openccm.corba.TheDynamicAnyFactory.getFactory().create_dyn_any(a); 128 org.omg.DynamicAny.DynSequence 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 ex) { 220 } catch (org.omg.DynamicAny.DynAnyPackage.InvalidValue ew) { 222 } catch (org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode ex) { 224 } 226 } 227 } 228 return ""; 229 } 230 231 237 public int getColumnCount() { return names.length; } 239 public String getColumnName(int col) { return names[col]; } 240 public int getRowCount() { return rows.length;} 241 public Object getValueAt(int row, int col) { return rows[row].get(col); } 242 }; 243 | Popular Tags |