1 57 58 package org.enhydra.apache.xerces.validators.common; 59 60 import org.enhydra.apache.xerces.framework.XMLContentSpec; 61 import org.enhydra.apache.xerces.utils.ImplementationMessages; 62 63 67 public class CMBinOp extends CMNode 68 { 69 public CMBinOp(int type, CMNode leftNode, CMNode rightNode) throws CMException 73 { 74 super(type); 75 76 if ((type() != XMLContentSpec.CONTENTSPECNODE_CHOICE) 78 && (type() != XMLContentSpec.CONTENTSPECNODE_SEQ)) 79 { 80 throw new CMException(ImplementationMessages.VAL_BST); 81 } 82 83 fLeftChild = leftNode; 85 fRightChild = rightNode; 86 } 87 88 89 final CMNode getLeft() 93 { 94 return fLeftChild; 95 } 96 97 final CMNode getRight() 98 { 99 return fRightChild; 100 } 101 102 103 boolean isNullable() throws CMException 107 { 108 if (type() == XMLContentSpec.CONTENTSPECNODE_CHOICE) 114 return (fLeftChild.isNullable() || fRightChild.isNullable()); 115 else if (type() == XMLContentSpec.CONTENTSPECNODE_SEQ) 116 return (fLeftChild.isNullable() && fRightChild.isNullable()); 117 else 118 throw new CMException(ImplementationMessages.VAL_BST); 119 } 120 121 122 protected void calcFirstPos(CMStateSet toSet) throws CMException 126 { 127 if (type() == XMLContentSpec.CONTENTSPECNODE_CHOICE) 128 { 129 toSet.setTo(fLeftChild.firstPos()); 131 toSet.union(fRightChild.firstPos()); 132 } 133 else if (type() == XMLContentSpec.CONTENTSPECNODE_SEQ) 134 { 135 toSet.setTo(fLeftChild.firstPos()); 141 if (fLeftChild.isNullable()) 142 toSet.union(fRightChild.firstPos()); 143 } 144 else 145 { 146 throw new CMException(ImplementationMessages.VAL_BST); 147 } 148 } 149 150 protected void calcLastPos(CMStateSet toSet) throws CMException 151 { 152 if (type() == XMLContentSpec.CONTENTSPECNODE_CHOICE) 153 { 154 toSet.setTo(fLeftChild.lastPos()); 156 toSet.union(fRightChild.lastPos()); 157 } 158 else if (type() == XMLContentSpec.CONTENTSPECNODE_SEQ) 159 { 160 toSet.setTo(fRightChild.lastPos()); 166 if (fRightChild.isNullable()) 167 toSet.union(fLeftChild.lastPos()); 168 } 169 else 170 { 171 throw new CMException(ImplementationMessages.VAL_BST); 172 } 173 } 174 175 176 private CMNode fLeftChild; 185 private CMNode fRightChild; 186 }; 187 | Popular Tags |