2 * Sone - DefaultOwnIdentity.java - Copyright © 2010 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.freenet.wot;
21 import java.util.Map.Entry;
25 * An own identity is an identity that the owner of the node has full control
28 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
30 public class DefaultOwnIdentity extends DefaultIdentity implements OwnIdentity {
32 /** The identity manager. */
33 private final WebOfTrustConnector webOfTrustConnector;
35 /** The insert URI of the identity. */
36 private final String insertUri;
39 * Creates a new own identity.
41 * @param webOfTrustConnector
42 * The identity manager
44 * The ID of the identity
46 * The nickname of the identity
48 * The request URI of the identity
50 * The insert URI of the identity
52 public DefaultOwnIdentity(WebOfTrustConnector webOfTrustConnector, String id, String nickname, String requestUri, String insertUri) {
53 super(webOfTrustConnector, id, nickname, requestUri);
54 this.webOfTrustConnector = webOfTrustConnector;
55 this.insertUri = insertUri;
66 public String getInsertUri() {
74 public void addContext(String context) throws WebOfTrustException {
75 webOfTrustConnector.addContext(this, context);
82 public void removeContext(String context) throws WebOfTrustException {
83 webOfTrustConnector.removeContext(this, context);
90 public void setContexts(Set<String> contexts) throws WebOfTrustException {
91 for (String context : getContexts()) {
92 if (!contexts.contains(context)) {
93 webOfTrustConnector.removeContext(this, context);
96 for (String context : contexts) {
97 if (!getContexts().contains(context)) {
98 webOfTrustConnector.addContext(this, context);
107 public void setProperty(String name, String value) throws WebOfTrustException {
108 webOfTrustConnector.setProperty(this, name, value);
115 public void removeProperty(String name) throws WebOfTrustException {
116 webOfTrustConnector.removeProperty(this, name);
123 public void setProperties(Map<String, String> properties) throws WebOfTrustException {
124 for (Entry<String, String> oldProperty : getProperties().entrySet()) {
125 if (!properties.containsKey(oldProperty.getKey())) {
126 webOfTrustConnector.removeProperty(this, oldProperty.getKey());
128 webOfTrustConnector.setProperty(this, oldProperty.getKey(), properties.get(oldProperty.getKey()));
131 for (Entry<String, String> newProperty : properties.entrySet()) {
132 if (!getProperties().containsKey(newProperty.getKey())) {
133 webOfTrustConnector.setProperty(this, newProperty.getKey(), newProperty.getValue());