001/* ----------------------------------------------------------------------------
002 * This file was automatically generated by SWIG (http://www.swig.org).
003 * Version 3.0.8
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 *  Base class for SBML converters.
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.  It is a class used in
017the implementation of extra functionality provided by libSBML.
018</p>
019
020 <p>
021 * The {@link SBMLConverter} class is the base class for the various SBML 
022 * <em>converters</em>: classes of objects that transform or convert SBML documents.
023 * These transformations can involve essentially anything that can be written
024 * algorithmically; examples include converting the units of measurement in a
025 * model, or converting from one Level+Version combination of SBML to
026 * another.  Applications can also create their own converters by subclassing
027 * {@link SBMLConverter} and following the examples of the existing converters.
028 <p>
029 * <p>
030 * <h2>General information about the use of SBML converters</h2>
031 <p>
032 * The use of all the converters follows a similar approach.  First, one
033 * creates a {@link ConversionProperties} object and calls
034 * {@link ConversionProperties#addOption(ConversionOption)}
035 * on this object with one arguments: a text string that identifies the desired
036 * converter.  (The text string is specific to each converter; consult the
037 * documentation for a given converter to find out how it should be enabled.)
038 <p>
039 * Next, for some converters, the caller can optionally set some
040 * converter-specific properties using additional calls to
041 * {@link ConversionProperties#addOption(ConversionOption)}.
042 * Many converters provide the ability to
043 * configure their behavior to some extent; this is realized through the use
044 * of properties that offer different options.  The default property values
045 * for each converter can be interrogated using the method
046 * {@link SBMLConverter#getDefaultProperties()} on the converter class in question .
047 <p>
048 * Finally, the caller should invoke the method
049 * {@link SBMLDocument#convert(ConversionProperties)}
050 * with the {@link ConversionProperties} object as an argument.
051 <p>
052 * <h3>Example of invoking an SBML converter</h3>
053 <p>
054 * The following code fragment illustrates an example using
055 * {@link SBMLReactionConverter}, which is invoked using the option string 
056 * <code>'replaceReactions':</code>
057 <p>
058<pre class='fragment'>
059{@link ConversionProperties} props = new {@link ConversionProperties}();
060if (props != null) {
061  props.addOption('replaceReactions');
062} else {
063  // Deal with error.
064}
065</pre>
066<p>
067 * In the case of {@link SBMLReactionConverter}, there are no options to affect
068 * its behavior, so the next step is simply to invoke the converter on
069 * an {@link SBMLDocument} object.  Continuing the example code:
070 <p>
071<pre class='fragment'>
072  // Assume that the variable 'document' has been set to an {@link SBMLDocument} object.
073  status = document.convert(config);
074  if (status != libsbml.LIBSBML_OPERATION_SUCCESS)
075  {
076    // Handle error somehow.
077    System.out.println('Error: conversion failed due to the following:');
078    document.printErrors();
079  }
080</pre>
081<p>
082 * Here is an example of using a converter that offers an option. The
083 * following code invokes {@link SBMLStripPackageConverter} to remove the
084 * SBML Level&nbsp;3 <em>Layout</em> package from a model.  It sets the name
085 * of the package to be removed by adding a value for the option named
086 * <code>'package'</code> defined by that converter:
087 <p>
088<pre class='fragment'>
089{@link ConversionProperties} config = new {@link ConversionProperties}();
090if (config != None) {
091  config.addOption('stripPackage');
092  config.addOption('package', 'layout');
093  status = document.convert(config);
094  if (status != LIBSBML_OPERATION_SUCCESS) {
095    // Handle error somehow.
096    System.out.println('Error: unable to strip the {@link Layout} package');
097    document.printErrors();
098  }
099} 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.12.0
110:
111 <p>
112 * <p>
113 * <ul>
114 * <li> {@link CobraToFbcConverter}
115 * <li> {@link CompFlatteningConverter}
116 * <li> {@link FbcToCobraConverter}
117 * <li> {@link FbcV1ToV2Converter}
118 * <li> {@link FbcV2ToV1Converter}
119 * <li> {@link SBMLFunctionDefinitionConverter}
120 * <li> {@link SBMLIdConverter}
121 * <li> {@link SBMLInferUnitsConverter}
122 * <li> {@link SBMLInitialAssignmentConverter}
123 * <li> {@link SBMLLevel1Version1Converter}
124 * <li> {@link SBMLLevelVersionConverter}
125 * <li> {@link SBMLLocalParameterConverter}
126 * <li> {@link SBMLReactionConverter}
127 * <li> {@link SBMLRuleConverter}
128 * <li> {@link SBMLStripPackageConverter}
129 * <li> {@link SBMLUnitsConverter}
130 *
131 * </ul>
132 */
133
134public class SBMLConverter {
135   private long swigCPtr;
136   protected boolean swigCMemOwn;
137
138   protected SBMLConverter(long cPtr, boolean cMemoryOwn)
139   {
140     swigCMemOwn = cMemoryOwn;
141     swigCPtr    = cPtr;
142   }
143
144   protected static long getCPtr(SBMLConverter obj)
145   {
146     return (obj == null) ? 0 : obj.swigCPtr;
147   }
148
149   protected static long getCPtrAndDisown (SBMLConverter obj)
150   {
151     long ptr = 0;
152
153     if (obj != null)
154     {
155       ptr             = obj.swigCPtr;
156       obj.swigCMemOwn = false;
157     }
158
159     return ptr;
160   }
161
162  protected void finalize() {
163    delete();
164  }
165
166  public synchronized void delete() {
167    if (swigCPtr != 0) {
168      if (swigCMemOwn) {
169        swigCMemOwn = false;
170        libsbmlJNI.delete_SBMLConverter(swigCPtr);
171      }
172      swigCPtr = 0;
173    }
174  }
175
176  protected void swigDirectorDisconnect() {
177    swigCMemOwn = false;
178    delete();
179  }
180
181  public void swigReleaseOwnership() {
182    swigCMemOwn = false;
183    libsbmlJNI.SBMLConverter_change_ownership(this, swigCPtr, false);
184  }
185
186  public void swigTakeOwnership() {
187    swigCMemOwn = true;
188    libsbmlJNI.SBMLConverter_change_ownership(this, swigCPtr, true);
189  }
190
191  
192/**
193   * Creates a new {@link SBMLConverter} object.
194   */ public
195 SBMLConverter() {
196    this(libsbmlJNI.new_SBMLConverter__SWIG_0(), true);
197    libsbmlJNI.SBMLConverter_director_connect(this, swigCPtr, swigCMemOwn, true);
198  }
199
200  
201/**
202   * Creates a new {@link SBMLConverter} object with a given name.
203   <p>
204   * @param name the name for the converter to create
205   */ public
206 SBMLConverter(String name) {
207    this(libsbmlJNI.new_SBMLConverter__SWIG_1(name), true);
208    libsbmlJNI.SBMLConverter_director_connect(this, swigCPtr, swigCMemOwn, true);
209  }
210
211  
212/**
213   * Copy constructor.
214   <p>
215   * This creates a copy of an {@link SBMLConverter} object.
216   <p>
217   * @param orig the {@link SBMLConverter} object to copy.
218   */ public
219 SBMLConverter(SBMLConverter orig) {
220    this(libsbmlJNI.new_SBMLConverter__SWIG_2(SBMLConverter.getCPtr(orig), orig), true);
221    libsbmlJNI.SBMLConverter_director_connect(this, swigCPtr, swigCMemOwn, true);
222  }
223
224  
225/**
226   * Creates and returns a deep copy of this {@link SBMLConverter} object.
227   <p>
228   * @return the (deep) copy of this {@link SBMLConverter} object.
229   */ public
230 SBMLConverter cloneObject() {
231    return libsbml.DowncastSBMLConverter((getClass() == SBMLConverter.class) ? libsbmlJNI.SBMLConverter_cloneObject(swigCPtr, this) : libsbmlJNI.SBMLConverter_cloneObjectSwigExplicitSBMLConverter(swigCPtr, this), true);
232}
233
234  
235/**
236   * Returns the SBML document that is the subject of the conversions.
237   <p>
238   * @return the current {@link SBMLDocument} object.
239   */ public
240 SBMLDocument getDocument() {
241    long cPtr = (getClass() == SBMLConverter.class) ? libsbmlJNI.SBMLConverter_getDocument__SWIG_0(swigCPtr, this) : libsbmlJNI.SBMLConverter_getDocumentSwigExplicitSBMLConverter__SWIG_0(swigCPtr, this);
242    return (cPtr == 0) ? null : new SBMLDocument(cPtr, false);
243  }
244
245  
246/**
247   * Returns the default properties of this converter.
248   <p>
249   * A given converter exposes one or more properties that can be adjusted
250   * in order to influence the behavior of the converter.  This method
251   * returns the <em>default</em> property settings for this converter.  It is
252   * meant to be called in order to discover all the settings for the
253   * converter object.  The run-time properties of the converter object can
254   * be adjusted by using the method
255   * {@link SBMLConverter#setProperties(ConversionProperties props)}.
256   <p>
257   * @return the default properties for the converter.
258   <p>
259   * @see #setProperties(ConversionProperties)
260   * @see #matchesProperties(ConversionProperties)
261   */ public
262 ConversionProperties getDefaultProperties() {
263    return new ConversionProperties((getClass() == SBMLConverter.class) ? libsbmlJNI.SBMLConverter_getDefaultProperties(swigCPtr, this) : libsbmlJNI.SBMLConverter_getDefaultPropertiesSwigExplicitSBMLConverter(swigCPtr, this), true);
264  }
265
266  
267/**
268   * Returns the target SBML namespaces of the currently set properties.
269   <p>
270   * SBML namespaces are used by libSBML to express the Level+Version of the
271   * SBML document (and, possibly, any SBML Level&nbsp;3 packages in
272   * use). Some converters' behavior is affected by the SBML namespace
273   * configured in the converter.  For example, in {@link SBMLLevelVersionConverter}
274   * (the converter for converting SBML documents from one Level+Version
275   * combination to another), the actions are fundamentally dependent on the
276   * SBML namespaces targeted.
277   <p>
278   * @return the {@link SBMLNamespaces} object that describes the SBML namespaces
279   * in effect, or <code>null</code> if none are set.
280   */ public
281 SBMLNamespaces getTargetNamespaces() {
282  return libsbml.DowncastSBMLNamespaces((getClass() == SBMLConverter.class) ? libsbmlJNI.SBMLConverter_getTargetNamespaces(swigCPtr, this) : libsbmlJNI.SBMLConverter_getTargetNamespacesSwigExplicitSBMLConverter(swigCPtr, this), false);
283}
284
285  
286/**
287   * Returns <code>true</code> if this converter matches the given properties.
288   <p>
289   * Given a {@link ConversionProperties} object <code>props</code>, this method checks that 
290   * <code>props</code> possesses an option value to enable this converter.  If it does,
291   * this method returns <code>true.</code>
292   <p>
293   * @param props the properties to match.
294   <p>
295   * @return <code>true</code> if the properties <code>props</code> would match the necessary
296   * properties for this type of converter, <code>false</code> otherwise.
297   */ public
298 boolean matchesProperties(ConversionProperties props) {
299    return (getClass() == SBMLConverter.class) ? libsbmlJNI.SBMLConverter_matchesProperties(swigCPtr, this, ConversionProperties.getCPtr(props), props) : libsbmlJNI.SBMLConverter_matchesPropertiesSwigExplicitSBMLConverter(swigCPtr, this, ConversionProperties.getCPtr(props), props);
300  }
301
302  
303/**
304   * Sets the SBML document to be converted.
305   <p>
306   * @param doc the document to use for this conversion.
307   <p>
308   * @return integer value indicating the success/failure of the operation.
309   *  The set of possible values that may
310   * be returned ultimately depends on the specific subclass of
311   * {@link SBMLConverter} being used, but the default method can return the
312   * following:
313   * <ul>
314   * <li> {@link libsbmlConstants#LIBSBML_OPERATION_SUCCESS LIBSBML_OPERATION_SUCCESS}
315   * </ul>
316   */ public
317 int setDocument(SBMLDocument doc) {
318    return (getClass() == SBMLConverter.class) ? libsbmlJNI.SBMLConverter_setDocument(swigCPtr, this, SBMLDocument.getCPtr(doc), doc) : libsbmlJNI.SBMLConverter_setDocumentSwigExplicitSBMLConverter(swigCPtr, this, SBMLDocument.getCPtr(doc), doc);
319  }
320
321  
322/**
323   * Sets the configuration properties to be used by this converter.
324   <p>
325   * @param props the {@link ConversionProperties} object defining the properties
326   * to set.
327   <p>
328   * @return integer value indicating the success/failure of the operation.
329   *  The set of possible values that may
330   * be returned ultimately depends on the specific subclass of
331   * {@link SBMLConverter} being used, but the default method can return the
332   * following values:
333   * <ul>
334   * <li> {@link libsbmlConstants#LIBSBML_OPERATION_SUCCESS LIBSBML_OPERATION_SUCCESS}
335   * <li> {@link libsbmlConstants#LIBSBML_OPERATION_FAILED LIBSBML_OPERATION_FAILED}
336   *
337   * </ul> <p>
338   * @see #getProperties()
339   * @see #matchesProperties(ConversionProperties)
340   */ public
341 int setProperties(ConversionProperties props) {
342    return (getClass() == SBMLConverter.class) ? libsbmlJNI.SBMLConverter_setProperties(swigCPtr, this, ConversionProperties.getCPtr(props), props) : libsbmlJNI.SBMLConverter_setPropertiesSwigExplicitSBMLConverter(swigCPtr, this, ConversionProperties.getCPtr(props), props);
343  }
344
345  
346/**
347   * Returns the current properties in effect for this converter.
348   <p>
349   * A given converter exposes one or more properties that can be adjusted
350   * in order to influence the behavior of the converter.  This method
351   * returns the current properties for this converter; in other words, the
352   * settings in effect at this moment.  To change the property values, you
353   * can use {@link SBMLConverter#setProperties(ConversionProperties props)}.
354   <p>
355   * @return the currently set configuration properties.
356   <p>
357   * @see #setProperties(ConversionProperties)
358   * @see #matchesProperties(ConversionProperties)
359   */ public
360 ConversionProperties getProperties() {
361    long cPtr = (getClass() == SBMLConverter.class) ? libsbmlJNI.SBMLConverter_getProperties(swigCPtr, this) : libsbmlJNI.SBMLConverter_getPropertiesSwigExplicitSBMLConverter(swigCPtr, this);
362    return (cPtr == 0) ? null : new ConversionProperties(cPtr, false);
363  }
364
365  
366/**
367   * Perform the conversion.
368   <p>
369   * This method causes the converter to do the actual conversion work,
370   * that is, to convert the {@link SBMLDocument} object set by
371   * {@link SBMLConverter#setDocument(SBMLDocument)} and
372   * with the configuration options set by
373   * {@link SBMLConverter#setProperties(ConversionProperties)}.
374   <p>
375   * @return  integer value indicating the success/failure of the operation.
376   *  The set of possible values that may
377   * be returned depends on the converter subclass; please consult
378   * the documentation for the relevant class to find out what the
379   * possibilities are.
380   */ public
381 int convert() {
382    return (getClass() == SBMLConverter.class) ? libsbmlJNI.SBMLConverter_convert(swigCPtr, this) : libsbmlJNI.SBMLConverter_convertSwigExplicitSBMLConverter(swigCPtr, this);
383  }
384
385  
386/**
387   * Returns the name of this converter.
388   <p>
389   * @return a string, the name of this converter.
390   */ public
391 String getName() {
392    return libsbmlJNI.SBMLConverter_getName(swigCPtr, this);
393  }
394
395}