use of com.cburch.logisim.tools.Library in project logisim-evolution by reds-heig.
the class XmlCircuitReader method getComponent.
/**
* Get a circuit's component from a read XML file. If the component has a
* non-null "trackercomp" field, it means that it is tracked, therefore it
* is skipped in the non-tracked version to avoid errors.
*
* @param elt
* XML element to parse
* @param reader
* XML file reader
* @return the component built from its XML description
* @throws XmlReaderException
*/
static Component getComponent(Element elt, XmlReader.ReadContext reader) throws XmlReaderException {
if (elt.getAttribute("trackercomp") != "" && !Main.VERSION.hasTracker()) {
return (null);
}
// Determine the factory that creates this element
String name = elt.getAttribute("name");
if (name == null || name.equals("")) {
throw new XmlReaderException(Strings.get("compNameMissingError"));
}
String libName = elt.getAttribute("lib");
Library lib = reader.findLibrary(libName);
if (lib == null) {
throw new XmlReaderException(Strings.get("compUnknownError", "no-lib"));
}
Tool tool = lib.getTool(name);
if (tool == null || !(tool instanceof AddTool)) {
if (libName == null || libName.equals("")) {
throw new XmlReaderException(Strings.get("compUnknownError", name));
} else {
throw new XmlReaderException(Strings.get("compAbsentError", name, libName));
}
}
ComponentFactory source = ((AddTool) tool).getFactory();
// Determine attributes
String loc_str = elt.getAttribute("loc");
AttributeSet attrs = source.createAttributeSet();
reader.initAttributeSet(elt, attrs, source);
// Create component if location known
if (loc_str == null || loc_str.equals("")) {
throw new XmlReaderException(Strings.get("compLocMissingError", source.getName()));
} else {
try {
Location loc = Location.parse(loc_str);
return source.createComponent(loc, attrs);
} catch (NumberFormatException e) {
throw new XmlReaderException(Strings.get("compLocInvalidError", source.getName(), loc_str));
}
}
}
Aggregations