use of cbit.util.xml.JDOMTreeWalker in project vcell by virtualcell.
the class CellQuanVCTranslator method isTimeVar.
private boolean isTimeVar(String varName) {
boolean flag = false;
JDOMTreeWalker walker = new JDOMTreeWalker(sRoot, new ElementFilter(MathMLTags.BVAR));
while (walker.hasNext()) {
Element bvar = (Element) walker.next();
String timeVar = bvar.getChildText(MathMLTags.IDENTIFIER, mathns);
if (varName.trim().equals(timeVar.trim())) {
flag = true;
break;
}
}
return flag;
}
use of cbit.util.xml.JDOMTreeWalker in project vcell by virtualcell.
the class CellQuanVCTranslator method addVarsAndConns.
// add all the components and variables to the name manager, and resolve all connections
protected void addVarsAndConns() {
JDOMTreeWalker walker = new JDOMTreeWalker(sRoot, new ElementFilter(CELLMLTags.VARIABLE));
Element temp;
String firstKey, secondKey;
while (walker.hasNext()) {
temp = (Element) walker.next();
firstKey = ((Element) temp.getParent()).getAttributeValue(CELLMLTags.name, sAttNamespace);
secondKey = temp.getAttributeValue(CELLMLTags.name, sAttNamespace);
nm.add(firstKey, secondKey);
}
walker = new JDOMTreeWalker(sRoot, new ElementFilter(CELLMLTags.CONNECTION));
Element mapComp, mapVar;
String comp1, comp2, var1, var2;
boolean flag;
while (walker.hasNext()) {
temp = (Element) walker.next();
Vector<String> vars1_vect = new Vector<String>();
Vector<String> vars2_vect = new Vector<String>();
mapComp = temp.getChild(CELLMLTags.MAP_COMP, sNamespace);
comp1 = mapComp.getAttributeValue(CELLMLTags.comp1, sAttNamespace);
comp2 = mapComp.getAttributeValue(CELLMLTags.comp2, sAttNamespace);
@SuppressWarnings("unchecked") Iterator<Element> i = temp.getChildren(CELLMLTags.MAP_VAR, sNamespace).iterator();
while (i.hasNext()) {
mapVar = i.next();
var1 = mapVar.getAttributeValue(CELLMLTags.var1, sAttNamespace);
var2 = mapVar.getAttributeValue(CELLMLTags.var2, sAttNamespace);
flag = isVisible(comp1, var1);
boolean connected;
if (flag) {
// component1/variable1 is the "output" variable so connect component2/variable2 to it
connected = nm.connect(comp2, var2, comp1, var1);
} else {
// connect to component2/variable2 if its the output
flag = isVisible(comp2, var2);
if (flag) {
connected = nm.connect(comp1, var1, comp2, var2);
} else {
// or allow connections to remain chained (in case the model defines groups)
flag = isMiddleComp(comp1, var1);
if (flag) {
connected = nm.connect(comp2, var2, comp1, var1);
} else {
connected = nm.connect(comp1, var1, comp2, var2);
}
}
}
if (!connected) {
System.err.println("Error: Unable to connect variables: " + comp1 + " " + var1 + ", " + comp2 + " " + var2);
} else {
// they are connected; add vars to vars_vectors
vars1_vect.add(var1);
vars2_vect.add(var2);
}
}
CellmlConnection newConnection = new CellmlConnection(comp1, comp2, vars1_vect, vars2_vect);
connectionsVector.add(newConnection);
}
nm.generateMangledNames();
}
use of cbit.util.xml.JDOMTreeWalker in project vcell by virtualcell.
the class CellQuanVCTranslator method getInitial.
private String getInitial(Element comp, String variableName) {
String initial = "0.0";
Element temp;
JDOMTreeWalker walker = new JDOMTreeWalker(comp, new ElementFilter(CELLMLTags.VARIABLE));
temp = walker.getMatchingElement(CELLMLTags.name, sAttNamespace, variableName);
if (temp != null) {
initial = temp.getAttributeValue(CELLMLTags.initial_value, sAttNamespace);
if (initial == null || initial.length() == 0)
initial = "0.0";
}
return initial;
}
use of cbit.util.xml.JDOMTreeWalker in project vcell by virtualcell.
the class CellQuanVCTranslator method isMiddleComp.
private boolean isMiddleComp(String comp, String var) {
boolean flag = false;
String 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) {
privateInterface = matchingVar.getAttributeValue(CELLMLTags.private_interface, sAttNamespace);
if (CELLMLTags.outInterface.equals(privateInterface))
flag = true;
}
}
return flag;
}
use of cbit.util.xml.JDOMTreeWalker in project vcell by virtualcell.
the class CellQuanVCTranslator method getMatchingVarRef.
private Element getMatchingVarRef(Element comp, String varName) {
JDOMTreeWalker walker = new JDOMTreeWalker(comp, new ElementFilter(CELLMLTags.ROLE));
Element temp = walker.getMatchingElement(CELLMLTags.delta_variable, sAttNamespace, varName);
if (temp != null) {
return (Element) temp.getParent();
} else {
return null;
}
}
Aggregations