Andrew,

The expression language does not have any bindings for xml tokens, unfortunately.... It probably should have at least a function that takes a StringToken and returns an XMLToken.

There are several possible immediate solutions:
1) In vergil, use the expression "<modifiers/>" (with the double quotes) that will generate a StringToken.
In java code, this is equivalent to setExpression("\"<modifiers/>\"");


2) Change the Parameter to a StringParameter. A String parameter has a different interpretation for expressions: from your point of view it makes the double quotes implicit. A variable named v can be referred to as $v with explicit string concatenation. In vergil, you would then use the expression <modifier/> (with no double quotes) and in java code, you would say setExpression("<modifier/>"); The down side of this is if you have a string that contains a dollar sign, you have to escape the dollar sign.

3) Change the Parameter to a StringAttribute, which is an uninterpreted string... This avoids the nastiness of explicit quotes and escaping dollar signs, but makes it impossible to refer to the value of other parameters symbolically.

Note that in each of these cases, when the expression is saved to XML, it must be be appropriately escaped (as you seem to be aware) using &lt;... This is done automatically by the routines that save your model as an XML file and is transparent from the point of view of Java or the user interface.

Steve

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]



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

Reply via email to