View Javadoc

1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.datadictionary.uif;
17  
18  import com.google.common.collect.Maps;
19  import org.kuali.rice.krad.datadictionary.DictionaryBeanBase;
20  
21  import java.util.HashMap;
22  import java.util.Map;
23  
24  /**
25   * Common base class for dictionary objects that can contain dynamic expressions within the
26   * property value
27   *
28   * <p>
29   * Should be extended by other classes to provide property expression support
30   * </p>
31   *
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   */
34  public class UifDictionaryBeanBase extends DictionaryBeanBase implements UifDictionaryBean {
35  
36      private Map<String, String> expressionGraph;
37      private Map<String, String> refreshExpressionGraph;
38      private Map<String, String> propertyExpressions;
39  
40      public UifDictionaryBeanBase() {
41          expressionGraph = new HashMap<String, String>();
42          refreshExpressionGraph = new HashMap<String, String>();
43          propertyExpressions = new HashMap<String, String>();
44      }
45  
46      /**
47       * @see org.kuali.rice.krad.datadictionary.uif.UifDictionaryBean#getExpressionGraph()
48       */
49      public Map<String, String> getExpressionGraph() {
50          return expressionGraph;
51      }
52  
53      /**
54       * @see org.kuali.rice.krad.datadictionary.uif.UifDictionaryBean#setExpressionGraph(java.util.Map<java.lang.String,java.lang.String>)
55       */
56      public void setExpressionGraph(Map<String, String> expressionGraph) {
57          this.expressionGraph = expressionGraph;
58      }
59  
60      /**
61       * @see org.kuali.rice.krad.datadictionary.uif.UifDictionaryBean#getRefreshExpressionGraph()
62       */
63      public Map<String, String> getRefreshExpressionGraph() {
64          return refreshExpressionGraph;
65      }
66  
67      /**
68       * @see org.kuali.rice.krad.datadictionary.uif.UifDictionaryBean#setRefreshExpressionGraph(java.util.Map<java.lang.String,java.lang.String>)
69       */
70      public void setRefreshExpressionGraph(Map<String, String> refreshExpressionGraph) {
71          this.refreshExpressionGraph = refreshExpressionGraph;
72      }
73  
74      /**
75       * @see org.kuali.rice.krad.datadictionary.uif.UifDictionaryBean#getPropertyExpressions
76       */
77      public Map<String, String> getPropertyExpressions() {
78          return propertyExpressions;
79      }
80  
81      /**
82       * @see org.kuali.rice.krad.datadictionary.uif.UifDictionaryBean#setPropertyExpressions
83       */
84      public void setPropertyExpressions(Map<String, String> propertyExpressions) {
85          this.propertyExpressions = propertyExpressions;
86      }
87  
88      /**
89       * @see org.kuali.rice.krad.datadictionary.uif.UifDictionaryBean#getPropertyExpression
90       */
91      public String getPropertyExpression(String propertyName) {
92          if (this.propertyExpressions.containsKey(propertyName)) {
93              return this.propertyExpressions.get(propertyName);
94          }
95  
96          return null;
97      }
98  
99      @Override
100     protected <T> void copyProperties(T dictionaryBaseBean) {
101         super.copyProperties(dictionaryBaseBean);
102         UifDictionaryBeanBase uifDictionaryBeanBaseCopy = (UifDictionaryBeanBase) dictionaryBaseBean;
103 
104         if (expressionGraph != null) {
105             Map<String, String> expressionGraphCopy = Maps.newHashMapWithExpectedSize(this.getExpressionGraph().size());
106             for (Map.Entry expressionGraphEntry : getExpressionGraph().entrySet()) {
107                 expressionGraphCopy.put(expressionGraphEntry.getKey().toString(),
108                         expressionGraphEntry.getValue().toString());
109             }
110 
111             uifDictionaryBeanBaseCopy.setExpressionGraph(expressionGraphCopy);
112         }
113 
114         if (refreshExpressionGraph != null) {
115             Map<String, String> refreshExpressionGraphCopy = Maps.newHashMapWithExpectedSize(
116                     this.getRefreshExpressionGraph().size());
117             for (Map.Entry refreshExpressionGraphEntry : getRefreshExpressionGraph().entrySet()) {
118                 refreshExpressionGraphCopy.put(refreshExpressionGraphEntry.getKey().toString(),
119                         refreshExpressionGraphEntry.getValue().toString());
120             }
121 
122             uifDictionaryBeanBaseCopy.setRefreshExpressionGraph(refreshExpressionGraphCopy);
123         }
124 
125         if (propertyExpressions != null) {
126             Map<String, String> propertyExpressionsCopy = Maps.newHashMapWithExpectedSize(
127                     this.getPropertyExpressions().size());
128             for (Map.Entry propertyExpressionsEntry : getPropertyExpressions().entrySet()) {
129                 propertyExpressionsCopy.put(propertyExpressionsEntry.getKey().toString(),
130                         propertyExpressionsEntry.getValue().toString());
131             }
132 
133             uifDictionaryBeanBaseCopy.setPropertyExpressions(propertyExpressionsCopy);
134         }
135     }
136 }