2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
18
package org.apache.xerces.impl.dtd.models;
20
import org.apache.xerces.impl.dtd.XMLContentSpec;
23
* Content model Bin-Op node.
27
* @version $Id: CMBinOp.java,v 1.2 2009/12/10 03:18:46 matthewoliver Exp $
29
public class CMBinOp extends CMNode
31
// -------------------------------------------------------------------
33
// -------------------------------------------------------------------
34
public CMBinOp(int type, CMNode leftNode, CMNode rightNode)
38
// Insure that its one of the types we require
39
if ((type() != XMLContentSpec.CONTENTSPECNODE_CHOICE)
40
&& (type() != XMLContentSpec.CONTENTSPECNODE_SEQ))
42
throw new RuntimeException("ImplementationMessages.VAL_BST");
45
// Store the nodes and init any data that needs it
46
fLeftChild = leftNode;
47
fRightChild = rightNode;
51
// -------------------------------------------------------------------
52
// Package, final methods
53
// -------------------------------------------------------------------
54
final CMNode getLeft()
59
final CMNode getRight()
65
// -------------------------------------------------------------------
66
// Package, inherited methods
67
// -------------------------------------------------------------------
68
public boolean isNullable()
71
// If its an alternation, then if either child is nullable then
72
// this node is nullable. If its a concatenation, then both of
73
// them have to be nullable.
75
if (type() == XMLContentSpec.CONTENTSPECNODE_CHOICE)
76
return (fLeftChild.isNullable() || fRightChild.isNullable());
77
else if (type() == XMLContentSpec.CONTENTSPECNODE_SEQ)
78
return (fLeftChild.isNullable() && fRightChild.isNullable());
80
throw new RuntimeException("ImplementationMessages.VAL_BST");
84
// -------------------------------------------------------------------
85
// Protected, inherited methods
86
// -------------------------------------------------------------------
87
protected void calcFirstPos(CMStateSet toSet)
89
if (type() == XMLContentSpec.CONTENTSPECNODE_CHOICE)
91
// Its the the union of the first positions of our children.
92
toSet.setTo(fLeftChild.firstPos());
93
toSet.union(fRightChild.firstPos());
95
else if (type() == XMLContentSpec.CONTENTSPECNODE_SEQ)
98
// If our left child is nullable, then its the union of our
99
// children's first positions. Else is our left child's first
102
toSet.setTo(fLeftChild.firstPos());
103
if (fLeftChild.isNullable())
104
toSet.union(fRightChild.firstPos());
108
throw new RuntimeException("ImplementationMessages.VAL_BST");
112
protected void calcLastPos(CMStateSet toSet)
114
if (type() == XMLContentSpec.CONTENTSPECNODE_CHOICE)
116
// Its the the union of the first positions of our children.
117
toSet.setTo(fLeftChild.lastPos());
118
toSet.union(fRightChild.lastPos());
120
else if (type() == XMLContentSpec.CONTENTSPECNODE_SEQ)
123
// If our right child is nullable, then its the union of our
124
// children's last positions. Else is our right child's last
127
toSet.setTo(fRightChild.lastPos());
128
if (fRightChild.isNullable())
129
toSet.union(fLeftChild.lastPos());
133
throw new RuntimeException("ImplementationMessages.VAL_BST");
138
// -------------------------------------------------------------------
139
// Private data members
143
// These are the references to the two nodes that are on either
144
// side of this binary operation.
145
// -------------------------------------------------------------------
146
private final CMNode fLeftChild;
147
private final CMNode fRightChild;