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.SwitchBuilder;
23  import javax.faces.flow.builder.SwitchCaseBuilder;
24  import org.apache.myfaces.flow.FlowImpl;
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 SwitchBuilderImpl extends SwitchBuilder
34  {
35      private FlowBuilderImpl _flowBuilder;
36      private FlowImpl _facesFlow;
37      private SwitchNodeImpl _switchNodeImpl;
38      private SwitchCaseBuilderImpl _lastSwitchCaseBuilderImpl;
39  
40      public SwitchBuilderImpl(FlowBuilderImpl flowBuilder, FlowImpl facesFlow, String switchNodeId)
41      {
42          this._flowBuilder = flowBuilder;
43          this._facesFlow = facesFlow;
44          this._switchNodeImpl = new SwitchNodeImpl(switchNodeId);
45          this._facesFlow.putSwitch(switchNodeId, _switchNodeImpl);
46          this._lastSwitchCaseBuilderImpl = new SwitchCaseBuilderImpl(
47              this._flowBuilder, this._facesFlow, this, this._switchNodeImpl);
48      }
49  
50      @Override
51      public SwitchCaseBuilder switchCase()
52      {
53          return this._lastSwitchCaseBuilderImpl.switchCase();
54      }
55  
56      @Override
57      public SwitchCaseBuilder defaultOutcome(String outcome)
58      {
59          if (ELText.isLiteral(outcome))
60          {
61              this._switchNodeImpl.setDefaultOutcome(outcome);
62          }
63          else
64          {
65              this._switchNodeImpl.setDefaultOutcome(_flowBuilder.createValueExpression(outcome));
66          }
67          return _lastSwitchCaseBuilderImpl;
68      }
69  
70      @Override
71      public SwitchCaseBuilder defaultOutcome(ValueExpression outcome)
72      {
73          this._switchNodeImpl.setDefaultOutcome(outcome);
74          return _lastSwitchCaseBuilderImpl;
75      }
76  
77      @Override
78      public SwitchBuilder markAsStartNode()
79      {
80          _facesFlow.setStartNodeId(_switchNodeImpl.getId());
81          return this;
82      }    
83  }