001/* ---------------------------------------------------------------------------- 002 * This file was automatically generated by SWIG (http://www.swig.org). 003 * Version 3.0.10 004 * 005 * Do not make changes to this file unless you know what you are doing--modify 006 * the SWIG interface file instead. 007 * ----------------------------------------------------------------------------- */ 008 009package org.sbml.libsbml; 010 011/** 012 * File and text-string SBML writer. 013 <p> 014 * <p style='color: #777; font-style: italic'> 015This class of objects is defined by libSBML only and has no direct 016equivalent in terms of SBML components. This class is not prescribed by 017the SBML specifications, although it is used to implement features 018defined in SBML. 019</p> 020 021 <p> 022 * The {@link SBMLWriter} class is the converse of {@link SBMLReader}, and provides the 023 * main interface for serializing SBML models into XML and writing the 024 * result to an output stream or to files and text strings. The methods 025 * for writing SBML all take an {@link SBMLDocument} object and a destination. 026 * They return a boolean or integer value to indicate success or failure. 027 <p> 028 * <h2>Support for writing compressed files</h2> 029 <p> 030 * LibSBML provides support for writing (as well as reading) compressed 031 * SBML files. The process is transparent to the calling 032 * application—the application does not need to do anything 033 * deliberate to invoke the functionality. If a given SBML filename ends 034 * with an extension for the <em>gzip</em>, <em>zip</em> or <em>bzip2</em> compression 035 * formats (respectively, <code>".gz"</code>, 036 * <code>".zip"</code>, or <code>".bz2"</code>), 037 * then the methods 038 * {@link SBMLWriter#writeSBML(SBMLDocument, String)} 039 * and {@link SBMLReader#readSBML(String)} 040 * will automatically compress and decompress the file while writing and 041 * reading it. If the filename has no such extension, it 042 * will be written and read uncompressed as normal. 043 <p> 044 * The compression feature requires that the <em>zlib</em> (for <em>gzip</em> and 045 * <em>zip</em> formats) and/or <em>bzip2</em> (for <em>bzip2</em> format) be available on the 046 * system running libSBML, and that libSBML was configured with their 047 * support compiled-in. Please see the libSBML <a href='../../../libsbml-installation.html'>installation instructions</a> for 048 * more information about this. The methods 049 * {@link SBMLWriter#hasZlib()} and 050 * {@link SBMLWriter#hasBzip2()} 051 * can be used by an application to query at run-time whether support 052 * for the compression libraries is available in the present copy of 053 * libSBML. 054 <p> 055 * Support for compression is not mandated by the SBML standard, but 056 * applications may find it helpful, particularly when large SBML models 057 * are being communicated across data links of limited bandwidth. 058 */ 059 060public class SBMLWriter { 061 private long swigCPtr; 062 protected boolean swigCMemOwn; 063 064 protected SBMLWriter(long cPtr, boolean cMemoryOwn) 065 { 066 swigCMemOwn = cMemoryOwn; 067 swigCPtr = cPtr; 068 } 069 070 protected static long getCPtr(SBMLWriter obj) 071 { 072 return (obj == null) ? 0 : obj.swigCPtr; 073 } 074 075 protected static long getCPtrAndDisown (SBMLWriter obj) 076 { 077 long ptr = 0; 078 079 if (obj != null) 080 { 081 ptr = obj.swigCPtr; 082 obj.swigCMemOwn = false; 083 } 084 085 return ptr; 086 } 087 088 protected void finalize() { 089 delete(); 090 } 091 092 public synchronized void delete() { 093 if (swigCPtr != 0) { 094 if (swigCMemOwn) { 095 swigCMemOwn = false; 096 libsbmlJNI.delete_SBMLWriter(swigCPtr); 097 } 098 swigCPtr = 0; 099 } 100 } 101 102 /** 103 * Equality comparison method for SBMLWriter. 104 * <p> 105 * Because the Java methods for libSBML are actually wrappers around code 106 * implemented in C++ and C, certain operations will not behave as 107 * expected. Equality comparison is one such case. An instance of a 108 * libSBML object class is actually a <em>proxy object</em> 109 * wrapping the real underlying C/C++ object. The normal <code>==</code> 110 * equality operator in Java will <em>only compare the Java proxy objects</em>, 111 * not the underlying native object. The result is almost never what you 112 * want in practical situations. Unfortunately, Java does not provide a 113 * way to override <code>==</code>. 114 * <p> 115 * The alternative that must be followed is to use the 116 * <code>equals()</code> method. The <code>equals</code> method on this 117 * class overrides the default java.lang.Object one, and performs an 118 * intelligent comparison of instances of objects of this class. The 119 * result is an assessment of whether two libSBML Java objects are truly 120 * the same underlying native-code objects. 121 * <p> 122 * The use of this method in practice is the same as the use of any other 123 * Java <code>equals</code> method. For example, 124 * <em>a</em><code>.equals(</code><em>b</em><code>)</code> returns 125 * <code>true</code> if <em>a</em> and <em>b</em> are references to the 126 * same underlying object. 127 * 128 * @param sb a reference to an object to which the current object 129 * instance will be compared 130 * 131 * @return <code>true</code> if <code>sb</code> refers to the same underlying 132 * native object as this one, <code>false</code> otherwise 133 */ 134 public boolean equals(Object sb) 135 { 136 if ( this == sb ) 137 { 138 return true; 139 } 140 return swigCPtr == getCPtr((SBMLWriter)(sb)); 141 } 142 143 /** 144 * Returns a hashcode for this SBMLWriter object. 145 * 146 * @return a hash code usable by Java methods that need them. 147 */ 148 public int hashCode() 149 { 150 return (int)(swigCPtr^(swigCPtr>>>32)); 151 } 152 153 154/** 155 * Creates a new {@link SBMLWriter}. 156 <p> 157 * The libSBML {@link SBMLWriter} objects offer methods for writing SBML in 158 * XML form to files and text strings. 159 */ public 160 SBMLWriter() { 161 this(libsbmlJNI.new_SBMLWriter(), true); 162 } 163 164 165/** 166 * Sets the name of this program, i.e., the program that is about to 167 * write out the {@link SBMLDocument}. 168 <p> 169 * If the program name and version are set (see 170 * {@link SBMLWriter#setProgramVersion(String)}), the 171 * following XML comment, intended for human consumption, will be written 172 * at the beginning of the XML document: 173 * <pre class='fragment'> 174 <!-- Created by <program name> version <program version> 175 on yyyy-MM-dd HH:mm with libSBML version <libsbml version>. --> 176 </pre> 177 <p> 178 * If the program name and version are not set at some point before 179 * calling the writeSBML() methods, no such comment is written out. 180 <p> 181 * @param name the name of this program (where 'this program' refers to 182 * program in which libSBML is embedded, not libSBML itself!) 183 <p> 184 * <p> 185 * @return integer value indicating success/failure of the 186 * function. This particular 187 * function only does one thing irrespective of user input or 188 * object state, and thus will only return a single value: 189 * <ul> 190 * <li> {@link libsbmlConstants#LIBSBML_OPERATION_SUCCESS LIBSBML_OPERATION_SUCCESS} 191 * 192 * </ul> <p> 193 * @see #setProgramVersion(String version) 194 */ public 195 int setProgramName(String name) { 196 return libsbmlJNI.SBMLWriter_setProgramName(swigCPtr, this, name); 197 } 198 199 200/** 201 * Sets the version of this program, i.e., the program that is about to 202 * write out the {@link SBMLDocument}. 203 <p> 204 * If the program version and name are set (see 205 * {@link SBMLWriter#setProgramName(String)}), the 206 * following XML comment, intended for human consumption, will be written 207 * at the beginning of the document: 208 * <pre class='fragment'> 209 <!-- Created by <program name> version <program version> 210 on yyyy-MM-dd HH:mm with libSBML version <libsbml version>. --> 211 </pre> 212 <p> 213 * If the program version and name are not set at some point before 214 * calling the writeSBML() methods, no such comment is written out. 215 <p> 216 * @param version the version of this program (where 'this program' 217 * refers to program in which libSBML is embedded, not libSBML itself!) 218 <p> 219 * <p> 220 * @return integer value indicating success/failure of the 221 * function. This particular 222 * function only does one thing irrespective of user input or 223 * object state, and thus will only return a single value: 224 * <ul> 225 * <li> {@link libsbmlConstants#LIBSBML_OPERATION_SUCCESS LIBSBML_OPERATION_SUCCESS} 226 * 227 * </ul> <p> 228 * @see #setProgramName(String name) 229 */ public 230 int setProgramVersion(String version) { 231 return libsbmlJNI.SBMLWriter_setProgramVersion(swigCPtr, this, version); 232 } 233 234 235/** 236 * Writes the given SBML document to filename. 237 <p> 238 * If the given filename ends with the suffix <code>".gz"</code> 239(for example, <code>"myfile.xml.gz"</code>), libSBML assumes the 240caller wants the file to be written compressed in <em>gzip</em> format. 241Similarly, if the given filename ends with <code>".zip"</code> or 242<code>".bz2"</code>, libSBML assumes the caller wants the file to 243be compressed in <em>zip</em> or <em>bzip2</em> format (respectively). 244Files whose names lack these suffixes will be written uncompressed. 245<em>Special considerations for the zip format</em>: If the given filename 246ends with <code>".zip"</code>, the file placed in the zip archive 247will have the suffix <code>".xml"</code> or 248<code>".sbml"</code>. For example, the file in the zip archive 249will be named <code>"test.xml"</code> if the given filename is 250<code>"test.xml.zip"</code> or <code>"test.zip"</code>. 251Similarly, the filename in the archive will be 252<code>"test.sbml"</code> if the given filename is 253<code>"test.sbml.zip"</code>. 254 255 <p> 256 * @param d the SBML document to be written. 257 <p> 258 * @param filename the name or full pathname of the file where the SBML 259 * is to be written. 260 <p> 261 * @return <code>true</code> on success and <code>false</code> if the filename could not be 262 * opened for writing. 263 <p> 264 * @note To write a gzip/zip file, libSBML needs to be configured and linked with 265the <a target="_blank" href="http://www.zlib.net/">zlib</a> library at 266compile time. It also needs to be linked with the <a target="_blank" 267href="">bzip2</a> library to write files in <em>bzip2</em> format. (Both 268of these are the default configurations for libSBML.) Errors about 269unreadable files will be logged and this method will return 270<code>false</code> if a compressed filename is given and libSBML was 271<em>not</em> linked with the corresponding required library. 272 273 <p> 274 * @see #setProgramVersion(String version) 275 * @see #setProgramName(String name) 276 */ public 277 boolean writeSBML(SBMLDocument d, String filename) { 278 return libsbmlJNI.SBMLWriter_writeSBML__SWIG_0(swigCPtr, this, SBMLDocument.getCPtr(d), d, libsbml.getAbsolutePath(filename)); 279 } 280 281 282/** 283 * Writes the given SBML document to the output stream. 284 <p> 285 * @param d the SBML document to be written. 286 <p> 287 * @param stream the stream object where the SBML is to be written. 288 <p> 289 * @return <code>true</code> on success and <code>false</code> if one of the underlying 290 * parser components fail (rare). 291 <p> 292 * @see #setProgramVersion(String version) 293 * @see #setProgramName(String name) 294 */ public 295 boolean writeSBML(SBMLDocument d, OStream stream) { 296 return libsbmlJNI.SBMLWriter_writeSBML__SWIG_1(swigCPtr, this, SBMLDocument.getCPtr(d), d, SWIGTYPE_p_std__ostream.getCPtr(stream.get_ostream()), stream); 297 } 298 299 300/** * @internal */ public 301 String writeToString(SBMLDocument d) { 302 return libsbmlJNI.SBMLWriter_writeToString(swigCPtr, this, SBMLDocument.getCPtr(d), d); 303 } 304 305 306/** 307 * Writes the given SBML document to filename. 308 <p> 309 * If the given filename ends with the suffix <code>".gz"</code> 310(for example, <code>"myfile.xml.gz"</code>), libSBML assumes the 311caller wants the file to be written compressed in <em>gzip</em> format. 312Similarly, if the given filename ends with <code>".zip"</code> or 313<code>".bz2"</code>, libSBML assumes the caller wants the file to 314be compressed in <em>zip</em> or <em>bzip2</em> format (respectively). 315Files whose names lack these suffixes will be written uncompressed. 316<em>Special considerations for the zip format</em>: If the given filename 317ends with <code>".zip"</code>, the file placed in the zip archive 318will have the suffix <code>".xml"</code> or 319<code>".sbml"</code>. For example, the file in the zip archive 320will be named <code>"test.xml"</code> if the given filename is 321<code>"test.xml.zip"</code> or <code>"test.zip"</code>. 322Similarly, the filename in the archive will be 323<code>"test.sbml"</code> if the given filename is 324<code>"test.sbml.zip"</code>. 325 326 <p> 327 * @param d the SBML document to be written. 328 <p> 329 * @param filename the name or full pathname of the file where the SBML 330 * is to be written. 331 <p> 332 * @return <code>true</code> on success and <code>false</code> if the filename could not be 333 * opened for writing. 334 <p> 335 * @note To write a gzip/zip file, libSBML needs to be configured and linked with 336the <a target="_blank" href="http://www.zlib.net/">zlib</a> library at 337compile time. It also needs to be linked with the <a target="_blank" 338href="">bzip2</a> library to write files in <em>bzip2</em> format. (Both 339of these are the default configurations for libSBML.) Errors about 340unreadable files will be logged and this method will return 341<code>false</code> if a compressed filename is given and libSBML was 342<em>not</em> linked with the corresponding required library. 343 344 <p> 345 * @see #setProgramVersion(String version) 346 * @see #setProgramName(String name) 347 */ public 348 boolean writeSBMLToFile(SBMLDocument d, String filename) { 349 return libsbmlJNI.SBMLWriter_writeSBMLToFile(swigCPtr, this, SBMLDocument.getCPtr(d), d, libsbml.getAbsolutePath(filename)); 350 } 351 352 353/** 354 * Writes the given SBML document to an in-memory string and returns a 355 * pointer to it. 356 <p> 357 * The string is owned by the caller and should be freed (with <code>free</code>()) 358 * when no longer needed. 359 <p> 360 * @param d the SBML document to be written. 361 <p> 362 * @return the string on success and <code>0</code> if one of the underlying parser 363 * components fail. 364 <p> 365 * @see #setProgramVersion(String version) 366 * @see #setProgramName(String name) 367 */ public 368 String writeSBMLToString(SBMLDocument d) { 369 return libsbmlJNI.SBMLWriter_writeSBMLToString(swigCPtr, this, SBMLDocument.getCPtr(d), d); 370 } 371 372 373/** 374 * Predicate returning <code>true</code> if this copy of libSBML has been linked 375 * with the <em>zlib</em> library. 376 <p> 377 * LibSBML supports reading and writing files compressed with either 378 * bzip2 or zip/gzip compression. The facility depends on libSBML having 379 * been compiled with the necessary support libraries. This method 380 * allows a calling program to inquire whether that is the case for the 381 * copy of libSBML it is using. 382 <p> 383 * @return <code>true</code> if libSBML is linked with zlib, <code>false</code> otherwise. 384 <p> 385 * 386 <p> 387 * @see SBMLWriter#hasBzip2() 388 */ public 389 static boolean hasZlib() { 390 return libsbmlJNI.SBMLWriter_hasZlib(); 391 } 392 393 394/** 395 * Predicate returning <code>true</code> if this copy of libSBML has been linked 396 * with the <em>bzip2</em> library. 397 <p> 398 * LibSBML supports reading and writing files compressed with either 399 * bzip2 or zip/gzip compression. The facility depends on libSBML having 400 * been compiled with the necessary support libraries. This method 401 * allows a calling program to inquire whether that is the case for the 402 * copy of libSBML it is using. 403 <p> 404 * @return <code>true</code> if libSBML is linked with bzip2, <code>false</code> otherwise. 405 <p> 406 * 407 <p> 408 * @see SBMLWriter#hasZlib() 409 */ public 410 static boolean hasBzip2() { 411 return libsbmlJNI.SBMLWriter_hasBzip2(); 412 } 413 414}