xquery/trunk/XQuery__InsertAsFirstIntoCommand.st
changeset 0 5057afe1ec87
child 232 9d8fd28b99b0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xquery/trunk/XQuery__InsertAsFirstIntoCommand.st	Tue Apr 08 19:47:42 2008 +0000
@@ -0,0 +1,76 @@
+"{ Package: 'stx:goodies/xmlsuite/xquery' }"
+
+"{ NameSpace: XQuery }"
+
+InsertCommand subclass:#InsertAsFirstIntoCommand
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	category:'XQuery-Update Facility'
+!
+
+
+!InsertAsFirstIntoCommand class methodsFor:'priorities'!
+
+priority
+    "Superclass says that I am responsible to implement this method"
+
+   ^20
+! !
+
+!InsertAsFirstIntoCommand 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]
+!
+
+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:56:03 / janfrog"
+! !
+
+!InsertAsFirstIntoCommand methodsFor:'executing'!
+
+execute
+    "Superclass says that I am responsible to implement this method"
+
+    self sourceSequence
+        do:[:node|self insert: node  asFirstInto: self targetSequence first]
+! !
+
+!InsertAsFirstIntoCommand methodsFor:'inserting'!
+
+insert:sourceNode asFirstInto: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
+            asFirstInto:targetNode item nodeId
+    ]
+
+    "Modified: / 05-12-2007 / 14:26:29 / janfrog"
+! !
+
+!InsertAsFirstIntoCommand class methodsFor:'documentation'!
+
+version
+    ^ '$Header: /opt/data/cvs/stx/goodies/xmlsuite/xquery/XQuery__InsertAsFirstIntoCommand.st,v 1.8 2008-01-02 14:07:01 wrobll1 Exp $'
+! !