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.ArrayList;
22  import java.util.Collections;
23  import java.util.List;
24  import javax.el.MethodExpression;
25  import javax.el.ValueExpression;
26  import javax.faces.flow.MethodCallNode;
27  import javax.faces.flow.Parameter;
28  
29  /**
30   *
31   * @since 2.2
32   * @author Leonardo Uribe
33   */
34  public class MethodCallNodeImpl extends MethodCallNode implements Freezable
35  {
36      private String _id;
37      private MethodExpression _methodExpression;
38      private ValueExpression _outcome;
39      
40      private List<Parameter> _parameters;
41      private List<Parameter> _unmodifiableParameters;
42      
43      private boolean _initialized;
44      
45      public MethodCallNodeImpl(String methodCallNodeId)
46      {
47          this._id = methodCallNodeId;
48          _parameters = new ArrayList<Parameter>();
49          _unmodifiableParameters = Collections.unmodifiableList(_parameters);
50      }
51  
52      @Override
53      public MethodExpression getMethodExpression()
54      {
55          return _methodExpression;
56      }
57  
58      @Override
59      public ValueExpression getOutcome()
60      {
61          return _outcome;
62      }
63  
64      @Override
65      public List<Parameter> getParameters()
66      {
67          return _unmodifiableParameters;
68      }
69      
70      public void addParameter(Parameter parameter)
71      {
72          checkInitialized();
73          _parameters.add(parameter);
74      }
75  
76      @Override
77      public String getId()
78      {
79          return _id;
80      }
81      
82      public void freeze()
83      {
84          _initialized = true;
85          
86          for (Parameter value : _parameters)
87          {
88              if (value instanceof Freezable)
89              {
90                  ((Freezable)value).freeze();
91              }
92          }
93      }
94      
95      private void checkInitialized() throws IllegalStateException
96      {
97          if (_initialized)
98          {
99              throw new IllegalStateException("Flow is inmutable once initialized");
100         }
101     }
102 
103     public void setMethodExpression(MethodExpression methodExpression)
104     {
105         checkInitialized();
106         this._methodExpression = methodExpression;
107     }
108 
109     public void setOutcome(ValueExpression outcome)
110     {
111         checkInitialized();
112         this._outcome = outcome;
113     }
114 
115     public void setId(String id)
116     {
117         checkInitialized();
118         this._id = id;
119     }
120 }