コード例 #1
0
 /**
  * @param element
  * @param schemaElement
  */
 private void validateMaxElementMult(Element element, ISchemaElement schemaElement) {
   // Validate max element occurence violations
   int maxSeverity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ELEMENT);
   if (maxSeverity != CompilerFlags.IGNORE) {
     HashSet maxElementSet =
         ElementOccurenceChecker.findMaxOccurenceViolations(schemaElement, element);
     Iterator maxIterator = maxElementSet.iterator();
     while (maxIterator.hasNext()) {
       reportMaxOccurenceViolation((ElementOccurrenceResult) maxIterator.next(), maxSeverity);
     }
   }
 }
コード例 #2
0
 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);
     }
   }
 }
コード例 #3
0
  private void computeAllowedElements(ISchemaType type, HashSet elementSet) {
    if (type instanceof ISchemaComplexType) {
      ISchemaComplexType complexType = (ISchemaComplexType) type;
      ISchemaCompositor compositor = complexType.getCompositor();
      if (compositor != null) computeAllowedElements(compositor, elementSet);

      ISchemaAttribute[] attrs = complexType.getAttributes();
      for (int i = 0; i < attrs.length; i++) {
        if (attrs[i].getKind() == IMetaAttribute.JAVA) elementSet.add(attrs[i].getName());
      }
    }
  }
コード例 #4
0
 private void computeAllowedElements(ISchemaCompositor compositor, HashSet elementSet) {
   ISchemaObject[] children = compositor.getChildren();
   for (int i = 0; i < children.length; i++) {
     ISchemaObject child = children[i];
     if (child instanceof ISchemaObjectReference) {
       ISchemaObjectReference ref = (ISchemaObjectReference) child;
       ISchemaElement refElement = (ISchemaElement) ref.getReferencedObject();
       if (refElement != null) elementSet.add(refElement.getName());
     } else if (child instanceof ISchemaCompositor) {
       computeAllowedElements((ISchemaCompositor) child, elementSet);
     }
   }
 }
コード例 #5
0
  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);
      }
    }
  }