[kepler-dev] Actor's class name?

Christopher Brooks cxh at eecs.berkeley.edu
Mon Nov 17 10:35:58 PST 2014


Hi Donghoon,

In Java, the fully qualified classname must be unique.  There is some 
magic that can be done with different class loaders and such, but in 
general, and in Kepler and Ptolemy, the fully qualified classname will 
be unique.  The fully qualified classname includes the package,  So, 
ptolemy.actor.lib.StringConstant is one actor. There can be another 
actor, ptolemy.actor.lib.mypackage.StringConstant.  Both actors could be 
used in a model.

Note that Kepler has actor oriented classes (see 
http://ptolemy.eecs.berkeley.edu/publications/papers/07/classesandInheritance/index.htm). 
The quick summary of actor oriented classes is that they are chunks of 
functionality implemented as Ptolemy models that can be reused by 
instantiation or subclassing.  The Sinewave actor is an actor-oriented 
class.  When you are calling parameter.getContainer().getClassName(), 
you are getting the className which may or may not be the same as the 
Java class name.

Probably the method that is being called is in 
ptolemy/kernel/util/NamedObj.java:
>    /** Return the MoML class name.  This is either the
>      *  class of which this object is an instance, or if this
>      *  object is itself a class, then the class that it extends.
>      *  By default, it will be the Java class name of this object.
>      *  This method never returns null.
>      *  @return The MoML class name.
>      *  @see MoMLExportable
>      *  @see #setClassName(String)
>      */
>     @Override
>     public String getClassName() {
>     if (_className == null) {
>             _className = getClass().getName();
>         }
>
>         return _className;
>     }

_className is set when instantiating clones for actor-oriented classes.


To get the last part of the fully qualified classname, see the 
lastIndexOf() method in the java.lang.String class: 
https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#lastIndexOf-int-

However, I think you just want to call NamedObj.getName(): 
parameter.getContainer().getName() should do the trick.

_Christopher

On 11/17/14 9:47 AM, DONGHOON KIM wrote:
> Dear Kepler folks,
>
> In ActorReference.pdf file, there are explanations of each actors.  I 
> have questions for this reference.
>
>   * I can see the class name next to an actor. For example, String
>     Constant (ptolemy.actor.lib.StringConst). The class name must be
>     unique (i.e., ptolemy.actor.lib.StringConst). If so, is the last
>     classname unique? In other words, "StringConst" is also unique?
>   * I can see the value of "StringConst" in _container in parameter
>     class. How can I just extract only last name "StringConst"?
>     Actually, I have tried several ways in SQLRecording.java like below:
>       o  System.out.println("3: " +
>         parameter.getContainer().toplevel().toString());
>       o  System.out.println("4: " +
>         parameter.getContainer().getClassName());
>       o  System.out.println("5: " + parameter.getContainer());
>
>     The output is :
>
>       o 3: ptolemy.actor.TypedCompositeActor {.Unnamed1}
>       o 4: ptolemy.actor.lib.StringConst
>       o 5: ptolemy.actor.lib.StringConst {.Unnamed1.DonghoonConstant}
>
> Please, let me know
>
> Thank you
>
> -Donghoon
>
>
> -- 
> Donghoon Kim
> Dept of Computer Science
> North Carolina State University
>
>
>
>
> _______________________________________________
> Kepler-dev mailing list
> Kepler-dev at kepler-project.org
> http://lists.nceas.ucsb.edu/kepler/mailman/listinfo/kepler-dev


-- 
Christopher Brooks, PMP                       University of California
Academic Program Manager & Software Engineer  US Mail: 337 Cory Hall
CHESS/iCyPhy/Ptolemy/TerraSwarm               Berkeley, CA 94720-1774
cxh at eecs.berkeley.edu, 707.332.0670           (Office: 545Q Cory)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nceas.ucsb.edu/kepler/pipermail/kepler-dev/attachments/20141117/78d0ea05/attachment.html>


More information about the Kepler-dev mailing list