KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > impl > dtd > models > CMBinOp


1 /*
2  * Copyright 1999-2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.xerces.impl.dtd.models;
18
19 import org.apache.xerces.impl.dtd.XMLContentSpec;
20
21 /**
22  * Content model Bin-Op node.
23  *
24  * @xerces.internal
25  *
26  * @version $Id: CMBinOp.java,v 1.4 2004/10/04 22:00:42 mrglavas Exp $
27  */

28 public class CMBinOp extends CMNode
29 {
30     // -------------------------------------------------------------------
31
// Constructors
32
// -------------------------------------------------------------------
33
public CMBinOp(int type, CMNode leftNode, CMNode rightNode)
34     {
35         super(type);
36
37         // Insure that its one of the types we require
38
if ((type() != XMLContentSpec.CONTENTSPECNODE_CHOICE)
39         && (type() != XMLContentSpec.CONTENTSPECNODE_SEQ))
40         {
41             throw new RuntimeException JavaDoc("ImplementationMessages.VAL_BST");
42         }
43
44         // Store the nodes and init any data that needs it
45
fLeftChild = leftNode;
46         fRightChild = rightNode;
47     }
48
49
50     // -------------------------------------------------------------------
51
// Package, final methods
52
// -------------------------------------------------------------------
53
final CMNode getLeft()
54     {
55         return fLeftChild;
56     }
57
58     final CMNode getRight()
59     {
60         return fRightChild;
61     }
62
63
64     // -------------------------------------------------------------------
65
// Package, inherited methods
66
// -------------------------------------------------------------------
67
public boolean isNullable()
68     {
69         //
70
// If its an alternation, then if either child is nullable then
71
// this node is nullable. If its a concatenation, then both of
72
// them have to be nullable.
73
//
74
if (type() == XMLContentSpec.CONTENTSPECNODE_CHOICE)
75             return (fLeftChild.isNullable() || fRightChild.isNullable());
76         else if (type() == XMLContentSpec.CONTENTSPECNODE_SEQ)
77             return (fLeftChild.isNullable() && fRightChild.isNullable());
78         else
79             throw new RuntimeException JavaDoc("ImplementationMessages.VAL_BST");
80     }
81
82
83     // -------------------------------------------------------------------
84
// Protected, inherited methods
85
// -------------------------------------------------------------------
86
protected void calcFirstPos(CMStateSet toSet)
87     {
88         if (type() == XMLContentSpec.CONTENTSPECNODE_CHOICE)
89         {
90             // Its the the union of the first positions of our children.
91
toSet.setTo(fLeftChild.firstPos());
92             toSet.union(fRightChild.firstPos());
93         }
94          else if (type() == XMLContentSpec.CONTENTSPECNODE_SEQ)
95         {
96             //
97
// If our left child is nullable, then its the union of our
98
// children's first positions. Else is our left child's first
99
// positions.
100
//
101
toSet.setTo(fLeftChild.firstPos());
102             if (fLeftChild.isNullable())
103                 toSet.union(fRightChild.firstPos());
104         }
105          else
106         {
107             throw new RuntimeException JavaDoc("ImplementationMessages.VAL_BST");
108         }
109     }
110
111     protected void calcLastPos(CMStateSet toSet)
112     {
113         if (type() == XMLContentSpec.CONTENTSPECNODE_CHOICE)
114         {
115             // Its the the union of the first positions of our children.
116
toSet.setTo(fLeftChild.lastPos());
117             toSet.union(fRightChild.lastPos());
118         }
119          else if (type() == XMLContentSpec.CONTENTSPECNODE_SEQ)
120         {
121             //
122
// If our right child is nullable, then its the union of our
123
// children's last positions. Else is our right child's last
124
// positions.
125
//
126
toSet.setTo(fRightChild.lastPos());
127             if (fRightChild.isNullable())
128                 toSet.union(fLeftChild.lastPos());
129         }
130          else
131         {
132             throw new RuntimeException JavaDoc("ImplementationMessages.VAL_BST");
133         }
134     }
135
136
137     // -------------------------------------------------------------------
138
// Private data members
139
//
140
// fLeftChild
141
// fRightChild
142
// These are the references to the two nodes that are on either
143
// side of this binary operation.
144
// -------------------------------------------------------------------
145
private CMNode fLeftChild;
146     private CMNode fRightChild;
147 };
148
149
Popular Tags