1 19 20 28 29 package org.netbeans.modules.xml.schema.refactoring.ui; 30 31 import java.text.MessageFormat ; 32 import java.util.List ; 33 import org.netbeans.modules.xml.schema.model.ComplexContent; 34 import org.netbeans.modules.xml.schema.model.ComplexContentRestriction; 35 import org.netbeans.modules.xml.schema.model.ComplexExtension; 36 import org.netbeans.modules.xml.schema.model.ElementReference; 37 import org.netbeans.modules.xml.schema.model.GlobalAttribute; 38 import org.netbeans.modules.xml.schema.model.GlobalAttributeGroup; 39 import org.netbeans.modules.xml.schema.model.GlobalComplexType; 40 import org.netbeans.modules.xml.schema.model.GlobalElement; 41 import org.netbeans.modules.xml.schema.model.GlobalGroup; 42 import org.netbeans.modules.xml.schema.model.GlobalSimpleType; 43 import org.netbeans.modules.xml.schema.model.GlobalType; 44 import org.netbeans.modules.xml.schema.model.LocalAttribute; 45 import org.netbeans.modules.xml.schema.model.LocalComplexType; 46 import org.netbeans.modules.xml.schema.model.LocalElement; 47 import org.netbeans.modules.xml.schema.model.LocalSimpleType; 48 import org.netbeans.modules.xml.schema.model.Redefine; 49 import org.netbeans.modules.xml.schema.model.Schema; 50 import org.netbeans.modules.xml.schema.model.Sequence; 51 import org.netbeans.modules.xml.schema.model.SimpleContent; 52 import org.netbeans.modules.xml.schema.model.SimpleContentRestriction; 53 import org.netbeans.modules.xml.schema.model.SimpleExtension; 54 import org.netbeans.modules.xml.schema.model.SimpleTypeRestriction; 55 import org.netbeans.modules.xml.schema.model.Union; 56 import org.netbeans.modules.xml.schema.model.visitor.DefaultSchemaVisitor; 57 import org.netbeans.modules.xml.xam.Component; 58 import org.netbeans.modules.xml.xam.dom.NamedComponentReference; 59 import org.netbeans.modules.xml.xam.Named; 60 import org.openide.ErrorManager; 61 import org.openide.util.NbBundle; 62 63 67 public class DisplayInfoVisitor extends DefaultSchemaVisitor { 68 69 private DisplayInfo info; 70 private static final String EMPTY_STRING = ""; 72 73 public DisplayInfoVisitor() { 74 75 } 76 77 public DisplayInfo getDisplayInfo(Component comp){ 78 info = new DisplayInfo(); 79 if (comp instanceof Named){ 80 info.setName(((Named)comp).getName()); 81 } 82 if (comp instanceof GlobalSimpleType){ 83 visit((GlobalSimpleType)comp); 84 } else if (comp instanceof GlobalComplexType){ 85 visit((GlobalComplexType)comp); 86 } else if (comp instanceof LocalComplexType){ 87 visit((LocalComplexType)comp); 88 } else if (comp instanceof GlobalElement){ 89 visit((GlobalElement)comp); 90 } else if (comp instanceof LocalElement){ 91 visit((LocalElement)comp); 92 } else if (comp instanceof Sequence){ 93 visit((Sequence)comp); 94 } else if (comp instanceof ComplexContent){ 95 visit((ComplexContent)comp); 96 } else if (comp instanceof SimpleContentRestriction){ 97 visit((SimpleContentRestriction)comp); 98 } else if (comp instanceof ComplexContentRestriction){ 99 visit((ComplexContentRestriction)comp); 100 } else if (comp instanceof SimpleContent){ 101 visit((SimpleContent)comp); 102 } else if (comp instanceof ComplexExtension){ 103 visit((ComplexExtension)comp); 104 } else if (comp instanceof SimpleExtension){ 105 visit((SimpleExtension)comp); 106 } else if (comp instanceof SimpleTypeRestriction){ 107 visit((SimpleTypeRestriction)comp); 108 } else if (comp instanceof LocalSimpleType){ 109 visit((LocalSimpleType)comp); 110 } else if (comp instanceof GlobalAttribute){ 111 visit((GlobalAttribute)comp); 112 } else if (comp instanceof GlobalAttributeGroup){ 113 visit((GlobalAttributeGroup)comp); 114 } else if (comp instanceof GlobalGroup){ 115 visit((GlobalGroup)comp); 116 } else if (comp instanceof LocalAttribute){ 117 visit((LocalAttribute)comp); 118 } else if (comp instanceof ElementReference){ 119 visit((ElementReference)comp); 120 } else if (comp instanceof Union){ 121 visit((Union)comp); 122 } else if (comp instanceof Schema){ 123 visit((Schema)comp); 124 } else if (comp instanceof Redefine){ 125 visit((Redefine)comp); 126 } else { 127 ErrorManager.getDefault().log(ErrorManager.WARNING, 128 "DisplayInfoVisitor unrecognized type " 129 + comp==null?"":comp.getClass().toString()); } 131 return info; 132 133 } 134 135 @Override 136 public void visit(GlobalSimpleType gst) { 137 super.visit(gst); 138 info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class, 139 "LBL_Global_Simple_Type")); 140 } 141 142 143 @Override 144 public void visit(GlobalElement ge) { 145 146 super.visit(ge); 147 info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class, 148 "LBL_Global_Element")); 149 150 NamedComponentReference type = ge.getType(); 151 if (type != null){ 152 GlobalType gt = ge.getType().get(); 153 info.setElementType(gt==null? 155 NbBundle.getMessage(DisplayInfoVisitor.class,"LBL_Undetermined_Type") 156 :gt.getName()); 157 } 158 159 } 160 161 162 @Override 163 public void visit(GlobalComplexType gct) { 164 165 super.visit(gct); 166 info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class, 167 "LBL_Global_Complex_Type")); 168 } 169 170 @Override 171 public void visit(LocalElement le) { 172 173 super.visit(le); 174 info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class, 175 "LBL_Local_Element")); 176 177 NamedComponentReference type = le.getType(); 178 if (type != null){ 179 GlobalType gt = le.getType().get(); 180 info.setElementType(gt==null? 182 NbBundle.getMessage(DisplayInfoVisitor.class,"LBL_Undetermined_Type") 183 :gt.getName()); 184 } 185 } 186 187 @Override 188 public void visit(Sequence s) { 189 190 super.visit(s); 191 info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class, 192 "LBL_Sequence")); 193 } 194 195 @Override 196 public void visit(LocalComplexType type) { 197 198 super.visit(type); 199 info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class, 200 "LBL_Local_Complex_Type")); 201 } 202 203 @Override 204 public void visit(ComplexContent cc) { 205 206 super.visit(cc); 207 info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class, 208 "LBL_ComplexContent")); 209 } 210 211 @Override 212 public void visit(SimpleContentRestriction scr) { 213 214 super.visit(scr); 215 info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class, 216 "LBL_SimpleContentRestriction")); 217 } 218 219 @Override 220 public void visit(ComplexContentRestriction ccr) { 221 222 super.visit(ccr); 223 info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class, 224 "LBL_ComplexContentRestriction")); 225 } 226 227 @Override 228 public void visit(SimpleContent sc) { 229 230 super.visit(sc); 231 info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class, 232 "LBL_SimpleContent")); 233 } 234 235 @Override 236 public void visit(ComplexExtension ce) { 237 238 super.visit(ce); 239 info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class, 240 "LBL_ComplexExtension")); 241 } 242 243 @Override 244 public void visit(SimpleExtension se) { 245 246 super.visit(se); 247 info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class, 248 "LBL_SimpleExtension")); 249 } 250 251 @Override 252 public void visit(SimpleTypeRestriction str) { 253 254 super.visit(str); 255 info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class, 256 "LBL_SimpleTypeRestriction")); 257 } 258 259 @Override 260 public void visit(LocalSimpleType type) { 261 262 super.visit(type); 263 info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class, 264 "LBL_LocalSimpleType")); 265 } 266 267 @Override 268 public void visit(GlobalAttribute ga) { 269 270 super.visit(ga); 271 info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class, 272 "LBL_GlobalAttribute")); 273 274 NamedComponentReference type = ga.getType(); 275 if (type != null){ 276 GlobalType gt = ga.getType().get(); 277 info.setElementType(gt==null? 279 NbBundle.getMessage(DisplayInfoVisitor.class,"LBL_Undetermined_Type") 280 :gt.getName()); 281 } 282 } 283 284 @Override 285 public void visit(GlobalAttributeGroup gag) { 286 287 super.visit(gag); 288 info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class, 289 "LBL_GlobalAttributeGroup")); 290 } 291 292 @Override 293 public void visit(GlobalGroup gd) { 294 295 super.visit(gd); 296 info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class, 297 "LBL_GlobalGroup")); 298 } 299 300 @Override 301 public void visit(LocalAttribute la) { 302 303 super.visit(la); 304 info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class, 305 "LBL_LocalAttribute")); 306 307 NamedComponentReference type = la.getType(); 308 if (type != null){ 309 GlobalType gt = la.getType().get(); 310 info.setElementType(gt==null? 312 NbBundle.getMessage(DisplayInfoVisitor.class,"LBL_Undetermined_Type") 313 :gt.getName()); 314 } 315 } 316 317 public void visit(ElementReference er) { 318 super.visit(er); 319 info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class, 321 "LBL_Local_Element")); 322 323 info.setElementType(NbBundle.getMessage(DisplayInfoVisitor.class, 324 "LBL_Global_Element")); 325 326 NamedComponentReference<GlobalElement> ref = 327 er.getRef(); 328 if (ref != null){ 329 info.setName(MessageFormat.format(NbBundle.getMessage( 330 DisplayInfoVisitor.class, 331 "LBL_References_Ref"), 332 new Object [] {ref.getQName().getLocalPart()})); 333 } 334 335 336 337 } 338 339 public void visit(Schema schema) { 340 super.visit(schema); 341 info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class, 343 "LBL_Schema")); 344 345 info.setName(schema.getTargetNamespace()); 346 347 348 349 } 350 351 public void visit(Union union) { 352 super.visit(union); 353 info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class, 355 "LBL_Union")); 356 357 List <NamedComponentReference<GlobalSimpleType>> members = 358 union.getMemberTypes(); 359 StringBuffer names = new StringBuffer (NbBundle.getMessage(DisplayInfoVisitor.class, 360 "LBL_Union_Members")); 361 names.append(" "); if (members.size() < 1){ 363 names.append(NbBundle.getMessage(DisplayInfoVisitor.class, 364 "LBL_Union_Members_None")); 365 } 366 else { 367 for (NamedComponentReference n:members){ 368 names.append(n.getQName().toString()); 369 names.append(" "); } 371 } 372 info.setName(names.toString()); 375 376 } 377 378 379 public void visit(Redefine redefine) { 380 super.visit(redefine); 381 info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class, 383 "LBL_Redefine")); 384 385 info.setName(NbBundle.getMessage(DisplayInfoVisitor.class, 386 "LBL_Redefinition")); 387 388 } 389 390 391 public static class DisplayInfo { 392 393 private String name = EMPTY_STRING; 394 private String compType = EMPTY_STRING; 395 private String elementType = EMPTY_STRING; 396 397 398 public DisplayInfo() { 399 400 } 401 402 406 public String getName() { 407 408 return this.name; 409 } 410 411 415 public void setName(String name) { 416 if (name == null ){ 417 name = EMPTY_STRING; 418 } 419 420 this.name = name; 421 } 422 423 424 428 public String getCompType() { 429 430 return this.compType; 431 } 432 433 437 public void setCompType(String compType) { 438 if (compType == null ){ 439 compType = EMPTY_STRING; 440 } 441 442 this.compType = compType; 443 } 444 445 446 451 public String getElementType() { 452 453 return this.elementType; 454 } 455 456 460 public void setElementType(String elementType) { 461 if (elementType == null ){ 462 elementType = EMPTY_STRING; 463 } 464 465 this.elementType = elementType; 466 } 467 468 } 469 470 471 } 472 | Popular Tags |