source: trunk/lang/java/Library.java @ 3719

Last change on this file since 3719 was 3177, checked in by mmc, 12 years ago

Updated all of the copyright notices to reference the transfer to
the new HUBzero Foundation, LLC.

File size: 3.7 KB
Line 
1/*
2 * ======================================================================
3 *  AUTHOR:  Ben Rafferty, Purdue University
4 *  Copyright (c) 2004-2012  HUBzero Foundation, LLC
5 *
6 *  See the file "license.terms" for information on usage and
7 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
8 * ======================================================================
9 */
10
11/*
12 * This file defines a Java class that implemements the rappture XML library.
13 * The class methods call the corresponding native code through c++ glue code
14 * located in jRpLibrary.cc.
15 */
16
17package rappture;
18
19public class Library{
20  static {
21    System.loadLibrary("JRappture");
22  }
23
24  // Constructor---------------------------------------------------------------
25  public Library(String path){
26    libPtr = jRpLibrary(path);
27  }
28
29  public Library(){
30    libPtr = jRpLibrary(null);
31  }
32
33  // Pseudo-Destructor.  Called when the object is garbage collected.----------
34  protected void finalize() throws Throwable {
35    try {
36      jRpDeleteLibrary(libPtr);
37    } finally {
38        super.finalize();
39    }
40  }
41
42  // Public Methods------------------------------------------------------------
43 
44  public byte[] getData(String path){
45    return jRpGetData(libPtr, path);
46  }
47
48  public double getDouble(String path){
49    return jRpGetDouble(libPtr, path);
50  }
51
52  public String getString(String path){
53    return jRpGetString(libPtr, path);
54  }
55
56  public int getInt(String path){
57    return jRpGetInt(libPtr, path);
58  }
59
60  public String get(String path){  // alias for getString
61    return jRpGetString(libPtr, path);
62  }
63
64  public void put(String path, Object value, boolean append){
65    // convert generic object to string
66    jRpPut(libPtr, path, value.toString(), append);
67  }
68
69  public void put(String path, Object value){
70    jRpPut(libPtr, path, value.toString(), false);
71  }
72
73  public void putData(String path, byte[] b, boolean append){
74    jRpPutData(libPtr, path, b, b.length, append);
75  }
76
77  public void putData(String path, byte[] b){
78    jRpPutData(libPtr, path, b, b.length, false);
79  }
80
81  public void putFile(String path, String fileName,
82                      boolean compress, boolean append){
83    jRpPutFile(libPtr, path, fileName, compress, append);
84  }
85
86  public void putFile(String path, String fileName, boolean compress){
87    jRpPutFile(libPtr, path, fileName, compress, false);
88  }
89
90  public void putFile(String path, String fileName){
91    jRpPutFile(libPtr, path, fileName, true, false);
92  }
93
94  public void result(int exitStatus){
95    jRpResult(libPtr, exitStatus);
96  }
97
98  public void result(){
99    jRpResult(libPtr, 0);
100  }
101
102  public String xml(){
103    return jRpXml(libPtr);
104  }
105
106
107  // Native Functions----------------------------------------------------------
108  private native long jRpLibrary(String path);
109  private native void jRpDeleteLibrary(long libPtr);
110
111  private native byte[] jRpGetData(long libPtr, String path);
112  private native double jRpGetDouble(long libPtr, String path);
113  private native int jRpGetInt(long libPtr, String path);
114  private native String jRpGetString(long libPtr, String path);
115
116  private native void jRpPut(long libPtr, String path,
117                             String value, boolean append);
118  private native void jRpPutData(long libPtr, String path,
119                                 byte[] b, int nbytes, boolean append);
120  private native void jRpPutFile(long libPtr, String path, String fileName,
121                                 boolean compress, boolean append);
122
123  private native void jRpResult(long libPtr, int exitStatus); 
124  private native String jRpXml(long libPtr);
125
126  // Private Attributes--------------------------------------------------------
127  private long libPtr;  //pointer to c++ RpLibrary
128
129}
130
Note: See TracBrowser for help on using the repository browser.