[kepler-users] kepler parameters
Christopher Brooks
cxh at eecs.berkeley.edu
Mon Oct 24 23:31:23 PDT 2011
Hi Kianwee,
I found a message that I sent that sums up the issue, see below.
So yes, this is a bug, but fixing it would break backward compatibility
with ptolemy.util.FileUtilities.nameToFile().
I've attached your classpath.xml as well.
_Christopher
> I took a further look at FileParameter and why we sometimes
> see xxxxxCLASSPATHxxxx
>
>
> If I have a FileParameter that starts with $CLASSPATH,
> then both stringValue() and asFile() will return a String
> or a File that has xxxxxxCLASSPATHxxxxx in it:
>
> bash-3.2$ $PTII/bin/ptjacl
> % set myEntity [java::new {ptolemy.kernel.Entity String} myEntity]
> java0x1
> % set myFileParameter [java::new ptolemy.data.expr.FileParameter $myEntity myFileParameter]
> java0x2
> % $myFileParameter setExpression {$CLASSPATH/makefile}
> % $myFileParameter stringValue
> xxxxxxCLASSPATHxxxxxx/makefile
> % set f [$myFileParameter asFile]
> java0x3
> % $f toString
> xxxxxxCLASSPATHxxxxxx/makefile
>
> However, getting the FileParameter as a URL works:
> % set url [$myFileParameter asURL]
> java0x4
> % $url toString
> file:/Users/cxh/ptII/makefile
>
>
> This occurs for the following reasons:
>
> * Constant.java declares $CLASSPATH as a constant with the value
> xxxxxxCLASSPATHxxxxxx, which we later search for in FileUtilities.
>
> * FileParameter.asFile() calls FileUtilities.nameToFile()
>
> * FileParameter.asURL() calls FileUtilities.nameToURL()
>
> * The difference between FileUtilities.nameToFile() and nameToURL()
> is documented in nameToFile as:
>
> *<p>This method is similar to
> * {@link #nameToURL(String, URI, ClassLoader)}
> * except that in this method, the file or URL must be readable.
> * Usually, this method is use for write a file and
> * {@link #nameToURL(String, URI, ClassLoader)} is used for reading.
>
> Also, nameToFile() does not handle CLASSPATH, but nameToURL() does.
>
> One possible solution would be to make nameToFile() look in the CLASSPATH.
> However, in nameToFile(), the name need not necessarily exist. This
> is a documented feature of nameToFile(), and one I don't think we should
> change. The problem is that if we call nameToFile() with something
> that starts with $CLASSPATH that does not exist in the classpath, then
> it is a mistake to call new File() on a String that starts with
> $CLASSPATH because the path of the File will have $CLASSPATH in it,
> which is not likely to work. Instead, I decided to replace $CLASSPATH
> with $PTII, which is more likely to exist (but will have problems
> with Jar URLs).
>
> Anyway, I modified nameToFile() to handle $CLASSPATH. In general,
> I think it is a bug if the user ever sees xxxxxxCLASSPATHxxxxxxx.
>
> This also neatly solves the problem that Michael was having with
> bcvtp and not finding the executable.
On 10/24/11 10:36 PM, kianwee chen wrote:
> I did a file which show xxxxxxCLASSPATHxxxxxxx as a text display. It
> is attached with the email.
>
> ckw
>
> On Tue, Oct 25, 2011 at 11:46 AM, Christopher Brooks
> <cxh at eecs.berkeley.edu <mailto:cxh at eecs.berkeley.edu>> wrote:
>
> Hi Kianwee,
> Usually the classpath is set when the Java process is started up.
> Consult the web for more information about the Java classpath.
> Basically, the classpath is a set of directories, jar files and
> zip files that Java searches to find Java class files and
> resources. I've found that referring to resources using
> $CLASSPATH is necessary when models are delivered as Java Web
> Start applications or as applets. The problem is somewhat
> complex, but has to do with jar urls and caching.
>
> The xxxxxxCLASSPATHxxxxxxx is a hack and should not appear. If
> you send me a model that shows xxxxxxxCLASSPATHxxxxx, I'll take a
> look.
>
> Kepler uses kar files that contain Ptolemy models that are xml
> files. I'm not that familiar with kar files, but I believe you
> could use the jar command to unjar a kar file and then use a file
> editor to edit the .xml file.
> You can also export a .xml file from Kepler and then edit that
> using a file editor and then open the .xml file from within Kepler.
>
> _Christopher
>
>
> On 10/24/11 8:22 PM, kianwee chen wrote:
>> Thanks for the quick reply
>> I often end up using $CLASSPATH, which looks inthe classpath for
>> the resource.
>>
>> I type in the $CLASSPATH and this is what is return "
>> xxxxxxCLASSPATHxxxxxx " is there a way to set the classpath ?
>>
>> For a CompositeActor, you would probably need to edit the MoML by
>> hand and add a Parameter:
>>
>> How do you edit the MoML of a composite actor by hand ? I right
>> click and try all the options but did not get any options that
>> allow me to edit the MoML
>>
>> thanks
>> ckw
>>
>> I typed in the $CLASSPATH and I only get this
>> On Tue, Oct 25, 2011 at 12:46 AM, Christopher Brooks
>> <cxh at eecs.berkeley.edu <mailto:cxh at eecs.berkeley.edu>> wrote:
>>
>> Hi Kianwee,
>> My comments are interspersed with your text below.
>>
>>
>> On 10/24/11 8:39 AM, Edward A. Lee wrote:
>>>
>>> The documentation for FileParameter says:
>>>
>>> "If this attribute contains a parameter named allowFiles
>>> with value false, then when a file browser is used to select
>>> a file, that file browser will be set to not show files
>>> (only directories will be shown). If this attribute contains
>>> a parameter named allowDirectories with value true, then the
>>> file browser will permit the user to select directories (the
>>> default behavior is that when a directory is selected, that
>>> directory is opened and its contained files and directories
>>> are listed)."
>>>
>>> (I'm not sure about Kepler, but in Ptolemy, just drag in a
>>> FileParameter
>>> from the Utilities menu, right click on it, and select
>>> Documentation.)
>>>
>>> I'm not sure what you mean by "list parameter." Can you cite
>>> a specific
>>> example?
>>>
>>> Edward
>>>
>>>
>>> On 10/24/11 3:22 AM, kianwee chen wrote:
>>>> Hi everyone, I am trying to create a composite actor and
>>>> trying to setup
>>>> the parameters for the composite actor. Thus I have some
>>>> question on
>>>> adding parameters in composite actors.
>>>>
>>>> 1.) Directory parameter:
>>>>
>>>> -I would like to let the users specify a directory on the
>>>> composite
>>>> actor parameters interface, I know there is a file
>>>> parameter but I need
>>>> a directory parameter. How can I customise a directory
>>>> parameter ?
>>
>> See Edward's explanation above.
>>
>>>>
>>>> -I have a problem with relative path too, when I setup a
>>>> file parameter
>>>> it returns the string of the path relative to my current
>>>> kepler file
>>>> that is open. Is there a way to get the base file path ?
>>>> Something like
>>>> $CWD, but instead the file path of my currently open file ?
>>
>> The FileParameter documentation says:
>>
>> <p>If the model containing this
>> attribute has been saved to a MoML file, then the file name
>> can be
>> given relative to the directory containing that MoML file.
>> If the model has not been saved to a file,
>> then the classpath is used for identifying relative file
>> names.</p>
>>
>> <p>Files can be given relative to a <i>base</i>, where the
>> baseis
>> the URI of the first container above this one that has a
>> URIAttribute.
>> Normally, this URI specifies the file or URL containing the
>> model
>> definition. Thus, files that are referred to here can be
>> kept in the
>> same directory as the model, or in a related directory, and can
>> moved together with the model.</p>
>>
>> So, if you type in a relative path, then the file should be
>> relative to the model.
>>
>> There is a Ptolemy test at
>> ptolemy/actor/lib/io/test/auto/FileReader.xml
>> that illustrates the various possibilities. If this test is
>> run in the ptolemy/actor/lib/io/test
>> directory, then it will work. If the test is run elsewhere,
>> then the "FileReader Relative to CWD"
>> actor will fail because that actor uses $CWD, which is
>> expected to be ptolemy/actor/lib/io/test
>> in that test.
>>
>> In Java, the value of the user.dir property is the " User's
>> current working directory".
>> However, when a Java program is opened in a graphical
>> windowing system by clicking on
>> a menu choice, then the value of user.dir is not clearly
>> defined. It should probably be
>> the same value as the user's home directory, but I've seen
>> various values.
>> For a FileParameter, the value of $CWD is set to the value of
>> the user.dir property,
>> which is probably not what you want. I often end up using
>> $CLASSPATH, which looks in
>> the classpath for the resource. The file chooser does not
>> have a way to add $CLASSPATH,
>> you have to type it in manually.
>>
>>
>>
>>>>
>>>> 2.) List Parameter:
>>>> - I have seen some actor have List parameters how do I
>>>> customise one for
>>>> my composite actor too ?
>>
>> For atomic actors, the ptolemy/actor/lib/MathFunction.java
>> uses the addChoice() method:
>>
>> // Parameters
>> function = new StringParameter(this, "function");
>> function.setExpression("exp");
>> function.addChoice("exp");
>> function.addChoice("log");
>> function.addChoice("modulo");
>> function.addChoice("sign");
>> function.addChoice("square");
>> function.addChoice("sqrt");
>> _function = _EXP;
>>
>> I believe that addChoice() is defined in ptolemy/gui/Query.java
>>
>> For a CompositeActor, you would probably need to edit the
>> MoML by hand and add a Parameter:
>>
>> <property name="function"
>> class="ptolemy.data.expr.StringParameter" value="square">
>> <property name="style"
>> class="ptolemy.actor.gui.style.ChoiceStyle">
>> <property name="exp"
>> class="ptolemy.kernel.util.StringAttribute" value="exp">
>> </property>
>> <property name="log"
>> class="ptolemy.kernel.util.StringAttribute" value="log">
>> </property>
>> <property name="modulo"
>> class="ptolemy.kernel.util.StringAttribute" value="modulo">
>> </property>
>> <property name="sign"
>> class="ptolemy.kernel.util.StringAttribute" value="sign">
>> </property>
>> <property name="square"
>> class="ptolemy.kernel.util.StringAttribute" value="square">
>> </property>
>> <property name="sqrt"
>> class="ptolemy.kernel.util.StringAttribute" value="sqrt">
>> </property>
>> </property>
>> </property>
>>
>> _Christopher
>>
>>>>
>>>> Thanks alot !!
>>>> ckw
>>>>
>>>>
>>>> _______________________________________________
>>>> Kepler-users mailing list
>>>> Kepler-users at kepler-project.org
>>>> <mailto:Kepler-users at kepler-project.org>
>>>> http://lists.nceas.ucsb.edu/kepler/mailman/listinfo/kepler-users
>>>>
>>>
>>>
>>> _______________________________________________
>>> Kepler-users mailing list
>>> Kepler-users at kepler-project.org <mailto:Kepler-users at kepler-project.org>
>>> http://lists.nceas.ucsb.edu/kepler/mailman/listinfo/kepler-users
>>
>> --
>> 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 <tel:510.643.9841> (Office: 545Q Cory)
>> home: (F-Tu)707.665.0131 <tel:707.665.0131> cell:707.332.0670 <tel: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 <tel:510.643.9841> (Office: 545Q Cory)
> home: (F-Tu)707.665.0131 <tel:707.665.0131> cell:707.332.0670 <tel: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 (Office: 545Q Cory)
home: (F-Tu) 707.665.0131 cell: 707.332.0670
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nceas.ucsb.edu/kepler/pipermail/kepler-users/attachments/20111024/37008a9a/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: classpath.xml
Type: text/xml
Size: 27056 bytes
Desc: not available
URL: <http://lists.nceas.ucsb.edu/kepler/pipermail/kepler-users/attachments/20111024/37008a9a/attachment.xml>
More information about the Kepler-users
mailing list