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 javax.el.ValueExpression;
22  import javax.faces.flow.builder.SwitchCaseBuilder;
23  import org.apache.myfaces.flow.FlowImpl;
24  import org.apache.myfaces.flow.SwitchCaseImpl;
25  import org.apache.myfaces.flow.SwitchNodeImpl;
26  import org.apache.myfaces.view.facelets.el.ELText;
27  
28  /**
29   *
30   * @since 2.2
31   * @author Leonardo Uribe
32   */
33  public class SwitchCaseBuilderImpl extends SwitchCaseBuilder
34  {
35      private FlowBuilderImpl _flowBuilder;
36      private FlowImpl _facesFlow;
37      private SwitchBuilderImpl _switchBuilderImpl;
38      private SwitchNodeImpl _switchNodeImpl;
39      private SwitchCaseImpl _switchCase;
40  
41      public SwitchCaseBuilderImpl(FlowBuilderImpl flowBuilder, FlowImpl facesFlow, 
42          SwitchBuilderImpl switchBuilderImpl, SwitchNodeImpl switchNode)
43      {
44          this._flowBuilder = flowBuilder;
45          this._facesFlow = facesFlow;
46          this._switchBuilderImpl = switchBuilderImpl;
47          this._switchNodeImpl = switchNode;
48          this._switchCase = null;
49      }
50      
51      @Override
52      public SwitchCaseBuilder condition(String expression)
53      {
54          if (ELText.isLiteral(expression))
55          {
56              this._switchCase.setCondition(Boolean.valueOf(expression));
57          }
58          else
59          {
60              this._switchCase.setCondition(_flowBuilder.createValueExpression(expression));
61          }
62          return this;
63      }
64  
65      @Override
66      public SwitchCaseBuilder condition(ValueExpression expression)
67      {
68          this._switchCase.setCondition(expression);
69          return this;
70      }
71  
72      @Override
73      public SwitchCaseBuilder fromOutcome(String outcome)
74      {
75          this._switchCase.setFromOutcome(outcome);
76          return this;
77      }
78  
79      @Override
80      public SwitchCaseBuilder switchCase()
81      {
82          this._switchCase =  new SwitchCaseImpl();
83          this._switchNodeImpl.addCase(this._switchCase);
84          return this;
85      }
86  }