Search in sources :

Example 1 with IDStoreException

use of org.eclipse.ecf.storage.IDStoreException in project ecf by eclipse.

the class IDEntry method addAssociateFromName.

private void addAssociateFromName(String name, SortedMap results) {
    try {
        // Get index of first :
        int index = name.indexOf(DELIMITER);
        // If not found then the name is not well-formed
        if (index == -1)
            // $NON-NLS-1$
            throw new IDStoreException("Associate ID not well-formed");
        // Get the index string
        String indexStr = name.substring(0, index);
        Integer resultIndex = null;
        // Create resultIndex from indexStr
        try {
            resultIndex = Integer.valueOf(indexStr);
        } catch (NumberFormatException e) {
            // $NON-NLS-1$
            throw new IDStoreException("Associate ID not well-formed", e);
        }
        // get remainder string
        name = name.substring(index + 1);
        // Get index of second :
        index = name.indexOf(DELIMITER);
        if (index == -1)
            // $NON-NLS-1$
            throw new IDStoreException("Associate ID not well-formed");
        // Get namespace name before index
        String namespaceName = name.substring(0, index);
        ISecurePreferences namespacePrefs = getPreferences(getNamespaceRoot(), namespaceName);
        if (namespacePrefs == null)
            throw new IDStoreException(// $NON-NLS-1$
            "Cannot find Namespace=" + namespaceName);
        // Get ID name after index
        String idName = name.substring(index + 1);
        ISecurePreferences idPrefs = getPreferences(namespacePrefs, idName);
        if (idPrefs == null)
            throw new IDStoreException(// $NON-NLS-1$ //$NON-NLS-2$
            "ID=" + idName + " not found in Namespace=" + namespaceName);
        // Put new IDEntry in sorted collection ordered by resultIndex
        results.put(resultIndex, new IDEntry(idPrefs));
    } catch (IDStoreException e) {
        Activator.getDefault().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, "Unable to create associate ID", // $NON-NLS-1$
        e));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IIDEntry(org.eclipse.ecf.storage.IIDEntry) IDStoreException(org.eclipse.ecf.storage.IDStoreException) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences)

Example 2 with IDStoreException

use of org.eclipse.ecf.storage.IDStoreException in project ecf by eclipse.

the class IDEntry method putAssociate.

public void putAssociate(String key, IIDEntry entry, boolean encrypt) throws IDStoreException {
    if (key == null)
        // $NON-NLS-1$
        throw new IDStoreException("key cannot be null");
    if (entry == null)
        // $NON-NLS-1$
        throw new IDStoreException("entry cannot be null");
    ISecurePreferences associateNode = prefs.node(key);
    ISecurePreferences prefs = entry.getPreferences();
    // This is where associates are created with form:
    // <index>:<namespace>:<idname>
    String entryAssociate = String.valueOf(associateNode.childrenNames().length) + DELIMITER + prefs.parent().name() + DELIMITER + prefs.name();
    associateNode.node(entryAssociate);
}
Also used : IDStoreException(org.eclipse.ecf.storage.IDStoreException) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences)

Aggregations

IDStoreException (org.eclipse.ecf.storage.IDStoreException)2 ISecurePreferences (org.eclipse.equinox.security.storage.ISecurePreferences)2 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 IIDEntry (org.eclipse.ecf.storage.IIDEntry)1