1 /*
   2  * reserved comment block
   3  * DO NOT REMOVE OR ALTER!
   4  */
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *      http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 package com.sun.org.apache.xerces.internal.impl.xs.models;
  23 
  24 import com.sun.org.apache.xerces.internal.impl.dtd.models.CMNode;
  25 import com.sun.org.apache.xerces.internal.impl.dtd.models.CMStateSet;
  26 
  27 /**
  28  * Content model leaf node.
  29  *
  30  * @xerces.internal
  31  *
  32  * @author Neil Graham, IBM
  33  */
  34 public class XSCMLeaf
  35     extends CMNode {
  36 
  37     //
  38     // Data
  39     //
  40 
  41     /** This is the leaf: element decl or wildcard decl. */
  42     private Object fLeaf = null;
  43 
  44     /**
  45      * Identify the particle: for UPA checking
  46      */
  47     private int fParticleId = -1;
  48 
  49     /**
  50      * Part of the algorithm to convert a regex directly to a DFA
  51      * numbers each leaf sequentially. If its -1, that means its an
  52      * epsilon node. Zero and greater are non-epsilon positions.
  53      */
  54     private int fPosition = -1;
  55 
  56     //
  57     // Constructors
  58     //
  59 
  60     /** Constructs a content model leaf. */
  61     public XSCMLeaf(int type, Object leaf, int id, int position)  {
  62         super(type);
  63 
  64         // Store the element index and position
  65         fLeaf = leaf;
  66         fParticleId = id;
  67         fPosition = position;
  68     }
  69 
  70     //
  71     // Package methods
  72     //
  73 
  74     final Object getLeaf() {
  75         return fLeaf;
  76     }
  77 
  78     final int getParticleId() {
  79         return fParticleId;
  80     }
  81 
  82     final int getPosition() {
  83         return fPosition;
  84     }
  85 
  86     final void setPosition(int newPosition) {
  87         fPosition = newPosition;
  88     }
  89 
  90     //
  91     // CMNode methods
  92     //
  93 
  94     // package
  95 
  96     public boolean isNullable() {
  97         // Leaf nodes are never nullable unless its an epsilon node
  98         return (fPosition == -1);
  99     }
 100 
 101     public String toString() {
 102         StringBuffer strRet = new StringBuffer(fLeaf.toString());
 103         if (fPosition >= 0) {
 104             strRet.append
 105             (
 106                 " (Pos:"
 107                 + Integer.toString(fPosition)
 108                 + ")"
 109             );
 110         }
 111         return strRet.toString();
 112     }
 113 
 114     // protected
 115 
 116     protected void calcFirstPos(CMStateSet toSet) {
 117         // If we are an epsilon node, then the first pos is an empty set
 118         if (fPosition == -1)
 119             toSet.zeroBits();
 120 
 121         // Otherwise, its just the one bit of our position
 122         else
 123             toSet.setBit(fPosition);
 124     }
 125 
 126     protected void calcLastPos(CMStateSet toSet) {
 127         // If we are an epsilon node, then the last pos is an empty set
 128         if (fPosition == -1)
 129             toSet.zeroBits();
 130 
 131         // Otherwise, its just the one bit of our position
 132         else
 133             toSet.setBit(fPosition);
 134     }
 135 
 136 } // class XSCMLeaf