FileDocCategorySizeDatePackage
DocumentTypeImpl.javaAPI DocJava SE 6 API14011Tue Jun 10 00:22:36 BST 2008com.sun.org.apache.xerces.internal.dom

DocumentTypeImpl

public class DocumentTypeImpl extends ParentNode implements DocumentType
This class represents a Document Type declaraction in the document itself, not a Document Type Definition (DTD). An XML document may (or may not) have such a reference.

DocumentType is an Extended DOM feature, used in XML documents but not in HTML.

Note that Entities and Notations are no longer children of the DocumentType, but are parentless nodes hung only in their appropriate NamedNodeMaps.

This area is UNDERSPECIFIED IN REC-DOM-Level-1-19981001 Most notably, absolutely no provision was made for storing and using Element and Attribute information. Nor was the linkage between Entities and Entity References nailed down solidly.

xerces.internal
author
Arnaud Le Hors, IBM
author
Joe Kesselman, IBM
author
Andy Clark, IBM
version
$Id: DocumentTypeImpl.java,v 1.2.6.1 2005/08/31 11:00:24 sunithareddy Exp $
since
PR-DOM-Level-1-19980818.

Fields Summary
static final long
serialVersionUID
Serialization version.
protected String
name
Document type name.
protected NamedNodeMapImpl
entities
Entities.
protected NamedNodeMapImpl
notations
Notations.
protected NamedNodeMapImpl
elements
Elements.
protected String
publicID
protected String
systemID
protected String
internalSubset
private int
doctypeNumber
The following are required for compareDocumentPosition
private Hashtable
userData
Constructors Summary
public DocumentTypeImpl(CoreDocumentImpl ownerDocument, String name)
Factory method for creating a document type node.

             
         
        super(ownerDocument);

        this.name = name;
        // DOM
        entities  = new NamedNodeMapImpl(this);
        notations = new NamedNodeMapImpl(this);

        // NON-DOM
        elements = new NamedNodeMapImpl(this);

    
public DocumentTypeImpl(CoreDocumentImpl ownerDocument, String qualifiedName, String publicID, String systemID)
Factory method for creating a document type node.

        this(ownerDocument, qualifiedName);
        this.publicID = publicID;
        this.systemID = systemID;

    
Methods Summary
public org.w3c.dom.NodecloneNode(boolean deep)
Clones the node.


    	DocumentTypeImpl newnode = (DocumentTypeImpl)super.cloneNode(deep);
    	// NamedNodeMaps must be cloned explicitly, to avoid sharing them.
    	newnode.entities  = entities.cloneMap(newnode);
    	newnode.notations = notations.cloneMap(newnode);
    	newnode.elements  = elements.cloneMap(newnode);

    	return newnode;

    
public org.w3c.dom.NamedNodeMapgetElements()
NON-DOM: Access the collection of ElementDefinitions.

see
ElementDefinitionImpl

        if (needsSyncChildren()) {
            synchronizeChildren();
        }
    	return elements;
    
public org.w3c.dom.NamedNodeMapgetEntities()
Access the collection of general Entities, both external and internal, defined in the DTD. For example, in:

<!doctype example SYSTEM "ex.dtd" [
<!ENTITY foo "foo">
<!ENTITY bar "bar">
<!ENTITY % baz "baz">
]>

The Entities map includes foo and bar, but not baz. It is promised that only Nodes which are Entities will exist in this NamedNodeMap.

For HTML, this will always be null.

Note that "built in" entities such as & and < should be converted to their actual characters before being placed in the DOM's contained text, and should be converted back when the DOM is rendered as XML or HTML, and hence DO NOT appear here.

        if (needsSyncChildren()) {
            synchronizeChildren();
            }
    	return entities;
    
public java.lang.StringgetInternalSubset()
Introduced in DOM Level 2.

Return the internalSubset given as a string.

since
WD-DOM-Level-2-19990923

        if (needsSyncData()) {
            synchronizeData();
        }
        return internalSubset;
    
public java.lang.StringgetName()
Name of this document type. If we loaded from a DTD, this should be the name immediately following the DOCTYPE keyword.


        if (needsSyncData()) {
            synchronizeData();
        }
    	return name;

    
public java.lang.StringgetNodeName()
Returns the document type name

        if (needsSyncData()) {
            synchronizeData();
        }
        return name;
    
protected intgetNodeNumber()
NON-DOM Get the number associated with this doctype.

         // If the doctype has a document owner, get the node number 
         // relative to the owner doc
         if (getOwnerDocument()!=null) 
            return super.getNodeNumber();

         // The doctype is disconnected and not associated with any document.
         // Assign the doctype a number relative to the implementation.
         if (doctypeNumber==0) {
          
            CoreDOMImplementationImpl cd = (CoreDOMImplementationImpl)CoreDOMImplementationImpl.getDOMImplementation();
            doctypeNumber = cd.assignDocTypeNumber();   
         }
         return doctypeNumber;
    
public shortgetNodeType()
A short integer indicating what type of node this is. The named constants for this value are defined in the org.w3c.dom.Node interface.

        return Node.DOCUMENT_TYPE_NODE;
    
public org.w3c.dom.NamedNodeMapgetNotations()
Access the collection of Notations defined in the DTD. A notation declares, by name, the format of an XML unparsed entity or is used to formally declare a Processing Instruction target.

        if (needsSyncChildren()) {
            synchronizeChildren();
            }
    	return notations;
    
