}
public OMElement createOMElement(String localName, OMNamespace ns,
OMContainer parent) throws OMDOMException {
if (parent == null) {
return new ElementImpl((DocumentImpl) this.createOMDocument(),
localName, (NamespaceImpl) ns, this);
}
switch (((ParentNode) parent).getNodeType()) {
case Node.ELEMENT_NODE: // We are adding a new child to an elem
ElementImpl parentElem = (ElementImpl) parent;
ElementImpl elem = new ElementImpl((DocumentImpl) parentElem
.getOwnerDocument(), localName, (NamespaceImpl) ns, this);
parentElem.appendChild(elem);
return elem;
case Node.DOCUMENT_NODE:
DocumentImpl docImpl = (DocumentImpl) parent;
return new ElementImpl(docImpl, localName,
(NamespaceImpl) ns, this);
case Node.DOCUMENT_FRAGMENT_NODE:
DocumentFragmentImpl docFragImpl = (DocumentFragmentImpl) parent;
return new ElementImpl((DocumentImpl) docFragImpl
.getOwnerDocument(), localName, (NamespaceImpl) ns, this);
default:
throw new OMDOMException(
"The parent container can only be an ELEMENT, DOCUMENT " +
"or a DOCUMENT FRAGMENT");