Author: batosai
Date: 2008-08-15 21:54:08 +0000 (Fri, 15 Aug 2008)
New Revision: 21923

Modified:
   trunk/apps/WoT/src/plugins/WoT/Identity.java
   trunk/apps/WoT/src/plugins/WoT/WoTplugin.java
Log:
Handle properties handling through FCP.

Modified: trunk/apps/WoT/src/plugins/WoT/Identity.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/Identity.java        2008-08-15 20:54:27 UTC 
(rev 21922)
+++ trunk/apps/WoT/src/plugins/WoT/Identity.java        2008-08-15 21:54:08 UTC 
(rev 21923)
@@ -202,8 +202,10 @@
         * Gets the property value or null if the property doesn't exist
         * @param key
         * @return
+        * @throws InvalidParameterException 
         */
-       public String getProp(String key) {
+       public String getProp(String key) throws InvalidParameterException {
+               if(!props.containsKey(key)) throw new 
InvalidParameterException("Property '"+key+"' isn't set on this identity");
                return props.get(key);
        }

@@ -211,8 +213,10 @@
         * Removes a property from the list. Does nothing if it didn't exist.
         * @param key
         * @param db
+        * @throws InvalidParameterException 
         */
-       public void removeProp(String key, ObjectContainer db) {
+       public void removeProp(String key, ObjectContainer db) throws 
InvalidParameterException {
+               if(!props.containsKey(key)) throw new 
InvalidParameterException("Property '"+key+"' isn't set on this identity");
                props.remove(key.trim());
                db.store(props);
        }

Modified: trunk/apps/WoT/src/plugins/WoT/WoTplugin.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/WoTplugin.java       2008-08-15 20:54:27 UTC 
(rev 21922)
+++ trunk/apps/WoT/src/plugins/WoT/WoTplugin.java       2008-08-15 21:54:08 UTC 
(rev 21923)
@@ -253,6 +253,15 @@
                        else if(params.get("Message").equals("RemoveContext")) {
                                replysender.send(handleRemoveContext(params), 
data);
                        }
+                       else if(params.get("Message").equals("SetProperty")) {
+                               replysender.send(handleSetProperty(params), 
data);
+                       }
+                       else if(params.get("Message").equals("GetProperty")) {
+                               replysender.send(handleGetProperty(params), 
data);
+                       }
+                       else if(params.get("Message").equals("RemoveProperty")) 
{
+                               replysender.send(handleRemoveProperty(params), 
data);
+                       }
                        else {
                                throw new Exception("Unknown message (" + 
params.get("Message") + ")");
                        }
@@ -429,6 +438,47 @@
                return sfs;
        }

+       private SimpleFieldSet handleSetProperty(SimpleFieldSet params) throws 
InvalidParameterException, MalformedURLException, UnknownIdentityException {
+               
+               SimpleFieldSet sfs = new SimpleFieldSet(false);
+
+               if(params.get("Identity") == null || params.get("Property") == 
null || params.get("Value") == null) throw new 
InvalidParameterException("Missing mandatory parameter");
+
+               Identity identity = 
wot.getOwnIdentityByURI(params.get("Identity"));
+               identity.setProp(params.get("Property"), params.get("Value"), 
db);
+               
+               sfs.putAppend("Message", "PropertyAdded");
+               return sfs;
+       }
+
+       private SimpleFieldSet handleGetProperty(SimpleFieldSet params) throws 
InvalidParameterException, MalformedURLException, UnknownIdentityException {
+               
+               SimpleFieldSet sfs = new SimpleFieldSet(false);
+
+               if(params.get("Identity") == null || params.get("Property") == 
null) throw new InvalidParameterException("Missing mandatory parameter");
+
+               Identity identity = 
wot.getOwnIdentityByURI(params.get("Identity"));
+               
+               sfs.putAppend("Message", "PropertyValue");
+               sfs.putAppend("Property", 
identity.getProp(params.get("Property")));
+               
+               return sfs;
+       }
+
+       
+       private SimpleFieldSet handleRemoveProperty(SimpleFieldSet params) 
throws InvalidParameterException, MalformedURLException, 
UnknownIdentityException {
+               
+               SimpleFieldSet sfs = new SimpleFieldSet(false);
+
+               if(params.get("Identity") == null || params.get("Property") == 
null) throw new InvalidParameterException("Missing mandatory parameter");
+
+               Identity identity = 
wot.getOwnIdentityByURI(params.get("Identity"));
+               identity.removeProp(params.get("Property"), db);
+               
+               sfs.putAppend("Message", "PropertyRemoved");
+               return sfs;
+       }
+       
        private SimpleFieldSet errorMessageFCP (Exception e) {

                SimpleFieldSet sfs = new SimpleFieldSet(false);


Reply via email to