Skip to main content
summaryrefslogtreecommitdiffstats
blob: f4ed8bebfb07eec23397f26cdeeaf1265eea4419 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/****************************************************************************
 * Copyright (c) 2008 Composent, Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Composent, Inc. - initial API and implementation
 *****************************************************************************/

package org.eclipse.ecf.internal.storage;

import org.eclipse.ecf.core.*;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.identity.IDCreateException;
import org.eclipse.ecf.storage.*;
import org.eclipse.equinox.security.storage.ISecurePreferences;
import org.eclipse.equinox.security.storage.StorageException;

/**
 *
 */
public class ContainerEntry implements IContainerEntry {

	private static final String FACTORY_NAME_KEY = "factoryName"; //$NON-NLS-1$

	ISecurePreferences prefs;
	IIDEntry idEntry;

	ID containerID;

	/**
	 * @param idEntry 
	 */
	public ContainerEntry(IIDEntry idEntry) {
		this.idEntry = idEntry;
		ISecurePreferences prefs = idEntry.getPreferences();
		this.prefs = prefs.node(ContainerStore.CONTAINER_NODE_NAME);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ecf.storage.IContainerEntry#createContainer()
	 */
	public IContainer createContainer() throws ContainerCreateException {
		try {
			IContainer container = ContainerFactory.getDefault().createContainer(getFactoryName(), getContainerID());
			IStorableContainerAdapter containerAdapter = (IStorableContainerAdapter) container.getAdapter(IStorableContainerAdapter.class);
			if (containerAdapter != null) {
				containerAdapter.handleRestore(prefs);
			}
			return container;
		} catch (IDCreateException e) {
			throw new ContainerCreateException("Could not create ID for container", e); //$NON-NLS-1$
		} catch (StorageException e) {
			throw new ContainerCreateException("Exception on restore", e); //$NON-NLS-1$
		}
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ecf.storage.IContainerEntry#delete()
	 */
	public void delete() {
		prefs.removeNode();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ecf.storage.IContainerEntry#getContainerID()
	 */
	public ID getContainerID() throws IDCreateException {
		if (containerID == null) {
			containerID = idEntry.createID();
		}
		return containerID;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ecf.storage.IContainerEntry#getFactoryName()
	 */
	public String getFactoryName() throws StorageException {
		return prefs.get(FACTORY_NAME_KEY, ""); //$NON-NLS-1$
	}

	protected void setFactoryName(String factoryName, boolean encrypt) throws StorageException {
		prefs.put(FACTORY_NAME_KEY, factoryName, encrypt);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ecf.storage.IContainerEntry#getPreferences()
	 */
	public ISecurePreferences getPreferences() {
		return prefs;
	}

}

Back to the top