/* * @(#)ContentModel.java 1.11 04/05/05 * * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package javax.swing.text.html.parser; import java.util.Vector; import java.util.Enumeration; import java.io.*; /** * A representation of a content model. A content model is * basically a restricted BNF expression. It is restricted in * the sense that it must be deterministic. This means that you * don't have to represent it as a finite state automata.
* See Annex H on page 556 of the SGML handbook for more information.
*
* @author Arthur van Hoff
* @version 1.11,05/05/04
*
*/
public final class ContentModel implements Serializable {
/**
* Type. Either '*', '?', '+', ',', '|', '&'.
*/
public int type;
/**
* The content. Either an Element or a ContentModel.
*/
public Object content;
/**
* The next content model (in a ',', '|' or '&' expression).
*/
public ContentModel next;
public ContentModel() {
}
/**
* Create a content model for an element.
*/
public ContentModel(Element content) {
this(0, content, null);
}
/**
* Create a content model of a particular type.
*/
public ContentModel(int type, ContentModel content) {
this(type, content, null);
}
/**
* Create a content model of a particular type.
*/
public ContentModel(int type, Object content, ContentModel next) {
this.type = type;
this.content = content;
this.next = next;
}
/**
* Return true if the content model could
* match an empty input stream.
*/
public boolean empty() {
switch (type) {
case '*':
case '?':
return true;
case '+':
case '|':
for (ContentModel m = (ContentModel)content ; m != null ; m = m.next) {
if (m.empty()) {
return true;
}
}
return false;
case ',':
case '&':
for (ContentModel m = (ContentModel)content ; m != null ; m = m.next) {
if (!m.empty()) {
return false;
}
}
return true;
default:
return false;
}
}
/**
* Update elemVec with the list of elements that are
* part of the this contentModel.
*/
public void getElements(Vector