You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xerces.apache.org by Thomas Bensler <tb...@debis.com> on 2000/02/16 13:56:38 UTC

[Xerces-J] customized DOM tree

Hi folks,

we are developing a Java application (using Xerces, latest release)
which should be able to create a "customized" DOM tree out of a flat XML
file. The word "customized" means that the tree (mostly) consists of
myElementImpl (instead of ElementImpl). myElementImpl is derived from
ElementImpl and contains some additional properties (i. e. a reference
of a object tree representing the content declaration of that element
type which is not a part of DOM).

Putting it into practice may done as follows:

- new class myDOMParser derived from DOMParser
   - call setDocumentClassName("myDocumentImpl") in constructor to
     switch the document factory
- new class myDocumentImpl derived from DocumentImpl
   - override createElement(java.lang.String) to produce
     myElementImpl objects instead ElementImpl objects

The original source code of DocumentImpl.createElement is:

  public Element createElement(String tagName) throws DOMException {
    if (!isXMLName(tagName)) {
      throw new DOMExceptionImpl(DOMException.INVALID_CHARACTER_ERR,
        "INVALID_CHARACTER_ERR");
    }
    return new ElementImpl(this, tagName);
  }

<QUESTION>
  If I do it like this:

  class myDocumentImpl extends DocumentImpl {
    createElement(String tagname) throws DOMException {
      Element localElement = super.createElement(tagname);
      ...
    }
  }

  ... how can I make a new myElementImpl object out of localElement
  (which is a ElementImpl instance)? Some kind of cloning? No idea.

  If I do it like this:

  class myDocumentImpl extends DocumentImpl throws DOMException {
    myDocumentImpl.createElement(String tagname) {
      // no super call
      if (!isXMLName(tagName)) {
        throw new DOMExceptionImpl(...);
      }
      return new myElementImpl(this, tagname);
    }
  }

  ... I would lose functionality of DocumentImpl.createElement (okay
  there is not much code in it but I do not want to lose it anyway).
</QUESTION>

Any suggestions how to solve this problem?

Thank you for helping!!

Ciao, Bens.
______________________________________________________________________
      _______
     / __   /____________ ______
    / /_/  // __  /     //     /\        Thomas Bensler
   /   ___// /_/ /      7  ___/_/       debis Systemhaus GEI
  / __    7  ___/  /   /___    /\     Lademannbogen 21-23
 / /_/   /  /  /  /   /       / /    D-22339 Hamburg
/_______/_____/__/___/_______/ /   fon: +49-40-5395-1879
\_______\_____\__\___\_______\/   net: tbensler@debis.com


Re: [Xerces-J] customized DOM tree

Posted by Sven Reimers <re...@tu-harburg.de>.
Hi,

The second way you propose
should not work AFAIK, because
you would have the same method with
different returntypes. I think that this
is not allowed according to JavaLangSpec. 

Cloneing is no possible way, sine cloneable
is not supported by the classes. 

Just my 2c.

Sven

===========================================
Sven Reimers
AB 2-05
Arbeitsbereich fuer
Prozessautomatisierungstechnik
TU Hamburg-Harburg
===========================================

Thomas Bensler wrote:
> 
> Hi folks,
> 
> we are developing a Java application (using Xerces, latest release)
> which should be able to create a "customized" DOM tree out of a flat XML
> file. The word "customized" means that the tree (mostly) consists of
> myElementImpl (instead of ElementImpl). myElementImpl is derived from
> ElementImpl and contains some additional properties (i. e. a reference
> of a object tree representing the content declaration of that element
> type which is not a part of DOM).
> 
> Putting it into practice may done as follows:
> 
> - new class myDOMParser derived from DOMParser
>    - call setDocumentClassName("myDocumentImpl") in constructor to
>      switch the document factory
> - new class myDocumentImpl derived from DocumentImpl
>    - override createElement(java.lang.String) to produce
>      myElementImpl objects instead ElementImpl objects
> 
> The original source code of DocumentImpl.createElement is:
> 
>   public Element createElement(String tagName) throws DOMException {
>     if (!isXMLName(tagName)) {
>       throw new DOMExceptionImpl(DOMException.INVALID_CHARACTER_ERR,
>         "INVALID_CHARACTER_ERR");
>     }
>     return new ElementImpl(this, tagName);
>   }
> 
> <QUESTION>
>   If I do it like this:
> 
>   class myDocumentImpl extends DocumentImpl {
>     createElement(String tagname) throws DOMException {
>       Element localElement = super.createElement(tagname);
>       ...
>     }
>   }
> 
>   ... how can I make a new myElementImpl object out of localElement
>   (which is a ElementImpl instance)? Some kind of cloning? No idea.
> 
>   If I do it like this:
> 
>   class myDocumentImpl extends DocumentImpl throws DOMException {
>     myDocumentImpl.createElement(String tagname) {
>       // no super call
>       if (!isXMLName(tagName)) {
>         throw new DOMExceptionImpl(...);
>       }
>       return new myElementImpl(this, tagname);
>     }
>   }
> 
>   ... I would lose functionality of DocumentImpl.createElement (okay
>   there is not much code in it but I do not want to lose it anyway).
> </QUESTION>
> 
> Any suggestions how to solve this problem?
> 
> Thank you for helping!!
> 
> Ciao, Bens.
> ______________________________________________________________________
>       _______
>      / __   /____________ ______
>     / /_/  // __  /     //     /\        Thomas Bensler
>    /   ___// /_/ /      7  ___/_/       debis Systemhaus GEI
>   / __    7  ___/  /   /___    /\     Lademannbogen 21-23
>  / /_/   /  /  /  /   /       / /    D-22339 Hamburg
> /_______/_____/__/___/_______/ /   fon: +49-40-5395-1879
> \_______\_____\__\___\_______\/   net: tbensler@debis.com