~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/CMLeaf.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
import org.apache.xerces.xni.QName;
 
22
 
 
23
/**
 
24
 * Content model leaf node.
 
25
 * 
 
26
 * @xerces.internal
 
27
 *
 
28
 * @version $Id: CMLeaf.java,v 1.2 2009/12/10 03:18:46 matthewoliver Exp $
 
29
 */
 
30
public class CMLeaf 
 
31
    extends CMNode {
 
32
 
 
33
    //
 
34
    // Data
 
35
    //
 
36
 
 
37
    /** This is the element that this leaf represents. */
 
38
    private final QName fElement = new QName();
 
39
 
 
40
    /**
 
41
     * Part of the algorithm to convert a regex directly to a DFA
 
42
     * numbers each leaf sequentially. If its -1, that means its an
 
43
     * epsilon node. Zero and greater are non-epsilon positions.
 
44
     */
 
45
    private int fPosition = -1;
 
46
 
 
47
    //
 
48
    // Constructors
 
49
    //
 
50
 
 
51
    /** Constructs a content model leaf. */
 
52
    public CMLeaf(QName element, int position)  {
 
53
        super(XMLContentSpec.CONTENTSPECNODE_LEAF);
 
54
 
 
55
        // Store the element index and position
 
56
        fElement.setValues(element);
 
57
        fPosition = position;
 
58
    }
 
59
 
 
60
    /** Constructs a content model leaf. */
 
61
    public CMLeaf(QName element)  {
 
62
        super(XMLContentSpec.CONTENTSPECNODE_LEAF);
 
63
 
 
64
        // Store the element index and position
 
65
        fElement.setValues(element);
 
66
    }
 
67
 
 
68
    //
 
69
    // Package methods
 
70
    //
 
71
 
 
72
    final QName getElement()
 
73
    {
 
74
        return fElement;
 
75
    }
 
76
 
 
77
    final int getPosition()
 
78
    {
 
79
        return fPosition;
 
80
    }
 
81
 
 
82
    final void setPosition(int newPosition)
 
83
    {
 
84
        fPosition = newPosition;
 
85
    }
 
86
 
 
87
    //
 
88
    // CMNode methods
 
89
    //
 
90
 
 
91
    // package
 
92
 
 
93
    public boolean isNullable() 
 
94
    {
 
95
        // Leaf nodes are never nullable unless its an epsilon node
 
96
        return (fPosition == -1);
 
97
    }
 
98
 
 
99
    public String toString()
 
100
    {
 
101
        StringBuffer strRet = new StringBuffer(fElement.toString());
 
102
        strRet.append(" (");
 
103
        strRet.append(fElement.uri);
 
104
        strRet.append(',');
 
105
        strRet.append(fElement.localpart);
 
106
        strRet.append(')');
 
107
        if (fPosition >= 0) {
 
108
            strRet.append(" (Pos:")
 
109
                  .append(Integer.toString(fPosition))
 
110
                  .append(')');
 
111
        }
 
112
        return strRet.toString();
 
113
    }
 
114
 
 
115
    // protected
 
116
 
 
117
    protected void calcFirstPos(CMStateSet toSet) 
 
118
    {
 
119
        // If we are an epsilon node, then the first pos is an empty set
 
120
        if (fPosition == -1)
 
121
            toSet.zeroBits();
 
122
 
 
123
        // Otherwise, its just the one bit of our position
 
124
        else
 
125
            toSet.setBit(fPosition);
 
126
    }
 
127
 
 
128
    protected void calcLastPos(CMStateSet toSet) 
 
129
    {
 
130
        // If we are an epsilon node, then the last pos is an empty set
 
131
        if (fPosition == -1)
 
132
            toSet.zeroBits();
 
133
 
 
134
        // Otherwise, its just the one bit of our position
 
135
        else
 
136
            toSet.setBit(fPosition);
 
137
    }
 
138
 
 
139
} // class CMLeaf
 
140
 
 
141