use of net.sourceforge.processdash.data.SaveableData in project processdash by dtuma.
the class SizeEstimatingTemplate method renameLegacyDataElements.
private static void renameLegacyDataElements(DataRepository data, String path) {
for (int i = 0; i < ELEMENTS_TO_RENAME.length; i++) {
String legacyName = ELEMENTS_TO_RENAME[i][0];
String newName = ELEMENTS_TO_RENAME[i][1];
String legacyDataName = DataRepository.createDataName(path, legacyName);
String newDataName = DataRepository.createDataName(path, newName);
SaveableData value = data.getValue(legacyDataName);
if (value instanceof DoubleData) {
data.putValue(newDataName, value);
data.restoreDefaultValue(legacyDataName);
}
}
}
use of net.sourceforge.processdash.data.SaveableData in project processdash by dtuma.
the class OpenDocument method findFile.
/** Find a file in the document list.
* @param name the name of the file to find
* @return the XML element corresponding to the named document.
*/
protected Element findFile(String name) throws IOException {
// Look for an inheritable value for the FILE_XML element in the
// data repository.
DataRepository data = getDataRepository();
String pfx = getPrefix();
if (pfx == null)
pfx = "/";
StringBuffer prefix = new StringBuffer(pfx);
ListData list;
Element result = null;
SaveableData val;
for (val = data.getInheritableValue(prefix, FILE_XML_DATANAME); val != null; val = data.getInheritableValue(chop(prefix), FILE_XML_DATANAME)) {
if (val != null && !(val instanceof SimpleData))
val = val.getSimpleValue();
if (val instanceof StringData)
list = ((StringData) val).asList();
else if (val instanceof ListData)
list = (ListData) val;
else
list = null;
if (list != null)
for (int i = 0; i < list.size(); i++) {
String url = (String) list.get(i);
Document docList = getDocumentTree(url);
if (docList != null) {
result = (new FileFinder(name, docList)).file;
if (result != null)
return result;
}
}
if (prefix.length() == 0)
break;
}
return null;
}
use of net.sourceforge.processdash.data.SaveableData in project processdash by dtuma.
the class DataRepository method parseSimpleData.
public Map<String, SimpleData> parseSimpleData(String contents) throws InvalidDatafileFormat {
Map<String, Object> rawData = new HashMap();
try {
loadDatafile(null, new StringReader(contents), rawData, DO_NOT_FOLLOW_INCLUDES, DO_CLOSE);
} catch (InvalidDatafileFormat idf) {
throw idf;
} catch (Exception e) {
return Collections.EMPTY_MAP;
}
Map<String, SimpleData> result = new HashMap();
for (Entry<String, Object> e : rawData.entrySet()) {
SaveableData sd = instantiateValue(e.getKey(), "", e.getValue(), false);
if (sd == null || sd instanceof SimpleData)
result.put(e.getKey(), (SimpleData) sd);
}
return result;
}
use of net.sourceforge.processdash.data.SaveableData in project processdash by dtuma.
the class DataRepository method restoreDefaultValue.
public void restoreDefaultValue(String name) {
DataElement d = (DataElement) data.get(name);
if (d == null)
// lazy default value.
return;
Object defaultValue = lookupDefaultValueObject(name, d);
SaveableData value = null;
if (defaultValue != null) {
String prefix = "";
boolean readOnly = false;
if (d.datafile != null) {
prefix = d.datafile.prefix;
readOnly = !d.datafile.canWrite;
}
value = instantiateValue(name, prefix, defaultValue, readOnly);
}
putValue(name, value, defaultValue != null);
}
use of net.sourceforge.processdash.data.SaveableData in project processdash by dtuma.
the class DataRepository method instantiateValue.
private SaveableData instantiateValue(String name, String dataPrefix, Object valueObj, boolean readOnly) {
SaveableData o = null;
if (valueObj instanceof SimpleData) {
o = (SimpleData) valueObj;
if (readOnly)
o = o.getEditable(false);
} else if (valueObj instanceof CompiledScript) {
o = new CompiledFunction(name, (CompiledScript) valueObj, this, dataPrefix);
} else if (valueObj instanceof SearchFactory) {
o = ((SearchFactory) valueObj).buildFor(name, this, dataPrefix);
} else if (valueObj instanceof String) {
String value = (String) valueObj;
if (value.startsWith("=")) {
readOnly = true;
value = value.substring(1);
}
try {
o = ValueFactory.createQuickly(name, value, this, dataPrefix);
} catch (MalformedValueException mfe) {
// temporary fix to allow old PSP for Engineers add-on to work in 1.7
if ("![(&&\tCompleted)]".equals(value)) {
valueObj = Compiler.compile("[Completed]");
o = new CompiledFunction(name, (CompiledScript) valueObj, this, dataPrefix);
} else {
o = new MalformedData(value);
}
}
if (readOnly && o != null)
o.setEditable(false);
}
return o;
}
Aggregations