FileDocCategorySizeDatePackage
XMLDTDDescription.javaAPI DocJava SE 6 API8324Tue Jun 10 00:22:40 BST 2008com.sun.org.apache.xerces.internal.impl.dtd

XMLDTDDescription

public class XMLDTDDescription extends XMLResourceIdentifierImpl implements XMLDTDDescription
All information specific to DTD grammars.
xerces.internal
author
Neil Graham, IBM
version
$Id: XMLDTDDescription.java,v 1.1.2.1 2005/08/01 03:36:44 jeffsuttor Exp $

Fields Summary
protected String
fRootName
protected Vector
fPossibleRoots
Constructors Summary
public XMLDTDDescription(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(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;