Don’t cache properties, either, and implement property manipulation.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 30 Oct 2010 00:09:49 +0000 (02:09 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 30 Oct 2010 00:09:49 +0000 (02:09 +0200)
src/main/java/net/pterodactylus/sone/freenet/wot/Identity.java
src/main/java/net/pterodactylus/sone/freenet/wot/OwnIdentity.java
src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java

index 60e24d6..d4288ea 100644 (file)
@@ -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<String, String> properties = Collections.synchronizedMap(new HashMap<String, String>());
-
        /**
         * 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<String, String> 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);
        }
 
        //
index 2384520..3716229 100644 (file)
@@ -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);
        }
 
        //
index 20c0b50..49c76d7 100644 (file)
@@ -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
        //