ZorbaXQDocumentManager.java
Go to the documentation of this file.
1 /*
2  * Copyright 2006-2012 The FLWOR Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.zorbaxquery.api.xqj;
17 
18 import java.util.ArrayList;
19 import java.util.Collection;
20 import javax.xml.xquery.XQException;
21 import javax.xml.xquery.XQItem;
22 import org.zorbaxquery.api.DocumentManager;
23 
24 public class ZorbaXQDocumentManager {
25 
26  private boolean closed = false;
27  DocumentManager dc;
28  private Collection<ZorbaXQSequence> sequences = new ArrayList<ZorbaXQSequence>();
29 
30  protected ZorbaXQDocumentManager(DocumentManager aDocumentManager) {
31  dc = aDocumentManager;
32  }
33 
34  public void close() throws XQException {
35  for (ZorbaXQSequence exp : sequences ){
36  exp.close(); // Notify the dependents objects to close
37  }
38  closed = true;
39  }
40  public boolean isClosed() {
41  return closed;
42  }
43 
44  public ZorbaXQSequence availableDocuments() throws XQException {
45  isClosedXQException();
46  ZorbaXQSequence result = new ZorbaXQSequence(dc.availableDocuments().getIterator());
47  sequences.add(result);
48  return result;
49  }
50 
51  public void put(String aName, javax.xml.xquery.XQItem aDoc) throws XQException {
52  isClosedXQException();
53  dc.put(aName, ((org.zorbaxquery.api.xqj.ZorbaXQItem)aDoc).getZorbaItem());
54  }
55  public void remove(String aName) throws XQException {
56  isClosedXQException();
57  dc.remove(aName);
58  }
59  public XQItem document(String aName) throws XQException {
60  isClosedXQException();
61  return new org.zorbaxquery.api.xqj.ZorbaXQItem(dc.document(aName));
62  }
63  public boolean isAvailableDocument(String aName) throws XQException {
64  isClosedXQException();
65  return dc.isAvailableDocument(aName);
66  }
67 
68  private void isClosedXQException() throws XQException {
69  if (closed) {
70  throw new XQException("DocumentManager is closed");
71  }
72  }
73 }