Search in sources :

Example 26 with SaveableData

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);
        }
    }
}
Also used : SaveableData(net.sourceforge.processdash.data.SaveableData) DoubleData(net.sourceforge.processdash.data.DoubleData)

Example 27 with SaveableData

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;
}
Also used : Element(org.w3c.dom.Element) DataRepository(net.sourceforge.processdash.data.repository.DataRepository) SimpleData(net.sourceforge.processdash.data.SimpleData) SaveableData(net.sourceforge.processdash.data.SaveableData) StringData(net.sourceforge.processdash.data.StringData) Document(org.w3c.dom.Document) ListData(net.sourceforge.processdash.data.ListData)

Example 28 with SaveableData

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;
}
Also used : HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) StringReader(java.io.StringReader) SimpleData(net.sourceforge.processdash.data.SimpleData) EscapeString(net.sourceforge.processdash.util.EscapeString) SaveableData(net.sourceforge.processdash.data.SaveableData) MalformedValueException(net.sourceforge.processdash.data.MalformedValueException) PatternSyntaxException(java.util.regex.PatternSyntaxException) FileNotFoundException(java.io.FileNotFoundException) ConcurrentModificationException(java.util.ConcurrentModificationException) LexerException(net.sourceforge.processdash.data.compiler.lexer.LexerException) IOException(java.io.IOException) CompilationException(net.sourceforge.processdash.data.compiler.CompilationException) ParserException(net.sourceforge.processdash.data.compiler.parser.ParserException) ExecutionException(net.sourceforge.processdash.data.compiler.ExecutionException)

Example 29 with SaveableData

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);
}
Also used : SaveableData(net.sourceforge.processdash.data.SaveableData) EscapeString(net.sourceforge.processdash.util.EscapeString)

Example 30 with SaveableData

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;
}
Also used : CompiledScript(net.sourceforge.processdash.data.compiler.CompiledScript) MalformedValueException(net.sourceforge.processdash.data.MalformedValueException) SimpleData(net.sourceforge.processdash.data.SimpleData) SaveableData(net.sourceforge.processdash.data.SaveableData) EscapeString(net.sourceforge.processdash.util.EscapeString) MalformedData(net.sourceforge.processdash.data.MalformedData)

Aggregations

SaveableData (net.sourceforge.processdash.data.SaveableData)38 SimpleData (net.sourceforge.processdash.data.SimpleData)14 EscapeString (net.sourceforge.processdash.util.EscapeString)11 MalformedValueException (net.sourceforge.processdash.data.MalformedValueException)6 Iterator (java.util.Iterator)5 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)4 ConcurrentModificationException (java.util.ConcurrentModificationException)4 HashMap (java.util.HashMap)4 PatternSyntaxException (java.util.regex.PatternSyntaxException)4 DoubleData (net.sourceforge.processdash.data.DoubleData)4 CompilationException (net.sourceforge.processdash.data.compiler.CompilationException)4 ExecutionException (net.sourceforge.processdash.data.compiler.ExecutionException)4 LexerException (net.sourceforge.processdash.data.compiler.lexer.LexerException)4 ParserException (net.sourceforge.processdash.data.compiler.parser.ParserException)4 Map (java.util.Map)3 WeakHashMap (java.util.WeakHashMap)3 DateData (net.sourceforge.processdash.data.DateData)3 NumberData (net.sourceforge.processdash.data.NumberData)3 StringData (net.sourceforge.processdash.data.StringData)3