Example #1
0
  /**
   * Get the ISchemaElement corresponding to this IDocumentElementNode
   *
   * @param node
   * @param extensionPoint the extension point of the schema, if <code>null</code> it will be
   *     deduced
   * @return the ISchemaElement for <code>node</code>
   */
  public static ISchemaElement getSchemaElement(IDocumentElementNode node, String extensionPoint) {
    if (extensionPoint == null) {
      IMonitorObject obj = getTopLevelParent(node);
      if (!(obj instanceof IMonitorExtension)) return null;
      extensionPoint = ((IMonitorExtension) obj).getPoint();
    }
    ISchema schema = MDECore.getDefault().getSchemaRegistry().getSchema(extensionPoint);
    if (schema == null) return null;

    // Bug 213457 - look up elements based on the schema in which the parent is found
    if (schema.getIncludes().length == 0 || "extension".equals(node.getXMLTagName())) // $NON-NLS-1$
    return schema.findElement(node.getXMLTagName());

    // if element is not "extension" & has multiple sub-schemas,
    // Then search for the element in the same schema in which the parent element if found.
    Stack stack = new Stack();
    while (node != null) {
      String tagName = node.getXMLTagName();
      if ("extension".equals(tagName)) // $NON-NLS-1$
      break;
      stack.push(node.getXMLTagName());
      node = node.getParentNode();
    }
    ISchemaElement element = null;
    while (!stack.isEmpty()) {
      element = schema.findElement((String) stack.pop());
      if (element == null) return null;
      schema = element.getSchema();
    }
    return element;
  }
Example #2
0
  /**
   * Scans up the node's parents till it reaches a IPluginExtension or IPluginExtensionPoint (or
   * null) and returns the result.
   *
   * @param node
   * @return the IPluginExtension or IPluginExtensionPoint that contains <code>node</code>
   */
  public static IMonitorObject getTopLevelParent(IDocumentRange range) {
    IDocumentElementNode node = null;
    if (range instanceof IDocumentAttributeNode)
      node = ((IDocumentAttributeNode) range).getEnclosingElement();
    else if (range instanceof IDocumentTextNode)
      node = ((IDocumentTextNode) range).getEnclosingElement();
    else if (range instanceof IMonitorElement) node = (IDocumentElementNode) range;
    else if (range instanceof IMonitorObject)
      // not an attribute/text node/element -> return direct node
      return (IMonitorObject) range;

    while (node != null
        && !(node instanceof IMonitorExtension)
        && !(node instanceof IMonitorExtensionPoint)) node = node.getParentNode();

    return node != null ? (IMonitorObject) node : null;
  }