Example usage for java.util.prefs BackingStoreException BackingStoreException

List of usage examples for java.util.prefs BackingStoreException BackingStoreException

Introduction

In this page you can find the example usage for java.util.prefs BackingStoreException BackingStoreException.

Prototype

public BackingStoreException(Throwable cause) 

Source Link

Document

Constructs a BackingStoreException with the specified cause.

Usage

From source file:hr.fer.zemris.vhdllab.platform.preference.DatabasePreferences.java

@Override
public void flush() throws BackingStoreException {
    super.flush();
    if (this == userRoot()) {
        try {/*from w  w  w .  ja va  2 s.  c om*/
            manager.saveFiles();
        } catch (RuntimeException e) {
            throw new BackingStoreException(e);
        }
    }
}

From source file:com.adito.boot.PropertyPreferences.java

protected void flushSpi() throws BackingStoreException {
    if (prefs == null) {
        return;/* ww w . j  a  va 2 s  . c o  m*/
    }
    if (prefFile == null) {
        prefFile = new File(dir, "prefs.properties");
    }
    if (!dir.exists() && !dir.mkdirs()) {
        throw new BackingStoreException("Failed to create node directory " + dir.getPath() + ".");
    }
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(prefFile);
        prefs.store(fos, name());
    } catch (IOException ioe) {
        throw new BackingStoreException(ioe);
    } finally {
        Util.closeStream(fos);
    }
}

From source file:com.adito.boot.PropertyPreferences.java

protected void removeNodeSpi() throws BackingStoreException {
    if (!Util.delTree(dir)) {
        throw new BackingStoreException("Failed to remove preferencese node " + dir.getPath() + ".");
    }//  ww w.  j a  v a  2 s.c o m
}

From source file:com.delcyon.capo.Configuration.java

/**
 * Encapsulation of XML preferences/*from  www . j a  v  a  2 s. c o  m*/
 * @param key
 * @param value
 * @throws BackingStoreException 
 */
private void putXmlPref(String key, String value) throws BackingStoreException {
    try {
        synchronized (configDocument) {

            Element entryElement = (Element) XPath.selectSingleNode(configDocument,
                    "//entry[@key = '" + key + "']");
            if (entryElement != null) {
                entryElement.setAttribute("value", value);
            } else {
                entryElement = configDocument.createElementNS(null, "entry");
                entryElement.setAttribute("key", key);
                entryElement.setAttribute("value", value);
                configDocument.getDocumentElement().appendChild(entryElement);
            }
        }
    } catch (Exception exception) {
        throw new BackingStoreException(exception.getMessage());
    }
}

From source file:com.delcyon.capo.Configuration.java

private synchronized void sync() throws BackingStoreException {

    try {//from ww  w. j  a v a2s  .com
        Set<Entry<String, String>> preferenceEntrySet = preferenceValueHashMap.entrySet();
        for (Entry<String, String> entry : preferenceEntrySet) {
            //do not persist certain preferences
            if (entry.getKey().equals(PREFERENCE.CLIENT_VERIFICATION_PASSWORD.getLongOption())
                    && CapoApplication.isServer() == false) {
                continue;
            } else {
                putXmlPref(entry.getKey(), entry.getValue());
            }

        }
        if (disableAutoSync == false) {
            FileOutputStream configFileOutputStream = new FileOutputStream(capoConfigFile);
            TransformerFactory tFactory = TransformerFactory.newInstance();
            Transformer transformer = tFactory.newTransformer();
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            transformer.transform(new DOMSource(configDocument), new StreamResult(configFileOutputStream));
            configFileOutputStream.close();
        }
    } catch (Exception exception) {
        CapoApplication.logger.log(Level.WARNING, "Couldn't sync config file", exception);
        throw new BackingStoreException(exception.getMessage());
    }

}

From source file:org.nuclos.client.common.prefs.NuclosPreferencesRoot.java

/**
 * flushes the whole tree/*w w  w.j a va 2 s  .c om*/
 */
