[jboss-svn-commits] JBoss Portal SVN: r5218 - in trunk: core/src/main/org/jboss/portal/core/controller/portlet core/src/main/org/jboss/portal/core/portlet/user identity/src/main/org/jboss/portal/identity identity/src/main/org/jboss/portal/identity/db identity/src/main/org/jboss/portal/test/identity

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Sep 18 02:38:07 EDT 2006


Author: julien at jboss.com
Date: 2006-09-18 02:37:43 -0400 (Mon, 18 Sep 2006)
New Revision: 5218

Added:
   trunk/identity/src/main/org/jboss/portal/identity/ProfileMap.java
   trunk/identity/src/main/org/jboss/portal/identity/db/ProfileMapImpl.java
Removed:
   trunk/identity/src/main/org/jboss/portal/identity/PropertyMap.java
   trunk/identity/src/main/org/jboss/portal/identity/db/PropertyMapImpl.java
Modified:
   trunk/core/src/main/org/jboss/portal/core/controller/portlet/ControllerUserContext.java
   trunk/core/src/main/org/jboss/portal/core/portlet/user/UserPortlet.java
   trunk/identity/src/main/org/jboss/portal/identity/User.java
   trunk/identity/src/main/org/jboss/portal/identity/db/UserImpl.java
   trunk/identity/src/main/org/jboss/portal/test/identity/UserTestCase.java
Log:
- rename identit PropertyMap to more appropriate ProfileMap
- update ProfileMap implementation to reflect java.util.Map contract with respect to NullPointerException

