fchen8@gmail.com | 11 Apr 2008 05:29
Picon

Is it possible to extend nsIDOMNode and alike?

I have Mozilla embedded in my application through Java-xpcom. I want
to attach certain reference (to Java object) to each of the nodes in
the DOM tree. In another word, once I get a nsIDOMNode from Mozilla, I
would like to call methods on its attached reference. I can certainly
build a map and store the references in it. But it won't scale well
and constantly adding/removing from a big map is kind of expensive.
Since nsIDOMNode is an interface, I am thinking if I can wrap
Mozilla's implementation in my own class and somehow provide that
class back to Mozilla DOM then I should be able to achieve what I
need. The problem now lies in how to provide the class back to
Mozilla. nsIDOMDOMImplementation looks like a potential entry point
but is read-only on nsIDOMDocument. Is the route I am taking even
possible in xpcom? Are there any other solutions that you can suggest?
Thanks in advance for your help.

Feng
Jonas Sicking | 12 Apr 2008 00:22
Gravatar

Re: Is it possible to extend nsIDOMNode and alike?

fchen8 <at> gmail.com wrote:
> I have Mozilla embedded in my application through Java-xpcom. I want
> to attach certain reference (to Java object) to each of the nodes in
> the DOM tree. In another word, once I get a nsIDOMNode from Mozilla, I
> would like to call methods on its attached reference. I can certainly
> build a map and store the references in it. But it won't scale well
> and constantly adding/removing from a big map is kind of expensive.
> Since nsIDOMNode is an interface, I am thinking if I can wrap
> Mozilla's implementation in my own class and somehow provide that
> class back to Mozilla DOM then I should be able to achieve what I
> need. The problem now lies in how to provide the class back to
> Mozilla. nsIDOMDOMImplementation looks like a potential entry point
> but is read-only on nsIDOMDocument. Is the route I am taking even
> possible in xpcom? Are there any other solutions that you can suggest?
> Thanks in advance for your help.

Passing back another object is unlikely going to work. The nodes in 
mozilla have to implement a large number of interfaces and you'd have to 
get them exactly right for all types of nodes for things to work properly.

What you could do instead is to QueryInterface the node to nsINode and 
use the Get/Set/Delete/UnsetProperty API to store any additional 
information about the node that you need.

Note though that behind the scene that is implemented using a hash 
table, so if you're worried about performance with that then this API 
isn't going to help you much.

