1 /* ---------------------------------------------------------------------------- 2 * This file was automatically generated by SWIG (http://www.swig.org). 3 * Version 4.0.2 4 * 5 * Do not make changes to this file unless you know what you are doing--modify 6 * the SWIG interface file instead. 7 * ----------------------------------------------------------------------------- */ 8 9 package org.sbml.libsbml; 10 11 /** 12 * Base class for SBML converters. 13 <p> 14 * <p style='color: #777; font-style: italic'> 15 This class of objects is defined by libSBML only and has no direct 16 equivalent in terms of SBML components. It is a class used in 17 the implementation of extra functionality provided by libSBML. 18 </p> 19 20 <p> 21 * The {@link SBMLConverter} class is the base class for the various SBML 22 * <em>converters</em>: classes of objects that transform or convert SBML documents. 23 * These transformations can involve essentially anything that can be written 24 * algorithmically; examples include converting the units of measurement in a 25 * model, or converting from one Level+Version combination of SBML to 26 * another. Applications can also create their own converters by subclassing 27 * {@link SBMLConverter} and following the examples of the existing converters. 28 <p> 29 * <p> 30 * <h2>General information about the use of SBML converters</h2> 31 <p> 32 * The use of all the converters follows a similar approach. First, one 33 * creates a {@link ConversionProperties} object and calls 34 * {@link ConversionProperties#addOption(ConversionOption)} 35 * on this object with one argument: a text string that identifies the desired 36 * converter. (The text string is specific to each converter; consult the 37 * documentation for a given converter to find out how it should be enabled.) 38 <p> 39 * Next, for some converters, the caller can optionally set some 40 * converter-specific properties using additional calls to 41 * {@link ConversionProperties#addOption(ConversionOption)}. 42 * Many converters provide the ability to 43 * configure their behavior to some extent; this is realized through the use 44 * of properties that offer different options. The default property values 45 * for each converter can be interrogated using the method 46 * {@link SBMLConverter#getDefaultProperties()} on the converter class in question . 47 <p> 48 * Finally, the caller should invoke the method 49 * {@link SBMLDocument#convert(ConversionProperties)} 50 * with the {@link ConversionProperties} object as an argument. 51 <p> 52 * <h3>Example of invoking an SBML converter</h3> 53 <p> 54 * The following code fragment illustrates an example using 55 * {@link SBMLReactionConverter}, which is invoked using the option string 56 * <code>'replaceReactions':</code> 57 <p> 58 <pre class='fragment'> 59 {@link ConversionProperties} props = new {@link ConversionProperties}(); 60 if (props != null) { 61 props.addOption('replaceReactions'); 62 } else { 63 // Deal with error. 64 } 65 </pre> 66 <p> 67 * In the case of {@link SBMLReactionConverter}, there are no options to affect 68 * its behavior, so the next step is simply to invoke the converter on 69 * an {@link SBMLDocument} object. Continuing the example code: 70 <p> 71 <pre class='fragment'> 72 // Assume that the variable 'document' has been set to an {@link SBMLDocument} object. 73 status = document.convert(config); 74 if (status != libsbml.LIBSBML_OPERATION_SUCCESS) 75 { 76 // Handle error somehow. 77 System.out.println('Error: conversion failed due to the following:'); 78 document.printErrors(); 79 } 80 </pre> 81 <p> 82 * Here is an example of using a converter that offers an option. The 83 * following code invokes {@link SBMLStripPackageConverter} to remove the 84 * SBML Level 3 <em>Layout</em> package from a model. It sets the name 85 * of the package to be removed by adding a value for the option named 86 * <code>'package'</code> defined by that converter: 87 <p> 88 <pre class='fragment'> 89 {@link ConversionProperties} config = new {@link ConversionProperties}(); 90 if (config != None) { 91 config.addOption('stripPackage'); 92 config.addOption('package', 'layout'); 93 status = document.convert(config); 94 if (status != LIBSBML_OPERATION_SUCCESS) { 95 // Handle error somehow. 96 System.out.println('Error: unable to strip the Layout package'); 97 document.printErrors(); 98 } 99 } else { 100 // Handle error somehow. 101 System.out.println('Error: unable to create {@link ConversionProperties} object'); 102 } 103 </pre> 104 <p> 105 * <h3>Available SBML converters in libSBML</h3> 106 <p> 107 * LibSBML provides a number of built-in converters; by convention, their 108 * names end in <em>Converter</em>. The following are the built-in converters 109 * provided by libSBML 5.19.0: 110 <p> 111 * @copydetails doc_list_of_libsbml_converters 112 */ 113 114 public class SBMLConverter { 115 private long swigCPtr; 116 protected boolean swigCMemOwn; 117 SBMLConverter(long cPtr, boolean cMemoryOwn)118 protected SBMLConverter(long cPtr, boolean cMemoryOwn) 119 { 120 swigCMemOwn = cMemoryOwn; 121 swigCPtr = cPtr; 122 } 123 getCPtr(SBMLConverter obj)124 protected static long getCPtr(SBMLConverter obj) 125 { 126 return (obj == null) ? 0 : obj.swigCPtr; 127 } 128 getCPtrAndDisown(SBMLConverter obj)129 protected static long getCPtrAndDisown (SBMLConverter obj) 130 { 131 long ptr = 0; 132 133 if (obj != null) 134 { 135 ptr = obj.swigCPtr; 136 obj.swigCMemOwn = false; 137 } 138 139 return ptr; 140 } 141 142 @SuppressWarnings("deprecation") finalize()143 protected void finalize() { 144 delete(); 145 } 146 delete()147 public synchronized void delete() { 148 if (swigCPtr != 0) { 149 if (swigCMemOwn) { 150 swigCMemOwn = false; 151 libsbmlJNI.delete_SBMLConverter(swigCPtr); 152 } 153 swigCPtr = 0; 154 } 155 } 156 swigDirectorDisconnect()157 protected void swigDirectorDisconnect() { 158 swigCMemOwn = false; 159 delete(); 160 } 161 swigReleaseOwnership()162 public void swigReleaseOwnership() { 163 swigCMemOwn = false; 164 libsbmlJNI.SBMLConverter_change_ownership(this, swigCPtr, false); 165 } 166 swigTakeOwnership()167 public void swigTakeOwnership() { 168 swigCMemOwn = true; 169 libsbmlJNI.SBMLConverter_change_ownership(this, swigCPtr, true); 170 } 171 172 173 /** 174 * Creates a new {@link SBMLConverter} object. 175 */ public SBMLConverter()176 SBMLConverter() { 177 this(libsbmlJNI.new_SBMLConverter__SWIG_0(), true); 178 libsbmlJNI.SBMLConverter_director_connect(this, swigCPtr, true, true); 179 } 180 181 182 /** 183 * Creates a new {@link SBMLConverter} object with a given name. 184 <p> 185 * @param name the name for the converter to create. 186 */ public SBMLConverter(String name)187 SBMLConverter(String name) { 188 this(libsbmlJNI.new_SBMLConverter__SWIG_1(name), true); 189 libsbmlJNI.SBMLConverter_director_connect(this, swigCPtr, true, true); 190 } 191 192 193 /** 194 * Copy constructor. 195 <p> 196 * This creates a copy of an {@link SBMLConverter} object. 197 <p> 198 * @param orig the {@link SBMLConverter} object to copy. 199 */ public SBMLConverter(SBMLConverter orig)200 SBMLConverter(SBMLConverter orig) { 201 this(libsbmlJNI.new_SBMLConverter__SWIG_2(SBMLConverter.getCPtr(orig), orig), true); 202 libsbmlJNI.SBMLConverter_director_connect(this, swigCPtr, true, true); 203 } 204 205 206 /** 207 * Creates and returns a deep copy of this {@link SBMLConverter} object. 208 <p> 209 * @return the (deep) copy of this {@link SBMLConverter} object. 210 */ public cloneObject()211 SBMLConverter cloneObject() { 212 return libsbml.DowncastSBMLConverter((getClass() == SBMLConverter.class) ? libsbmlJNI.SBMLConverter_cloneObject(swigCPtr, this) : libsbmlJNI.SBMLConverter_cloneObjectSwigExplicitSBMLConverter(swigCPtr, this), true); 213 } 214 215 216 /** 217 * Returns the SBML document that is the subject of the conversions. 218 <p> 219 * @return the current {@link SBMLDocument} object. 220 */ public getDocument()221 SBMLDocument getDocument() { 222 long cPtr = (getClass() == SBMLConverter.class) ? libsbmlJNI.SBMLConverter_getDocument__SWIG_0(swigCPtr, this) : libsbmlJNI.SBMLConverter_getDocumentSwigExplicitSBMLConverter__SWIG_0(swigCPtr, this); 223 return (cPtr == 0) ? null : new SBMLDocument(cPtr, false); 224 } 225 226 227 /** 228 * Returns the default properties of this converter. 229 <p> 230 * A given converter exposes one or more properties that can be adjusted 231 * in order to influence the behavior of the converter. This method 232 * returns the <em>default</em> property settings for this converter. It is 233 * meant to be called in order to discover all the settings for the 234 * converter object. The run-time properties of the converter object can 235 * be adjusted by using the method 236 * {@link SBMLConverter#setProperties(ConversionProperties props)}. 237 <p> 238 * @return the default properties for the converter. 239 <p> 240 * @see #setProperties(ConversionProperties) 241 * @see #matchesProperties(ConversionProperties) 242 */ public getDefaultProperties()243 ConversionProperties getDefaultProperties() { 244 return new ConversionProperties((getClass() == SBMLConverter.class) ? libsbmlJNI.SBMLConverter_getDefaultProperties(swigCPtr, this) : libsbmlJNI.SBMLConverter_getDefaultPropertiesSwigExplicitSBMLConverter(swigCPtr, this), true); 245 } 246 247 248 /** 249 * Returns the target SBML namespaces of the currently set properties. 250 <p> 251 * SBML namespaces are used by libSBML to express the Level+Version of the 252 * SBML document (and, possibly, any SBML Level 3 packages in 253 * use). Some converters' behavior is affected by the SBML namespace 254 * configured in the converter. For example, in {@link SBMLLevelVersionConverter} 255 * (the converter for converting SBML documents from one Level+Version 256 * combination to another), the actions are fundamentally dependent on the 257 * SBML namespaces targeted. 258 <p> 259 * @return the {@link SBMLNamespaces} object that describes the SBML namespaces 260 * in effect, or <code>null</code> if none are set. 261 */ public getTargetNamespaces()262 SBMLNamespaces getTargetNamespaces() { 263 return libsbml.DowncastSBMLNamespaces((getClass() == SBMLConverter.class) ? libsbmlJNI.SBMLConverter_getTargetNamespaces(swigCPtr, this) : libsbmlJNI.SBMLConverter_getTargetNamespacesSwigExplicitSBMLConverter(swigCPtr, this), false); 264 } 265 266 267 /** 268 * Returns <code>true</code> if this converter matches the given properties. 269 <p> 270 * Given a {@link ConversionProperties} object <code>props</code>, this method checks that 271 * <code>props</code> possesses an option value to enable this converter. If it does, 272 * this method returns <code>true.</code> 273 <p> 274 * @param props the properties to match. 275 <p> 276 * @return <code>true</code> if the properties <code>props</code> would match the necessary 277 * properties for this type of converter, <code>false</code> otherwise. 278 */ public matchesProperties(ConversionProperties props)279 boolean matchesProperties(ConversionProperties props) { 280 return (getClass() == SBMLConverter.class) ? libsbmlJNI.SBMLConverter_matchesProperties(swigCPtr, this, ConversionProperties.getCPtr(props), props) : libsbmlJNI.SBMLConverter_matchesPropertiesSwigExplicitSBMLConverter(swigCPtr, this, ConversionProperties.getCPtr(props), props); 281 } 282 283 284 /** 285 * Sets the SBML document to be converted. 286 <p> 287 * @param doc the document to use for this conversion. 288 <p> 289 * @return integer value indicating the success/failure of the operation. 290 * The set of possible values that may 291 * be returned ultimately depends on the specific subclass of 292 * {@link SBMLConverter} being used, but the default method can return the 293 * following: 294 * <ul> 295 * <li> {@link libsbmlConstants#LIBSBML_OPERATION_SUCCESS LIBSBML_OPERATION_SUCCESS} 296 * </ul> 297 */ public setDocument(SBMLDocument doc)298 int setDocument(SBMLDocument doc) { 299 return (getClass() == SBMLConverter.class) ? libsbmlJNI.SBMLConverter_setDocument(swigCPtr, this, SBMLDocument.getCPtr(doc), doc) : libsbmlJNI.SBMLConverter_setDocumentSwigExplicitSBMLConverter(swigCPtr, this, SBMLDocument.getCPtr(doc), doc); 300 } 301 302 303 /** 304 * Sets the configuration properties to be used by this converter. 305 <p> 306 * @param props the {@link ConversionProperties} object defining the properties 307 * to set. 308 <p> 309 * @return integer value indicating the success/failure of the operation. 310 * The set of possible values that may 311 * be returned ultimately depends on the specific subclass of 312 * {@link SBMLConverter} being used, but the default method can return the 313 * following values: 314 * <ul> 315 * <li> {@link libsbmlConstants#LIBSBML_OPERATION_SUCCESS LIBSBML_OPERATION_SUCCESS} 316 * <li> {@link libsbmlConstants#LIBSBML_OPERATION_FAILED LIBSBML_OPERATION_FAILED} 317 * 318 * </ul> <p> 319 * @see #getProperties() 320 * @see #matchesProperties(ConversionProperties) 321 */ public setProperties(ConversionProperties props)322 int setProperties(ConversionProperties props) { 323 return (getClass() == SBMLConverter.class) ? libsbmlJNI.SBMLConverter_setProperties(swigCPtr, this, ConversionProperties.getCPtr(props), props) : libsbmlJNI.SBMLConverter_setPropertiesSwigExplicitSBMLConverter(swigCPtr, this, ConversionProperties.getCPtr(props), props); 324 } 325 326 327 /** 328 * Returns the current properties in effect for this converter. 329 <p> 330 * A given converter exposes one or more properties that can be adjusted 331 * in order to influence the behavior of the converter. This method 332 * returns the current properties for this converter; in other words, the 333 * settings in effect at this moment. To change the property values, you 334 * can use {@link SBMLConverter#setProperties(ConversionProperties props)}. 335 <p> 336 * @return the currently set configuration properties. 337 <p> 338 * @see #setProperties(ConversionProperties) 339 * @see #matchesProperties(ConversionProperties) 340 */ public getProperties()341 ConversionProperties getProperties() { 342 long cPtr = (getClass() == SBMLConverter.class) ? libsbmlJNI.SBMLConverter_getProperties(swigCPtr, this) : libsbmlJNI.SBMLConverter_getPropertiesSwigExplicitSBMLConverter(swigCPtr, this); 343 return (cPtr == 0) ? null : new ConversionProperties(cPtr, false); 344 } 345 346 347 /** 348 * Perform the conversion. 349 <p> 350 * This method causes the converter to do the actual conversion work, 351 * that is, to convert the {@link SBMLDocument} object set by 352 * {@link SBMLConverter#setDocument(SBMLDocument)} and 353 * with the configuration options set by 354 * {@link SBMLConverter#setProperties(ConversionProperties)}. 355 <p> 356 * @return integer value indicating the success/failure of the operation. 357 * The set of possible values that may 358 * be returned depends on the converter subclass; please consult 359 * the documentation for the relevant class to find out what the 360 * possibilities are. 361 */ public convert()362 int convert() { 363 return (getClass() == SBMLConverter.class) ? libsbmlJNI.SBMLConverter_convert(swigCPtr, this) : libsbmlJNI.SBMLConverter_convertSwigExplicitSBMLConverter(swigCPtr, this); 364 } 365 366 367 /** 368 * Returns the name of this converter. 369 <p> 370 * @return a string, the name of this converter. 371 */ public getName()372 String getName() { 373 return libsbmlJNI.SBMLConverter_getName(swigCPtr, this); 374 } 375 376 } 377