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. The possible values 187 * returned by this function are: 188 * <ul> 189 * <li> {@link libsbmlConstants#LIBSBML_OPERATION_SUCCESS LIBSBML_OPERATION_SUCCESS} 190 * 191 * </ul> <p> 192 * @see #setProgramVersion(String version) 193 */ public 194 int setProgramName(String name) { 195 return libsbmlJNI.SBMLWriter_setProgramName(swigCPtr, this, name); 196 } 197 198 199/** 200 * Sets the version of this program, i.e., the program that is about to 201 * write out the {@link SBMLDocument}. 202 <p> 203 * If the program version and name are set (see 204 * {@link SBMLWriter#setProgramName(String)}), the 205 * following XML comment, intended for human consumption, will be written 206 * at the beginning of the document: 207 * <pre class='fragment'> 208 <!-- Created by <program name> version <program version> 209 on yyyy-MM-dd HH:mm with libSBML version <libsbml version>. --> 210 </pre> 211 <p> 212 * If the program version and name are not set at some point before 213 * calling the writeSBML() methods, no such comment is written out. 214 <p> 215 * @param version the version of this program (where 'this program' 216 * refers to program in which libSBML is embedded, not libSBML itself!) 217 <p> 218 * <p> 219 * @return integer value indicating success/failure of the 220 * function. The possible values 221 * returned by this function are: 222 * <ul> 223 * <li> {@link libsbmlConstants#LIBSBML_OPERATION_SUCCESS LIBSBML_OPERATION_SUCCESS} 224 * 225 * </ul> <p> 226 * @see #setProgramName(String name) 227 */ public 228 int setProgramVersion(String version) { 229 return libsbmlJNI.SBMLWriter_setProgramVersion(swigCPtr, this, version); 230 } 231 232 233/** 234 * Writes the given SBML document to filename. 235 <p> 236 * If the given filename ends with the suffix <code>".gz"</code> 237(for example, <code>"myfile.xml.gz"</code>), libSBML assumes the 238caller wants the file to be written compressed in <em>gzip</em> format. 239Similarly, if the given filename ends with <code>".zip"</code> or 240<code>".bz2"</code>, libSBML assumes the caller wants the file to 241be compressed in <em>zip</em> or <em>bzip2</em> format (respectively). 242Files whose names lack these suffixes will be written uncompressed. 243<em>Special considerations for the zip format</em>: If the given filename 244ends with <code>".zip"</code>, the file placed in the zip archive 245will have the suffix <code>".xml"</code> or 246<code>".sbml"</code>. For example, the file in the zip archive 247will be named <code>"test.xml"</code> if the given filename is 248<code>"test.xml.zip"</code> or <code>"test.zip"</code>. 249Similarly, the filename in the archive will be 250<code>"test.sbml"</code> if the given filename is 251<code>"test.sbml.zip"</code>. 252 253 <p> 254 * @param d the SBML document to be written 255 <p> 256 * @param filename the name or full pathname of the file where the SBML 257 * is to be written. 258 <p> 259 * @return <code>true</code> on success and <code>false</code> if the filename could not be 260 * opened for writing. 261 <p> 262 * @note To write a gzip/zip file, libSBML needs to be configured and linked with 263the <a target="_blank" href="http://www.zlib.net/">zlib</a> library at 264compile time. It also needs to be linked with the <a target="_blank" 265href="">bzip2</a> library to write files in <em>bzip2</em> format. (Both 266of these are the default configurations for libSBML.) Errors about 267unreadable files will be logged and this method will return 268<code>false</code> if a compressed filename is given and libSBML was 269<em>not</em> linked with the corresponding required library. 270 271 <p> 272 * @see #setProgramVersion(String version) 273 * @see #setProgramName(String name) 274 */ public 275 boolean writeSBML(SBMLDocument d, String filename) { 276 return libsbmlJNI.SBMLWriter_writeSBML__SWIG_0(swigCPtr, this, SBMLDocument.getCPtr(d), d, libsbml.getAbsolutePath(filename)); 277 } 278 279 280/** 281 * Writes the given SBML document to the output stream. 282 <p> 283 * @param d the SBML document to be written 284 <p> 285 * @param stream the stream object where the SBML is to be written. 286 <p> 287 * @return <code>true</code> on success and <code>false</code> if one of the underlying 288 * parser components fail (rare). 289 <p> 290 * @see #setProgramVersion(String version) 291 * @see #setProgramName(String name) 292 */ public 293 boolean writeSBML(SBMLDocument d, OStream stream) { 294 return libsbmlJNI.SBMLWriter_writeSBML__SWIG_1(swigCPtr, this, SBMLDocument.getCPtr(d), d, SWIGTYPE_p_std__ostream.getCPtr(stream.get_ostream()), stream); 295 } 296 297 298/** * @internal */ public 299 String writeToString(SBMLDocument d) { 300 return libsbmlJNI.SBMLWriter_writeToString(swigCPtr, this, SBMLDocument.getCPtr(d), d); 301 } 302 303 304/** 305 * Writes the given SBML document to filename. 306 <p> 307 * If the given filename ends with the suffix <code>".gz"</code> 308(for example, <code>"myfile.xml.gz"</code>), libSBML assumes the 309caller wants the file to be written compressed in <em>gzip</em> format. 310Similarly, if the given filename ends with <code>".zip"</code> or 311<code>".bz2"</code>, libSBML assumes the caller wants the file to 312be compressed in <em>zip</em> or <em>bzip2</em> format (respectively). 313Files whose names lack these suffixes will be written uncompressed. 314<em>Special considerations for the zip format</em>: If the given filename 315ends with <code>".zip"</code>, the file placed in the zip archive 316will have the suffix <code>".xml"</code> or 317<code>".sbml"</code>. For example, the file in the zip archive 318will be named <code>"test.xml"</code> if the given filename is 319<code>"test.xml.zip"</code> or <code>"test.zip"</code>. 320Similarly, the filename in the archive will be 321<code>"test.sbml"</code> if the given filename is 322<code>"test.sbml.zip"</code>. 323 324 <p> 325 * @param d the SBML document to be written 326 <p> 327 * @param filename the name or full pathname of the file where the SBML 328 * is to be written. 329 <p> 330 * @return <code>true</code> on success and <code>false</code> if the filename could not be 331 * opened for writing. 332 <p> 333 * @note To write a gzip/zip file, libSBML needs to be configured and linked with 334the <a target="_blank" href="http://www.zlib.net/">zlib</a> library at 335compile time. It also needs to be linked with the <a target="_blank" 336href="">bzip2</a> library to write files in <em>bzip2</em> format. (Both 337of these are the default configurations for libSBML.) Errors about 338unreadable files will be logged and this method will return 339<code>false</code> if a compressed filename is given and libSBML was 340<em>not</em> linked with the corresponding required library. 341 342 <p> 343 * @see #setProgramVersion(String version) 344 * @see #setProgramName(String name) 345 */ public 346 boolean writeSBMLToFile(SBMLDocument d, String filename) { 347 return libsbmlJNI.SBMLWriter_writeSBMLToFile(swigCPtr, this, SBMLDocument.getCPtr(d), d, libsbml.getAbsolutePath(filename)); 348 } 349 350 351/** 352 * Writes the given SBML document to an in-memory string and returns a 353 * pointer to it. 354 <p> 355 * The string is owned by the caller and should be freed (with <code>free</code>()) 356 * when no longer needed. 357 <p> 358 * @param d the SBML document to be written 359 <p> 360 * @return the string on success and <code>0</code> if one of the underlying parser 361 * components fail. 362 <p> 363 * @see #setProgramVersion(String version) 364 * @see #setProgramName(String name) 365 */ public 366 String writeSBMLToString(SBMLDocument d) { 367 return libsbmlJNI.SBMLWriter_writeSBMLToString(swigCPtr, this, SBMLDocument.getCPtr(d), d); 368 } 369 370 371/** 372 * Predicate returning <code>true</code> if this copy of libSBML has been linked 373 * with the <em>zlib</em> library. 374 <p> 375 * LibSBML supports reading and writing files compressed with either 376 * bzip2 or zip/gzip compression. The facility depends on libSBML having 377 * been compiled with the necessary support libraries. This method 378 * allows a calling program to inquire whether that is the case for the 379 * copy of libSBML it is using. 380 <p> 381 * @return <code>true</code> if libSBML is linked with zlib, <code>false</code> otherwise. 382 <p> 383 * 384 <p> 385 * @see SBMLWriter#hasBzip2() 386 */ public 387 static boolean hasZlib() { 388 return libsbmlJNI.SBMLWriter_hasZlib(); 389 } 390 391 392/** 393 * Predicate returning <code>true</code> if this copy of libSBML has been linked 394 * with the <em>bzip2</em> library. 395 <p> 396 * LibSBML supports reading and writing files compressed with either 397 * bzip2 or zip/gzip compression. The facility depends on libSBML having 398 * been compiled with the necessary support libraries. This method 399 * allows a calling program to inquire whether that is the case for the 400 * copy of libSBML it is using. 401 <p> 402 * @return <code>true</code> if libSBML is linked with bzip2, <code>false</code> otherwise. 403 <p> 404 * 405 <p> 406 * @see SBMLWriter#hasZlib() 407 */ public 408 static boolean hasBzip2() { 409 return libsbmlJNI.SBMLWriter_hasBzip2(); 410 } 411 412}