use of net.sourceforge.usbdm.deviceEditor.validators.Validator in project usbdm-eclipse-plugins by podonoghue.
the class ParseMenuXML method parseMenuFile.
/**
* Parses document from top element
*
* @param name Name of file
* @param variableProvider Provides the variables. New variables will be added to this provider
* @param peripheral Peripheral associated with this document (if any)
*
* @return Data from model
*
* Looks for the file in the following locations in order:
* <li>Relative path : Stationery/Packages/180.ARM_Peripherals/Hardware/peripherals
* <li>Relative path : "USBDM Resource Path"/Stationery/Packages/180.ARM_Peripherals/Hardware/peripherals
*/
public static MenuData parseMenuFile(String name, VariableProvider variableProvider) throws Exception {
fName = name;
MenuData fData;
try {
// For debug try local directory
Path path = locateFile(name + ".xml");
fData = parse(XML_BaseParser.parseXmlFile(path), variableProvider, null);
} catch (Exception e) {
throw new Exception("Failed to parse " + name + ".xml", e);
}
for (ParseMenuXML.ValidatorInformation v : fData.getValidators()) {
try {
// Get validator class
Class<?> clazz = Class.forName(v.getClassName());
Constructor<?> constructor = clazz.getConstructor(PeripheralWithState.class, v.getParams().getClass());
Validator validator = (Validator) constructor.newInstance(variableProvider, v.getParams());
variableProvider.addValidator(validator);
} catch (Exception e) {
throw new Exception("Failed to add validator " + v.getClassName() + " for VariableProvider " + variableProvider.getName(), e);
}
}
return fData;
}
use of net.sourceforge.usbdm.deviceEditor.validators.Validator in project usbdm-eclipse-plugins by podonoghue.
the class DeviceInfo method loadSettings.
/**
* Load persistent settings
*/
public void loadSettings(Settings settings) {
try {
String variantName = settings.get(USBDMPROJECT_VARIANT_SETTING_KEY);
setVariantName(variantName);
Path path = locateFile("/peripherals/symbols/" + variantName + ".xml");
if (path != null) {
settings.load(path);
}
String subFamilyName = settings.get(USBDMPROJECT_SUBFAMILY_SETTING_KEY);
if (subFamilyName == null) {
subFamilyName = settings.get(USBDMPROJECT_OLD_SUBFAMILY_SETTING_KEY);
}
setDeviceSubFamily(subFamilyName);
for (String pinName : fPins.keySet()) {
Pin pin = fPins.get(pinName);
pin.loadSettings(settings);
}
for (String peripheralName : fPeripheralsMap.keySet()) {
Peripheral peripheral = fPeripheralsMap.get(peripheralName);
peripheral.loadSettings(settings);
}
for (String key : settings.getKeys()) {
Variable var = fVariables.get(key);
String value = settings.get(key);
if (var != null) {
if (!var.isDerived()) {
// Load persistent value associated with variable
var.setPersistentValue(value);
// System.err.println("Setting Variable "+key+" to "+value);
}
} else if (key.startsWith("$")) {
// Ignore these as loaded earlier
// System.err.println("WARNING: Discarding system setting "+key+" to "+value);
} else if (key.startsWith("/")) {
// Shouldn't be any unmatched peripheral settings
System.err.println("WARNING: Discarding unmatched peripheral settings " + key + "(" + value + ")");
} else {
// Load persistent value (parameter)
// System.err.println("Creating Variable "+key+"("+value+")");
var = new StringVariable(key, key);
var.setPersistentValue(value);
var.setDerived(true);
addVariable(key, var);
}
}
// Create dependencies between peripherals
for (Entry<String, Peripheral> entry : fPeripheralsMap.entrySet()) {
Peripheral peripheral = entry.getValue();
ArrayList<Validator> validators = peripheral.getValidators();
for (Validator validator : validators) {
// validator.createDependencies();
validator.addDependencies();
}
}
// System.err.println("Make sure peripherals have been updated");
/*
* Make sure critical peripherals have been updated in order first
*/
String[] criticalPeripherals = { "RTC", "OSC", "OSC0", "OSC_RF0", "MCG", "SIM" };
for (String name : criticalPeripherals) {
Peripheral peripheral = fPeripheralsMap.get(name);
if (peripheral instanceof PeripheralWithState) {
((PeripheralWithState) peripheral).variableChanged(null);
}
}
for (Entry<String, Peripheral> entry : fPeripheralsMap.entrySet()) {
Peripheral peripheral = entry.getValue();
if (peripheral instanceof PeripheralWithState) {
((PeripheralWithState) peripheral).variableChanged(null);
}
}
/*
* Notify changes of persistent variables,
* even on variables that were not loaded
* Shouldn't be necessary
*/
for (Entry<String, Variable> entry : fVariables.entrySet()) {
Variable var = entry.getValue();
if (!var.isDerived()) {
var.notifyListeners();
}
}
/**
* Sanity check - (usually) no persistent variables should change value initially
*/
for (Entry<String, Variable> entry : fVariables.entrySet()) {
String value = settings.get(entry.getKey());
if (value != null) {
Variable var = fVariables.get(entry.getKey());
if (!var.isDerived()) {
if (!var.getPersistentValue().equals(value)) {
System.err.println("WARNING: deviceEditor.information.DeviceInfo.loadSettings - Variable changed " + var.getName());
System.err.println("Current value = " + value);
System.err.println("Persistent value = " + var.getPersistentValue());
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
setDirty(false);
}
Aggregations