From d196ff9daeaf1661c48060bdeb426b051a0c1ef3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 30 Oct 2010 02:09:49 +0200 Subject: [PATCH] =?utf8?q?Don=E2=80=99t=20cache=20properties,=20either,=20?= =?utf8?q?and=20implement=20property=20manipulation.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../pterodactylus/sone/freenet/wot/Identity.java | 22 +++-------- .../sone/freenet/wot/OwnIdentity.java | 16 +++++--- .../sone/freenet/wot/WebOfTrustConnector.java | 46 ++++++++++++++++++++++ 3 files changed, 61 insertions(+), 23 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/Identity.java b/src/main/java/net/pterodactylus/sone/freenet/wot/Identity.java index 60e24d6..d4288ea 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/wot/Identity.java +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/Identity.java @@ -17,9 +17,6 @@ package net.pterodactylus.sone.freenet.wot; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; import java.util.Set; /** @@ -41,9 +38,6 @@ public class Identity { /** The request URI of the identity. */ private final String requestUri; - /** The properties of the identity. */ - protected final Map properties = Collections.synchronizedMap(new HashMap()); - /** * Creates a new identity. * @@ -124,24 +118,18 @@ public class Identity { } /** - * Returns the properties of the identity. - * - * @return The properties of the identity - */ - public Map getProperties() { - return Collections.unmodifiableMap(properties); - } - - /** * Returns the value of the property with the given name. * * @param name * The name of the property * @return The value of the property, or {@code null} if there is no such * property + * @throws PluginException + * if an error occured communicating with the Web of Trust + * plugin */ - public String getProperty(String name) { - return properties.get(name); + public String getProperty(String name) throws PluginException { + return webOfTrustConnector.getProperty(this, name); } // diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/OwnIdentity.java b/src/main/java/net/pterodactylus/sone/freenet/wot/OwnIdentity.java index 2384520..3716229 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/wot/OwnIdentity.java +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/OwnIdentity.java @@ -93,10 +93,12 @@ public class OwnIdentity extends Identity { * The name of the property to set * @param value * The new value of the property + * @throws PluginException + * if an error occured communicating with the Web of Trust + * plugin */ - public void setProperty(String name, String value) { - properties.put(name, value); - /* TODO - set property. */ + public void setProperty(String name, String value) throws PluginException { + webOfTrustConnector.setProperty(this, name, value); } /** @@ -104,10 +106,12 @@ public class OwnIdentity extends Identity { * * @param name * The name of the property to remove + * @throws PluginException + * if an error occured communicating with the Web of Trust + * plugin */ - public void removeProperty(String name) { - properties.remove(name); - /* TODO - remove property. */ + public void removeProperty(String name) throws PluginException { + webOfTrustConnector.removeProperty(this, name); } // diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java b/src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java index 20c0b50..49c76d7 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java @@ -188,6 +188,52 @@ public class WebOfTrustConnector implements ConnectorListener { performRequest(SimpleFieldSetConstructor.create().put("Message", "RemoveContext").put("Identity", ownIdentity.getId()).put("Context", context).get(), "ContextRemoved"); } + /** + * Returns the value of the property with the given name. + * + * @param identity + * The identity whose properties to check + * @param name + * The name of the property to return + * @return The value of the property, or {@code null} if there is no value + * @throws PluginException + * if an error occured talking to the Web of Trust plugin + */ + public String getProperty(Identity identity, String name) throws PluginException { + Reply reply = performRequest(SimpleFieldSetConstructor.create().put("Message", "GetProperty").put("Identity", identity.getId()).put("Property", name).get(), "PropertyValue", "Error"); + return reply.getFields().get("Property"); + } + + /** + * Sets the property with the given name to the given value. + * + * @param ownIdentity + * The identity to set the property on + * @param name + * The name of the property to set + * @param value + * The value to set + * @throws PluginException + * if an error occured talking to the Web of Trust plugin + */ + public void setProperty(OwnIdentity ownIdentity, String name, String value) throws PluginException { + performRequest(SimpleFieldSetConstructor.create().put("Message", "SetProperty").put("Identity", ownIdentity.getId()).put("Property", name).put("Value", value).get(), "PropertyAdded"); + } + + /** + * Removes the property with the given name. + * + * @param ownIdentity + * The identity to remove the property from + * @param name + * The name of the property to remove + * @throws PluginException + * if an error occured talking to the Web of Trust plugin + */ + public void removeProperty(OwnIdentity ownIdentity, String name) throws PluginException { + performRequest(SimpleFieldSetConstructor.create().put("Message", "RemoveProperty").put("Identity", ownIdentity.getId()).put("Property", name).get(), "PropertyRemoved"); + } + // // PRIVATE ACTIONS // -- 2.7.4