Search in sources :

Example 6 with JDOMTreeWalker

use of cbit.util.xml.JDOMTreeWalker in project vcell by virtualcell.

the class CellQuanVCTranslator method processMathExp.

// post-process a mathematical expression string to handle the variable mapping
private Expression processMathExp(Element comp, Expression exp) {
    try {
        String[] symbols = exp.getSymbols();
        String mName;
        JDOMTreeWalker walker;
        Element temp;
        if (symbols == null)
            return exp;
        for (int i = 0; i < symbols.length; i++) {
            walker = new JDOMTreeWalker(comp, new ElementFilter(CELLMLTags.VARIABLE));
            temp = walker.getMatchingElement(CELLMLTags.name, sAttNamespace, symbols[i]);
            if (temp != null) {
                mName = nm.getMangledName(comp.getAttributeValue(CELLMLTags.name, sAttNamespace), symbols[i]);
                if (!mName.equals(symbols[i])) {
                    exp = exp.getSubstitutedExpression(new Expression(symbols[i]), new Expression(mName));
                }
            }
            // added for a temporary fix for time:
            if (symbols[i].equals(CELLMLTags.timeVarCell)) {
                exp = exp.getSubstitutedExpression(new Expression(symbols[i]), new Expression(CELLMLTags.timeVar));
            }
        }
    } catch (ExpressionException e) {
        e.printStackTrace();
        return exp;
    }
    return exp;
}
Also used : Expression(cbit.vcell.parser.Expression) Element(org.jdom.Element) ElementFilter(org.jdom.filter.ElementFilter) ExpressionException(cbit.vcell.parser.ExpressionException) JDOMTreeWalker(cbit.util.xml.JDOMTreeWalker)

Example 7 with JDOMTreeWalker

use of cbit.util.xml.JDOMTreeWalker in project vcell by virtualcell.

the class CellQuanVCTranslator method isVisible.

// the absence of the 'optional' interface atts will result in a 'true' return.
private boolean isVisible(String comp, String var) {
    boolean flag = false;
    String publicInterface, privateInterface;
    JDOMTreeWalker walker = new JDOMTreeWalker(sRoot, new ElementFilter(CELLMLTags.COMPONENT));
    Element matchingComp = walker.getMatchingElement(CELLMLTags.name, sAttNamespace, comp);
    if (matchingComp != null) {
        walker = new JDOMTreeWalker(matchingComp, new ElementFilter(CELLMLTags.VARIABLE));
        Element matchingVar = walker.getMatchingElement(CELLMLTags.name, sAttNamespace, var);
        if (matchingVar != null) {
            publicInterface = matchingVar.getAttributeValue(CELLMLTags.public_interface, sAttNamespace);
            if (publicInterface == null)
                publicInterface = "";
            privateInterface = matchingVar.getAttributeValue(CELLMLTags.private_interface, sAttNamespace);
            if (privateInterface == null)
                privateInterface = "";
            if (!publicInterface.equals(CELLMLTags.inInterface) && !privateInterface.equals(CELLMLTags.inInterface))
                flag = true;
        }
    }
    return flag;
}
Also used : ElementFilter(org.jdom.filter.ElementFilter) Element(org.jdom.Element) JDOMTreeWalker(cbit.util.xml.JDOMTreeWalker)

Example 8 with JDOMTreeWalker

use of cbit.util.xml.JDOMTreeWalker in project vcell by virtualcell.

the class CellQuanVCTranslator method addRateFunction.

