~vcs-imports/xena/trunk

« back to all changes in this revision

Viewing changes to ext/src/xerces-2_9_1/src/org/apache/xerces/impl/dtd/models/CMBinOp.java

  • Committer: matthewoliver
  • Date: 2009-12-10 03:18:07 UTC
  • Revision ID: vcs-imports@canonical.com-20091210031807-l086qguzdlljtkl9
Merged Xena Testing into Xena Stable for the Xena 5 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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
 
8
 * 
 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
 
10
 * 
 
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.
 
16
 */
 
17
 
 
18
package org.apache.xerces.impl.dtd.models;
 
19
 
 
20
import org.apache.xerces.impl.dtd.XMLContentSpec;
 
21
 
 
22
/**
 
23
 * Content model Bin-Op node.
 
24
 * 
 
25
 * @xerces.internal
 
26
 *
 
27
 * @version $Id: CMBinOp.java,v 1.2 2009/12/10 03:18:46 matthewoliver Exp $
 
28
 */
 
29
public class CMBinOp extends CMNode
 
30
{
 
31
    // -------------------------------------------------------------------
 
32
    //  Constructors
 
33
    // -------------------------------------------------------------------
 
34
    public CMBinOp(int type, CMNode leftNode, CMNode rightNode) 
 
35
    {
 
36
        super(type);
 
37
 
 
38
        // Insure that its one of the types we require
 
39
        if ((type() != XMLContentSpec.CONTENTSPECNODE_CHOICE)
 
40
        &&  (type() != XMLContentSpec.CONTENTSPECNODE_SEQ))
 
41
        {
 
42
            throw new RuntimeException("ImplementationMessages.VAL_BST");
 
43
        }
 
44
 
 
45
        // Store the nodes and init any data that needs it
 
46
        fLeftChild = leftNode;
 
47
        fRightChild = rightNode;
 
48
    }
 
49
 
 
50
 
 
51
    // -------------------------------------------------------------------
 
52
    //  Package, final methods
 
53
    // -------------------------------------------------------------------
 
54
    final CMNode getLeft()
 
55
    {
 
56
        return fLeftChild;
 
57
    }
 
58
 
 
59
    final CMNode getRight()
 
60
    {
 
61
        return fRightChild;
 
62
    }
 
63
 
 
64
 
 
65
    // -------------------------------------------------------------------
 
66
    //  Package, inherited methods
 
67
    // -------------------------------------------------------------------
 
68
    public boolean isNullable() 
 
69
    {
 
70
        //
 
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.
 
74
        //
 
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());
 
79
        else
 
80
            throw new RuntimeException("ImplementationMessages.VAL_BST");
 
81
    }
 
82
 
 
83
 
 
84
    // -------------------------------------------------------------------
 
85
    //  Protected, inherited methods
 
86
    // -------------------------------------------------------------------
 
87
    protected void calcFirstPos(CMStateSet toSet) 
 
88
    {
 
89
        if (type() == XMLContentSpec.CONTENTSPECNODE_CHOICE)
 
90
        {
 
91
            // Its the the union of the first positions of our children.
 
92
            toSet.setTo(fLeftChild.firstPos());
 
93
            toSet.union(fRightChild.firstPos());
 
94
        }
 
95
         else if (type() == XMLContentSpec.CONTENTSPECNODE_SEQ)
 
96
        {
 
97
            //
 
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
 
100
            //  positions.
 
101
            //
 
102
            toSet.setTo(fLeftChild.firstPos());
 
103
            if (fLeftChild.isNullable())
 
104
                toSet.union(fRightChild.firstPos());
 
105
        }
 
106
         else
 
107
        {
 
108
            throw new RuntimeException("ImplementationMessages.VAL_BST");
 
109
        }
 
110
    }
 
111
 
 
112
    protected void calcLastPos(CMStateSet toSet) 
 
113
    {
 
114
        if (type() == XMLContentSpec.CONTENTSPECNODE_CHOICE)
 
115
        {
 
116
            // Its the the union of the first positions of our children.
 
117
            toSet.setTo(fLeftChild.lastPos());
 
118
            toSet.union(fRightChild.lastPos());
 
119
        }
 
120
         else if (type() == XMLContentSpec.CONTENTSPECNODE_SEQ)
 
121
        {
 
122
            //
 
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
 
125
            //  positions.
 
126
            //
 
127
            toSet.setTo(fRightChild.lastPos());
 
128
            if (fRightChild.isNullable())
 
129
                toSet.union(fLeftChild.lastPos());
 
130
        }
 
131
         else
 
132
        {
 
133
            throw new RuntimeException("ImplementationMessages.VAL_BST");
 
134
        }
 
135
    }
 
136
 
 
137
 
 
138
    // -------------------------------------------------------------------
 
139
    //  Private data members
 
140
    //
 
141
    //  fLeftChild
 
142
    //  fRightChild
 
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;
 
148
};
 
149