All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.thaiopensource.relaxng.pattern.RequiredElementsOrAttributesFunction Maven / Gradle / Ivy

Go to download

Jing is a validator for RELAX NG and other schema languages. This project was taken from http://code.google.com/p/jing-trang and mavenized for inclusion in the Wicket Stuff HTML Validator. The code was taken from the 20091111 release.

There is a newer version: 1.11
Show newest version
package com.thaiopensource.relaxng.pattern;

import com.thaiopensource.xml.util.Name;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
 * Common functionality between RequiredAttributesFunction and RequiredElementsFunction
 */
abstract class RequiredElementsOrAttributesFunction extends AbstractPatternFunction> {
  public Set caseOther(Pattern p) {
    return Collections.emptySet();
  }

  public Set caseChoice(ChoicePattern p) {
    Set s1 = p.getOperand1().apply(this);
    Set s2 = p.getOperand2().apply(this);
    if (s1.isEmpty())
      return s1;
    if (s2.isEmpty())
      return s2;
    s1.retainAll(s2);
    return s1;
  }

  protected Set caseNamed(NameClass nc) {
    if (!(nc instanceof SimpleNameClass))
      return Collections.emptySet();
    Set s = new HashSet();
    s.add(((SimpleNameClass)nc).getName());
    return s;
  }

  protected Set union(BinaryPattern p) {
    Set s1 = p.getOperand1().apply(this);
    Set s2 = p.getOperand2().apply(this);
    if (s1.isEmpty())
      return s2;
    if (s2.isEmpty())
      return s1;
    s1.addAll(s2);
    return s1;
  }

  public Set caseInterleave(InterleavePattern p) {
    return union(p);
  }

  public Set caseAfter(AfterPattern p) {
    return p.getOperand1().apply(this);
  }

  public Set caseOneOrMore(OneOrMorePattern p) {
    return p.getOperand().apply(this);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy