Rodolfo Ochoa has proposed merging lp:~zorba-coders/zorba/bug925143 into 
lp:zorba.

Requested reviews:
  Matthias Brantner (matthias-brantner)
  Cezar Andrei (cezar-andrei)
Related bugs:
  Bug #925143 in Zorba: "CollectionManager in SWIG apis"
  https://bugs.launchpad.net/zorba/+bug/925143

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug925143/+merge/102791

Collection Manager and Document Manager is ready on XQJ API.
-- 
https://code.launchpad.net/~zorba-coders/zorba/bug925143/+merge/102791
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog	2012-04-19 23:46:41 +0000
+++ ChangeLog	2012-04-20 05:12:20 +0000
@@ -12,6 +12,7 @@
   * Add jvm classpath to zorbacmd and to Zorba API. Tracked by #931816
   * Added support for NO_ICU (to not use ICU for unicode processing)
   * Added XQJ support.
+  * Added CollectionManager and DocumentManager support for XQJ.
 
 Optimization:
 

=== modified file 'swig/xqj/CMakeLists.txt'
--- swig/xqj/CMakeLists.txt	2012-03-26 23:06:10 +0000
+++ swig/xqj/CMakeLists.txt	2012-04-20 05:12:20 +0000
@@ -35,6 +35,11 @@
   CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/XQSequenceType.java" "${CMAKE_CURRENT_BINARY_DIR}/XQSequenceType.java")
   CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/XQStaticContext.java" "${CMAKE_CURRENT_BINARY_DIR}/XQStaticContext.java")
 
+  CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/XQCollection.java" "${CMAKE_CURRENT_BINARY_DIR}/XQCollection.java")
+  CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/XQCollectionManager.java" "${CMAKE_CURRENT_BINARY_DIR}/XQCollectionManager.java")
+  CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/XQDocumentManager.java" "${CMAKE_CURRENT_BINARY_DIR}/XQDocumentManager.java")
+  CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/XQXmlDataManager.java" "${CMAKE_CURRENT_BINARY_DIR}/XQXmlDataManager.java")
+
   MESSAGE(STATUS "SWIG Java: Generating XQJ TCK Tests")
   CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/tck/junit-4.9.jar" "${CMAKE_CURRENT_BINARY_DIR}/tck/junit-4.9.jar" COPYONLY)
   CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/tck/xqjapi.jar" "${CMAKE_CURRENT_BINARY_DIR}/tck/xqjapi.jar" COPYONLY)

=== added file 'swig/xqj/XQCollection.java'
--- swig/xqj/XQCollection.java	1970-01-01 00:00:00 +0000
+++ swig/xqj/XQCollection.java	2012-04-20 05:12:20 +0000
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.zorbaxquery.api.xqj;
+
+import java.util.ArrayList;
+import javax.xml.xquery.XQException;
+import org.zorbaxquery.api.Collection;
+import javax.xml.xquery.XQItem;
+
+public class XQCollection {
+
+    private boolean closed = false;
+    private Collection collection = null;
+    private java.util.Collection<XQSequence> sequences = new ArrayList<XQSequence>();
+
+    protected XQCollection(Collection col) {
+        collection = col;
+    }
+
+    public void close() throws XQException {
+        for (XQSequence exp : sequences ){
+            exp.close();  // Notify the dependents objects to close
+        }
+        closed = true;
+    }
+
+    public boolean isClosed() {
+        return closed;
+    }
+
+    public XQSequence contents() throws XQException {
+        isClosedXQException();
+        XQSequence result =  new XQSequence(collection.contents().getIterator());
+        sequences.add(result);
+        return result;
+    }
+
+    public void deleteNodeFirst() throws XQException {
+        isClosedXQException();
+        collection.deleteNodeFirst();
+    }
+
+    public void deleteNodeLast() throws XQException {
+        isClosedXQException();
+        collection.deleteNodeLast();
+    }
+
+    public void deleteNodes(XQSequence aNodes ) throws XQException {
+        isClosedXQException();
+        try {
+            collection.deleteNodes(aNodes.getItemSequence());
+        } catch (XQException e) {
+            throw e;
+        }
+    }   
+
+    public void deleteNodesFirst(long aNumNodes ) throws XQException {
+        isClosedXQException();
+        collection.deleteNodesFirst(aNumNodes);
+    }
+
+    public void deleteNodesLast(long aNumNodes ) throws XQException {
+        isClosedXQException();
+        collection.deleteNodesLast(aNumNodes);
+    }
+
+    public String getName() throws XQException {
+        isClosedXQException();
+        return collection.getName().getStringValue();
+    }
+
+    public XQItemType getType() throws XQException {
+        isClosedXQException();
+        return new XQItemType(collection.getType());
+    }
+
+    public long indexOf(XQItem aNode ) throws XQException {
+        isClosedXQException();
+        return collection.indexOf(((org.zorbaxquery.api.xqj.XQItem)aNode).getZorbaItem());
+    }
+
+    public void insertNodesAfter(XQItem aTarget, XQSequence aNodes ) throws XQException {
+        isClosedXQException();
+        try {
+            collection.insertNodesAfter(((org.zorbaxquery.api.xqj.XQItem)aTarget).getZorbaItem(), aNodes.getItemSequence());
+        } catch (XQException e) {
+            throw e;
+        }
+    }
+
+    public void insertNodesBefore(XQItem aTarget, XQSequence aNodes ) throws XQException {
+        isClosedXQException();
+        try {
+            collection.insertNodesBefore(((org.zorbaxquery.api.xqj.XQItem)aTarget).getZorbaItem(), aNodes.getItemSequence());
+        } catch (XQException e) {
+            throw e;
+        }
+    }
+
+    public void insertNodesFirst(XQSequence aNodes ) throws XQException {
+        isClosedXQException();
+        try {
+            collection.insertNodesFirst(aNodes.getItemSequence());
+        } catch (XQException e) {
+            throw e;
+        }
+    }
+
+    public void insertNodesLast(XQSequence aNodes ) throws XQException {
+        isClosedXQException();
+        try {
+            collection.insertNodesLast(aNodes.getItemSequence());
+        } catch (XQException e) {
+            throw e;
+        }
+    }
+
+    public boolean isStatic() throws XQException {
+        isClosedXQException();
+        return collection.isStatic();
+    }
+
+    private void isClosedXQException() throws XQException {
+        if (closed) {
+            throw new XQException("Collection is closed");
+        }
+    }
+     
+    
+}

