View Javadoc

1   /*
2    * $Id: AbstractPropertiesAccessor.java,v 1.18 2011/06/16 09:29:40 jbmeslin Exp $
3    */
4   package org.rcfaces.core.internal.component;
5   
6   import java.util.HashMap;
7   import java.util.Iterator;
8   import java.util.Map;
9   import java.util.Set;
10  
11  import javax.faces.context.FacesContext;
12  
13  import org.apache.commons.logging.Log;
14  import org.apache.commons.logging.LogFactory;
15  import org.rcfaces.core.model.ICommitableObject;
16  
17  /**
18   * 
19   * @author Olivier Oeuillot (latest modification by $Author: jbmeslin $)
20   * @version $Revision: 1.18 $ $Date: 2011/06/16 09:29:40 $
21   */
22  public abstract class AbstractPropertiesAccessor implements IPropertiesAccessor {
23      private static final String REVISION = "$Revision: 1.18 $";
24  
25      private static final Log LOG = LogFactory
26              .getLog(AbstractPropertiesAccessor.class);
27  
28      private static final boolean debugEnabled = LOG.isDebugEnabled();
29  
30      protected Map createMap(int size) {
31          return new HashMap(size);
32      }
33  
34      public IDeltaPropertiesAccessor createDeltaPropertiesAccessor() {
35          return new BasicDeltaPropertiesAccessor(this);
36      }
37  
38      public void putAll(FacesContext context, Set entries, Object undefinedValue) {
39          for (Iterator it = entries.iterator(); it.hasNext();) {
40              Map.Entry entry = (Map.Entry) it.next();
41  
42              String key = (String) entry.getKey();
43              Object value = entry.getValue();
44  
45              if (value == undefinedValue) {
46                  value = null;
47  
48              } else if (value instanceof ICommitableObject) {
49                  ICommitableObject commitableObject = (ICommitableObject) value;
50  
51                  if (commitableObject.isCommited() == false) {
52                      if (debugEnabled) {
53                          LOG.debug("Commit object '" + commitableObject + "'.");
54                      }
55  
56                      commitableObject.commit();
57                  }
58              }
59  
60              setProperty(context, key, value);
61          }
62      }
63  }