private void validateExistingExtensionAttributes( Element element, NamedNodeMap attrs, ISchemaElement schemaElement) { for (int i = 0; i < attrs.getLength(); i++) { Attr attr = (Attr) attrs.item(i); ISchemaAttribute attInfo = schemaElement.getAttribute(attr.getName()); if (attInfo == null) { HashSet allowedElements = new HashSet(); computeAllowedElements(schemaElement.getType(), allowedElements); if (allowedElements.contains(attr.getName())) { validateJavaAttribute(element, attr); } else { int flag = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ATTRIBUTE); if (flag != CompilerFlags.IGNORE) reportUnknownAttribute(element, attr.getName(), flag); } } else { validateExtensionAttribute(element, attr, attInfo); } } }
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); } } }