=== added file 'swig/xqj/XQCollectionManager.java'
--- swig/xqj/XQCollectionManager.java	1970-01-01 00:00:00 +0000
+++ swig/xqj/XQCollectionManager.java	2012-04-20 05:12:20 +0000
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.zorbaxquery.api.xqj;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import javax.xml.xquery.XQException;
+import org.zorbaxquery.api.CollectionManager;
+import javax.xml.xquery.XQSequence;
+import javax.xml.xquery.XQItem;
+
+
+public class XQCollectionManager {
+
+    private boolean closed = false;
+    private CollectionManager collectionManager = null;
+    private Collection<XQSequence> sequences = new ArrayList<XQSequence>();
+    private Collection<XQCollection> collections = new ArrayList<XQCollection>();
+
+    protected XQCollectionManager (CollectionManager cm) {
+        collectionManager = cm;
+    }
+
+    public void close() throws XQException {
+        for (XQSequence exp : sequences ){
+            exp.close();  // Notify the dependents objects to close
+        }
+        for (XQCollection exp : collections ){
+            exp.close();  // Notify the dependents objects to close
+        }
+        closed = true;
+    }
+
+    public boolean isClosed() {
+        return closed;
+    }
+
+    public XQSequence availableCollections() throws XQException {
+        isClosedXQException();
+        XQSequence result = new org.zorbaxquery.api.xqj.XQSequence(collectionManager.availableCollections());
+        sequences.add(result);
+        return result;
+    }
+
+    public void createCollection(XQItem aName ) throws XQException {
+        isClosedXQException();
+        collectionManager.createCollection(((org.zorbaxquery.api.xqj.XQItem)aName).getZorbaItem());
+    }
+
+    public void deleteCollection(XQItem aName ) throws XQException {
+        isClosedXQException();
+        collectionManager.deleteCollection(((org.zorbaxquery.api.xqj.XQItem)aName).getZorbaItem());
+    }
+
+    public XQCollection getCollection(XQItem aName ) throws XQException {
+        isClosedXQException();
+        XQCollection result = new XQCollection ( collectionManager.getCollection(((org.zorbaxquery.api.xqj.XQItem)aName).getZorbaItem()) );
+        collections.add(result);
+        return result;
+    }
+
+    public boolean isAvailableCollection(XQItem aName ) throws XQException {
+        isClosedXQException();
+        return collectionManager.isAvailableCollection( ((org.zorbaxquery.api.xqj.XQItem)aName).getZorbaItem() );
+    }
+
+    private void isClosedXQException() throws XQException {
+        if (closed) {
+            throw new XQException("CollectionManager is closed");
+        }
+    }
+    
+}

