FileDocCategorySizeDatePackage
XMLDTDDescription.javaAPI DocApache Xerces 3.0.16487Fri Sep 14 20:33:52 BST 2007org.apache.xerces.impl.dtd

XMLDTDDescription

public class XMLDTDDescription extends org.apache.xerces.util.XMLResourceIdentifierImpl implements org.apache.xerces.xni.grammars.XMLDTDDescription
All information specific to DTD grammars.
xerces.internal
author
Neil Graham, IBM
version
$Id: XMLDTDDescription.java 446755 2006-09-15 21:56:27Z mrglavas $

Fields Summary
protected String
fRootName
protected Vector
fPossibleRoots
Constructors Summary
public XMLDTDDescription(org.apache.xerces.xni.XMLResourceIdentifier id, String rootName)


    // Constructors:
         
        this.setValues(id.getPublicId(), id.getLiteralSystemId(),
                id.getBaseSystemId(), id.getExpandedSystemId());
        this.fRootName = rootName;
        this.fPossibleRoots = null;
    
public XMLDTDDescription(String publicId, String literalId, String baseId, String expandedId, String rootName)

        this.setValues(publicId, literalId, baseId, expandedId);
        this.fRootName = rootName;
        this.fPossibleRoots = null;
    
public XMLDTDDescription(org.apache.xerces.xni.parser.XMLInputSource source)

        this.setValues(source.getPublicId(), null,
                source.getBaseSystemId(), source.getSystemId());
        this.fRootName = null;
        this.fPossibleRoots = null;
    
Methods Summary
public booleanequals(java.lang.Object desc)
Compares this grammar with the given grammar. Currently, we compare as follows: - if grammar type not equal return false immediately - try and find a common root name: - if both have roots, use them - else if one has a root, examine other's possible root's for a match; - else try all combinations - test fExpandedSystemId and fPublicId as above

param
desc The description of the grammar to be compared with
return
True if they are equal, else false

        if(!(desc instanceof XMLGrammarDescription)) return false;
    	if (!getGrammarType().equals(((XMLGrammarDescription)desc).getGrammarType())) {
    	    return false;
    	}
        // assume it's a DTDDescription
        XMLDTDDescription dtdDesc = (XMLDTDDescription)desc;
        if(fRootName != null) {
            if((dtdDesc.fRootName) != null && !dtdDesc.fRootName.equals(fRootName)) {
                return false;
            } else if(dtdDesc.fPossibleRoots != null && !dtdDesc.fPossibleRoots.contains(fRootName)) {
                return false;
            }
        } else if(fPossibleRoots != null) {
            if(dtdDesc.fRootName != null) {
                if(!fPossibleRoots.contains(dtdDesc.fRootName)) { 
                    return false;
                }
            } else if(dtdDesc.fPossibleRoots == null) {
                return false;
            } else {
                boolean found = false;
                for(int i = 0; i<fPossibleRoots.size(); i++) {
                    String root = (String)fPossibleRoots.elementAt(i);
                    found = dtdDesc.fPossibleRoots.contains(root);
                    if(found) break;
                }
                if(!found) return false;
            }
        }
        // if we got this far we've got a root match... try other two fields,
        // since so many different DTD's have roots in common:
        if(fExpandedSystemId != null) {
            if(!fExpandedSystemId.equals(dtdDesc.fExpandedSystemId)) 
                return false;
        } 
        else if(dtdDesc.fExpandedSystemId != null)
            return false;
        if(fPublicId != null) {
            if(!fPublicId.equals(dtdDesc.fPublicId)) 
                return false;
        } 
        else if(dtdDesc.fPublicId != null)
            return false;
    	return true;
    
public java.lang.StringgetGrammarType()

        return XMLGrammarDescription.XML_DTD;
    
public java.lang.StringgetRootName()

return
the root name of this DTD or null if root name is unknown

        return fRootName;
    
public inthashCode()
Returns the hash code of this grammar Because our .equals method is so complex, we just return a very simple hash that might avoid calls to the equals method a bit...

return
The hash code

        if(fExpandedSystemId != null)
            return fExpandedSystemId.hashCode();
        if(fPublicId != null)
            return fPublicId.hashCode();
        // give up; hope .equals can handle it:
        return 0;
    
public voidsetPossibleRoots(java.util.Vector possibleRoots)
Set possible roots

        fPossibleRoots = possibleRoots;
    
public voidsetRootName(java.lang.String rootName)
Set the root name

        fRootName = rootName;
        fPossibleRoots = null;