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

Last change on this file since 1727 was 1727, checked in by braffert, 14 years ago

Last fix for building java bindings. Also added license info and more comments.

File size: 2.4 KB
Line 
1/*
2 * ======================================================================
3 *  AUTHOR:  Ben Rafferty, Purdue University
4 *  Copyright (c) 2010  Purdue Research Foundation
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  // Pseudo-Destructor.  Called when the object is garbage collected.----------
30  protected void finalize() throws Throwable {
31    try {
32      jRpDeleteLibrary(libPtr);
33    } finally {
34        super.finalize();
35    }
36  }
37
38  // Public Methods------------------------------------------------------------
39  public double getDouble(String path){
40    return jRpGetDouble(libPtr, path);
41  }
42
43  public String getString(String path){
44    return jRpGetString(libPtr, path);
45  }
46
47  public String get(String path){  // alias for getString
48    return jRpGetString(libPtr, path);
49  }
50
51  public void put(String path, Object value, boolean append){
52    // convert generic object to string
53    jRpPut(libPtr, path, value.toString(), append);
54  }
55
56  public void put(String path, Object value){
57    jRpPut(libPtr, path, value.toString(), false);
58  }
59
60  public void result(int exitStatus){
61    jRpResult(libPtr, exitStatus);
62  }
63
64  public void result(){
65    jRpResult(libPtr, 0);
66  }
67
68
69  // Native Functions----------------------------------------------------------
70  private native long jRpLibrary(String path);
71  private native void jRpDeleteLibrary(long libPtr);
72
73  private native double jRpGetDouble(long libPtr, String path);
74  private native String jRpGetString(long libPtr, String path);
75
76  private native void jRpPut(long libPtr, String path,
77                             String value, boolean append);
78
79  private native void jRpResult(long libPtr, int exitStatus); 
80
81  // Private Attributes--------------------------------------------------------
82  private long libPtr;  //pointer to c++ RpLibrary
83
84}
85
Note: See TracBrowser for help on using the repository browser.