1 11 12 package org.eclipse.core.internal.model; 13 14 import java.util.*; 15 import javax.xml.parsers.SAXParserFactory ; 16 import org.eclipse.core.internal.runtime.*; 17 import org.eclipse.core.runtime.*; 18 import org.eclipse.core.runtime.model.*; 19 import org.eclipse.osgi.util.NLS; 20 import org.osgi.framework.ServiceReference; 21 import org.xml.sax.*; 22 import org.xml.sax.helpers.DefaultHandler ; 23 24 public class PluginParser extends DefaultHandler implements IModel { 25 26 Factory factory; 28 29 String locationName = null; 32 33 Stack stateStack = new Stack(); 35 36 Stack objectStack = new Stack(); 39 40 Locator locator = null; 41 42 private static final int IGNORED_ELEMENT_STATE = 0; 44 private static final int INITIAL_STATE = 1; 45 private static final int PLUGIN_STATE = 2; 46 private static final int PLUGIN_RUNTIME_STATE = 3; 47 private static final int PLUGIN_REQUIRES_STATE = 4; 48 private static final int PLUGIN_EXTENSION_POINT_STATE = 5; 49 private static final int PLUGIN_EXTENSION_STATE = 6; 50 private static final int RUNTIME_LIBRARY_STATE = 7; 51 private static final int LIBRARY_EXPORT_STATE = 8; 52 private static final int PLUGIN_REQUIRES_IMPORT_STATE = 9; 54 private static final int CONFIGURATION_ELEMENT_STATE = 10; 55 private static final int FRAGMENT_STATE = 11; 56 57 private static final int EXTENSION_POINT_INDEX = 0; 61 private static final int EXTENSION_INDEX = 1; 62 private static final int LAST_INDEX = 1; 63 private Vector scratchVectors[] = new Vector[LAST_INDEX + 1]; 64 65 private ServiceReference parserReference; 66 67 public PluginParser(Factory factory) { 68 super(); 69 this.factory = factory; 70 } 71 72 83 public void setDocumentLocator(Locator locator) { 84 this.locator = locator; 85 } 86 87 public void characters(char[] ch, int start, int length) { 88 int state = ((Integer ) stateStack.peek()).intValue(); 89 if (state != CONFIGURATION_ELEMENT_STATE) 90 return; 91 if (state == CONFIGURATION_ELEMENT_STATE) { 92 ConfigurationElementModel currentConfigElement = (ConfigurationElementModel) objectStack.peek(); 95 String value = new String (ch, start, length); 96 String oldValue = currentConfigElement.getValueAsIs(); 97 if (oldValue == null) { 98 if (value.trim().length() != 0) 99 currentConfigElement.setValue(value); 100 } else { 101 currentConfigElement.setValue(oldValue + value); 102 } 103 } 104 } 105 106 public void endDocument() { 107 } 108 109 public void endElement(String uri, String elementName, String qName) { 110 switch (((Integer ) stateStack.peek()).intValue()) { 111 case IGNORED_ELEMENT_STATE : 112 stateStack.pop(); 113 break; 114 case INITIAL_STATE : 115 internalError(NLS.bind(Messages.parse_internalStack, elementName)); 117 break; 118 case PLUGIN_STATE : 119 case FRAGMENT_STATE : 120 if (elementName.equals(PLUGIN) || elementName.equals(FRAGMENT)) { 121 stateStack.pop(); 122 PluginModel root = (PluginModel) objectStack.peek(); 123 124 Vector extPointVector = scratchVectors[EXTENSION_POINT_INDEX]; 126 if (extPointVector.size() > 0) { 127 root.setDeclaredExtensionPoints((ExtensionPointModel[]) extPointVector.toArray(new ExtensionPointModel[extPointVector.size()])); 128 scratchVectors[EXTENSION_POINT_INDEX].removeAllElements(); 129 } 130 131 Vector extVector = scratchVectors[EXTENSION_INDEX]; 133 if (extVector.size() > 0) { 134 root.setDeclaredExtensions((ExtensionModel[]) extVector.toArray(new ExtensionModel[extVector.size()])); 135 scratchVectors[EXTENSION_INDEX].removeAllElements(); 136 } 137 } 138 break; 139 case PLUGIN_RUNTIME_STATE : 140 if (elementName.equals(RUNTIME)) { 141 stateStack.pop(); 142 Vector libVector = (Vector) objectStack.pop(); 145 if (libVector.size() > 0) { 146 PluginModel model = (PluginModel) objectStack.peek(); 147 model.setRuntime((LibraryModel[]) libVector.toArray(new LibraryModel[libVector.size()])); 148 } 149 } 150 break; 151 case PLUGIN_REQUIRES_STATE : 152 if (elementName.equals(PLUGIN_REQUIRES)) { 153 stateStack.pop(); 154 Vector importVector = (Vector) objectStack.pop(); 157 if (importVector.size() > 0) { 158 PluginModel parentDescriptor = (PluginModel) objectStack.peek(); 159 parentDescriptor.setRequires((PluginPrerequisiteModel[]) importVector.toArray(new PluginPrerequisiteModel[importVector.size()])); 160 } 161 } 162 break; 163 case PLUGIN_EXTENSION_POINT_STATE : 164 if (elementName.equals(EXTENSION_POINT)) { 165 stateStack.pop(); 166 } 167 break; 168 case PLUGIN_EXTENSION_STATE : 169 if (elementName.equals(EXTENSION)) { 170 stateStack.pop(); 171 ExtensionModel currentExtension = (ExtensionModel) objectStack.pop(); 173 PluginModel parent = (PluginModel) objectStack.peek(); 174 currentExtension.setParent(parent); 175 scratchVectors[EXTENSION_INDEX].addElement(currentExtension); 176 } 177 break; 178 case RUNTIME_LIBRARY_STATE : 179 if (elementName.equals(LIBRARY)) { 180 LibraryModel curLibrary = (LibraryModel) objectStack.pop(); 181 Vector exportsVector = (Vector) objectStack.pop(); 183 if (exportsVector.size() > 0) { 184 curLibrary.setExports((String []) exportsVector.toArray(new String [exportsVector.size()])); 185 } 186 187 Vector libraryVector = (Vector) objectStack.peek(); 189 libraryVector.addElement(curLibrary); 190 stateStack.pop(); 191 } 192 break; 193 case LIBRARY_EXPORT_STATE : 194 if (elementName.equals(LIBRARY_EXPORT)) { 195 stateStack.pop(); 196 } 197 break; 198 case PLUGIN_REQUIRES_IMPORT_STATE : 199 if (elementName.equals(PLUGIN_REQUIRES_IMPORT)) { 200 stateStack.pop(); 201 } 202 break; 203 case CONFIGURATION_ELEMENT_STATE : 204 stateStack.pop(); 206 ConfigurationElementModel currentConfigElement = (ConfigurationElementModel) objectStack.pop(); 208 209 String value = currentConfigElement.getValueAsIs(); 210 if (value != null) { 211 currentConfigElement.setValue(value.trim()); 212 } 213 214 Object parent = objectStack.peek(); 215 currentConfigElement.setParent(parent); 216 if (((Integer ) stateStack.peek()).intValue() == PLUGIN_EXTENSION_STATE) { 217 ConfigurationElementModel[] oldValues = (ConfigurationElementModel[]) ((ExtensionModel) parent).getSubElements(); 219 int size = (oldValues == null) ? 0 : oldValues.length; 220 ConfigurationElementModel[] newValues = new ConfigurationElementModel[size + 1]; 221 for (int i = 0; i < size; i++) { 222 newValues[i] = oldValues[i]; 223 } 224 newValues[size] = currentConfigElement; 225 ((ExtensionModel) parent).setSubElements(newValues); 226 } else { 227 ConfigurationElementModel[] oldValues = (ConfigurationElementModel[]) ((ConfigurationElementModel) parent).getSubElements(); 228 int size = (oldValues == null) ? 0 : oldValues.length; 229 ConfigurationElementModel[] newValues = new ConfigurationElementModel[size + 1]; 230 for (int i = 0; i < size; i++) { 231 newValues[i] = oldValues[i]; 232 } 233 newValues[size] = currentConfigElement; 234 ((ConfigurationElementModel) parent).setSubElements(newValues); 235 } 236 break; 237 } 238 } 239 240 public void error(SAXParseException ex) { 241 logStatus(ex); 242 } 243 244 public void fatalError(SAXParseException ex) throws SAXException { 245 logStatus(ex); 246 throw ex; 247 } 248 249 public void handleExtensionPointState(String elementName, Attributes attributes) { 250 251 stateStack.push(new Integer (IGNORED_ELEMENT_STATE)); 253 internalError(NLS.bind(Messages.parse_unknownElement, EXTENSION_POINT, elementName)); 254 } 255 256 public void handleExtensionState(String elementName, Attributes attributes) { 257 258 stateStack.push(new Integer (CONFIGURATION_ELEMENT_STATE)); 266 267 ConfigurationElementModel currentConfigurationElement = factory.createConfigurationElement(); 269 objectStack.push(currentConfigurationElement); 270 currentConfigurationElement.setName(elementName); 271 272 parseConfigurationElementAttributes(attributes); 277 } 278 279 public void handleInitialState(String elementName, Attributes attributes) { 280 if (elementName.equals(PLUGIN)) { 281 stateStack.push(new Integer (PLUGIN_STATE)); 282 parsePluginAttributes(attributes); 283 } else if (elementName.equals(FRAGMENT)) { 284 stateStack.push(new Integer (FRAGMENT_STATE)); 285 parseFragmentAttributes(attributes); 286 } else { 287 stateStack.push(new Integer (IGNORED_ELEMENT_STATE)); 288 internalError(NLS.bind(Messages.parse_unknownTopElement, elementName)); 289 } 290 } 291 292 public void handleLibraryExportState(String elementName, Attributes attributes) { 293 294 stateStack.push(new Integer (IGNORED_ELEMENT_STATE)); 296 internalError(NLS.bind(Messages.parse_unknownElement, LIBRARY_EXPORT, elementName)); 297 } 298 299 public void handleLibraryState(String elementName, Attributes attributes) { 300 if (elementName.equals(LIBRARY_EXPORT)) { 301 stateStack.push(new Integer (LIBRARY_EXPORT_STATE)); 303 LibraryModel currentLib = (LibraryModel) objectStack.peek(); 305 306 if (attributes == null) 307 return; 308 309 String maskValue = null; 310 311 int len = attributes.getLength(); 313 for (int i = 0; i < len; i++) { 314 String attrName = attributes.getLocalName(i); 315 String attrValue = attributes.getValue(i).trim(); 316 317 if (attrName.equals(LIBRARY_EXPORT_MASK)) 318 maskValue = attrValue; 319 else 320 internalError(NLS.bind(Messages.parse_unknownAttribute, LIBRARY, attrName)); 321 } 322 323 objectStack.pop(); 326 Vector exportMask = (Vector) objectStack.peek(); 327 objectStack.push(currentLib); 329 if ((maskValue != null) && (!exportMask.contains(maskValue))) 330 exportMask.addElement(maskValue); 331 return; 332 } 333 334 if (elementName.equals(LIBRARY_PACKAGES)) { 335 LibraryModel currentLib = (LibraryModel) objectStack.peek(); 336 if (attributes == null) 337 return; 338 for (int i = 0; i < attributes.getLength(); i++) { 339 if (LIBRARY_PACKAGES_PREFIXES.equals(attributes.getLocalName(i))) { 340 String line = attributes.getValue(i); 341 String [] prefixes = getArrayFromList(line); 342 currentLib.setPackagePrefixes(prefixes); 343 } 344 } 345 return; 346 } 347 348 stateStack.push(new Integer (IGNORED_ELEMENT_STATE)); 350 internalError(NLS.bind(Messages.parse_unknownElement, LIBRARY, elementName)); 351 return; 352 } 353 354 357 protected static String [] getArrayFromList(String line) { 358 if (line == null || line.trim().length() == 0) 359 return null; 360 Vector list = new Vector(); 361 StringTokenizer tokens = new StringTokenizer(line, ","); while (tokens.hasMoreTokens()) { 363 String token = tokens.nextToken().trim(); 364 if (token.length() != 0) 365 list.addElement(token); 366 } 367 return list.isEmpty() ? null : (String []) list.toArray(new String [0]); 368 } 369 370 public void handlePluginState(String elementName, Attributes attributes) { 371 372 if (elementName.equals(RUNTIME)) { 373 Object whatIsIt = objectStack.peek(); 375 if (((whatIsIt instanceof PluginDescriptorModel) && (((PluginDescriptorModel) objectStack.peek()).getRuntime() != null)) || ((whatIsIt instanceof PluginFragmentModel) && (((PluginFragmentModel) objectStack.peek()).getRuntime() != null))) { 376 stateStack.push(new Integer (IGNORED_ELEMENT_STATE)); 379 return; 380 } 381 stateStack.push(new Integer (PLUGIN_RUNTIME_STATE)); 382 objectStack.push(new Vector()); 384 return; 385 } 386 if (elementName.equals(PLUGIN_REQUIRES)) { 387 stateStack.push(new Integer (PLUGIN_REQUIRES_STATE)); 388 objectStack.push(new Vector()); 390 parseRequiresAttributes(attributes); 391 return; 392 } 393 if (elementName.equals(EXTENSION_POINT)) { 394 stateStack.push(new Integer (PLUGIN_EXTENSION_POINT_STATE)); 395 parseExtensionPointAttributes(attributes); 396 return; 397 } 398 if (elementName.equals(EXTENSION)) { 399 stateStack.push(new Integer (PLUGIN_EXTENSION_STATE)); 400 parseExtensionAttributes(attributes); 401 return; 402 } 403 404 stateStack.push(new Integer (IGNORED_ELEMENT_STATE)); 407 internalError(NLS.bind(Messages.parse_unknownElement, PLUGIN + " / " + FRAGMENT, elementName)); } 409 410 public void handleRequiresImportState(String elementName, Attributes attributes) { 411 412 stateStack.push(new Integer (IGNORED_ELEMENT_STATE)); 414 internalError(NLS.bind(Messages.parse_unknownElement, PLUGIN_REQUIRES_IMPORT, elementName)); 415 } 416 417 public void handleRequiresState(String elementName, Attributes attributes) { 418 419 if (elementName.equals(PLUGIN_REQUIRES_IMPORT)) { 420 parsePluginRequiresImport(attributes); 421 return; 422 } 423 stateStack.push(new Integer (IGNORED_ELEMENT_STATE)); 426 internalError(NLS.bind(Messages.parse_unknownElement, PLUGIN_REQUIRES, elementName)); 427 } 428 429 public void handleRuntimeState(String elementName, Attributes attributes) { 430 431 if (elementName.equals(LIBRARY)) { 432 stateStack.push(new Integer (RUNTIME_LIBRARY_STATE)); 434 parseLibraryAttributes(attributes); 436 return; 437 } 438 stateStack.push(new Integer (IGNORED_ELEMENT_STATE)); 441 internalError(NLS.bind(Messages.parse_unknownElement, RUNTIME, elementName)); 442 } 443 444 public void ignoreableWhitespace(char[] ch, int start, int length) { 445 } 446 447 private void logStatus(SAXParseException ex) { 448 String name = ex.getSystemId(); 449 if (name == null) 450 name = locationName; 451 if (name == null) 452 name = ""; else 454 name = name.substring(1 + name.lastIndexOf("/")); 456 String msg; 457 if (name.equals("")) msg = NLS.bind(Messages.parse_error, ex.getMessage()); 459 else 460 msg = NLS.bind(Messages.parse_errorNameLineColumn, (new String [] {name, Integer.toString(ex.getLineNumber()), Integer.toString(ex.getColumnNumber()), ex.getMessage()})); 461 factory.error(new Status(IStatus.WARNING, Platform.PI_RUNTIME, Platform.PARSE_PROBLEM, msg, ex)); 462 } 463 464 synchronized public PluginModel parsePlugin(InputSource in) throws Exception { 465 SAXParserFactory factory = acquireXMLParsing(); 466 if (factory == null) 467 return null; 469 try { 470 locationName = in.getSystemId(); 471 factory.setNamespaceAware(true); 472 factory.setNamespaceAware(true); 473 try { 474 factory.setFeature("http://xml.org/sax/features/string-interning", true); } catch (SAXException se) { 476 } 478 factory.setValidating(false); 479 factory.newSAXParser().parse(in, this); 480 return (PluginModel) objectStack.pop(); 481 } finally { 482 releaseXMLParsing(); 483 } 484 } 485 486 private SAXParserFactory acquireXMLParsing() { 487 parserReference = InternalPlatform.getDefault().getBundleContext().getServiceReference("javax.xml.parsers.SAXParserFactory"); if (parserReference == null) 489 return null; 490 return (SAXParserFactory ) InternalPlatform.getDefault().getBundleContext().getService(parserReference); 491 } 492 493 private void releaseXMLParsing() { 494 if (parserReference != null) 495 InternalPlatform.getDefault().getBundleContext().ungetService(parserReference); 496 } 497 498 public void parseConfigurationElementAttributes(Attributes attributes) { 499 500 ConfigurationElementModel parentConfigurationElement = (ConfigurationElementModel) objectStack.peek(); 501 parentConfigurationElement.setStartLine(locator.getLineNumber()); 502 503 Vector propVector = null; 504 505 int len = (attributes != null) ? attributes.getLength() : 0; 507 if (len == 0) 508 return; 509 propVector = new Vector(); 510 511 for (int i = 0; i < len; i++) { 512 String attrName = attributes.getLocalName(i); 513 String attrValue = attributes.getValue(i); 514 515 ConfigurationPropertyModel currentConfigurationProperty = factory.createConfigurationProperty(); 516 currentConfigurationProperty.setName(attrName); 517 currentConfigurationProperty.setValue(attrValue); 518 propVector.addElement(currentConfigurationProperty); 519 } 520 parentConfigurationElement.setProperties((ConfigurationPropertyModel[]) propVector.toArray(new ConfigurationPropertyModel[propVector.size()])); 521 propVector = null; 522 } 523 524 public void parseExtensionAttributes(Attributes attributes) { 525 526 PluginModel parent = (PluginModel) objectStack.peek(); 527 ExtensionModel currentExtension = factory.createExtension(); 528 currentExtension.setStartLine(locator.getLineNumber()); 529 objectStack.push(currentExtension); 530 531 int len = (attributes != null) ? attributes.getLength() : 0; 533 for (int i = 0; i < len; i++) { 534 String attrName = attributes.getLocalName(i); 535 String attrValue = attributes.getValue(i).trim(); 536 537 if (attrName.equals(EXTENSION_NAME)) 538 currentExtension.setName(attrValue); 539 else if (attrName.equals(EXTENSION_ID)) 540 currentExtension.setId(attrValue); 541 else if (attrName.equals(EXTENSION_TARGET)) { 542 String targetName; 544 if (attrValue.lastIndexOf('.') == -1) { 545 String baseId = parent instanceof PluginDescriptorModel ? parent.getId() : ((PluginFragmentModel) parent).getPlugin(); 546 targetName = baseId + "." + attrValue; } else 548 targetName = attrValue; 549 currentExtension.setExtensionPoint(targetName); 550 } else 551 internalError(NLS.bind(Messages.parse_unknownAttribute, EXTENSION, attrName)); 552 } 553 } 554 555 public void parseExtensionPointAttributes(Attributes attributes) { 556 557 ExtensionPointModel currentExtPoint = factory.createExtensionPoint(); 558 currentExtPoint.setStartLine(locator.getLineNumber()); 559 560 int len = (attributes != null) ? attributes.getLength() : 0; 562 for (int i = 0; i < len; i++) { 563 String attrName = attributes.getLocalName(i); 564 String attrValue = attributes.getValue(i).trim(); 565 566 if (attrName.equals(EXTENSION_POINT_NAME)) 567 currentExtPoint.setName(attrValue); 568 else if (attrName.equals(EXTENSION_POINT_ID)) 569 currentExtPoint.setId(attrValue); 570 else if (attrName.equals(EXTENSION_POINT_SCHEMA)) 571 currentExtPoint.setSchema(attrValue); 572 else 573 internalError(NLS.bind(Messages.parse_unknownAttribute, EXTENSION_POINT, attrName)); 574 } 575 PluginModel root = (PluginModel) objectStack.peek(); 577 currentExtPoint.setParent(root); 578 579 scratchVectors[EXTENSION_POINT_INDEX].addElement(currentExtPoint); 581 } 582 583 public void parseFragmentAttributes(Attributes attributes) { 584 PluginFragmentModel current = factory.createPluginFragment(); 585 current.setStartLine(locator.getLineNumber()); 586 objectStack.push(current); 587 588 int len = attributes.getLength(); 590 for (int i = 0; i < len; i++) { 591 String attrName = attributes.getLocalName(i); 592 String attrValue = attributes.getValue(i).trim(); 593 594 if (attrName.equals(FRAGMENT_ID)) 595 current.setId(attrValue); 596 else if (attrName.equals(FRAGMENT_NAME)) 597 current.setName(attrValue); 598 else if (attrName.equals(FRAGMENT_VERSION)) 599 current.setVersion(attrValue); 600 else if (attrName.equals(FRAGMENT_PROVIDER)) 601 current.setProviderName(attrValue); 602 else if (attrName.equals(FRAGMENT_PLUGIN_ID)) 603 current.setPlugin(attrValue); 604 else if (attrName.equals(FRAGMENT_PLUGIN_VERSION)) 605 current.setPluginVersion(attrValue); 606 else if (attrName.equals(FRAGMENT_PLUGIN_MATCH)) { 607 if (FRAGMENT_PLUGIN_MATCH_PERFECT.equals(attrValue)) 608 current.setMatch(PluginFragmentModel.FRAGMENT_MATCH_PERFECT); 609 else if (FRAGMENT_PLUGIN_MATCH_EQUIVALENT.equals(attrValue)) 610 current.setMatch(PluginFragmentModel.FRAGMENT_MATCH_EQUIVALENT); 611 else if (FRAGMENT_PLUGIN_MATCH_COMPATIBLE.equals(attrValue)) 612 current.setMatch(PluginFragmentModel.FRAGMENT_MATCH_COMPATIBLE); 613 else if (FRAGMENT_PLUGIN_MATCH_GREATER_OR_EQUAL.equals(attrValue)) 614 current.setMatch(PluginFragmentModel.FRAGMENT_MATCH_GREATER_OR_EQUAL); 615 else 616 internalError(NLS.bind(Messages.parse_validMatch, attrValue)); 617 } else 618 internalError(NLS.bind(Messages.parse_unknownAttribute, FRAGMENT, attrName)); 619 } 620 } 621 622 public void parseLibraryAttributes(Attributes attributes) { 623 objectStack.push(new Vector()); 625 LibraryModel current = factory.createLibrary(); 626 current.setStartLine(locator.getLineNumber()); 627 objectStack.push(current); 628 629 635 int len = (attributes != null) ? attributes.getLength() : 0; 637 for (int i = 0; i < len; i++) { 638 String attrName = attributes.getLocalName(i); 639 String attrValue = attributes.getValue(i).trim(); 640 641 if (attrName.equals(LIBRARY_NAME)) 642 current.setName(attrValue); 643 else if (attrName.equals(LIBRARY_TYPE)) { 644 attrValue = attrValue.toLowerCase(); 645 if (attrValue.equals(LibraryModel.CODE) || attrValue.equals(LibraryModel.RESOURCE)) 646 current.setType(attrValue.toLowerCase()); 647 else 648 internalError(NLS.bind(Messages.parse_unknownLibraryType, attrValue, current.getName())); 649 } else 650 internalError(NLS.bind(Messages.parse_unknownAttribute, LIBRARY, attrName)); 651 } 652 } 653 654 public void parsePluginAttributes(Attributes attributes) { 655 656 PluginDescriptorModel current = factory.createPluginDescriptor(); 657 current.setStartLine(locator.getLineNumber()); 658 objectStack.push(current); 659 660 int len = attributes.getLength(); 662 for (int i = 0; i < len; i++) { 663 String attrName = attributes.getLocalName(i); 664 String attrValue = attributes.getValue(i).trim(); 665 666 if (attrName.equals(PLUGIN_ID)) 667 current.setId(attrValue); 668 else if (attrName.equals(PLUGIN_NAME)) 669 current.setName(attrValue); 670 else if (attrName.equals(PLUGIN_VERSION)) 671 current.setVersion(attrValue); 672 else if (attrName.equals(PLUGIN_VENDOR) || (attrName.equals(PLUGIN_PROVIDER))) 673 current.setProviderName(attrValue); 674 else if (attrName.equals(PLUGIN_CLASS)) 675 current.setPluginClass(attrValue); 676 else 677 internalError(NLS.bind(Messages.parse_unknownAttribute, PLUGIN, attrName)); 678 } 679 } 680 681 public void parsePluginRequiresImport(Attributes attributes) { 682 PluginPrerequisiteModel current = factory.createPluginPrerequisite(); 683 current.setStartLine(locator.getLineNumber()); 684 685 int len = (attributes != null) ? attributes.getLength() : 0; 687 for (int i = 0; i < len; i++) { 688 String attrName = attributes.getLocalName(i); 689 String attrValue = attributes.getValue(i).trim(); 690 691 if (attrName.equals(PLUGIN_REQUIRES_PLUGIN)) 692 current.setPlugin(attrValue); 693 else if (attrName.equals(PLUGIN_REQUIRES_PLUGIN_VERSION)) 694 current.setVersion(attrValue); 695 else if (attrName.equals(PLUGIN_REQUIRES_OPTIONAL)) 696 current.setOptional(TRUE.equalsIgnoreCase(attrValue)); 697 else if (attrName.equals(PLUGIN_REQUIRES_MATCH)) { 698 if (PLUGIN_REQUIRES_MATCH_PERFECT.equals(attrValue)) 699 current.setMatchByte(PluginPrerequisiteModel.PREREQ_MATCH_PERFECT); 700 else if ((PLUGIN_REQUIRES_MATCH_EQUIVALENT.equals(attrValue)) || (PLUGIN_REQUIRES_MATCH_EXACT.equals(attrValue))) 701 current.setMatchByte(PluginPrerequisiteModel.PREREQ_MATCH_EQUIVALENT); 702 else if (PLUGIN_REQUIRES_MATCH_COMPATIBLE.equals(attrValue)) 703 current.setMatchByte(PluginPrerequisiteModel.PREREQ_MATCH_COMPATIBLE); 704 else if (PLUGIN_REQUIRES_MATCH_GREATER_OR_EQUAL.equals(attrValue)) 705 current.setMatchByte(PluginPrerequisiteModel.PREREQ_MATCH_GREATER_OR_EQUAL); 706 else 707 internalError(NLS.bind(Messages.parse_validMatch, attrValue)); 708 } else if (attrName.equals(PLUGIN_REQUIRES_EXPORT)) { 709 if (TRUE.equals(attrValue)) 710 current.setExport(true); 711 else if (FALSE.equals(attrValue)) 712 current.setExport(false); 713 else 714 internalError(NLS.bind(Messages.parse_validExport, attrValue)); 715 } else 716 internalError(NLS.bind(Messages.parse_unknownAttribute, PLUGIN_REQUIRES_IMPORT, attrName)); 717 718 } 719 ((Vector) objectStack.peek()).addElement(current); 721 } 722 723 public void parseRequiresAttributes(Attributes attributes) { 724 } 725 726 static String replace(String s, String from, String to) { 727 String str = s; 728 int fromLen = from.length(); 729 int toLen = to.length(); 730 int ix = str.indexOf(from); 731 while (ix != -1) { 732 str = str.substring(0, ix) + to + str.substring(ix + fromLen); 733 ix = str.indexOf(from, ix + toLen); 734 } 735 return str; 736 } 737 738 public void startDocument() { 739 stateStack.push(new Integer (INITIAL_STATE)); 740 for (int i = 0; i <= LAST_INDEX; i++) { 741 scratchVectors[i] = new Vector(); 742 } 743 } 744 745 public void startElement(String uri, String elementName, String qName, Attributes attributes) { 746 switch (((Integer ) stateStack.peek()).intValue()) { 747 case INITIAL_STATE : 748 handleInitialState(elementName, attributes); 749 break; 750 case FRAGMENT_STATE : 751 handlePluginState(elementName, attributes); 752 break; 753 case PLUGIN_STATE : 754 handlePluginState(elementName, attributes); 755 break; 756 case PLUGIN_RUNTIME_STATE : 757 handleRuntimeState(elementName, attributes); 758 break; 759 case PLUGIN_REQUIRES_STATE : 760 handleRequiresState(elementName, attributes); 761 break; 762 case PLUGIN_EXTENSION_POINT_STATE : 763 handleExtensionPointState(elementName, attributes); 764 break; 765 case PLUGIN_EXTENSION_STATE : 766 case CONFIGURATION_ELEMENT_STATE : 767 handleExtensionState(elementName, attributes); 768 break; 769 case RUNTIME_LIBRARY_STATE : 770 handleLibraryState(elementName, attributes); 771 break; 772 case LIBRARY_EXPORT_STATE : 773 handleLibraryExportState(elementName, attributes); 774 break; 775 case PLUGIN_REQUIRES_IMPORT_STATE : 776 handleRequiresImportState(elementName, attributes); 777 break; 778 default : 779 stateStack.push(new Integer (IGNORED_ELEMENT_STATE)); 780 internalError(NLS.bind(Messages.parse_unknownTopElement, elementName)); 781 } 782 } 783 784 public void warning(SAXParseException ex) { 785 logStatus(ex); 786 } 787 788 private void internalError(String message) { 789 if (locationName != null) 790 factory.error(new Status(IStatus.WARNING, Platform.PI_RUNTIME, Platform.PARSE_PROBLEM, locationName + ": " + message, null)); else 792 factory.error(new Status(IStatus.WARNING, Platform.PI_RUNTIME, Platform.PARSE_PROBLEM, message, null)); 793 } 794 795 } 796 | Popular Tags |