Refactor.
[yaz4j-moved-to-github.git] / src / main / java / org / yaz4j / Package.java
1 package org.yaz4j;
2
3 import org.yaz4j.jni.SWIGTYPE_p_ZOOM_package_p;
4 import org.yaz4j.jni.yaz4jlib;
5
6 public class Package {
7     private SWIGTYPE_p_ZOOM_package_p pack;
8     private ConnectionExtended connection;
9     private String type;
10
11     Package(SWIGTYPE_p_ZOOM_package_p pack, ConnectionExtended connection, String type) {
12         this.type = type;
13         this.connection = connection;
14         this.pack = pack;
15     }
16
17     public void finalize() {
18         _dispose();
19     }
20
21     /**
22      * Write option for a specified key
23      * @param key option name
24      * @param value option value
25      * @return package (self) for chainability
26      */
27     public Package option(String key, String value) {
28       yaz4jlib.ZOOM_package_option_set(pack, key, value);
29       return this;
30     }
31
32     /**
33      * Read option for a specified key.
34      * @param key option name
35      * @return option value
36      */
37     public String option(String key) {
38       return yaz4jlib.ZOOM_package_option_get(pack, key);
39     }
40
41     /**
42      * Send the package.
43      */
44     public void send() {
45         yaz4jlib.ZOOM_package_send(pack, type);
46     }
47
48     void _dispose() {
49         if (pack != null) {
50             yaz4jlib.ZOOM_package_destroy(pack);
51             connection = null;
52             pack = null;
53         }
54     }
55 }