KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > impl > xs > models > XSCMBinOp


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.xs.models;
18
19 import org.apache.xerces.impl.dtd.models.CMNode;
20 import org.apache.xerces.impl.dtd.models.CMStateSet;
21 import org.apache.xerces.impl.xs.XSModelGroupImpl;
22
23 /**
24  *
25  * Content model Bin-Op node.
26  *
27  * @xerces.internal
28  *
29  * @author Neil Graham, IBM
30  * @version $$
31  */

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

140
Popular Tags