View Javadoc

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  public class MemoryPropertySetFactory implements PropertySetFactory
19  {
20      private static final String MEMORY_PROPERTY_SET = "memory";
21  
22      private final Map<String, PropertySet> propertySets = new HashMap<String, PropertySet>();
23  
24      /**
25       * @param entity - the instance of {@link com.atlassian.user.Entity} for which a {@link com.opensymphony.module.propertyset.PropertySet} should be
26       *               retrieved.
27       * @return an instance of {@link com.opensymphony.module.propertyset.PropertySet} for the {@link com.atlassian.user.Entity}, otherwise null.
28       */
29      public PropertySet getPropertySet(Entity entity) throws EntityException
30      {
31          if (entity == null) throw new IllegalArgumentException("Cannot generate a propertyset for a null entity"); 
32  
33          PropertySet propertySet = propertySets.get(entity.getName());
34  
35          if (propertySet != null)
36              return propertySet;
37  
38          HashMap<String, Object> args = new HashMap<String, Object>();
39          args.put("entityName",  "_" + entity.getName());
40  
41          propertySet = PropertySetManager.getInstance(MEMORY_PROPERTY_SET, args);
42  
43          propertySets.put(entity.getName(), propertySet);
44  
45          return propertySet;
46      }
47  }