1 57 58 package org.enhydra.apache.xerces.validators.datatype; 59 60 import java.util.Hashtable ; 61 62 import org.enhydra.apache.xerces.utils.XMLMessages; 63 64 72 public class IDDatatypeValidator extends StringDatatypeValidator { 73 private static Object fNullValue = new Object (); 74 75 public IDDatatypeValidator () throws InvalidDatatypeFacetException { 76 this( null, null, false ); } 78 79 public IDDatatypeValidator ( DatatypeValidator base, Hashtable facets, 80 boolean derivedByList ) throws InvalidDatatypeFacetException { 81 82 super (base, facets, derivedByList); 84 85 if ( derivedByList ) 87 return; 88 89 if (base != null) 91 setTokenType(((IDDatatypeValidator)base).fTokenType); 92 else 93 setTokenType(SPECIAL_TOKEN_IDNAME); 94 } 95 96 99 public short getWSFacet() { 100 return COLLAPSE; 101 } 102 103 117 public Object validate(String content, Object state ) throws InvalidDatatypeValueException{ 118 super.validate(content, state); 120 121 if (state != null) { 122 if ( !addId( content, (Hashtable )state) ) { 123 InvalidDatatypeValueException error = 124 new InvalidDatatypeValueException( "ID '" + content +"' has to be unique" ); 125 error.setMinorCode(XMLMessages.MSG_ID_NOT_UNIQUE); 126 error.setMajorCode(XMLMessages.VC_ID); 127 throw error; 128 } 129 } 130 131 return null; 132 } 133 134 135 138 public Object clone() throws CloneNotSupportedException { 139 throw new CloneNotSupportedException ("clone() is not supported in "+this.getClass().getName()); 140 } 141 142 143 144 private boolean addId(String content, Hashtable IDList) { 145 if ( IDList.containsKey( content ) ) 146 return false; 147 148 try { 149 IDList.put( content, fNullValue ); 150 } 151 catch ( OutOfMemoryError ex ) { 152 System.out.println( "Out of Memory: Hashtable of ID's has " + IDList.size() + " Elements" ); 153 ex.printStackTrace(); 154 } 155 return true; 156 } } 158 | Popular Tags |