[Jslib] Re: RDF classes

Eric Plaster plaster@visi.com
Mon, 11 Feb 2002 16:55:09 -0600


Looks good to me martin.  If you want me to implement, test and document 
the changes, let me know.

When I get some free time, I'll have a look at you're other suggestions 
(root node).

Martin Kutschker wrote:

> Martin Kutschker wrote:
> 
>>
>> The container classes lack the insertAt and removeFrom calls the XPCOM 
>> interface provides.
> 
> 
> 
> RDFContainer.prototype.addSeqAt = function(aSeq, aIndex) {
>   return this.addContainer(aSeq, "seq", aIndex);
> };
> 
> RDFContainer.prototype.addBagAt = function(aBag, aIndex) {
>   return this.addContainer(aBag, "bag", aIndex);
> };
> 
> RDFContainer.prototype.addAlt = function(aAlt, aIndex) {
>   return this.addContainer(aAlt, "alt", aIndex);
> };
> 
> // XXX add third optional parameter
> RDFContainer.prototype.addContainer = function(aContainer, aType, aIndex)
> {
>   if(this.isValid()) {
>     if(!aContainer || !aType)
>       jslibError(null, "Must supply two arguments", null, 
> JS_RDFCONTAINER_FILE+":addContainer");
> 
> // XXX add check
>     if(aIndex && aIndex < 1)
>       jslibError(null, "Third argument must be integer greater then or 
> equal 1", null, JS_RDFCONTAINER_FILE+":addContainer");
> 
>     var res = this.RDF.GetResource(this.subject+":"+aContainer);
> 
>     if( this.resource ) {
>       this.RDFC.Init(this.dsource, this.resource );
> 
>       if(aType == "bag") {
>         this.RDFCUtils.MakeBag(this.dsource, res);
>       } else if(aType == "alt") {
>         this.RDFCUtils.MakeAlt(this.dsource, res);
>       } else {
>         this.RDFCUtils.MakeSeq(this.dsource, res);
>       }
> // XXX insert or append
>       if(aIndex)
>         this.RDFC.InsertElementAt(res, aIndex, true);
>       else
>         this.RDFC.AppendElement(res);
>     }
>     return new RDFContainer(aType, this.subject+":"+aContainer, 
> this.parent, this.dsource);
>   } else {
>     jslibError(null, "RDFContainer is no longer valid!\n", 
> "NS_ERROR_UNEXPECTED",
>           JS_RDFCONTAINER_FILE+":addContainer");
>     return null;
>   }
> };
> 
> RDFContainer.prototype.addNodeAt = function(aNode, aIndex) {
>   return this.addNode(aNode, aIndex);
> };
> 
> // XXX add "hidden" parameter (or revamp the function as private)
> RDFContainer.prototype.addNode = function(aNode, aIndex) {
>   if(this.isValid()) {
> // XXX add check
>     if(!aNode)
>       jslibError(null, "Must supply one argument", null, 
> JS_RDFCONTAINER_FILE+":addNode");
> 
>     if(aIndex && aIndex < 1)
>       jslibError(null, "Second argument must be integer greater then or 
> equal 1", null, JS_RDFCONTAINER_FILE+":addNode");
> 
>     var res = this.RDF.GetResource(this.subject+":"+aNode);
>     this.RDFC.Init(this.dsource, this.resource);
> 
> // XXX insert or append
>     if (aIndex)
>       this.RDFC.InsertElementAt(res, aIndex, true);
>     else
>       this.RDFC.AppendElement(res);
> 
>     return new RDFResource("node", this.subject+":"+aNode, this.subject, 
> this.dsource);
>   } else {
>       jslibError(null, "RDFContainer is no longer valid!\n", 
> "NS_ERROR_UNEXPECTED",
>             JS_RDFCONTAINER_FILE+":addNode");
>         return null;
>     }
> };
> 
> Masi