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.orchestra.flow.config;
20  
21  import java.io.Serializable;
22  
23  import javax.el.ValueExpression;
24  import javax.faces.context.FacesContext;
25  
26  import org.apache.myfaces.orchestra.flow.utils._ExpressionFactory;
27  import org.apache.myfaces.orchestra.lib.OrchestraException;
28  
29  /**
30   * Defines an "exported" parameter, from the point of view of the
31   * flow caller.
32   */
33  public class FlowParamSend implements Serializable
34  {
35      // For serialization. IMPORTANT; update this when changing the
36      // binary format of this class (eg adding fields).
37      private static final long serialVersionUID = 2L;
38  
39      private String name;
40      private String src;
41      private ValueExpression srcExpr;
42  
43      /** Constructor. */
44      public FlowParamSend()
45      {
46      }
47  
48      /**
49       * Check that all the properties of this object have valid values, ie
50       * whether the configuration specified by the user is valid.
51       */
52      public void validate()
53      {
54          if (name == null)
55          {
56              throw new OrchestraException("name is null");
57          }
58  
59          if (src == null)
60          {
61              throw new OrchestraException("src is null");
62          }
63      }
64  
65      /**
66       * Define the name of this parameter.
67       * <p>
68       * The called flow is expected to define a parameter with a matching name;
69       * <p> 
70       * Null is never returned.
71       */
72      public String getName()
73      {
74          return name;
75      }
76  
77      /** For use only during object initialization. */
78      public void setName(String name)
79      {
80          this.name = name;
81      }
82  
83      /**
84       * An EL expression which defines where the actual value passed by the caller
85       * should be fetched from when the call occurs.
86       * <p>
87       * Null is never returned.
88       */
89      public String getSrc()
90      {
91          return src;
92      }
93  
94      /** For use only during object initialization. */
95      public void setSrc(String expr)
96      {
97          this.src = expr;
98  
99          FacesContext fc = FacesContext.getCurrentInstance();
100         srcExpr = _ExpressionFactory.createValueExpression(fc, src);
101     }
102 
103     /**
104      * Evaluate the src EL expression and return the resulting object (or null).
105      */
106     public Object getSrcValue(FacesContext facesContext)
107     {
108         return srcExpr.getValue(facesContext.getELContext());
109     }
110 }