1 /* 2 * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved. 3 */ 4 /* 5 * Licensed to the Apache Software Foundation (ASF) under one or more 6 * contributor license agreements. See the NOTICE file distributed with 7 * this work for additional information regarding copyright ownership. 8 * The ASF licenses this file to You under the Apache License, Version 2.0 9 * (the "License"); you may not use this file except in compliance with 10 * the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 21 package com.sun.org.apache.xerces.internal.impl.dtd.models; 22 23 /** 24 * A content model node. 25 * 26 * @xerces.internal 27 * 28 */ 29 public abstract class CMNode 30 { 31 // ------------------------------------------------------------------- 32 // Constructors 33 // ------------------------------------------------------------------- CMNode(int type)34 public CMNode(int type) 35 { 36 fType = type; 37 } 38 39 40 // ------------------------------------------------------------------- 41 // Package, abstract methods 42 // ------------------------------------------------------------------- 43 // made this public so it could be implemented and used outside this package -neilg. isNullable()44 public abstract boolean isNullable() ; 45 46 47 // ------------------------------------------------------------------- 48 // Package final methods 49 // ------------------------------------------------------------------- type()50 public final int type() 51 { 52 return fType; 53 } 54 55 // made this public so it could be implemented and used outside this package -neilg. firstPos()56 public final CMStateSet firstPos() 57 { 58 if (fFirstPos == null) 59 { 60 fFirstPos = new CMStateSet(fMaxStates); 61 calcFirstPos(fFirstPos); 62 } 63 return fFirstPos; 64 } 65 66 // made this public so it could be implemented and used outside this package -neilg. lastPos()67 public final CMStateSet lastPos() 68 { 69 if (fLastPos == null) 70 { 71 fLastPos = new CMStateSet(fMaxStates); 72 calcLastPos(fLastPos); 73 } 74 return fLastPos; 75 } 76 setFollowPos(CMStateSet setToAdopt)77 final void setFollowPos(CMStateSet setToAdopt) 78 { 79 fFollowPos = setToAdopt; 80 } 81 setMaxStates(int maxStates)82 public final void setMaxStates(int maxStates) 83 { 84 fMaxStates = maxStates; 85 } 86 isCompactedForUPA()87 public boolean isCompactedForUPA() { 88 return fCompactedForUPA; 89 } 90 setIsCompactUPAModel(boolean value)91 public void setIsCompactUPAModel(boolean value) { 92 fCompactedForUPA = value; 93 } 94 95 /** 96 * Allows the user to set arbitrary data on this content model 97 * node. This is used by the a{n,m} optimization that runs 98 * in constant space. 99 */ setUserData(Object userData)100 public void setUserData(Object userData) { 101 fUserData = userData; 102 } 103 104 /** 105 * Allows the user to get arbitrary data set on this content 106 * model node. This is used by the a{n,m} optimization that runs 107 * in constant space. 108 */ getUserData()109 public Object getUserData() { 110 return fUserData; 111 } 112 113 // ------------------------------------------------------------------- 114 // Protected, abstract methods 115 // ------------------------------------------------------------------- calcFirstPos(CMStateSet toSet)116 protected abstract void calcFirstPos(CMStateSet toSet) ; 117 calcLastPos(CMStateSet toSet)118 protected abstract void calcLastPos(CMStateSet toSet) ; 119 120 121 // ------------------------------------------------------------------- 122 // Private data members 123 // 124 // fType 125 // The type of node. This indicates whether its a leaf or an 126 // operation. Though we also do derived classes for these types, 127 // it is too expensive to use runtime typing to find this out. 128 // This is one of the ContentSpecNode.NODE_XXX types. 129 // 130 // fFirstPos 131 // The set of NFA states that represent the entry states of this 132 // node in the DFA. 133 // 134 // fFollowPos 135 // The set of NFA states that can be gotten to from from this 136 // node in the DFA. 137 // 138 // fLastPos 139 // The set of NFA states that represent the final states of this 140 // node in the DFA. 141 // 142 // fMaxStates 143 // The maximum number of states that the NFA has, which means the 144 // max number of NFA states that have to be traced in the state 145 // sets during the building of the DFA. Its unfortunate that it 146 // has to be stored redundantly, but we need to fault in the 147 // state set members and they have to be sized to this size. We 148 // init to to -1 so it will cause an error if its used without 149 // being initialized. 150 // ------------------------------------------------------------------- 151 private final int fType; 152 private CMStateSet fFirstPos = null; 153 private CMStateSet fFollowPos = null; 154 private CMStateSet fLastPos = null; 155 private int fMaxStates = -1; 156 private Object fUserData = null; 157 /* 158 * This boolean is true if the model represented by the CMNode does not represent 159 * the true model from the schema, but has had its min/maxOccurs modified for a 160 * more compact representation (for purposes of UPA). 161 */ 162 private boolean fCompactedForUPA = false; 163 }; 164