Modified: trunk/core/src/main/org/jboss/portal/core/controller/portlet/ControllerUserContext.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/controller/portlet/ControllerUserContext.java	2006-09-18 04:21:11 UTC (rev 5217)
+++ trunk/core/src/main/org/jboss/portal/core/controller/portlet/ControllerUserContext.java	2006-09-18 06:37:43 UTC (rev 5218)
@@ -56,7 +56,7 @@
       User user = getUser();
       if (user != null)
       {
-         return user.getProperties();
+         return user.getProfile();
       }
       else
       {

Modified: trunk/core/src/main/org/jboss/portal/core/portlet/user/UserPortlet.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/portlet/user/UserPortlet.java	2006-09-18 04:21:11 UTC (rev 5217)
+++ trunk/core/src/main/org/jboss/portal/core/portlet/user/UserPortlet.java	2006-09-18 06:37:43 UTC (rev 5218)
@@ -258,7 +258,7 @@
             fillContextWithUserProfile(user, ctx);
 
             //
-            String selectedTimeZone = (String) user.getProperties().get(User.INFO_USER_TIME_ZONE_OFFSET);
+            String selectedTimeZone = (String) user.getProfile().get(User.INFO_USER_TIME_ZONE_OFFSET);
             for(int i = 0; i < UserPortletConstants.TIME_ZONE_OFFSETS.length; i++)
             {
                if(UserPortletConstants.TIME_ZONE_OFFSETS[i] != null)
@@ -274,7 +274,7 @@
             }
 
             //
-            String selectedLocale = (String) user.getProperties().get(User.INFO_USER_LOCALE);
+            String selectedLocale = (String) user.getProfile().get(User.INFO_USER_LOCALE);
             for(Iterator i = LocaleInfo.getAll().iterator(); i.hasNext();)
             {
                LocaleInfo info = (LocaleInfo) i.next();
@@ -289,7 +289,7 @@
             }
 
             //
-            String selectedTheme = (String) user.getProperties().get(User.INFO_USER_THEME);
+            String selectedTheme = (String) user.getProfile().get(User.INFO_USER_THEME);
             ThemeService themeService = (ThemeService) getPortletContext().getAttribute("ThemeService");
             for(Iterator i = themeService.getThemes().iterator(); i.hasNext();)
             {
@@ -719,19 +719,19 @@
       ctx.put("FAKEEMAIL", user.getFakeEmail());
       ctx.put("THEME", user.getTheme());
       ctx.put("VIEWREALEMAIL", user.getViewRealEmail() ? "checked=\"checked\"" : "");
-      ctx.put("HOMEPAGE", (String) (user.getProperties().get(User.INFO_USER_HOMEPAGE)));
-      ctx.put("ICQ", (String) (user.getProperties().get(User.INFO_USER_IM_ICQ)));
-      ctx.put("AIM", (String) (user.getProperties().get(User.INFO_USER_IM_AIM)));
-      ctx.put("YIM", (String) (user.getProperties().get(User.INFO_USER_IM_YIM)));
-      ctx.put("MSNM", (String) (user.getProperties().get(User.INFO_USER_IM_MSNM)));
-      ctx.put("SKYPE", (String) (user.getProperties().get(User.INFO_USER_IM_SKYPE)));
-      ctx.put("SIGNATURE", (String) (user.getProperties().get(User.INFO_USER_SIGNATURE)));
-      ctx.put("LOCATION", (String) (user.getProperties().get(User.INFO_USER_LOCATION)));
-      ctx.put("OCCUPATION", (String) (user.getProperties().get(User.INFO_USER_OCCUPATION)));
-      ctx.put("INTERESTS", (String) (user.getProperties().get(User.INFO_USER_INTERESTS)));
-      ctx.put("EXTRA", (String) (user.getProperties().get(User.INFO_USER_EXTRA)));
-      ctx.put("QUESTION", (String) (user.getProperties().get(User.INFO_USER_SECURITY_QUESTION)));
-      ctx.put("ANSWER", (String) (user.getProperties().get(User.INFO_USER_SECURITY_ANSWER)));
+      ctx.put("HOMEPAGE", (String) (user.getProfile().get(User.INFO_USER_HOMEPAGE)));
+      ctx.put("ICQ", (String) (user.getProfile().get(User.INFO_USER_IM_ICQ)));
+      ctx.put("AIM", (String) (user.getProfile().get(User.INFO_USER_IM_AIM)));
+      ctx.put("YIM", (String) (user.getProfile().get(User.INFO_USER_IM_YIM)));
+      ctx.put("MSNM", (String) (user.getProfile().get(User.INFO_USER_IM_MSNM)));
+      ctx.put("SKYPE", (String) (user.getProfile().get(User.INFO_USER_IM_SKYPE)));
+      ctx.put("SIGNATURE", (String) (user.getProfile().get(User.INFO_USER_SIGNATURE)));
+      ctx.put("LOCATION", (String) (user.getProfile().get(User.INFO_USER_LOCATION)));
+      ctx.put("OCCUPATION", (String) (user.getProfile().get(User.INFO_USER_OCCUPATION)));
+      ctx.put("INTERESTS", (String) (user.getProfile().get(User.INFO_USER_INTERESTS)));
+      ctx.put("EXTRA", (String) (user.getProfile().get(User.INFO_USER_EXTRA)));
+      ctx.put("QUESTION", (String) (user.getProfile().get(User.INFO_USER_SECURITY_QUESTION)));
+      ctx.put("ANSWER", (String) (user.getProfile().get(User.INFO_USER_SECURITY_ANSWER)));
    }
 
    /**
@@ -852,7 +852,7 @@
 
          if(timezoneoffset.shortValue() != UNDEFINED_TIMEZONE)
          {
-            user.getProperties().put(User.INFO_USER_TIME_ZONE_OFFSET, timezoneoffset.toString());
+            user.getProfile().put(User.INFO_USER_TIME_ZONE_OFFSET, timezoneoffset.toString());
          }
 
          LocaleInfo localeInfo = LocaleInfo.decodeLocaleInfo(locale);
@@ -1066,7 +1066,7 @@
    {
       if((value != null) && (value.trim().length() != 0))
       {
-         user.getProperties().put(key, value);
+         user.getProfile().put(key, value);
       }
    }
 

Copied: trunk/identity/src/main/org/jboss/portal/identity/ProfileMap.java (from rev 5217, trunk/identity/src/main/org/jboss/portal/identity/PropertyMap.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity/PropertyMap.java	2006-09-18 04:21:11 UTC (rev 5217)
+++ trunk/identity/src/main/org/jboss/portal/identity/ProfileMap.java	2006-09-18 06:37:43 UTC (rev 5218)
@@ -0,0 +1,42 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.portal.identity;
+
+import java.util.Map;
+
+/**
+ * Extends <code>java.util.Map</code> to provide meta information about user profile.
+ *
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision$
+ */
+public interface ProfileMap extends Map
+{
+   /**
+    * Return true if the profile value is read only.
+    *
+    * @param key
+    * @return true if the profile value is read only
+    * @throws ClassCastException if the key is not an instance of string
+    */
+   boolean isReadOnly(Object key);
+}


Property changes on: trunk/identity/src/main/org/jboss/portal/identity/ProfileMap.java
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Deleted: trunk/identity/src/main/org/jboss/portal/identity/PropertyMap.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity/PropertyMap.java	2006-09-18 04:21:11 UTC (rev 5217)
+++ trunk/identity/src/main/org/jboss/portal/identity/PropertyMap.java	2006-09-18 06:37:43 UTC (rev 5218)
@@ -1,35 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.portal.identity;
-
-import java.util.Map;
-
-/**
- * Extends <code>java.util.Map</code> to provide meta information about user properties.
- *
- * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-public interface PropertyMap extends Map
-{
-   boolean isReadOnly(Object key);
-}

Modified: trunk/identity/src/main/org/jboss/portal/identity/User.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity/User.java	2006-09-18 04:21:11 UTC (rev 5217)
+++ trunk/identity/src/main/org/jboss/portal/identity/User.java	2006-09-18 06:37:43 UTC (rev 5218)
@@ -88,7 +88,7 @@
    /**
     * Returns the user properties.
     */
-   PropertyMap getProperties();
+   ProfileMap getProfile();
 
    // Properties declared in this interface for convenient access ******************************************************
 

Copied: trunk/identity/src/main/org/jboss/portal/identity/db/ProfileMapImpl.java (from rev 5217, trunk/identity/src/main/org/jboss/portal/identity/db/PropertyMapImpl.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity/db/PropertyMapImpl.java	2006-09-18 04:21:11 UTC (rev 5217)
+++ trunk/identity/src/main/org/jboss/portal/identity/db/ProfileMapImpl.java	2006-09-18 06:37:43 UTC (rev 5218)
@@ -0,0 +1,284 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.portal.identity.db;
+
+import org.jboss.portal.identity.ProfileMap;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Collection;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Collections;
+
+/**
+ * A mutable map that expose user properties.
+ *
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision$
+ */
+public class ProfileMapImpl implements ProfileMap
+{
+
+   /** . */
+   private UserImpl user;
+
+   public ProfileMapImpl(UserImpl user)
+   {
+      if (user == null)
+      {
+         throw new IllegalArgumentException();
+      }
+      this.user = user;
+   }
+
+   public boolean isReadOnly(Object key)
+   {
+      if (key == null)
+      {
+         return false;
+      }
+      if (key instanceof String == false)
+      {
+         throw new ClassCastException("Key must be a string");
+      }
+      UserImpl.PropertyAccessor accessor = (UserImpl.PropertyAccessor)UserImpl.ACCESSORS.get(key);
+      return accessor != null && !accessor.isWritable();
+   }
+
+   public int size()
+   {
+      return UserImpl.ACCESSORS.size() + user.getDynamic().size();
+   }
+
+   public boolean isEmpty()
+   {
+      return false;
+   }
+
+   /**
+    * @throws ClassCastException if the key is not an instance of string
+    */
+   public boolean containsKey(Object key) throws ClassCastException
+   {
+      if (key == null)
+      {
+         return false;
+      }
+      if (key instanceof String == false)
+      {
+         throw new ClassCastException("Key must be a string");
+      }
+      UserImpl.PropertyAccessor accessor = (UserImpl.PropertyAccessor)UserImpl.ACCESSORS.get(key);
+      if (accessor != null)
+      {
+         return true;
+      }
+      return user.getDynamic().containsKey(key);
+   }
+
+   /**
+    * @throws ClassCastException if the value is not an instance of string
+    */
+   public boolean containsValue(Object value) throws ClassCastException
+   {
+      if (value == null)
+      {
+         throw new NullPointerException("Key cannot be null");
+      }
+      if (value instanceof String == false)
+      {
+         throw new ClassCastException("Value must be a string");
+      }
+      for (Iterator i = UserImpl.ACCESSORS.values().iterator();i.hasNext();)
+      {
+         UserImpl.PropertyAccessor accessor = (UserImpl.PropertyAccessor)i.next();
+         Object value2 = accessor.get(user);
+         if (value == value2 || value.equals(value2))
+         {
+            return true;
+         }
+      }
+      return user.getDynamic().containsValue(value);
+   }
+
+   /**
+    * @throws ClassCastException if the key is not an instance of string
+    */
+   public Object get(Object key)
+   {
+      if (key == null)
+      {
+         return null;
+      }
+      if (key instanceof String == false)
+      {
+         throw new ClassCastException("Key must be a string");
+      }
+      UserImpl.PropertyAccessor accessor = (UserImpl.PropertyAccessor)UserImpl.ACCESSORS.get(key);
+      if (accessor != null)
+      {
+         return accessor.get(user);
+      }
+      return user.getDynamic().get(key);
+   }
+
+   /**
+    * Put a value in the dynamic map.
+    *
+    * If the key is not an instance of string then an IllegalArgumentException is thrown.
+    * If the value is mapped to an accessor of a non writable field then an IllegalArgumentException is thrown.
+    * If the value is mapped to an accessor of a non nullable field and the field is null then an IllegalArgumentException is thrown.
+    *
+    * @throws IllegalArgumentException
+    */
+   public Object put(Object key, Object newValue) throws IllegalArgumentException
+   {
+      if (key == null)
+      {
+         return null;
+      }
+      if (key instanceof String == false)
+      {
+         throw new ClassCastException("Key is not a String");
+      }
+      UserImpl.PropertyAccessor accessor = (UserImpl.PropertyAccessor)UserImpl.ACCESSORS.get(key);
+      if (accessor != null)
+      {
+         if (newValue == null && !accessor.isNullable())
+         {
+            throw new NullPointerException("Key " + key + " is not nullable");
+         }
+         if (!accessor.isWritable())
+         {
+            throw new IllegalArgumentException("Key " + key + " is not modifiable");
+         }
+         else
+         {
+            Object oldValue = accessor.get(user);
+            accessor.set(user, (String)newValue);
+            return oldValue;
+         }
+      }
+      if (newValue instanceof String == false)
+      {
+         throw new ClassCastException("Dynamic value must be a string");
+      }
+      return user.getDynamic().put(key, newValue);
+   }
+
+   /**
+    * Only affect dynamic properties, otherwise it throws an IllegalArgumentException.
+    *
+    * @throws IllegalArgumentException if the key is a not a dynamic property
+    */
+   public Object remove(Object key) throws IllegalArgumentException
+   {
+      if (key instanceof String == false)
+      {
+         throw new ClassCastException("Key is not a String");
+      }
+      UserImpl.PropertyAccessor accessor = (UserImpl.PropertyAccessor)UserImpl.ACCESSORS.get(key);
+      if (accessor != null)
+      {
+         throw new IllegalArgumentException("Key " + key + " is not removable");
+      }
+      return user.getDynamic().remove(key);
+   }
+
+   /**
+    * Clear only dynamic properties.
+    */
+   public void clear()
+   {
+      user.getDynamic().clear();
+   }
+
+   public Set keySet()
+   {
+      // Get
+      Set set = new HashSet(size());
+
+      //
+      set.addAll(user.getDynamic().keySet());
+      set.addAll(UserImpl.ACCESSORS.keySet());
+      return set;
+   }
+
+   public Collection values()
+   {
+      ArrayList collection = new ArrayList(size());
+      for (Iterator i = UserImpl.ACCESSORS.values().iterator();i.hasNext();)
+      {
+         UserImpl.PropertyAccessor accessor = (UserImpl.PropertyAccessor)i.next();
+         collection.add(accessor.get(user));
+      }
+      collection.addAll(user.getDynamic().values());
+      return collection;
+   }
+
+   /**
+    * Returns an immutable collection of entries.
+    */
+   public Set entrySet()
+   {
+      Map copy = new HashMap(user.getDynamic());
+      for (Iterator i = UserImpl.ACCESSORS.values().iterator();i.hasNext();)
+      {
+         UserImpl.PropertyAccessor accessor = (UserImpl.PropertyAccessor)i.next();
+         copy.put(accessor.getPropertyName(), accessor.get(user));
+      }
+      return Collections.unmodifiableMap(copy).entrySet();
+   }
+
+   public void putAll(Map map)
+   {
+      // todo : check all properties ok with changes before proceeding
+      for (Iterator i = map.entrySet().iterator();i.hasNext();)
+      {
+         Map.Entry entry = (Map.Entry)i.next();
+         Object key = entry.getKey();
+         if (key instanceof String)
+         {
+            Object value = entry.getValue();
+            UserImpl.PropertyAccessor accessor = (UserImpl.PropertyAccessor)UserImpl.ACCESSORS.get(key);
+            if (accessor != null)
+            {
+               if (accessor.isWritable())
+               {
+                  accessor.set(user, (String)value);
+               }
+               else
+               {
+                  // julien : Do something better ?
+               }
+            }
+            else
+            {
+               user.getDynamic().put(key, value);
+            }
+         }
+      }
+   }
+}


Property changes on: trunk/identity/src/main/org/jboss/portal/identity/db/ProfileMapImpl.java
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Deleted: trunk/identity/src/main/org/jboss/portal/identity/db/PropertyMapImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity/db/PropertyMapImpl.java	2006-09-18 04:21:11 UTC (rev 5217)
+++ trunk/identity/src/main/org/jboss/portal/identity/db/PropertyMapImpl.java	2006-09-18 06:37:43 UTC (rev 5218)
@@ -1,246 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.portal.identity.db;
-
-import org.jboss.portal.identity.PropertyMap;
-
-import java.util.Iterator;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.Collection;
-import java.util.ArrayList;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Collections;
-
-/**
- * A mutable map that expose user properties.
- *
- * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-public class PropertyMapImpl implements PropertyMap
-{
-
-   private UserImpl user;
-
-   public PropertyMapImpl(UserImpl user)
-   {
-      this.user = user;
-   }
-
-   public boolean isReadOnly(Object key)
-   {
-      if (!(key instanceof String))
-      {
-         return false;
-      }
-      UserImpl.PropertyAccessor accessor = (UserImpl.PropertyAccessor)UserImpl.ACCESSORS.get(key);
-      return accessor != null && !accessor.isWritable();
-   }
-
-   public int size()
-   {
-      return UserImpl.ACCESSORS.size() + user.getDynamic().size();
-   }
-
-   public boolean isEmpty()
-   {
-      return false;
-   }
-
-   public boolean containsKey(Object key)
-   {
-      if (!(key instanceof String))
-      {
-         return false;
-      }
-      UserImpl.PropertyAccessor accessor = (UserImpl.PropertyAccessor)UserImpl.ACCESSORS.get(key);
-      if (accessor != null)
-      {
-         return true;
-      }
-      return user.getDynamic().containsKey(key);
-   }
-
-   public boolean containsValue(Object value1)
-   {
-      for (Iterator i = UserImpl.ACCESSORS.values().iterator();i.hasNext();)
-      {
-         UserImpl.PropertyAccessor accessor = (UserImpl.PropertyAccessor)i.next();
-         Object value2 = accessor.get(user);
-         if (value1 == value2 || (value1 != null && value1.equals(value2)))
-         {
-            return true;
-         }
-      }
-      return user.getDynamic().containsValue(value1);
-   }
-
-   public Object get(Object key)
-   {
-      if (!(key instanceof String))
-      {
-         return null;
-      }
-      UserImpl.PropertyAccessor accessor = (UserImpl.PropertyAccessor)UserImpl.ACCESSORS.get(key);
-      if (accessor != null)
-      {
-         return accessor.get(user);
-      }
-      return user.getDynamic().get(key);
-   }
-
-   /**
-    * Put a value in the dynamic map.
-    *
-    * If the key is not an instance of string then an IllegalArgumentException is thrown.
-    * If the value is mapped to an accessor of a non writable field then an IllegalArgumentException is thrown.
-    * If the value is mapped to an accessor of a non nullable field and the field is null then an IllegalArgumentException is thrown.
-    *
-    * @throws IllegalArgumentException
-    */
-   public Object put(Object key, Object newValue) throws IllegalArgumentException
-   {
-      if (!(key instanceof String))
-      {
-         throw new IllegalArgumentException("Key is not a String");
-      }
-      UserImpl.PropertyAccessor accessor = (UserImpl.PropertyAccessor)UserImpl.ACCESSORS.get(key);
-      if (accessor != null)
-      {
-         if (newValue == null && !accessor.isNullable())
-         {
-            throw new IllegalArgumentException("Key " + key + " is not nullable");
-         }
-         if (!accessor.isWritable())
-         {
-            throw new IllegalArgumentException("Key " + key + " is not modifiable");
-         }
-         else
-         {
-            Object oldValue = accessor.get(user);
-            accessor.set(user, (String)newValue);
-            return oldValue;
-         }
-      }
-      if (!(newValue instanceof String))
-      {
-         throw new IllegalArgumentException("Dynamic value must be a string");
-      }
-      return user.getDynamic().put(key, newValue);
-   }
-
-   /**
-    * Only affect dynamic properties, otherwise it throws an IllegalArgumentException.
-    *
-    * @throws IllegalArgumentException if the key is a not a dynamic property
-    */
-   public Object remove(Object key) throws IllegalArgumentException
-   {
-      if (!(key instanceof String))
-      {
-         return null;
-      }
-      UserImpl.PropertyAccessor accessor = (UserImpl.PropertyAccessor)UserImpl.ACCESSORS.get(key);
-      if (accessor != null)
-      {
-         throw new IllegalArgumentException("Key " + key + " is not removable");
-      }
-      return user.getDynamic().remove(key);
-   }
-
-   /**
-    * Clear only dynamic properties.
-    */
-   public void clear()
-   {
-      user.getDynamic().clear();
-   }
-
-   public Set keySet()
-   {
-      // Get
-      Set set = new HashSet(size());
-
-      //
-      set.addAll(user.getDynamic().keySet());
-      set.addAll(UserImpl.ACCESSORS.keySet());
-      return set;
-   }
-
-   public Collection values()
-   {
-      ArrayList collection = new ArrayList(size());
-      for (Iterator i = UserImpl.ACCESSORS.values().iterator();i.hasNext();)
-      {
-         UserImpl.PropertyAccessor accessor = (UserImpl.PropertyAccessor)i.next();
-         collection.add(accessor.get(user));
-      }
-      collection.addAll(user.getDynamic().values());
-      return collection;
-   }
-
-   /**
-    * Returns an immutable collection of entries.
-    */
-   public Set entrySet()
-   {
-      Map copy = new HashMap(user.getDynamic());
-      for (Iterator i = UserImpl.ACCESSORS.values().iterator();i.hasNext();)
-      {
-         UserImpl.PropertyAccessor accessor = (UserImpl.PropertyAccessor)i.next();
-         copy.put(accessor.getPropertyName(), accessor.get(user));
-      }
-      return Collections.unmodifiableMap(copy).entrySet();
-   }
-
-   public void putAll(Map map)
-   {
-      // todo : check all properties ok with changes before proceeding
-      for (Iterator i = map.entrySet().iterator();i.hasNext();)
-      {
-         Map.Entry entry = (Map.Entry)i.next();
-         Object key = entry.getKey();
-         if (key instanceof String)
-         {
-            Object value = entry.getValue();
-            UserImpl.PropertyAccessor accessor = (UserImpl.PropertyAccessor)UserImpl.ACCESSORS.get(key);
-            if (accessor != null)
-            {
-               if (accessor.isWritable())
-               {
-                  accessor.set(user, (String)value);
-               }
-               else
-               {
-                  // julien : Do something better ?
-               }
-            }
-            else
-            {
-               user.getDynamic().put(key, value);
-            }
-         }
-      }
-   }
-}

Modified: trunk/identity/src/main/org/jboss/portal/identity/db/UserImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity/db/UserImpl.java	2006-09-18 04:21:11 UTC (rev 5217)
+++ trunk/identity/src/main/org/jboss/portal/identity/db/UserImpl.java	2006-09-18 06:37:43 UTC (rev 5218)
@@ -23,7 +23,7 @@
 
 import org.apache.log4j.Logger;
 import org.jboss.portal.identity.User;
-import org.jboss.portal.identity.PropertyMap;
+import org.jboss.portal.identity.ProfileMap;
 import org.jboss.portal.identity.Role;
 import org.jboss.portal.common.p3p.P3PConstants;
 import org.jboss.portal.common.util.LocaleInfo;
@@ -62,7 +62,7 @@
    {
       Map map = new HashMap();
 
-      // Map attributes defined by the JSR 168 spec
+      // Map attributes defined by the JSR 168 spec P3P.
       map.put(P3PConstants.INFO_USER_NAME_NICKNAME, new StringPropertyAccessor(P3PConstants.INFO_USER_NAME_NICKNAME, "userName", false, false));
       map.put(P3PConstants.INFO_USER_BUSINESS_INFO_ONLINE_EMAIL, new StringPropertyAccessor(P3PConstants.INFO_USER_BUSINESS_INFO_ONLINE_EMAIL, "realEmail", true, true));
       map.put(P3PConstants.INFO_USER_NAME_GIVEN, new StringPropertyAccessor(P3PConstants.INFO_USER_NAME_GIVEN, "givenName", true, true));
@@ -77,34 +77,43 @@
       return Collections.unmodifiableMap(map);
    }
 
-   /**
-    * Non mapped.
+   /*
+    * Transient fields.
     */
-   protected Long key;
-   protected boolean enabled;
-   protected String password;
 
-   /**
-    * P3P mapped.
+   protected ProfileMap profile;
+   protected Set roleNames;
+
+   /*
+    * P3P mapped persistent fields.
     */
+
    protected String userName;
    protected String givenName;
    protected String familyName;
    protected String realEmail;
 
-   /**
-    * Extension mapped.
+   /*
+    * Non mapped persistent fields.
     */
+
+   protected Long key;
+   protected boolean enabled;
+   protected String password;
+
+   /*
+    * Extension mapped persistent fields.
+    */
+
    protected String fakeEmail;
    protected boolean viewRealEmail;
    protected Date registrationDate;
 
-   /**
-    * Other fields.
+   /*
+    * Persistent associations
     */
+
    protected Map dynamic;
-   protected PropertyMap properties;
-   protected Set roleNames;
    protected Set roles;
 
    /**
@@ -115,7 +124,7 @@
       this.key = null;
       this.userName = null;
       this.dynamic = null;
-      this.properties = new PropertyMapImpl(this);
+      this.profile = new ProfileMapImpl(this);
       this.roles = null;
       this.registrationDate = null;
       this.enabled = false;
@@ -129,7 +138,7 @@
       this.key = null;
       this.userName = userName;
       this.dynamic = new HashMap();
-      this.properties = new PropertyMapImpl(this);
+      this.profile = new ProfileMapImpl(this);
       this.roles = new HashSet();
       this.registrationDate = new Date();
       this.enabled = false;
@@ -307,9 +316,9 @@
    /**
     *
     */
-   public PropertyMap getProperties()
+   public ProfileMap getProfile()
    {
-      return properties;
+      return profile;
    }
 
    public String getPassword()

Modified: trunk/identity/src/main/org/jboss/portal/test/identity/UserTestCase.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/UserTestCase.java	2006-09-18 04:21:11 UTC (rev 5217)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/UserTestCase.java	2006-09-18 06:37:43 UTC (rev 5218)
@@ -28,7 +28,7 @@
 import org.jboss.portal.identity.db.UserModuleImpl;
 import org.jboss.portal.identity.db.RoleModuleImpl;
 import org.jboss.portal.identity.User;
-import org.jboss.portal.identity.PropertyMap;
+import org.jboss.portal.identity.ProfileMap;
 import org.jboss.portal.common.p3p.P3PConstants;
 import org.apache.log4j.Appender;
 import org.apache.log4j.ConsoleAppender;
@@ -223,7 +223,7 @@
    {
       begin();
       User user = userModule.createUser("testname", "testpassword", "testemail");
-      PropertyMap map = user.getProperties();
+      ProfileMap map = user.getProfile();
       assertNull(map.get("foo"));
       assertFalse(map.isReadOnly("foo"));
       map.put("foo", "value");
@@ -233,7 +233,7 @@
 
       begin();
       user = userModule.findUserByUserName("testname");
-      map = user.getProperties();
+      map = user.getProfile();
       assertEquals("value", map.get("foo"));
       assertFalse(map.isReadOnly("foo"));
       commit();
@@ -245,7 +245,7 @@
 
       //
       User user = userModule.createUser("testname", "testpassword", "testemail");
-      PropertyMap map = user.getProperties();
+      ProfileMap map = user.getProfile();
       assertEquals("testname", map.get(P3PConstants.INFO_USER_NAME_NICKNAME));
 
       // Test cannot remove a static property
@@ -275,7 +275,7 @@
          map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, null);
          fail("Should not be capable to nullify a non nullable static property");
       }
-      catch (IllegalArgumentException expected)
+      catch (NullPointerException expected)
       {
       }
       map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "true");
@@ -297,7 +297,7 @@
       try
       {
          map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "truee");
-         fail("Should not be capable to set the value to boolean static property");
+         fail("Should not be capable to set a bad value to boolean property");
       }
       catch (IllegalArgumentException expected)
       {




More information about the jboss-svn-commits mailing list