xquery/trunk/XQuery__InsertBeforeCommand.st
changeset 0 5057afe1ec87
child 232 9d8fd28b99b0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xquery/trunk/XQuery__InsertBeforeCommand.st	Tue Apr 08 19:47:42 2008 +0000
@@ -0,0 +1,81 @@
+"{ Package: 'stx:goodies/xmlsuite/xquery' }"
+
+"{ NameSpace: XQuery }"
+
+InsertCommand subclass:#InsertBeforeCommand
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	category:'XQuery-Update Facility'
+!
+
+
+!InsertBeforeCommand class methodsFor:'priorities'!
+
+priority
+    "Superclass says that I am responsible to implement this method"
+
+    ^20
+! !
+
+!InsertBeforeCommand 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:23:52 / janfrog"
+!
+
+checkTargetSequence: anXQuerySequence 
+
+    self
+        assert: (anXQuerySequence containsSingleElement and:[anXQuerySequence first item hasParent ]) 
+        description: 'target must be a single element or document node with parent (see section 2.3.1.)'.
+
+    "Modified: / 21-11-2007 / 11:24:16 / janfrog"
+! !
+
+!InsertBeforeCommand methodsFor:'executing'!
+
+execute
+    "Superclass says that I am responsible to implement this method"
+
+    self sourceSequence
+        do:[:node|self insert: node  before: self targetSequence first]
+
+    "Created: / 21-11-2007 / 11:22:58 / janfrog"
+! !
+
+!InsertBeforeCommand methodsFor:'inserting'!
+
+insert:sourceNode before:targetNode 
+    |importedSourceNodeId|
+
+    importedSourceNodeId := targetNode documentAdaptor 
+                importForeignNode:sourceNode item nodeId
+                adaptor:sourceNode documentAdaptor.
+    (sourceNode type == XQuerySequenceItem typeAttribute) ifFalse:[
+        targetNode documentAdaptor updInsert:importedSourceNodeId
+            before:targetNode item nodeId
+    ] ifTrue:[
+        targetNode documentAdaptor updInsertAttribute:importedSourceNodeId
+            into:targetNode item xpathParent first nodeId
+    ]
+
+    "Created: / 21-11-2007 / 11:27:30 / janfrog"
+    "Modified: / 05-12-2007 / 14:26:29 / janfrog"
+! !
+
+!InsertBeforeCommand class methodsFor:'documentation'!
+
+version
+    ^ '$Header: /opt/data/cvs/stx/goodies/xmlsuite/xquery/XQuery__InsertBeforeCommand.st,v 1.3 2008-01-02 14:05:15 wrobll1 Exp $'
+! !