xquery/trunk/XQuery__InsertIntoCommand.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Tue, 08 Apr 2008 19:47:42 +0000
changeset 0 5057afe1ec87
child 232 9d8fd28b99b0
permissions -rw-r--r--
Initial import from CVS

"{ Package: 'stx:goodies/xmlsuite/xquery' }"

"{ NameSpace: XQuery }"

InsertCommand subclass:#InsertIntoCommand
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'XQuery-Update Facility'
!


!InsertIntoCommand class methodsFor:'priorities'!

priority
    "Superclass says that I am responsible to implement this method"

   ^10
! !

!InsertIntoCommand methodsFor:'checks'!

checkSourceSequence:anXQuerySequence 

    | foundNonAttribute |
    foundNonAttribute := false.
    anXQuerySequence do:
        [:seqItem|
        self 
            assert: ((seqItem type == XQuerySequenceItem typeAttribute and:[foundNonAttribute])) not
            description:'An attribute found after non-attribute (see section 2.3.1.)'.
        foundNonAttribute := (seqItem type == XQuerySequenceItem typeAttribute) not]

    "Modified: / 21-11-2007 / 11:25:04 / janfrog"
!

checkTargetSequence: anXQuerySequence 

    self
        assert: anXQuerySequence containsSingleElement
        description: 'target must be a single element or document node (see section 2.3.1.)'.

    "Modified: / 05-12-2007 / 21:55:39 / janfrog"
! !

!InsertIntoCommand methodsFor:'executing'!

execute
    "Superclass says that I am responsible to implement this method"

    self sourceSequence
        do:[:node|self insert: node  into: self targetSequence first]

    "Created: / 21-11-2007 / 11:23:12 / janfrog"
! !

!InsertIntoCommand methodsFor:'inserting'!

insert:sourceNode into:targetNode 
    |importedSourceNodeId|

    importedSourceNodeId := targetNode documentAdaptor 
                importForeignNode:sourceNode item nodeId
                adaptor:sourceNode documentAdaptor.
    (sourceNode type == XQuerySequenceItem typeAttribute) ifTrue:[
        targetNode documentAdaptor updInsertAttribute:importedSourceNodeId
            into:targetNode item nodeId
    ] ifFalse:[
        targetNode documentAdaptor updInsert:importedSourceNodeId
            into:targetNode item nodeId
    ]

    "Created: / 21-11-2007 / 11:29:01 / janfrog"
    "Modified: / 05-12-2007 / 14:26:29 / janfrog"
! !

!InsertIntoCommand class methodsFor:'documentation'!

version
    ^ '$Header: /opt/data/cvs/stx/goodies/xmlsuite/xquery/XQuery__InsertIntoCommand.st,v 1.3 2008-01-02 14:06:39 wrobll1 Exp $'
! !