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.el.unified;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  import javax.el.ArrayELResolver;
25  import javax.el.BeanELResolver;
26  import javax.el.CompositeELResolver;
27  import javax.el.ELResolver;
28  import javax.el.ListELResolver;
29  import javax.el.MapELResolver;
30  import javax.el.ResourceBundleELResolver;
31  
32  import org.apache.myfaces.config.RuntimeConfig;
33  import org.apache.myfaces.el.FlashELResolver;
34  import org.apache.myfaces.el.unified.resolver.CompositeComponentELResolver;
35  import org.apache.myfaces.el.unified.resolver.ManagedBeanResolver;
36  import org.apache.myfaces.el.unified.resolver.ResourceBundleResolver;
37  import org.apache.myfaces.el.unified.resolver.ResourceResolver;
38  import org.apache.myfaces.el.unified.resolver.ScopedAttributeResolver;
39  import org.apache.myfaces.el.unified.resolver.implicitobject.ImplicitObjectResolver;
40  
41  /**
42   * Create the el resolver for faces. see 1.2 spec section 5.6.2
43   * 
44   * @author Mathias Broekelmann (latest modification by $Author: jakobk $)
45   * @version $Revision: 985940 $ $Date: 2010-08-16 09:07:28 -0500 (Mon, 16 Aug 2010) $
46   */
47  public class ResolverBuilderForFaces extends ResolverBuilderBase implements ELResolverBuilder
48  {
49      public ResolverBuilderForFaces(RuntimeConfig config)
50      {
51          super(config);
52      }
53  
54      public void build(CompositeELResolver compositeElResolver)
55      {
56          // add the ELResolvers to a List first to be able to sort them
57          List<ELResolver> list = new ArrayList<ELResolver>();
58          
59          list.add(ImplicitObjectResolver.makeResolverForFaces());
60          list.add(new CompositeComponentELResolver());
61  
62          addFromRuntimeConfig(list);
63  
64          //Flash object is instanceof Map, so it is necessary to resolve
65          //before MapELResolver. Better to put this one before
66          list.add(new FlashELResolver());
67          list.add(new ManagedBeanResolver());
68          list.add(new ResourceResolver());
69          list.add(new ResourceBundleELResolver());
70          list.add(new ResourceBundleResolver());
71          list.add(new MapELResolver());
72          list.add(new ListELResolver());
73          list.add(new ArrayELResolver());
74          list.add(new BeanELResolver());
75          
76          // give the user a chance to sort the resolvers
77          sortELResolvers(list);
78          
79          // add the resolvers from the list to the CompositeELResolver
80          for (ELResolver resolver : list)
81          {
82              compositeElResolver.add(resolver);
83          }
84          
85          // the ScopedAttributeResolver has to be the last one in every
86          // case, because it always sets propertyResolved to true (per the spec)
87          compositeElResolver.add(new ScopedAttributeResolver());
88      }
89  
90  }