3770132c884f4020accc72734c4138ea69414941
[yaz4j-moved-to-github.git] / src / main / java / org / yaz4j / Record.java
1 package org.yaz4j;
2
3 import org.yaz4j.jni.SWIGTYPE_p_ZOOM_record_p;
4 import org.yaz4j.jni.SWIGTYPE_p_int;
5 import org.yaz4j.jni.yaz4jlib;
6
7 public class Record implements Cloneable {
8     private SWIGTYPE_p_ZOOM_record_p record;
9     private ResultSet rset;
10     private boolean disposed = false;
11
12     Record(SWIGTYPE_p_ZOOM_record_p record, ResultSet rset) {
13         this.record = record;
14         this.rset = rset;
15     }
16
17     protected Record(SWIGTYPE_p_ZOOM_record_p record) {
18         this.record = record;
19     }
20
21     public void finalize() {
22         _dispose();
23     }
24
25     public byte[] get(String type) {
26         SWIGTYPE_p_int length = null;
27         return yaz4jlib.ZOOM_record_get_bytes(record, type, length);
28     }
29
30     public String render() {
31         return new String(get("render"));
32     }
33
34     public byte[] getContent() {
35         return get("raw");
36     }
37
38     public String getSyntax() {
39         return new String(get("syntax"));
40     }
41
42     public String getDatabase() {
43         return new String(get("database"));
44     }
45
46     public Object clone() {
47         SWIGTYPE_p_ZOOM_record_p clone = yaz4jlib.ZOOM_record_clone(record);
48         return new Record(clone);
49     }
50
51     void _dispose() {
52         if (!disposed) {
53             //was cloned, need to dealloc?
54             if (rset == null)
55                 yaz4jlib.ZOOM_record_destroy(record);
56             rset = null;
57             record = null;
58             disposed = true;
59         }
60     }
61 }