FileDocCategorySizeDatePackage
GenericElementNode.javaAPI DocphoneME MR2 API (J2ME)6677Wed May 02 18:00:34 BST 2007com.sun.perseus.model

GenericElementNode

public class GenericElementNode extends ElementNode
A GenericElementNode is used to model elements which are either unknown to Perseus or have no special behavior or attributes. Note that GenericElementNode is needed because we want to avoid storing a namespaceURI and localName references for nodes which always return constants for these values. Another option was to have namespaceURI and localName be attributes of ElementNode, but that would have forced us to carry two extra references on all nodes, which is superfluous.
version
$Id: GenericElementNode.java,v 1.3 2006/04/21 06:37:21 st125089 Exp $

Fields Summary
protected String
namespaceURI
The element's namespace URI.
protected String
localName
The element's local name.
protected String
content
The text content
Constructors Summary
public GenericElementNode(String namespaceURI, String localName, DocumentNode doc)
Constructor, providing the element's namespace and local name

param
namespaceURI the element's namespace. May be null.
param
localName the element's localName. Should not be null.
param
doc the DocumentNode this node belongs to. Should not be null.
throws
IllegalArgumentException if one of the arguments is null.

        super(doc);

        if (localName == null) {
            throw new IllegalArgumentException();
        }

        this.namespaceURI = namespaceURI;
        this.localName = localName;
    
Methods Summary
public voidappendTextChild(java.lang.String text)

param
text the text to append to this node's content. If text is null or empty, this does nothing.

        if (text == null || text.length() == 0) {
            return;
        }

        if (content == null) {
            setContent(text);
        } else {
            setContent(content + text);
        }
    
TraitAnimcreateTraitAnimImpl(java.lang.String traitName)

param
traitName the trait name.

        if (SVGConstants.SVG_TEXT_PSEUDO_ATTRIBUTE == traitName) {
            return new StringTraitAnim(this, NULL_NS, traitName);
        } else {
            return super.createTraitAnimImpl(traitName);
        }
    
public java.lang.StringgetContent()

return
this node's text content as a string

        return content;
    
public java.lang.StringgetLocalName()

return
the localName provided in the constructor.

        return localName;
    
public java.lang.StringgetNamespaceURI()

return
the namespaceURI provided in the constructor.

        return namespaceURI;
    
public java.lang.StringgetTraitImpl(java.lang.String name)
Handles #text traits.

param
name the requested trait's name (e.g., "#text")
return
the requested trait's string value (e.g., "Hello SVG Text")
throws
DOMException with error code NOT_SUPPORTED_ERROR if the requested trait is not supported on this element or null.
throws
DOMException with error code TYPE_MISMATCH_ERR if requested trait's computed value cannot be converted to a String (SVG Tiny only).

        if (SVGConstants.SVG_TEXT_PSEUDO_ATTRIBUTE == name) {
            if (content == null) {
                return "";
            }
            return getContent();
        } else {
            return super.getTraitImpl(name);
        }
    
public ElementNodenewInstance(DocumentNode doc)
Used by DocumentNode to create a new instance from a prototype GenericElementNode.

param
doc the DocumentNode for which a new node is should be created.
return
a new GenericElementNode for the requested document.

        return new GenericElementNode(namespaceURI, localName, doc);
    
public voidsetContent(java.lang.String newContent)

param
newContent this node's new content string

        if (equal(newContent, content)) {
            return;
        }
        modifyingNode();
        this.content = newContent;
        modifiedNode();
    
public voidsetTraitImpl(java.lang.String name, java.lang.String value)
Handles the #text traits.

param
name the trait's name (e.g., "#text")
param
value the trait's value (e.g, "Hello SVG Text")
throws
DOMException with error code NOT_SUPPORTED_ERROR if the requested trait is not supported on this element or null.
throws
DOMException with error code TYPE_MISMATCH_ERR if the requested trait's value cannot be specified as a String
throws
DOMException with error code INVALID_ACCESS_ERR if the input value is an invalid value for the given trait or null.
throws
DOMException with error code NO_MODIFICATION_ALLOWED_ERR: if attempt is made to change readonly trait.

        if (SVGConstants.SVG_TEXT_PSEUDO_ATTRIBUTE == name) {
            if (value == null) {
                throw illegalTraitValue(name, value);
            }
            setContent(value);
        } else {
            super.setTraitImpl(name, value);
        }