xpath/trunk/XQuery__InsertAsLastIntoCommand.st
changeset 0 5057afe1ec87
equal deleted inserted replaced
-1:000000000000 0:5057afe1ec87
       
     1 "{ Package: 'stx:goodies/xmlsuite/xpath' }"
       
     2 
       
     3 "{ NameSpace: XQuery }"
       
     4 
       
     5 InsertCommand subclass:#InsertAsLastIntoCommand
       
     6 	instanceVariableNames:''
       
     7 	classVariableNames:''
       
     8 	poolDictionaries:''
       
     9 	category:'XQuery-Update Facility'
       
    10 !
       
    11 
       
    12 
       
    13 !InsertAsLastIntoCommand methodsFor:'checks'!
       
    14 
       
    15 checkSourceSequence:anXQuerySequence 
       
    16 
       
    17     | foundNonAttribute |
       
    18     foundNonAttribute := false.
       
    19     anXQuerySequence do:
       
    20         [:seqItem|
       
    21         self 
       
    22             assert: ((seqItem type == XQuerySequenceItem typeAttribute and:[foundNonAttribute])) not
       
    23             description:'An attribute found after non-attribute (see section 2.3.1.)'.
       
    24         foundNonAttribute := (seqItem type == XQuerySequenceItem typeAttribute) not]
       
    25 
       
    26     "Modified: / 21-11-2007 / 11:24:56 / janfrog"
       
    27 !
       
    28 
       
    29 checkTargetSequence: anXQuerySequence 
       
    30 
       
    31     self
       
    32         assert: anXQuerySequence containsSingleElement & anXQuerySequence first type == XQuerySequenceItem typeNode 
       
    33         description: 'target must be a single element or document node (see section 2.3.1.)'.
       
    34 
       
    35     "Modified: / 21-11-2007 / 11:26:23 / janfrog"
       
    36 ! !
       
    37 
       
    38 !InsertAsLastIntoCommand methodsFor:'executing'!
       
    39 
       
    40 execute
       
    41     "Superclass says that I am responsible to implement this method"
       
    42 
       
    43     self sourceSequence
       
    44         do:[:node|self insert: node asLastInto: self targetSequence first]
       
    45 
       
    46     "Created: / 21-11-2007 / 11:22:31 / janfrog"
       
    47 ! !
       
    48 
       
    49 !InsertAsLastIntoCommand methodsFor:'inserting'!
       
    50 
       
    51 insert:sourceNode asLastInto:targetNode
       
    52 
       
    53     |importedSourceNodeId|
       
    54 
       
    55     importedSourceNodeId := targetNode documentAdaptor
       
    56                                 importForeingNode: sourceNode item nodeId
       
    57                                 adaptor: sourceNode documentAdaptor.
       
    58 
       
    59     (sourceNode type == XQuerySequenceItem typeAttribute) ifTrue:[
       
    60         targetNode documentAdaptor updInsertAttribute: importedSourceNodeId into: targetNode item nodeId
       
    61     ] ifFalse:[
       
    62 
       
    63         targetNode documentAdaptor updInsert:importedSourceNodeId asLastInto:targetNode item nodeId
       
    64     ]
       
    65 
       
    66     "Created: / 21-11-2007 / 11:28:21 / janfrog"
       
    67 ! !
       
    68 
       
    69 !InsertAsLastIntoCommand class methodsFor:'documentation'!
       
    70 
       
    71 version
       
    72     ^ '$Header: /opt/data/cvs/stx/goodies/xmlsuite/xpath/XQuery__InsertAsLastIntoCommand.st,v 1.1 2007-11-22 21:58:23 vranyj1 Exp $'
       
    73 ! !