1   package com.atlassian.user.impl.memory.properties;
2   
3   
4   import com.atlassian.user.Entity;
5   import com.atlassian.user.EntityException;
6   import com.atlassian.user.properties.PropertySetFactory;
7   import com.opensymphony.module.propertyset.PropertySet;
8   import com.opensymphony.module.propertyset.PropertySetManager;
9   
10  import java.util.HashMap;
11  import java.util.Map;
12  
13  /**
14   * Provides memory propertysets and keeps track of them.
15   *
16   * A real implementation would split the persistence from the factory.
17   *
18   * @deprecated since 2.2 because it should not be used in production. Will be moved to test code in 3.0.
19   */
20  public class MemoryPropertySetFactory implements PropertySetFactory
21  {
22      private static final String MEMORY_PROPERTY_SET = "memory";
23  
24      private final Map<String, PropertySet> propertySets = new HashMap<String, PropertySet>();
25  
26      /**
27       * @param entity - the instance of {@link com.atlassian.user.Entity} for which a {@link com.opensymphony.module.propertyset.PropertySet} should be
28       *               retrieved.
29       * @return an instance of {@link com.opensymphony.module.propertyset.PropertySet} for the {@link com.atlassian.user.Entity}, otherwise null.
30       */
31      public PropertySet getPropertySet(Entity entity) throws EntityException
32      {
33          if (entity == null) throw new IllegalArgumentException("Cannot generate a propertyset for a null entity"); 
34  
35          PropertySet propertySet = propertySets.get(entity.getName());
36  
37          if (propertySet != null)
38              return propertySet;
39  
40          HashMap<String, Object> args = new HashMap<String, Object>();
41          args.put("entityName",  "_" + entity.getName());
42  
43          propertySet = PropertySetManager.getInstance(MEMORY_PROPERTY_SET, args);
44  
45          propertySets.put(entity.getName(), propertySet);
46  
47          return propertySet;
48      }
49  }