001/* ----------------------------------------------------------------------------
002 * This file was automatically generated by SWIG (http://www.swig.org).
003 * Version 3.0.7
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 validators.
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 * LibSBML implements facilities for verifying that a given SBML document
023 * is valid according to the SBML specifications; it also exposes the
024 * validation interface so that user programs and SBML Level&nbsp;3 package
025 * authors may use the facilities to implement new validators.  There are
026 * two main interfaces to libSBML's validation facilities, based on the
027 * classes Validator and {@link SBMLValidator}.
028 <p>
029 * The Validator class is the basis of the system for validating an SBML
030 * document against the validation rules defined in the SBML
031 * specifications.  The scheme used by Validator relies is compact and uses
032 * the <em>visitor</em> programming pattern, but it relies on C/C++ features and
033 * is not directly accessible from language bindings.  {@link SBMLValidator} offers
034 * a framework for straightforward class-based extensibility, so that user
035 * code can subclass {@link SBMLValidator} to implement new validation systems,
036 * different validators can be introduced or turned off at run-time, and
037 * interfaces can be provided in the libSBML language bindings.
038 * {@link SBMLValidator} can call Validator functionality internally (as is the
039 * case in the current implementation of SBMLInternalValidator) or use
040 * entirely different implementation approaches, as necessary.
041 <p>
042 * Users of libSBML may already be familiar with the facilities encompassed
043 * by the validation system, in the form of the consistency-checking methods
044 * defined on {@link SBMLDocument}.  The methods {@link SBMLDocument#setConsistencyChecks(int, boolean)},
045 * {@link SBMLDocument#checkConsistency()}, {@link SBMLDocument#checkInternalConsistency()}
046 * and other method of that sort are in fact implemented via {@link SBMLValidator},
047 * specifically as methods on the class SBMLInternalValidator.
048 <p>
049 * Authors may use {@link SBMLValidator} as the base class for their own validator
050 * extensions to libSBML.  The class SBMLInternalValidator may serve as a
051 * code example for how to implement such things.
052 */
053
054public class SBMLValidator {
055   private long swigCPtr;
056   protected boolean swigCMemOwn;
057
058   protected SBMLValidator(long cPtr, boolean cMemoryOwn)
059   {
060     swigCMemOwn = cMemoryOwn;
061     swigCPtr    = cPtr;
062   }
063
064   protected static long getCPtr(SBMLValidator obj)
065   {
066     return (obj == null) ? 0 : obj.swigCPtr;
067   }
068
069   protected static long getCPtrAndDisown (SBMLValidator obj)
070   {
071     long ptr = 0;
072
073     if (obj != null)
074     {
075       ptr             = obj.swigCPtr;
076       obj.swigCMemOwn = false;
077     }
078
079     return ptr;
080   }
081
082  protected void finalize() {
083    delete();
084  }
085
086  public synchronized void delete() {
087    if (swigCPtr != 0) {
088      if (swigCMemOwn) {
089        swigCMemOwn = false;
090        libsbmlJNI.delete_SBMLValidator(swigCPtr);
091      }
092      swigCPtr = 0;
093    }
094  }
095
096  protected void swigDirectorDisconnect() {
097    swigCMemOwn = false;
098    delete();
099  }
100
101  public void swigReleaseOwnership() {
102    swigCMemOwn = false;
103    libsbmlJNI.SBMLValidator_change_ownership(this, swigCPtr, false);
104  }
105
106  public void swigTakeOwnership() {
107    swigCMemOwn = true;
108    libsbmlJNI.SBMLValidator_change_ownership(this, swigCPtr, true);
109  }
110
111  
112/**
113   * Creates a new {@link SBMLValidator}.
114   */ public
115 SBMLValidator() {
116    this(libsbmlJNI.new_SBMLValidator__SWIG_0(), true);
117    libsbmlJNI.SBMLValidator_director_connect(this, swigCPtr, swigCMemOwn, true);
118  }
119
120  
121/**
122   * Copy constructor; creates a copy of an {@link SBMLValidator} object.
123   <p>
124   * @param orig the object to copy.
125   */ public
126 SBMLValidator(SBMLValidator orig) {
127    this(libsbmlJNI.new_SBMLValidator__SWIG_1(SBMLValidator.getCPtr(orig), orig), true);
128    libsbmlJNI.SBMLValidator_director_connect(this, swigCPtr, swigCMemOwn, true);
129  }
130
131  
132/**
133   * Creates and returns a deep copy of this {@link SBMLValidator} object.
134   <p>
135   * @return the (deep) copy of this {@link SBMLValidator} object.
136   */ public
137 SBMLValidator cloneObject() {
138    long cPtr = (getClass() == SBMLValidator.class) ? libsbmlJNI.SBMLValidator_cloneObject(swigCPtr, this) : libsbmlJNI.SBMLValidator_cloneObjectSwigExplicitSBMLValidator(swigCPtr, this);
139    return (cPtr == 0) ? null : new SBMLValidator(cPtr, true);
140  }
141
142  
143/**
144   * Returns the current SBML document in use by this validator.
145   <p>
146   * @return the current SBML document
147   <p>
148   * @see #setDocument(SBMLDocument)
149   */ public
150 SBMLDocument getDocument() {
151    long cPtr = (getClass() == SBMLValidator.class) ? libsbmlJNI.SBMLValidator_getDocument__SWIG_0(swigCPtr, this) : libsbmlJNI.SBMLValidator_getDocumentSwigExplicitSBMLValidator__SWIG_0(swigCPtr, this);
152    return (cPtr == 0) ? null : new SBMLDocument(cPtr, false);
153  }
154
155  
156/** 
157   * Sets the current SBML document to the given {@link SBMLDocument} object.
158   <p>
159   * @param doc the document to use for this validation
160   <p>
161   * <p>
162 * @return integer value indicating success/failure of the
163 * function.   The possible values
164 * returned by this function are:
165   * <ul>
166   * <li> {@link libsbmlConstants#LIBSBML_OPERATION_SUCCESS LIBSBML_OPERATION_SUCCESS}
167   *
168   * </ul> <p>
169   * @see #getDocument()
170   */ public
171 int setDocument(SBMLDocument doc) {
172    return (getClass() == SBMLValidator.class) ? libsbmlJNI.SBMLValidator_setDocument(swigCPtr, this, SBMLDocument.getCPtr(doc), doc) : libsbmlJNI.SBMLValidator_setDocumentSwigExplicitSBMLValidator(swigCPtr, this, SBMLDocument.getCPtr(doc), doc);
173  }
174
175  
176/** 
177   * Runs this validator on the current SBML document.
178   <p>
179   * @return an integer value indicating the success/failure of the
180   * validation.   The possible values returned by this
181   * function are determined by the specific subclasses of this class.
182   */ public
183 long validate() {
184    return (getClass() == SBMLValidator.class) ? libsbmlJNI.SBMLValidator_validate__SWIG_0(swigCPtr, this) : libsbmlJNI.SBMLValidator_validateSwigExplicitSBMLValidator__SWIG_0(swigCPtr, this);
185  }
186
187  
188/**
189   * Clears this validator's list of failures.
190   <p>
191   * If you are validating multiple SBML documents with the same validator,
192   * call this method after you have processed the list of failures from
193   * the last validation run and before validating the next document.
194   */ public
195 void clearFailures() {
196    if (getClass() == SBMLValidator.class) libsbmlJNI.SBMLValidator_clearFailures(swigCPtr, this); else libsbmlJNI.SBMLValidator_clearFailuresSwigExplicitSBMLValidator(swigCPtr, this);
197  }
198
199  
200/**
201   * Adds the given failure to this list of Validators failures.
202   <p>
203   * @param err an {@link SBMLError} object representing an error or warning
204   */ public
205 void logFailure(SBMLError err) {
206    libsbmlJNI.SBMLValidator_logFailure(swigCPtr, this, SBMLError.getCPtr(err), err);
207  }
208
209  
210/**
211   * Validates the given {@link SBMLDocument} object.
212   <p>
213   * This is identical to calling setDocument(SBMLDocument )
214   * followed by validate().
215   <p>
216   * @param d the SBML document to validate
217   <p>
218   * @return the number of validation failures that occurred.  The objects
219   * describing the actual failures can be retrieved using getFailures().
220   */ public
221 long validate(SBMLDocument d) {
222    return libsbmlJNI.SBMLValidator_validate__SWIG_1(swigCPtr, this, SBMLDocument.getCPtr(d), d);
223  }
224
225  
226/**
227   * Validates the SBML document located at the given <code>filename</code>.
228   <p>
229   * This is a convenience method that saves callers the trouble of
230   * using {@link SBMLReader} to read the document first.
231   <p>
232   * @param filename the path to the file to be read and validated.
233   <p>
234   * @return the number of validation failures that occurred.  The objects
235   * describing the actual failures can be retrieved using getFailures().
236   */ public
237 long validate(String filename) {
238    return libsbmlJNI.SBMLValidator_validate__SWIG_2(swigCPtr, this, libsbml.getAbsolutePath(filename));
239  }
240
241  
242/**
243   * Returns the list of errors or warnings logged during parsing,
244   * consistency checking, or attempted translation of this model.
245   <p>
246   * Note that this refers to the {@link SBMLDocument} object's error log (i.e.,
247   * the list returned by {@link SBMLDocument#getErrorLog()}).  <em>That</em> list of
248   * errors and warnings is <em>separate</em> from the validation failures
249   * tracked by this validator (i.e., the list returned by getFailures()).
250   <p>
251   * @return the {@link SBMLErrorLog} used for the {@link SBMLDocument}
252   */ public
253 SBMLErrorLog getErrorLog() {
254    long cPtr = libsbmlJNI.SBMLValidator_getErrorLog(swigCPtr, this);
255    return (cPtr == 0) ? null : new SBMLErrorLog(cPtr, false);
256  }
257
258  
259/**
260   * Returns the {@link Model} object stored in the {@link SBMLDocument}.
261   <p>
262   * It is important to note that this method <em>does not create</em> a
263   * {@link Model} instance.  The model in the {@link SBMLDocument} must have been created
264   * at some prior time, for example using {@link SBMLDocument#createModel()} 
265   * or {@link SBMLDocument#setModel(Model)}.
266   * This method returns <code>null</code> if a model does not yet exist.
267   <p>
268   * @return the {@link Model} contained in this validator's {@link SBMLDocument} object.
269   <p>
270   * @see SBMLDocument#setModel(Model)
271   * @see SBMLDocument#createModel()
272   */ public
273 Model getModel() {
274    long cPtr = libsbmlJNI.SBMLValidator_getModel__SWIG_0(swigCPtr, this);
275    return (cPtr == 0) ? null : new Model(cPtr, false);
276  }
277
278  
279/** 
280   * Returns the number of failures encountered in the last validation run.
281   <p>
282   * This method returns the number of failures logged by this validator.
283   * This number only reflects <em>this</em> validator's actions; the number may
284   * not be the same as the number of errors and warnings logged on the
285   * {@link SBMLDocument} object's error log (i.e., the object returned by
286   * {@link SBMLDocument#getErrorLog()}), because other parts of libSBML may log
287   * errors and warnings beyond those found by this validator.
288   <p>
289   * @return the number of errors logged by this validator. 
290   */ public
291 long getNumFailures() {
292    return libsbmlJNI.SBMLValidator_getNumFailures(swigCPtr, this);
293  }
294
295  
296/** 
297   * Returns the failure object at index n in this validator's list of
298   * failures logged during the last run.
299   <p>
300   * Callers should use getNumFailures() first, to find out the number
301   * of entries in this validator's list of failures.
302   <p>
303   * @param n an integer indicating the index of the object to return from
304   * the failures list; index values start at 0.
305   <p>
306   * @return the failure at the given index number.
307   <p>
308   * @see #getNumFailures()
309   */ public
310 SBMLError getFailure(long n) {
311    long cPtr = libsbmlJNI.SBMLValidator_getFailure(swigCPtr, this, n);
312    return (cPtr == 0) ? null : new SBMLError(cPtr, false);
313  }
314
315}