=== modified file 'swig/xqj/XQConnection.java'
--- swig/xqj/XQConnection.java	2012-04-19 23:07:13 +0000
+++ swig/xqj/XQConnection.java	2012-04-20 05:12:20 +0000
@@ -79,12 +79,12 @@
     private Collection<XQPreparedExpression> cPreparedExpression;
     private Collection<XQMetaData> cMetadata;
     private XQStaticContext lStaticContext;
+    private XQXmlDataManager lXmlDataManager;
     private Properties properties;
     private StringVector uriPaths;
     private StringVector libPaths;
     private StringVector modulePaths;
     
-    //TODO: Rodolfo ALL CASES should return an exception("Not implemented yet")
     protected Zorba getZorbaInstance() throws XQException {
         if (zorba!=null) {
             return zorba;
@@ -162,10 +162,20 @@
         if (lStaticContext != null ) {
             ((org.zorbaxquery.api.xqj.XQStaticContext)lStaticContext).getZorbaStaticContext().destroy();
         }
+        if (lXmlDataManager != null) {
+            lXmlDataManager.close();
+        }
         zorba.shutdown();
         InMemoryStore.shutdown ( store );
         closed = true;
     }
+    
+    public XQXmlDataManager getXmlDataManager() {
+        if (lXmlDataManager==null) {
+            lXmlDataManager = new XQXmlDataManager(zorba);
+        }
+        return lXmlDataManager;
+    }
 
     @Override
     public void setAutoCommit(boolean bln) throws XQException {
@@ -183,18 +193,6 @@
     public void commit() throws XQException {
         isClosedXQException();
         throw new UnsupportedOperationException("Zorba does not support transactions... yet...");
-        /*
-        if (!autocommit) {
-            try {
-                query.execute();
-            } catch (Exception e) {
-                throw new XQException("Error executing query");
-            }
-        } else {
-            throw new XQException("Autocommit was specified");
-        }
-         
-         */
     }
 
     @Override

=== added file 'swig/xqj/XQDocumentManager.java'
--- swig/xqj/XQDocumentManager.java	1970-01-01 00:00:00 +0000
+++ swig/xqj/XQDocumentManager.java	2012-04-20 05:12:20 +0000
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.zorbaxquery.api.xqj;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import javax.xml.xquery.XQException;
+import org.zorbaxquery.api.DocumentManager;
+import javax.xml.xquery.XQItem;
+
+public class XQDocumentManager {
+
+    private boolean closed = false;
+    DocumentManager dc;
+    private Collection<XQSequence> sequences = new ArrayList<XQSequence>();
+    
+    protected XQDocumentManager(DocumentManager aDocumentManager) {
+        dc = aDocumentManager;
+    }
+
+    public void close() throws XQException {
+        for (XQSequence exp : sequences ){
+            exp.close();  // Notify the dependents objects to close
+        }
+        closed = true;
+    }
+    public boolean isClosed() {
+        return closed;
+    }
+
+    public XQSequence availableDocuments() throws XQException {
+        isClosedXQException();
+        XQSequence result = new XQSequence(dc.availableDocuments().getIterator());
+        sequences.add(result);
+        return result;
+    }
+
+    public void put(String aName, javax.xml.xquery.XQItem aDoc)  throws XQException {
+        isClosedXQException();
+        dc.put(aName, ((org.zorbaxquery.api.xqj.XQItem)aDoc).getZorbaItem());
+    }
+    public void remove(String aName) throws XQException {
+        isClosedXQException();
+        dc.remove(aName);
+    }
+    public XQItem document(String aName) throws XQException {
+        isClosedXQException();
+        return new org.zorbaxquery.api.xqj.XQItem(dc.document(aName));
+    }
+    public boolean isAvailableDocument(String aName) throws XQException {
+        isClosedXQException();
+        return dc.isAvailableDocument(aName);
+    }
+    
+    private void isClosedXQException() throws XQException {
+        if (closed) {
+            throw new XQException("DocumentManager is closed");
+        }
+    }
+}

=== modified file 'swig/xqj/XQSequence.java'
--- swig/xqj/XQSequence.java	2012-04-19 23:07:13 +0000
+++ swig/xqj/XQSequence.java	2012-04-20 05:12:20 +0000
@@ -33,6 +33,8 @@
 import org.w3c.dom.Node;
 import org.xml.sax.ContentHandler;
 import org.zorbaxquery.api.Item;
+import org.zorbaxquery.api.ItemSequence;
+import org.zorbaxquery.api.Iterator;
 
 public class XQSequence implements javax.xml.xquery.XQSequence {
 
@@ -42,6 +44,7 @@
     private Collection<XQItem> content = new ArrayList<XQItem>();
     private int position = 0;
     int size = 0;
+    private ItemSequence itemSequence = null;
 
     public XQSequence(javax.xml.xquery.XQSequence sequence) throws XQException {
         try {
@@ -72,6 +75,37 @@
         size = content.size();
     }
 
+    public XQSequence(org.zorbaxquery.api.Iterator iterator) {
+        if (iterator.isOpen()) {
+            org.zorbaxquery.api.Item item = null;
+            while (iterator.next(item)) {
+                XQItem xItem = new org.zorbaxquery.api.xqj.XQItem(item);
+                content.add(xItem);
+            }
+            size = content.size();
+        }
+    }
+
+    protected XQSequence(ItemSequence seq) {
+        itemSequence = seq;
+        org.zorbaxquery.api.Iterator iterator = seq.getIterator();
+        if (iterator.isOpen()) {
+            org.zorbaxquery.api.Item item = null;
+            while (iterator.next(item)) {
+                XQItem xItem = new org.zorbaxquery.api.xqj.XQItem(item);
+                content.add(xItem);
+            }
+            size = content.size();
+        }
+    }
+
+    protected ItemSequence getItemSequence() throws XQException {
+        if (itemSequence==null) {
+            throw new XQException("This Sequence is not a Zorba ItemSequence object");
+        }
+        return itemSequence;
+    }
+    
     @Override
     public boolean absolute(int i) throws XQException {
         isClosedXQException();

=== added file 'swig/xqj/XQXmlDataManager.java'
--- swig/xqj/XQXmlDataManager.java	1970-01-01 00:00:00 +0000
+++ swig/xqj/XQXmlDataManager.java	2012-04-20 05:12:20 +0000
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.zorbaxquery.api.xqj;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import javax.xml.xquery.XQException;
+import org.zorbaxquery.api.XmlDataManager;
+import org.zorbaxquery.api.Zorba;
+
+
+public class XQXmlDataManager {
+    
+    private boolean closed = false;
+    private XmlDataManager dm;
+    private XQDocumentManager lDocumentManager;
+    private XQCollectionManager lCollectionManager;
+    private XQCollectionManager lW3CollectionManager;
+    private Collection<XQSequence> sequences = new ArrayList<XQSequence>();
+
+    protected XQXmlDataManager(Zorba zorba) {
+        dm = zorba.getXmlDataManager();
+    }
+    
+    public void close() throws XQException {
+        if (lDocumentManager!=null) {
+            lDocumentManager.close();
+        }
+        if (lCollectionManager!=null) {
+            lCollectionManager.close();
+        }
+        if (lW3CollectionManager!=null) {
+            lW3CollectionManager.close();
+        }
+        for (XQSequence exp : sequences ){
+            exp.close();  // Notify the dependents objects to close
+        }
+        closed = true;
+    }
+
+    public boolean isClosed() {
+        return closed;
+    }
+    
+    public XQDocumentManager getDocumentManager()  throws XQException {
+        isClosedXQException();
+        if (lDocumentManager==null) {
+            lDocumentManager = new XQDocumentManager(dm.getDocumentManager());
+        }
+        return lDocumentManager;
+    }
+    
+    public XQCollectionManager getCollectionManager()  throws XQException {
+        isClosedXQException();
+        if (lCollectionManager==null) {
+            lCollectionManager = new XQCollectionManager(dm.getCollectionManager());
+        }
+        return lCollectionManager;
+    }
+    
+    public XQCollectionManager getW3CCollectionManager()  throws XQException {
+        isClosedXQException();
+        if (lW3CollectionManager==null) {
+            lW3CollectionManager = new XQCollectionManager(dm.getW3CCollectionManager());
+        }
+        return lW3CollectionManager;
+    }
+    
+    public XQSequence parseXML(String xmlText) throws XQException {
+        isClosedXQException();
+        XQSequence result = new XQSequence(dm.parseXML(xmlText));
+        sequences.add(result);
+        return result;
+    }
+    
+    private void isClosedXQException() throws XQException {
+        if (closed) {
+            throw new XQException("XmlDataManager is closed");
+        }
+    }
+}

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to