@Override
protected void flushSpi() throws BackingStoreException {
    try {
        if (this.isDirty()) {
            if (facade == null) {
                throw new NuclosFatalException(SpringLocaleDelegate.getInstance().getMessage(
                        "NuclosPreferences.1", "Benutzereinstellungen k\u00f6nnen nicht gespeichert werden."));
            } else {
                final ByteArrayOutputStream baos = new ByteArrayOutputStream();
                this.exportSubtree(baos);
                final String sXml = baos.toString("UTF-8");
                log.debug("sXml = " + sXml);
                byte[] bytes = baos.toByteArray();
                facade.modifyUserPreferences(new PreferencesVO(bytes));
                this.setDirty(false);
            }
        }
    } catch (Exception ex) {
        throw new BackingStoreException(ex);
    }
}

From source file:org.openconcerto.sql.preferences.SQLPreferences.java

@Override
protected void removeNodeSpi() throws BackingStoreException {
    synchronized (this.lock) {
        try {/*  w w w  .j a v a  2  s  .  c o m*/
            final SQLRow node = this.getNode();
            if (node != null) {
                SQLUtils.executeAtomic(getWriteDS(), new ConnectionHandlerNoSetup<Object, SQLException>() {
                    @Override
                    public Object handle(SQLDataSource ds) throws SQLException {
                        deleteValues(null);
                        ds.execute("DELETE FROM " + getNodeWT().getSQLName().quote() + " where \"ID\" = "
                                + node.getID());
                        return null;
                    }
                });
                replicate();
                this.resetNode();
            }
        } catch (Exception e) {
            throw new BackingStoreException(e);
        }
        this.values = null;
        this.removedKeys.clear();
        this.changedValues.clear();
    }
}

From source file:org.openconcerto.sql.preferences.SQLPreferences.java

@Override
protected String[] keysSpi() throws BackingStoreException {
    try {/*from w  w  w .j  a  va2  s  .  c  o m*/
        synchronized (this.lock) {
            final Set<String> committedKeys = this.getValues().keySet();
            final Set<String> res;
            if (this.removedKeys.isEmpty() && this.changedValues.isEmpty()) {
                res = committedKeys;
            } else {
                res = new HashSet<String>(committedKeys);
                res.removeAll(this.removedKeys);
                res.addAll(this.changedValues.keySet());
            }
            return res.toArray(new String[res.size()]);
        }
    } catch (Exception e) {
        throw new BackingStoreException(e);
    }
}

From source file:org.openconcerto.sql.preferences.SQLPreferences.java

@Override
protected String[] childrenNamesSpi() throws BackingStoreException {
    try {//from   w  w w.ja  v  a2  s  . c o m
        synchronized (this.lock) {
            final SQLRow node = this.getNode();
            if (node == null) {
                // OK since "This method need not return the names of any nodes already cached"
                // so if we call pref.node("a/b/c") with no existing nodes this still works
                return new String[0];
            }

            final int nodeID = node.getID();
            final SQLSelect sel = new SQLSelect().addSelect(this.getNodeRT().getField("NAME"));
            final Where w = new Where(this.getNodeRT().getField("ID_PARENT"), "=", nodeID);
            sel.setWhere(w);
            @SuppressWarnings("unchecked")
            final List<String> names = (List<String>) execute(sel.asString(),
                    SQLDataSource.COLUMN_LIST_HANDLER);
            return names.toArray(new String[names.size()]);
        }
    } catch (Exception e) {
        throw new BackingStoreException(e);
    }
}

From source file:org.openconcerto.sql.preferences.SQLPreferences.java

@Override
protected void flushSpi() throws BackingStoreException {
    synchronized (this.lock) {
        if (!this.nodeExists(""))
            // values and node already removed in removeNodeSpi()
            return;
        try {/* w w w.j  a v a 2 s .  c om*/
            SQLUtils.executeAtomic(getWriteDS(), new ConnectionHandlerNoSetup<Object, SQLException>() {
                @Override
                public Object handle(SQLDataSource ds) throws SQLException {
                    flushTxn();
                    return null;
                }
            });
        } catch (Exception e) {
            throw new BackingStoreException(e);
        }
    }
}