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.builder;
20  
21  import java.util.List;
22  import javax.el.MethodExpression;
23  import javax.el.ValueExpression;
24  import javax.faces.flow.Parameter;
25  import javax.faces.flow.builder.MethodCallBuilder;
26  import org.apache.myfaces.flow.FlowImpl;
27  import org.apache.myfaces.flow.MethodCallNodeImpl;
28  
29  /**
30   *
31   * @since 2.2
32   * @author Leonardo Uribe
33   */
34  public class MethodCallBuilderImpl extends MethodCallBuilder
35  {
36      private FlowImpl _facesFlow;
37      private MethodCallNodeImpl _methodCallNode;
38      private FlowBuilderImpl _flowBuilder;
39  
40      public MethodCallBuilderImpl(FlowBuilderImpl flowBuilder, FlowImpl facesFlow, String methodCallNodeId)
41      {
42          this._flowBuilder = flowBuilder;
43          this._facesFlow = facesFlow;
44          this._methodCallNode = new MethodCallNodeImpl(methodCallNodeId);
45          this._facesFlow.addMethodCall(_methodCallNode);
46      }
47  
48      @Override
49      public MethodCallBuilder expression(MethodExpression me)
50      {
51          this._methodCallNode.setMethodExpression(me);
52          return this;
53      }
54  
55      @Override
56      public MethodCallBuilder expression(String methodExpression)
57      {
58          this._methodCallNode.setMethodExpression(
59              _flowBuilder.createMethodExpression(methodExpression));
60          return this;
61      }
62  
63      @Override
64      public MethodCallBuilder expression(String methodExpression, Class[] paramTypes)
65      {
66          this._methodCallNode.setMethodExpression(
67              _flowBuilder.createMethodExpression(methodExpression, paramTypes));
68          return this;
69      }
70  
71      @Override
72      public MethodCallBuilder parameters(List<Parameter> parameters)
73      {
74          for (Parameter p : parameters)
75          {
76              this._methodCallNode.addParameter(p);
77          }
78          return this;
79      }
80  
81      @Override
82      public MethodCallBuilder defaultOutcome(String outcome)
83      {
84          this._methodCallNode.setOutcome(
85              this._flowBuilder.createValueExpression(outcome));
86          return this;
87      }
88  
89      @Override
90      public MethodCallBuilder defaultOutcome(ValueExpression outcome)
91      {
92          this._methodCallNode.setOutcome(outcome);
93          return this;
94      }
95  
96      @Override
97      public MethodCallBuilder markAsStartNode()
98      {
99          _facesFlow.setStartNodeId(_methodCallNode.getId());
100         return this;
101     }
102     
103 }