(I guess this response overlaps somewhat with Steve's...)


I haven't tried myself using the XML token type in parameters, so
I've cc'd Yang Zhao, who created it... She can probably explain
to to create parameters with XML values. But there are a few things
that strike me as odd here.

Parameter values are expressions, so at a minimum, your XML needs to be
a string:

pModifiers.setExpression("\"<modifiers/>\"");

But even then, it will evaluate to a string, not an XML token.
I would think we would need a function to parse this to an XML token,
something like:

pModifiers.setExpression("parseXML(\"<modifiers/>\")");

However, it's not clear to me at all why this should be an instance
of Parameter.  The Parameter class is about hooking into the expression
language, and being able to write expressions in terms of other parameters.
At a minimum, I would think that StringParameter would make more sense.
A still better choice would be to subclass StringParameter to create
an XMLParameter.  This would always deliver a value that is an XMLToken.
Then you could do something like:

                pModifiers = new XMLParameter(this, "modifiers");
                pModifiers.setExpression("<modifiers value=\"$foo\"/>");

where "foo" is some other parameter (of arbitrary type) anywhere in
scope in the model.

A third alternative would be to create a subclass of ConfigurableAttribute
that supported XML, but this would probably be harder to tie into
the expression language as above...

Edward

At 01:40 PM 4/14/2004 -0700, Zimdars, Andrew wrote:
I'm trying to construct a container that takes an XML fragment as a parameter value. I've tried two approaches to this, and both result in exceptions (possibly due to limitations in the Microstar XML parser, or laxity in my attempt to use XML).

If I use

public MyChannel extends WirelessChannel {

        // ...
        public Parameter pModifiers;
        // ...

        public MyContainer(CompositeEntity container, String name)
        throws IllegalActionException {
                super(container, name);
                // ...
                pModifiers = new Parameter(this, "modifiers");
                pModifiers.setExpression("<modifiers/>");
                pModifiers.setTypeEquals(BaseType.XMLTOKEN);
        }

public void attributeChanged(Attribute attribute)
throws IllegalActionException {
if (attribute == pModifiers);
Document doc;
try {
doc = ((XMLToken) pModifiers.getToken()).getDomTree();
}
catch (Exception e) {
// Results in exception here;
// the parser gets confused when it hits the first "<"
}
}
}


then an exception occurs while building the Vergil palette that contains my entity: the AElfred parser tries to interpret the value of the parameter with name "modifiers" and gets confused, because "<" isn't a valid token in an XML attribute. (The same thing happens if I set the type of pModifiers to BaseType.STRING and attempt to parse it on my own.) However, if I use

public MyChannel extends WirelessChannel {

        // ...
        public Parameter pModifiers;
        // ...

        public MyContainer(CompositeEntity container, String name)
        throws IllegalActionException {
                super(container, name);
                // ...
                pModifiers = new Parameter(this, "modifiers");
                pModifiers.setToken(new XMLToken("<modifiers/>"));
                pModifiers.setTypeEquals(BaseType.XMLTOKEN);
        }

public void attributeChanged(Attribute attribute)
throws IllegalActionException {
if (attribute == pModifiers);
Document doc;
try {
doc = ((XMLToken) pModifiers.getToken()).getDomTree();
}
catch (Exception e) {
// Results in exception here;
// the parser gets confused when it hits the first "<"
}
}
}


then Vergil startup goes okay, but I get an XML parsing exception when I try to update the "modifiers" parameter (say, from "<modifiers/> to "<modifiers></modifiers>", which should be semantically equivalent).

Is it possible to include an XML expression as a mutable part of an entity's configuration, just as string or record parameters are mutable? (Keep in mind that the XML expression isn't MoML.) I'd be happy to treat the expression as a plain string and do the parsing myself, but replacing all of the tag delimiters with escape sequences (e.g. &lt; or &gt;) would be inconvenient.

Thanks,

Andy Z.

-----
Andrew Zimdars
Modeling, Simulation, and Information Sciences (Org. ABCS)
Advanced Technology Center, Lockheed Martin Space Systems Co.
Bldg. 153, Col. 2J4
1111 Lockheed Martin Way, Sunnyvale, CA  94089

w: 408.742.2111 m: 510.915.0662

----------------------------------------------------------------------------
Posted to the ptolemy-hackers mailing list.  Please send administrative
mail for this list to: [EMAIL PROTECTED]

------------ Edward A. Lee, Professor 518 Cory Hall, UC Berkeley, Berkeley, CA 94720 phone: 510-642-0455, fax: 510-642-2739 [EMAIL PROTECTED], http://ptolemy.eecs.berkeley.edu/~eal


---------------------------------------------------------------------------- Posted to the ptolemy-hackers mailing list. Please send administrative mail for this list to: [EMAIL PROTECTED]

Reply via email to