1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.nxqd;
17
18 import net.sf.nxqd.common.NxqdUtils;
19
20 import java.util.logging.Level;
21 import java.util.logging.Logger;
22 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.Map;
25
26 import org.w3c.dom.Document;
27
28 /**
29 * The class <code>NxqdContainer</code> is the for
30 * interacting with Nxqd containers, such as adding or deleting documents.
31 *
32 * @author <a href="mailto:webhiker@sourceforge.net">webhiker</a>
33 * @version 1.0
34 */
35 public class NxqdContainer extends NxqdConsumer {
36
37 /**
38 * The variable <code>logger</code> is used for logging events.
39 *
40 */
41 private static Logger logger = Logger.getLogger(NxqdContainer.class.getName());
42
43 private String containerName;
44
45 protected NxqdContainer(final NxqdManager manager,
46 final String containerName) throws NxqdException {
47 super(manager);
48 this.containerName = containerName;
49 }
50
51 /**
52 * The <code>getName</code> method returns the name of this Container.
53 *
54 * @return a <code>String</code> value
55 */
56 public final String getName() {
57 return this.containerName;
58 }
59
60 /**
61 * Returns the number of XML Documents in this container.
62 *
63 * @return an <code>long</code> value
64 * @exception XmlException if an error occurs
65 */
66 public long getNumDocuments()
67 throws NxqdException {
68 return getNxqdManager().getNumDocuments(getName());
69 }
70
71
72 /**
73 * The <code>putDocument</code> method adds the document to this
74 * container using the specified documentId. An exception is thrown if
75 * the specified documentId already exists.
76 *
77 * @param documentId a <code>String</code> value
78 * @param document a <code>NxqdXMLValue</code> value
79 * @exception NxqdException if an error occurs
80 */
81 public void putDocument(final String documentId,
82 NxqdXMLValue document) throws NxqdException {
83 getNxqdManager().putDocument(getName(),
84 documentId,
85 document.asString());
86 }
87
88 /**
89 * The <code>getDocument</code> method retrieves the specified document from this
90 * container using the specified documentId. An exception is thrown if
91 * the specified documentId does not exist.
92 *
93 * @param documentId a <code>String</code> value
94 * @return a <code>NxqdXMLValue</code> value
95 * @exception NxqdException if an error occurs
96 */
97 public NxqdXMLValue getDocument(final String documentId) throws NxqdException {
98 return new NxqdXMLValue(getNxqdManager().getDocument(getName(),
99 documentId));
100 }
101
102 /**
103 * The <code>deleteDocument</code> method deletes the specified document from this
104 * container using the specified documentId. An exception is thrown if
105 * an error occurred while deleting the document.
106 *
107 * @param documentId a <code>String</code> value
108 * @exception NxqdException if an error occurs
109 */
110 public void deleteDocument(final String documentId) throws NxqdException {
111 getNxqdManager().deleteDocument(getName(),
112 documentId);
113 }
114
115 /**
116 * The <code>documentExists</code> method checks if
117 * the specified document exists. It will return
118 * true if the document exists, false otherwise.
119 * A NxqdException is thrown if other errors occur.
120 *
121 * @param documentId a <code>String</code> value
122 * @return a <code>boolean</code> value
123 * @exception NxqdException if an error occurs
124 */
125 public boolean documentExists(String documentId) throws NxqdException {
126 return getNxqdManager().documentExists(getName(),
127 documentId);
128 }
129
130 /**
131 * The <code>listDocuments</code> method returns a List containing
132 * the document id's managed by the server. This list may
133 * be empty, but it will never be null, and contains <code>String</code>
134 * values.
135 *
136 * @return a <code>List</code> value
137 * @exception NxqdException if an error occurs
138 */
139 public List listDocuments() throws NxqdException {
140 return getNxqdManager().listDocuments(getName());
141 }
142
143 /**
144 * The <code>putBlob</code> method stores the specified blob object as a binary
145 * resources in the database under the specified id.
146 *
147 * @param blobId a <code>String</code> value
148 * @param blob a <code>NxqdBlobValue</code> value
149 * @exception NxqdException if an error occurs
150 */
151 public void putBlob(final String blobId,
152 final NxqdBlobValue blob) throws NxqdException {
153 getNxqdManager().putBlob(getName(),
154 blobId,
155 blob.getBlob());
156 }
157
158 /**
159 * The <code>getBlob</code> method retrieves the specified blob from the database.
160 *
161 * @param blobId a <code>String</code> value
162 * @return a <code>NxqdBlobValue</code> value
163 * @exception NxqdException if an error occurs
164 */
165 public NxqdBlobValue getBlob(final String blobId) throws NxqdException {
166 return new NxqdBlobValue(getNxqdManager().getBlob(getName(),
167 blobId));
168 }
169
170 /**
171 * The <code>deleteBlob</code> method deletes the specified blob from this
172 * container using the specified blobId. An exception is thrown if
173 * an error occurred while deleting the document.
174 *
175 * @param blobId a <code>String</code> value
176 * @exception NxqdException if an error occurs
177 */
178 public void deleteBlob(final String blobId) throws NxqdException {
179 getNxqdManager().deleteBlob(getName(),
180 blobId);
181 }
182
183 /**
184 * The <code>listBlobs</code> method lists the id's of
185 * the blobs managed by this container.
186 *
187 * @return a <code>List</code> value
188 * @exception NxqdException if an error occurs
189 */
190 public List listBlobs() throws NxqdException {
191 return getNxqdManager().listBlobs(getName());
192 }
193
194 /**
195 * The <code>blobExists</code> method checks if
196 * the specified blob exists. It will return
197 * true if the blob exists, false otherwise.
198 * A NxqdException is thrown if other errors occur.
199 *
200 * @param blobId a <code>String</code> value
201 * @return a <code>boolean</code> value
202 * @exception NxqdException if an error occurs
203 */
204 public boolean blobExists(String blobId) throws NxqdException {
205 return getNxqdManager().blobExists(getName(),
206 blobId);
207 }
208
209 }
210