ptolemy.actor.lib.hoc
Class ModelUtilities

java.lang.Object
  extended by ptolemy.actor.lib.hoc.ModelUtilities

public class ModelUtilities
extends java.lang.Object

A collection of utilities for manipulating a Ptolemy model. FIXME: Currently there is only one major operation for invoke the execution of a model. We may add more later.

Since:
Ptolemy II 4.1
Version:
$Id: ModelUtilities.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Yang Zhao
Accepted Rating:
Red (cxh)
Proposed Rating:
Yellow (eal)

Constructor Summary
private ModelUtilities()
          Instances of this class cannot be created.
 
Method Summary
private static RecordToken _getResult(CompositeActor model, java.lang.String[] resultLabels)
          Iterate over the resultLabels and check whether the specified model has Attribute with the same name of a label.
private static void _setAttribute(CompositeActor model, RecordToken args)
          Iterate over the labelSet of the args argument and check whether the specified model has Attribute with the same name of a label.
static RecordToken executeModel(CompositeActor model, RecordToken args, java.lang.String[] resultLabels)
          This method takes model argument which is type of CompositeActor.
static RecordToken executeModel(java.net.URL url, RecordToken args, java.lang.String[] resultLabels)
          This method takes a url specifying the model to be execute.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ModelUtilities

private ModelUtilities()
Instances of this class cannot be created.

Method Detail

executeModel

public static RecordToken executeModel(java.net.URL url,
                                       RecordToken args,
                                       java.lang.String[] resultLabels)
                                throws IllegalActionException
This method takes a url specifying the model to be execute. The args argument is a record token that will be used to set corresponding attributes of the specified model by naming match, (see _setAttribute() method). The results of executing the model is returned back by setting the value of some Attributes. In particular, only Attributes that have name matches the resultLabels are returned. The return result is a RecordToken which has the resultLabels as its field.

Parameters:
url - The Model url.
args - A set of attributes of the specified model.
resultLabels - Labels of the returned result.
Returns:
The execution result.
Throws:
IllegalActionException - If can not parse the url or failed to execute the model.

executeModel

public static RecordToken executeModel(CompositeActor model,
                                       RecordToken args,
                                       java.lang.String[] resultLabels)
                                throws IllegalActionException
This method takes model argument which is type of CompositeActor. The args argument is a record token that will be used to set corresponding attributes of the specified model by naming match, (see _setAttribute() method). The results of executing the model is returned back by setting the value of some Attributes. In particular, only Attributes that have name matches the resultLabels are returned. The return result is a RecordToken which has the resultLabels as its field.

Parameters:
model - The Model.
args - A set of attributes of the specified model.
resultLabels - Labels of the returned result.
Returns:
The execution result.
Throws:
IllegalActionException - If failed to execute the model.

_setAttribute

private static void _setAttribute(CompositeActor model,
                                  RecordToken args)
                           throws IllegalActionException
Iterate over the labelSet of the args argument and check whether the specified model has Attribute with the same name of a label. If so, set the value of the attribute to be the value of that record field.

Throws:
IllegalActionException - If reading the ports or setting the parameters causes it.

_getResult

private static RecordToken _getResult(CompositeActor model,
                                      java.lang.String[] resultLabels)
                               throws IllegalActionException
Iterate over the resultLabels and check whether the specified model has Attribute with the same name of a label. If so, get the value of the attribute and return a record token with labels equal to resultLabels and values equal to the corresponding attribute value.

Parameters:
model - The model executed.
resultLabels - Labels of the returned result.
Returns:
The execution result.
Throws:
IllegalActionException - If reading the ports or setting the parameters causes it.