/** * 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; }
private void validateInternalExtensionAttribute(Element element, ISchemaElement schemaElement) { int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_INTERNAL); if (severity == CompilerFlags.IGNORE) return; if (schemaElement instanceof ISchemaRootElement) { ISchemaRootElement rootElement = (ISchemaRootElement) schemaElement; String epid = schemaElement.getSchema().getPluginId(); String pid = fModel.getMonitorBase().getId(); if (epid == null || pid == null) return; if (rootElement.isInternal() && !epid.equals(pid)) { String point = element.getAttribute("point"); // $NON-NLS-1$ if (point == null) return; // should never come to this... report( NLS.bind(MDECoreMessages.Builders_Manifest_internal_rootElement, point), getLine(element, "point"), severity, MDEMarkerFactory.CAT_DEPRECATION); // $NON-NLS-1$ } } }
public static String getCounterKey(ISchemaElement elementInfo) { return elementInfo.getSchema().getQualifiedPointId() + "." + elementInfo.getName(); // $NON-NLS-1$ }
protected void validateElement(Element element, ISchema schema, boolean isTopLevel) { String elementName = element.getNodeName(); ISchemaElement schemaElement = schema.findElement(elementName); // Validate element occurrence violations if ((schemaElement != null) && (schemaElement.getType() instanceof ISchemaComplexType)) { validateMaxElementMult(element, schemaElement); validateMinElementMult(element, schemaElement); } ISchemaElement parentSchema = null; if (!"extension".equals(elementName)) { // $NON-NLS-1$ Node parent = element.getParentNode(); parentSchema = schema.findElement(parent.getNodeName()); } else if (isTopLevel == false) { // This is an "extension" element; but, not a top level one. // It is nested within another "extension" element somewhere // e.g. "extension" element is a child element of another element // that is not a "plugin" elment // element // Report illegal element int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ELEMENT); reportIllegalElement(element, severity); return; } if (parentSchema != null) { int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ELEMENT); if (severity != CompilerFlags.IGNORE) { HashSet allowedElements = new HashSet(); computeAllowedElements(parentSchema.getType(), allowedElements); if (!allowedElements.contains(elementName)) { reportIllegalElement(element, severity); return; } } } if (schemaElement == null && parentSchema != null) { ISchemaAttribute attr = parentSchema.getAttribute(elementName); if (attr != null && attr.getKind() == IMetaAttribute.JAVA) { if (attr.isDeprecated()) reportDeprecatedAttribute(element, element.getAttributeNode("class")); // $NON-NLS-1$ validateJavaAttribute(element, element.getAttributeNode("class")); // $NON-NLS-1$ } } else { if (schemaElement != null) { validateRequiredExtensionAttributes(element, schemaElement); validateExistingExtensionAttributes(element, element.getAttributes(), schemaElement); validateInternalExtensionAttribute(element, schemaElement); if (schemaElement.isDeprecated()) { if (schemaElement instanceof ISchemaRootElement) reportDeprecatedRootElement( element, ((ISchemaRootElement) schemaElement).getDeprecatedSuggestion()); else reportDeprecatedElement(element); } if (schemaElement.hasTranslatableContent()) validateTranslatableElementContent(element); // Bug 213457 - look up elements based on the schema in which the parent is found schema = schemaElement.getSchema(); } NodeList children = element.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { validateElement((Element) children.item(i), schema, false); } } }