public java.lang.StringgetPublicId()
Introduced in DOM Level 2.

Return the public identifier of this Document type.

since
WD-DOM-Level-2-19990923

        if (needsSyncData()) {
            synchronizeData();
        }
        return publicID;
    
public java.lang.StringgetSystemId()
Introduced in DOM Level 2.

Return the system identifier of this Document type.

since
WD-DOM-Level-2-19990923

        if (needsSyncData()) {
            synchronizeData();
        }
        return systemID;
    
public java.lang.StringgetTextContent()

        return null;
    
public java.lang.ObjectgetUserData(java.lang.String key)

        if (userData == null) {
            return null;
        }
        Object o = userData.get(key);
        if (o != null) {
            UserDataRecord r = (UserDataRecord) o;
            return r.fData;
        }
        return null;
    
protected java.util.HashtablegetUserDataRecord()

        return userData;
    
public booleanisEqualNode(org.w3c.dom.Node arg)
DOM Level 3 WD- Experimental. Override inherited behavior from ParentNodeImpl to support deep equal.

        
        if (!super.isEqualNode(arg)) {
            return false;
        }
        
        if (needsSyncData()) {
            synchronizeData();
        }
        DocumentTypeImpl argDocType = (DocumentTypeImpl) arg;

        //test if the following string attributes are equal: publicId, 
        //systemId, internalSubset.
        if ((getPublicId() == null && argDocType.getPublicId() != null)
            || (getPublicId() != null && argDocType.getPublicId() == null)
            || (getSystemId() == null && argDocType.getSystemId() != null)
            || (getSystemId() != null && argDocType.getSystemId() == null)
            || (getInternalSubset() == null
                && argDocType.getInternalSubset() != null)
            || (getInternalSubset() != null
                && argDocType.getInternalSubset() == null)) {
            return false;
        }

        if (getPublicId() != null) {
            if (!getPublicId().equals(argDocType.getPublicId())) {
                return false;
            }
        }

        if (getSystemId() != null) {
            if (!getSystemId().equals(argDocType.getSystemId())) {
                return false;
            }
        }

        if (getInternalSubset() != null) {
            if (!getInternalSubset().equals(argDocType.getInternalSubset())) {
                return false;
            }
        }

        //test if NamedNodeMaps entities and notations are equal
        NamedNodeMapImpl argEntities = argDocType.entities;

        if ((entities == null && argEntities != null)
            || (entities != null && argEntities == null))
            return false;

        if (entities != null && argEntities != null) {
            if (entities.getLength() != argEntities.getLength())
                return false;

            for (int index = 0; entities.item(index) != null; index++) {
                Node entNode1 = entities.item(index);
                Node entNode2 =
                    argEntities.getNamedItem(entNode1.getNodeName());

                if (!((NodeImpl) entNode1).isEqualNode((NodeImpl) entNode2))
                    return false;
            }
        }

        NamedNodeMapImpl argNotations = argDocType.notations;

        if ((notations == null && argNotations != null)
            || (notations != null && argNotations == null))
            return false;

        if (notations != null && argNotations != null) {
            if (notations.getLength() != argNotations.getLength())
                return false;

            for (int index = 0; notations.item(index) != null; index++) {
                Node noteNode1 = notations.item(index);
                Node noteNode2 =
                    argNotations.getNamedItem(noteNode1.getNodeName());

                if (!((NodeImpl) noteNode1).isEqualNode((NodeImpl) noteNode2))
                    return false;
            }
        }

        return true;
    
public voidsetInternalSubset(java.lang.String internalSubset)
NON-DOM.

Set the internalSubset given as a string.

        if (needsSyncData()) {
            synchronizeData();
        }
        this.internalSubset = internalSubset;
    
voidsetOwnerDocument(com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl doc)
NON-DOM set the ownerDocument of this node and its children

        super.setOwnerDocument(doc);
        entities.setOwnerDocument(doc);
        notations.setOwnerDocument(doc);
        elements.setOwnerDocument(doc);
    
public voidsetReadOnly(boolean readOnly, boolean deep)
NON-DOM: Subclassed to flip the entities' and notations' readonly switch as well.

see
NodeImpl#setReadOnly

    	
        if (needsSyncChildren()) {
            synchronizeChildren();
        }
        super.setReadOnly(readOnly, deep);

        // set read-only property
        elements.setReadOnly(readOnly, true);
        entities.setReadOnly(readOnly, true);
    	notations.setReadOnly(readOnly, true);

    
public voidsetTextContent(java.lang.String textContent)

        // no-op
    
public java.lang.ObjectsetUserData(java.lang.String key, java.lang.Object data, org.w3c.dom.UserDataHandler handler)

        if(userData == null)
            userData = new Hashtable();
        if (data == null) {
            if (userData != null) {
                Object o = userData.remove(key);
                if (o != null) {
                    UserDataRecord r = (UserDataRecord) o;
                    return r.fData;
                }
            }
            return null;
        }
        else {
            Object o = userData.put(key, new UserDataRecord(data, handler));
            if (o != null) {
                UserDataRecord r = (UserDataRecord) o;
                return r.fData;
            }
        }
        return null;