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;
20  
21  import java.util.Iterator;
22  
23  import javax.faces.FactoryFinder;
24  import javax.faces.event.PhaseEvent;
25  import javax.faces.event.PhaseId;
26  import javax.faces.event.PhaseListener;
27  import javax.faces.lifecycle.LifecycleFactory;
28  
29  import org.apache.myfaces.el.unified.ELResolverBuilder;
30  
31  /**
32   * The class will initialize the resolver for JSP
33   * 
34   * @author Mathias Broekelmann (latest modification by $Author: lu4242 $)
35   * @version $Revision: 1237538 $ $Date: 2012-01-29 22:43:13 -0500 (Sun, 29 Jan 2012) $
36   */
37  public final class ResolverForJSPInitializer implements PhaseListener
38  {
39      private final ELResolverBuilder _resolverBuilder;
40      private volatile boolean initialized;
41      private final javax.el.CompositeELResolver _resolverForJSP;
42  
43      public ResolverForJSPInitializer(final ELResolverBuilder resolverBuilder,
44                                       final javax.el.CompositeELResolver resolverForJSP)
45      {
46          _resolverBuilder = resolverBuilder;
47          _resolverForJSP = resolverForJSP;
48      }
49  
50      public void beforePhase(final PhaseEvent event)
51      {
52          if (!initialized)
53          {
54              synchronized(this)
55              {
56                  if (!initialized)
57                  {
58                      _resolverBuilder.build(_resolverForJSP);
59  
60                      LifecycleFactory factory = (LifecycleFactory) 
61                              FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
62                      for (Iterator<String> iter = factory.getLifecycleIds(); iter.hasNext();)
63                      {
64                          factory.getLifecycle(iter.next()).removePhaseListener(this);
65                      }
66                      
67                      initialized = true;
68                  }
69              }
70          }
71      }
72  
73      public void afterPhase(final PhaseEvent event)
74      {
75      }
76  
77      public PhaseId getPhaseId()
78      {
79          return PhaseId.ANY_PHASE;
80      }
81  
82  }