[kepler-dev] Instatiating an Actor in Java

Christopher Brooks cxh at eecs.berkeley.edu
Mon May 10 18:31:27 PDT 2010


Hi Ivens,
I just update the Ptolemy II faq, see:
http://ptolemy.eecs.berkeley.edu/ptolemyII/ptIIfaq.htm#MoML
--start--
Ptolemy II stores models in an XML format called MoML. The design doc covers MoML in detail.

The beauty of using a human readable (though verbose) file format is that we can use standard tools like XSLT and sed to transform models.

The MoML dtd may be found at http://ptolemy.eecs.berkeley.edu/xml/dtd/MoML_1.dtd

MoML files can have <configure> ... <configure> tags in them that are not part of the dtd and thus a validating parser may fail. One workaround is to remove the configure tags with a script before 
validating, see $PTII/ptolemy/moml/test/removeconfigure.

To remove location information from a model, see ptolemy/moml/filter/RemoveGraphicalClasses.java.

MoML files do not contain information about port direction and such. This is intentional because the actors are defined elsewhere in Java or in other MoML files. These definitions may be overridden 
The easiest way to get all the information from a model is to parse the xml file and then traverse the model in Java and write out information of interest. For example, see the 
ptolemy.kernel.CompositeEntity.deepEntityList() and ptolemy.kernel.CompositeEntity.exportMoML() methods. There may be some code at 
https://code.kepler-project.org/code/kepler/trunk/modules/moml2graphviz/ that is of interest.

In addition, MoML is registered as a MIME type, see http://www.iana.org/assignments/media-types/model/vnd.moml+xml
---end---

When asked about this awhile back, Edward wrote:
> The principle followed in exporting a MoML file is that
> actors are instances of a class defined elsewhere. If the
> class defines ports to be input or output ports, then the
> MoML file does not mention those ports.
>
> This is the same principle followed in object-oriented
> software. When you create an instance of a class, you say
>
>   x = new ClassName();
>
> not
>
>   x = new ClassName() {
>      public void foo();
>      public int bar(int arg);
>      ...
>   }
>
> In creating the instance, you don't repeat properties
> of the class.
>
> That said, it would not be hard to export tool that would
> produce either DIF or dotfile representations of a model.
> But there is not enough information in a MoML file alone
> to do that. You also have to have the class definitions
> that the MoML file refers to.  Those may be other MoML files,
> or, more commonly, Java files.
>
> The easiest way to do the export, therefore, would be to
> use Ptolemy II to parse the model, then, in Java code,
> traverse the model and export the requisite format.
>
> Edward

_Christopher


On 5/10/10 5:52 PM, Ivens wrote:
> Hi Christopher,
>
> The XML file generated by Kepler to represent an workflow does not have all information about the actors used in that workflow. For example: ports.
> I would like to understand how kepler get this information.
> Is there a document that I can read?
>
> Thanks.
>
> On Sun, May 9, 2010 at 12:15 AM, Christopher Brooks <cxh at eecs.berkeley.edu <mailto:cxh at eecs.berkeley.edu>> wrote:
>
>     Hi Ivens,
>     Have a look at how the Kepler build system invokes a model.
>     See
>     https://kepler-project.org/developers/reference/executing-kepler-from-the-command-line
>
>     Ptolemy models can be invoked using
>     ptolemy/moml/MoMLSimpleApplication.java
>
>     Typically one does something like:
>     MoMLParser parser = new MoMLParser();
>     CompositeActor toplevel = (CompositeActor) parser.parseFile("Foo.xml");
>
>     _Christopher
>
>     On 5/8/10 5:20 PM, Ivens wrote:
>
>         Hello everybody,
>
>         I have a Java method called "myMethod".
>         The objective of this method is to instantiate the class of every actor presented in a kepler's workflow.
>
>         anActor = new ?();
>
>         My source of information about the workflow is the XML file that representates it.
>         I can retrieve the class of the actors and give it to the method as a parameter, but I don't know how I would write the code above.
>
>         Can someone help me?
>
>         Thanks,
>         Ivens
>
>
>
>         _______________________________________________
>         Kepler-dev mailing list
>         Kepler-dev at kepler-project.org <mailto:Kepler-dev at kepler-project.org>
>         http://mercury.nceas.ucsb.edu/kepler/mailman/listinfo/kepler-dev
>
>
>     --
>     Christopher Brooks, PMP                       University of California
>     CHESS Executive Director                      US Mail: 337 Cory Hall
>     Programmer/Analyst CHESS/Ptolemy/Trust        Berkeley, CA 94720-1774
>     ph: 510.643.9841 fax:510.642.2718             (Office: 545Q Cory)
>     home: (F-Tu) 707.665.0131 cell: 707.332.0670
>
>

-- 
Christopher Brooks, PMP                       University of California
CHESS Executive Director                      US Mail: 337 Cory Hall
Programmer/Analyst CHESS/Ptolemy/Trust        Berkeley, CA 94720-1774
ph: 510.643.9841 fax:510.642.2718	      (Office: 545Q Cory)
home: (F-Tu) 707.665.0131 cell: 707.332.0670


More information about the Kepler-dev mailing list