1 57 58 package com.sun.org.apache.xerces.internal.impl.dtd; 59 60 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarDescription; 61 import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier; 62 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; 63 64 import com.sun.org.apache.xerces.internal.util.XMLResourceIdentifierImpl; 65 import java.util.Vector ; 66 67 73 74 public class XMLDTDDescription extends XMLResourceIdentifierImpl 75 implements com.sun.org.apache.xerces.internal.xni.grammars.XMLDTDDescription { 76 77 79 protected String fRootName = null; 82 83 protected Vector fPossibleRoots = null; 86 87 public XMLDTDDescription(XMLResourceIdentifier id, String rootName) { 89 this.setValues(id.getPublicId(), id.getLiteralSystemId(), 90 id.getBaseSystemId(), id.getExpandedSystemId()); 91 this.fRootName = rootName; 92 this.fPossibleRoots = null; 93 } 95 public XMLDTDDescription(String publicId, String literalId, 96 String baseId, String expandedId, String rootName) { 97 this.setValues(publicId, literalId, baseId, expandedId); 98 this.fRootName = rootName; 99 this.fPossibleRoots = null; 100 } 102 public XMLDTDDescription(XMLInputSource source) { 103 this.setValues(source.getPublicId(), null, 104 source.getBaseSystemId(), source.getSystemId()); 105 this.fRootName = null; 106 this.fPossibleRoots = null; 107 } 109 111 public String getGrammarType () { 112 return XMLGrammarDescription.XML_DTD; 113 } 115 public String getRootName() { 118 return fRootName; 119 } 121 public void setRootName(String rootName) { 123 fRootName = rootName; 124 fPossibleRoots = null; 125 } 126 127 public void setPossibleRoots(Vector possibleRoots) { 129 fPossibleRoots = possibleRoots; 130 } 131 132 145 public boolean equals(Object desc) { 146 if(!(desc instanceof XMLGrammarDescription)) return false; 147 if (!getGrammarType().equals(((XMLGrammarDescription)desc).getGrammarType())) { 148 return false; 149 } 150 XMLDTDDescription dtdDesc = (XMLDTDDescription)desc; 152 if(fRootName != null) { 153 if((dtdDesc.fRootName) != null && !dtdDesc.fRootName.equals(fRootName)) { 154 return false; 155 } else if(dtdDesc.fPossibleRoots != null && !dtdDesc.fPossibleRoots.contains(fRootName)) { 156 return false; 157 } 158 } else if(fPossibleRoots != null) { 159 if(dtdDesc.fRootName != null) { 160 if(!fPossibleRoots.contains(dtdDesc.fRootName)) { 161 return false; 162 } 163 } else if(dtdDesc.fPossibleRoots == null) { 164 return false; 165 } else { 166 boolean found = false; 167 for(int i = 0; i<fPossibleRoots.size(); i++) { 168 String root = (String )fPossibleRoots.elementAt(i); 169 found = dtdDesc.fPossibleRoots.contains(root); 170 if(found) break; 171 } 172 if(!found) return false; 173 } 174 } 175 if(fExpandedSystemId != null) { 178 if(!fExpandedSystemId.equals(dtdDesc.fExpandedSystemId)) 179 return false; 180 } 181 else if(dtdDesc.fExpandedSystemId != null) 182 return false; 183 if(fPublicId != null) { 184 if(!fPublicId.equals(dtdDesc.fPublicId)) 185 return false; 186 } 187 else if(dtdDesc.fPublicId != null) 188 return false; 189 return true; 190 } 191 192 198 public int hashCode() { 199 if(fExpandedSystemId != null) 200 return fExpandedSystemId.hashCode(); 201 if(fPublicId != null) 202 return fPublicId.hashCode(); 203 return 0; 205 } 206 } 208 | Popular Tags |