That said, hash tables generally scale really well. It shouldn't be any 
slower to use a hashtable with 1000 entries, than one with 2 (not 
(Continue reading)

fchen8@gmail.com | 14 Apr 2008 16:51
Picon

Re: Is it possible to extend nsIDOMNode and alike?

On Apr 11, 6:22 pm, Jonas Sicking <jo... <at> sicking.cc> wrote:
> fch... <at> gmail.com wrote:
> > I have Mozilla embedded in my application through Java-xpcom. I want
> > to attach certain reference (to Java object) to each of the nodes in
> > the DOM tree. In another word, once I get a nsIDOMNode from Mozilla, I
> > would like to call methods on its attached reference. I can certainly
> > build a map and store the references in it. But it won't scale well
> > and constantly adding/removing from a big map is kind of expensive.
> > Since nsIDOMNode is an interface, I am thinking if I can wrap
> > Mozilla's implementation in my own class and somehow provide that
> > class back to Mozilla DOM then I should be able to achieve what I
> > need. The problem now lies in how to provide the class back to
> > Mozilla. nsIDOMDOMImplementation looks like a potential entry point
> > but is read-only on nsIDOMDocument. Is the route I am taking even
> > possible in xpcom? Are there any other solutions that you can suggest?
> > Thanks in advance for your help.
>
> Passing back another object is unlikely going to work. The nodes in
> mozilla have to implement a large number of interfaces and you'd have to
> get them exactly right for all types of nodes for things to work properly.
>
> What you could do instead is to QueryInterface the node to nsINode and
> use the Get/Set/Delete/UnsetProperty API to store any additional
> information about the node that you need.
>
> Note though that behind the scene that is implemented using a hash
> table, so if you're worried about performance with that then this API
> isn't going to help you much.
>
> That said, hash tables generally scale really well. It shouldn't be any
(Continue reading)

Jonas Sicking | 15 Apr 2008 01:54
Gravatar

Re: Is it possible to extend nsIDOMNode and alike?

fchen8 <at> gmail.com wrote:
> On Apr 11, 6:22 pm, Jonas Sicking <jo... <at> sicking.cc> wrote:
>> fch... <at> gmail.com wrote:
>>> I have Mozilla embedded in my application through Java-xpcom. I want
>>> to attach certain reference (to Java object) to each of the nodes in
>>> the DOM tree. In another word, once I get a nsIDOMNode from Mozilla, I
>>> would like to call methods on its attached reference. I can certainly
>>> build a map and store the references in it. But it won't scale well
>>> and constantly adding/removing from a big map is kind of expensive.
>>> Since nsIDOMNode is an interface, I am thinking if I can wrap
>>> Mozilla's implementation in my own class and somehow provide that
>>> class back to Mozilla DOM then I should be able to achieve what I
>>> need. The problem now lies in how to provide the class back to
>>> Mozilla. nsIDOMDOMImplementation looks like a potential entry point
>>> but is read-only on nsIDOMDocument. Is the route I am taking even
>>> possible in xpcom? Are there any other solutions that you can suggest?
>>> Thanks in advance for your help.
>> Passing back another object is unlikely going to work. The nodes in
>> mozilla have to implement a large number of interfaces and you'd have to
>> get them exactly right for all types of nodes for things to work properly.
>>
>> What you could do instead is to QueryInterface the node to nsINode and
>> use the Get/Set/Delete/UnsetProperty API to store any additional
>> information about the node that you need.
>>
>> Note though that behind the scene that is implemented using a hash
>> table, so if you're worried about performance with that then this API
>> isn't going to help you much.
>>
>> That said, hash tables generally scale really well. It shouldn't be any
(Continue reading)

fchen8@gmail.com | 15 Apr 2008 23:15
Picon

Re: Is it possible to extend nsIDOMNode and alike?

On Apr 14, 7:54 pm, Jonas Sicking <jo... <at> sicking.cc> wrote:
> fch... <at> gmail.com wrote:
> > On Apr 11, 6:22 pm, Jonas Sicking <jo... <at> sicking.cc> wrote:
> >> fch... <at> gmail.com wrote:
> >>> I have Mozilla embedded in my application through Java-xpcom. I want
> >>> to attach certain reference (to Java object) to each of the nodes in
> >>> the DOM tree. In another word, once I get a nsIDOMNode from Mozilla, I
> >>> would like to call methods on its attached reference. I can certainly
> >>> build a map and store the references in it. But it won't scale well
> >>> and constantly adding/removing from a big map is kind of expensive.
> >>> Since nsIDOMNode is an interface, I am thinking if I can wrap
> >>> Mozilla's implementation in my own class and somehow provide that
> >>> class back to Mozilla DOM then I should be able to achieve what I
> >>> need. The problem now lies in how to provide the class back to
> >>> Mozilla. nsIDOMDOMImplementation looks like a potential entry point
> >>> but is read-only on nsIDOMDocument. Is the route I am taking even
> >>> possible in xpcom? Are there any other solutions that you can suggest?
> >>> Thanks in advance for your help.
> >> Passing back another object is unlikely going to work. The nodes in
> >> mozilla have to implement a large number of interfaces and you'd have to
> >> get them exactly right for all types of nodes for things to work properly.
>
> >> What you could do instead is to QueryInterface the node to nsINode and
> >> use the Get/Set/Delete/UnsetProperty API to store any additional
> >> information about the node that you need.
>
> >> Note though that behind the scene that is implemented using a hash
> >> table, so if you're worried about performance with that then this API
> >> isn't going to help you much.
>
(Continue reading)

Jonas Sicking | 16 Apr 2008 01:13
Gravatar

Re: Is it possible to extend nsIDOMNode and alike?

fchen8 <at> gmail.com wrote:
> On Apr 14, 7:54 pm, Jonas Sicking <jo... <at> sicking.cc> wrote:
>> fch... <at> gmail.com wrote:
>>> On Apr 11, 6:22 pm, Jonas Sicking <jo... <at> sicking.cc> wrote:
>>>> fch... <at> gmail.com wrote:
>>>>> I have Mozilla embedded in my application through Java-xpcom. I want
>>>>> to attach certain reference (to Java object) to each of the nodes in
>>>>> the DOM tree. In another word, once I get a nsIDOMNode from Mozilla, I
>>>>> would like to call methods on its attached reference. I can certainly
>>>>> build a map and store the references in it. But it won't scale well
>>>>> and constantly adding/removing from a big map is kind of expensive.
>>>>> Since nsIDOMNode is an interface, I am thinking if I can wrap
>>>>> Mozilla's implementation in my own class and somehow provide that
>>>>> class back to Mozilla DOM then I should be able to achieve what I
>>>>> need. The problem now lies in how to provide the class back to
>>>>> Mozilla. nsIDOMDOMImplementation looks like a potential entry point
>>>>> but is read-only on nsIDOMDocument. Is the route I am taking even
>>>>> possible in xpcom? Are there any other solutions that you can suggest?
>>>>> Thanks in advance for your help.
>>>> Passing back another object is unlikely going to work. The nodes in
>>>> mozilla have to implement a large number of interfaces and you'd have to
>>>> get them exactly right for all types of nodes for things to work properly.
>>>> What you could do instead is to QueryInterface the node to nsINode and
>>>> use the Get/Set/Delete/UnsetProperty API to store any additional
>>>> information about the node that you need.
>>>> Note though that behind the scene that is implemented using a hash
>>>> table, so if you're worried about performance with that then this API
>>>> isn't going to help you much.
>>>> That said, hash tables generally scale really well. It shouldn't be any
>>>> slower to use a hashtable with 1000 entries, than one with 2 (not
(Continue reading)

fchen8@gmail.com | 16 Apr 2008 22:34
Picon

Re: Is it possible to extend nsIDOMNode and alike?

On Apr 15, 7:13 pm, Jonas Sicking <jo... <at> sicking.cc> wrote:
> fch... <at> gmail.com wrote:
> > On Apr 14, 7:54 pm, Jonas Sicking <jo... <at> sicking.cc> wrote:
> >> fch... <at> gmail.com wrote:
> >>> On Apr 11, 6:22 pm, Jonas Sicking <jo... <at> sicking.cc> wrote:
> >>>> fch... <at> gmail.com wrote:
> >>>>> I have Mozilla embedded in my application through Java-xpcom. I want
> >>>>> to attach certain reference (to Java object) to each of the nodes in
> >>>>> the DOM tree. In another word, once I get a nsIDOMNode from Mozilla, I
> >>>>> would like to call methods on its attached reference. I can certainly
> >>>>> build a map and store the references in it. But it won't scale well
> >>>>> and constantly adding/removing from a big map is kind of expensive.
> >>>>> Since nsIDOMNode is an interface, I am thinking if I can wrap
> >>>>> Mozilla's implementation in my own class and somehow provide that
> >>>>> class back to Mozilla DOM then I should be able to achieve what I
> >>>>> need. The problem now lies in how to provide the class back to
> >>>>> Mozilla. nsIDOMDOMImplementation looks like a potential entry point
> >>>>> but is read-only on nsIDOMDocument. Is the route I am taking even
> >>>>> possible in xpcom? Are there any other solutions that you can suggest?
> >>>>> Thanks in advance for your help.
> >>>> Passing back another object is unlikely going to work. The nodes in
> >>>> mozilla have to implement a large number of interfaces and you'd have to
> >>>> get them exactly right for all types of nodes for things to work properly.
> >>>> What you could do instead is to QueryInterface the node to nsINode and
> >>>> use the Get/Set/Delete/UnsetProperty API to store any additional
> >>>> information about the node that you need.
> >>>> Note though that behind the scene that is implemented using a hash
> >>>> table, so if you're worried about performance with that then this API
> >>>> isn't going to help you much.
> >>>> That said, hash tables generally scale really well. It shouldn't be any
(Continue reading)

Jonas Sicking | 17 Apr 2008 00:49
Gravatar

Re: Is it possible to extend nsIDOMNode and alike?

fchen8 <at> gmail.com wrote:
> On Apr 15, 7:13 pm, Jonas Sicking <jo... <at> sicking.cc> wrote:
>> fch... <at> gmail.com wrote:
>>> On Apr 14, 7:54 pm, Jonas Sicking <jo... <at> sicking.cc> wrote:
>>>> fch... <at> gmail.com wrote:
>>>>> On Apr 11, 6:22 pm, Jonas Sicking <jo... <at> sicking.cc> wrote:
>>>>>> fch... <at> gmail.com wrote:
>>>>>>> I have Mozilla embedded in my application through Java-xpcom. I want
>>>>>>> to attach certain reference (to Java object) to each of the nodes in
>>>>>>> the DOM tree. In another word, once I get a nsIDOMNode from Mozilla, I
>>>>>>> would like to call methods on its attached reference. I can certainly
>>>>>>> build a map and store the references in it. But it won't scale well
>>>>>>> and constantly adding/removing from a big map is kind of expensive.
>>>>>>> Since nsIDOMNode is an interface, I am thinking if I can wrap
>>>>>>> Mozilla's implementation in my own class and somehow provide that
>>>>>>> class back to Mozilla DOM then I should be able to achieve what I
>>>>>>> need. The problem now lies in how to provide the class back to
>>>>>>> Mozilla. nsIDOMDOMImplementation looks like a potential entry point
>>>>>>> but is read-only on nsIDOMDocument. Is the route I am taking even
>>>>>>> possible in xpcom? Are there any other solutions that you can suggest?
>>>>>>> Thanks in advance for your help.
>>>>>> Passing back another object is unlikely going to work. The nodes in
>>>>>> mozilla have to implement a large number of interfaces and you'd have to
>>>>>> get them exactly right for all types of nodes for things to work properly.
>>>>>> What you could do instead is to QueryInterface the node to nsINode and
>>>>>> use the Get/Set/Delete/UnsetProperty API to store any additional
>>>>>> information about the node that you need.
>>>>>> Note though that behind the scene that is implemented using a hash
>>>>>> table, so if you're worried about performance with that then this API
>>>>>> isn't going to help you much.
(Continue reading)


Gmane