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: 1236890 $ $Date: 2012-01-27 16:19:09 -0500 (Fri, 27 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, final javax.el.CompositeELResolver resolverForJSP)
44      {
45          _resolverBuilder = resolverBuilder;
46          _resolverForJSP = resolverForJSP;
47      }
48  
49      public void beforePhase(final PhaseEvent event)
50      {
51          if (!initialized)
52          {
53              synchronized(this)
54              {
55                  if (!initialized)
56                  {
57                      _resolverBuilder.build(_resolverForJSP);
58  
59                      LifecycleFactory factory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
60                      for (Iterator<String> iter = factory.getLifecycleIds(); iter.hasNext();)
61                      {
62                          factory.getLifecycle(iter.next()).removePhaseListener(this);
63                      }
64                      
65                      initialized = true;
66                  }
67              }
68          }
69      }
70  
71      public void afterPhase(final PhaseEvent event)
72      {
73      }
74  
75      public PhaseId getPhaseId()
76      {
77          return PhaseId.ANY_PHASE;
78      }
79  
80  }