private Function addRateFunction(Element varRef, String compName, String mangledName) {
    Element role;
    String stoich = null, roleAtt = null;
    // can only imply the delta function if the stoichiometry attribute is present also
    // not sure if there can be more than one, if not, could just pass in the 'role' element itself.
    @SuppressWarnings("unchecked") Iterator<Element> i = varRef.getChildren(CELLMLTags.ROLE, sNamespace).iterator();
    while (i.hasNext()) {
        role = i.next();
        stoich = role.getAttributeValue(CELLMLTags.stoichiometry, sAttNamespace);
        roleAtt = role.getAttributeValue(CELLMLTags.role, sAttNamespace);
        if (stoich != null)
            break;
    }
    if (stoich != null) {
        // Can only imply the function if a variable_ref with a role of "rate" exists
        JDOMTreeWalker reactionWalker = new JDOMTreeWalker((Element) varRef.getParent(), new ElementFilter(CELLMLTags.ROLE));
        Element rateRole = reactionWalker.getMatchingElement(CELLMLTags.role, sAttNamespace, CELLMLTags.rateRole);
        if (rateRole != null) {
            String rateVarName = ((Element) rateRole.getParent()).getAttributeValue(CELLMLTags.variable, sAttNamespace);
            StringBuffer formula = new StringBuffer("(");
            if (roleAtt.equals(CELLMLTags.productRole))
                formula.append("-(");
            formula.append(stoich + "*" + nm.getMangledName(compName, rateVarName));
            if (roleAtt.equals(CELLMLTags.productRole))
                formula.append(")");
            formula.append(")");
            try {
                Domain domain = null;
                return new Function(mangledName, new Expression(formula.toString()), domain);
            // fnsVector.add(function);
            // mathDescription.addVariable(function);
            } catch (Exception e) {
                e.printStackTrace(System.out);
                throw new RuntimeException("Error adding function (" + mangledName + ") to mathDexcription : " + e.getMessage());
            }
        }
    }
    return null;
}
Also used : Function(cbit.vcell.math.Function) Expression(cbit.vcell.parser.Expression) Element(org.jdom.Element) ElementFilter(org.jdom.filter.ElementFilter) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) Domain(cbit.vcell.math.Variable.Domain) ExpressionException(cbit.vcell.parser.ExpressionException) JDOMTreeWalker(cbit.util.xml.JDOMTreeWalker)

Example 9 with JDOMTreeWalker

use of cbit.util.xml.JDOMTreeWalker in project vcell by virtualcell.

the class CellQuanVCTranslator method fixMathMLBug.

// temporary method.
private void fixMathMLBug(Element math) {
    ArrayList<Element> l = new ArrayList<Element>();
    @SuppressWarnings("unchecked") Iterator<Element> walker = new JDOMTreeWalker(math, new ContentFilter(ContentFilter.ELEMENT));
    while (walker.hasNext()) l.add(walker.next());
    Element temp;
    for (int i = 0; i < l.size(); i++) {
        temp = l.get(i);
        if (temp.getName().equals(MathMLTags.CONSTANT)) {
            @SuppressWarnings("unchecked") ArrayList<Attribute> atts = new ArrayList<Attribute>(temp.getAttributes());
            org.jdom.Attribute att;
            for (int j = 0; j < atts.size(); j++) {
                att = atts.get(j);
                temp.removeAttribute(att.getName(), mathns);
            }
            temp.removeNamespaceDeclaration(mathns);
        }
    }
}
Also used : Attribute(org.jdom.Attribute) Element(org.jdom.Element) ArrayList(java.util.ArrayList) Attribute(org.jdom.Attribute) ContentFilter(org.jdom.filter.ContentFilter) JDOMTreeWalker(cbit.util.xml.JDOMTreeWalker)

Example 10 with JDOMTreeWalker

use of cbit.util.xml.JDOMTreeWalker in project vcell by virtualcell.

the class TransFilter method mangleCELLVC.

// mainly mangles the ci element.
private void mangleCELLVC(Element e) {
    JDOMTreeWalker walker;
    Element temp;
    String key, value;
    Iterator<String> i = hash.keySet().iterator();
    while (i.hasNext()) {
        key = i.next();
        value = hash.get(key);
        walker = new JDOMTreeWalker(e, new ElementFilter(MathMLTags.IDENTIFIER, Namespace.getNamespace(Translator.MATHML_NS)));
        while (walker.hasNext()) {
            temp = walker.next();
            // System.out.println(key + " " + value + " " + temp.getName() + " " + temp.getTextTrim());
            if (temp.getTextTrim().equals(key))
                temp.setText(value);
        }
    }
}
Also used : Element(org.jdom.Element) ElementFilter(org.jdom.filter.ElementFilter) JDOMTreeWalker(cbit.util.xml.JDOMTreeWalker)

Aggregations

JDOMTreeWalker (cbit.util.xml.JDOMTreeWalker)10 Element (org.jdom.Element)10 ElementFilter (org.jdom.filter.ElementFilter)9 Expression (cbit.vcell.parser.Expression)2 ExpressionException (cbit.vcell.parser.ExpressionException)2 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)1 Function (cbit.vcell.math.Function)1 Domain (cbit.vcell.math.Variable.Domain)1 ArrayList (java.util.ArrayList)1 Vector (java.util.Vector)1 Attribute (org.jdom.Attribute)1 ContentFilter (org.jdom.filter.ContentFilter)1