Esempio n. 1
3
 private Object removeFromMap(Serializable key, String mapKey) {
   Object ret = null;
   if (component.initialStateMarked()) {
     Map<String, Object> dMap = (Map<String, Object>) deltaMap.get(key);
     if (dMap != null) {
       ret = dMap.remove(mapKey);
       if (dMap.isEmpty()) {
         deltaMap.remove(key);
       }
     }
   }
   Map<String, Object> map = (Map<String, Object>) get(key);
   if (map != null) {
     if (ret == null) {
       ret = map.remove(mapKey);
     } else {
       map.remove(mapKey);
     }
     if (map.isEmpty()) {
       defaultMap.remove(key);
     }
   }
   if (ret != null && !component.initialStateMarked()) {
     deltaMap.remove(key);
   }
   return ret;
 }
Esempio n. 2
0
 /**
  * One and only implementation of save-state - makes all other implementations unnecessary.
  *
  * @param context
  * @return the saved state
  */
 public Object saveState(FacesContext context) {
   if (component.initialStateMarked()) {
     return saveMap(deltaMap);
   } else {
     return saveMap(defaultMap);
   }
 }
Esempio n. 3
0
  /**
   * We need to remove from both maps, if we do remove an existing key.
   *
   * @param key
   * @return the removed object in the delta-map. if not present, the removed object from the main
   *     map
   */
  public Object remove(Serializable key) {
    if (component.initialStateMarked()) {
      Object retVal = deltaMap.remove(key);

      if (retVal == null) {
        return defaultMap.remove(key);
      } else {
        defaultMap.remove(key);
        return retVal;
      }
    } else {
      return defaultMap.remove(key);
    }
  }
Esempio n. 4
0
  /**
   * Put the object in the main-map and/or the delta-map, if necessary.
   *
   * @param key
   * @param value
   * @return the original value in the delta-map, if not present, the old value in the main map
   */
  public Object put(Serializable key, Object value) {

    if (component.initialStateMarked() || value instanceof PartialStateHolder) {
      Object retVal = deltaMap.put(key, value);

      if (retVal == null) {
        return defaultMap.put(key, value);
      } else {
        defaultMap.put(key, value);
        return retVal;
      }
    } else {
      return defaultMap.put(key, value);
    }
  }
Esempio n. 5
0
  public void add(Serializable key, Object value) {

    if (component.initialStateMarked() || value instanceof PartialStateHolder) {
      List<Object> deltaList = (List<Object>) deltaMap.get(key);
      if (deltaList == null) {
        deltaList = new ArrayList<Object>(4);
        deltaMap.put(key, deltaList);
      }
      deltaList.add(value);
    }
    List<Object> items = (List<Object>) get(key);
    if (items == null) {
      items = new ArrayList<Object>(4);
      defaultMap.put(key, items);
    }
    items.add(value);
  }
Esempio n. 6
0
  private Object saveMap(Map<Serializable, Object> map) {

    FacesContext fc = FacesContext.getCurrentInstance();

    Object[] savedState = new Object[map.size() * 2 + 1];

    int i = 0;

    for (Map.Entry<Serializable, Object> entry : map.entrySet()) {
      Object value = entry.getValue();
      if (value == null) {
        value = Void.TYPE;
      }
      savedState[i * 2] = entry.getKey();
      if (value instanceof Collection) {
        value = saveAttachedState(fc, value);
      }
      savedState[i * 2 + 1] = value instanceof Serializable ? value : saveAttachedState(fc, value);
      i++;
    }
    savedState[savedState.length - 1] = component.initialStateMarked();
    return savedState;
  }
Esempio n. 7
0
  public Object put(Serializable key, String mapKey, Object value) {

    Object ret = null;
    if (component.initialStateMarked() || value instanceof PartialStateHolder) {
      Map<String, Object> dMap = (Map<String, Object>) deltaMap.get(key);
      if (dMap == null) {
        dMap = new HashMap<String, Object>(5);
        deltaMap.put(key, dMap);
      }
      ret = dMap.put(mapKey, value);
    }
    Map<String, Object> map = (Map<String, Object>) get(key);
    if (map == null) {
      map = new HashMap<String, Object>(8);
      defaultMap.put(key, map);
    }
    if (ret == null) {
      return map.put(mapKey, value);
    } else {
      map.put(mapKey, value);
      return ret;
    }
  }
Esempio n. 8
0
 private Object removeFromList(Serializable key, Object value) {
   Object ret = null;
   if (component.initialStateMarked() || value instanceof PartialStateHolder) {
     Collection<Object> deltaList = (Collection<Object>) deltaMap.get(key);
     if (deltaList != null) {
       ret = deltaList.remove(value);
       if (deltaList.isEmpty()) {
         deltaMap.remove(key);
       }
     }
   }
   Collection<Object> list = (Collection<Object>) get(key);
   if (list != null) {
     if (ret == null) {
       ret = list.remove(value);
     } else {
       list.remove(value);
     }
     if (list.isEmpty()) {
       defaultMap.remove(key);
     }
   }
   return ret;
 }