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.uif.lifecycle.model;
17  
18  import java.util.Map;
19  
20  import org.kuali.rice.krad.uif.UifConstants;
21  import org.kuali.rice.krad.uif.layout.LayoutManager;
22  import org.kuali.rice.krad.uif.lifecycle.ApplyModelComponentPhase;
23  import org.kuali.rice.krad.uif.lifecycle.ViewLifecyclePhase;
24  import org.kuali.rice.krad.uif.lifecycle.ViewLifecycleTaskBase;
25  import org.kuali.rice.krad.uif.util.LifecycleElement;
26  
27  /**
28  * * Push attributes to the component context.
29   * 
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  public class PopulateComponentContextTask extends ViewLifecycleTaskBase<LifecycleElement> {
33  
34      /**
35       * Constructor.
36       * 
37       * @param phase The apply model phase for the component.
38       */
39      public PopulateComponentContextTask(ViewLifecyclePhase phase) {
40          super(phase, LifecycleElement.class);
41      }
42  
43      /**
44       * {@inheritDoc}
45       */
46      @Override
47      public ApplyModelComponentPhase getElementState() {
48          return (ApplyModelComponentPhase) super.getElementState();
49      }
50  
51      /**
52       * {@inheritDoc}
53       */
54      @Override
55      protected void performLifecycleTask() {
56          LifecycleElement element = getElementState().getElement();
57          LifecycleElement parent = getElementState().getParent();
58         
59          Map<String, Object> commonContext = getElementState().getCommonContext();
60          
61          if (parent != null) {
62              element.pushObjectToContext(UifConstants.ContextVariableNames.PARENT, parent);
63          }
64  
65          // set context on component for evaluating expressions
66          element.pushAllToContext(commonContext);
67  
68          // set context evaluate expressions on the layout manager
69          if (element instanceof LayoutManager) {
70              element.pushObjectToContext(UifConstants.ContextVariableNames.MANAGER, element);
71          }
72      }
73  
74  }