View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.flow;
20  
21  import java.util.Collections;
22  import java.util.HashMap;
23  import java.util.Map;
24  import javax.el.ValueExpression;
25  import javax.faces.context.FacesContext;
26  import javax.faces.flow.FlowCallNode;
27  import javax.faces.flow.Parameter;
28  
29  /**
30   *
31   * @since 2.2
32   * @author Leonardo Uribe
33   */
34  public class FlowCallNodeImpl extends FlowCallNode implements Freezable
35  {
36      private String _id;
37      private String _calledFlowId;
38      private ValueExpression _calledFlowIdEL;
39      private String _calledFlowDocumentId;
40      private ValueExpression _calledFlowDocumentIdEL;
41      
42      private Map<String, Parameter> _outboundParametersMap;
43      private Map<String, Parameter> _unmodifiableOutboundParametersMap;
44      
45      private boolean _initialized;
46  
47      public FlowCallNodeImpl(String id)
48      {
49          this._id = id;
50          _outboundParametersMap = new HashMap<String, Parameter>();
51          _unmodifiableOutboundParametersMap = Collections.unmodifiableMap(_outboundParametersMap);
52      }
53      
54      @Override
55      public Map<String, Parameter> getOutboundParameters()
56      {
57          return _unmodifiableOutboundParametersMap;
58      }
59      
60      public void putOutboundParameter(String key, Parameter value)
61      {
62          checkInitialized();
63          _outboundParametersMap.put(key, value);
64      }
65  
66      @Override
67      public String getCalledFlowDocumentId(FacesContext context)
68      {
69          if (_calledFlowDocumentIdEL != null)
70          {
71              return (String) _calledFlowDocumentIdEL.getValue(context.getELContext());
72          }
73          return _calledFlowDocumentId;
74      }
75  
76      @Override
77      public String getCalledFlowId(FacesContext context)
78      {
79          if (_calledFlowIdEL != null)
80          {
81              return (String) _calledFlowIdEL.getValue(context.getELContext());
82          }
83          return _calledFlowId;
84      }
85  
86      @Override
87      public String getId()
88      {
89          return _id;
90      }
91  
92      public void setId(String id)
93      {
94          checkInitialized();
95          this._id = id;
96      }
97  
98      public void setCalledFlowId(String calledFlowId)
99      {
100         checkInitialized();
101         this._calledFlowId = calledFlowId;
102         this._calledFlowIdEL = null;
103     }
104 
105     public void setCalledFlowDocumentId(String calledFlowDocumentId)
106     {
107         checkInitialized();
108         this._calledFlowDocumentId = calledFlowDocumentId;
109         this._calledFlowDocumentIdEL = null;
110     }
111     
112     public void freeze()
113     {
114         _initialized = true;
115         
116         for (Map.Entry<String, Parameter> entry : _outboundParametersMap.entrySet())
117         {
118             if (entry.getValue() instanceof Freezable)
119             {
120                 ((Freezable)entry.getValue()).freeze();
121             }
122         }
123     }
124     
125     private void checkInitialized() throws IllegalStateException
126     {
127         if (_initialized)
128         {
129             throw new IllegalStateException("Flow is inmutable once initialized");
130         }
131     }
132 
133     /**
134      * @param calledFlowIdEL the _calledFlowIdEL to set
135      */
136     public void setCalledFlowId(ValueExpression calledFlowIdEL)
137     {
138         this._calledFlowIdEL = calledFlowIdEL;
139         this._calledFlowId = null;
140     }
141 
142     /**
143      * @param calledFlowDocumentIdEL the _calledFlowDocumentIdEL to set
144      */
145     public void setCalledFlowDocumentId(ValueExpression calledFlowDocumentIdEL)
146     {
147         this._calledFlowDocumentIdEL = calledFlowDocumentIdEL;
148         this._calledFlowDocumentId = null;
149     }
150 }