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  
20  package org.apache.myfaces.tobago.internal.lifecycle;
21  
22  import org.slf4j.Logger;
23  import org.slf4j.LoggerFactory;
24  
25  import javax.faces.lifecycle.Lifecycle;
26  import javax.faces.lifecycle.LifecycleFactory;
27  import java.util.Iterator;
28  
29  public class TobagoLifecycleFactory extends LifecycleFactory {
30  
31    private static final Logger LOG = LoggerFactory.getLogger(TobagoLifecycleFactory.class);
32  
33    private LifecycleFactory factory;
34    private TobagoLifecycle defaultLifecycle;
35  
36    public TobagoLifecycleFactory(LifecycleFactory factory) {
37      this.factory = factory;
38      defaultLifecycle = new TobagoLifecycle();
39      if (LOG.isInfoEnabled()) {
40        LOG.info("new TobagoLifecycleFactory");
41      }
42    }
43  
44    public void addLifecycle(String lifecycleId, Lifecycle lifecycle) {
45      factory.addLifecycle(lifecycleId, lifecycle);
46      if (LOG.isInfoEnabled()) {
47        LOG.info("Lifecycle added : " + lifecycleId + " = " + lifecycle.getClass().getName() + "");
48      }
49    }
50  
51    public Lifecycle getLifecycle(String lifecycleId) {
52      if (LifecycleFactory.DEFAULT_LIFECYCLE.equals(lifecycleId)) {
53        if (LOG.isInfoEnabled()) {
54          LOG.info("getLifecycle(\"" + lifecycleId + "\")  -> TobagoLifecycle");
55        }
56        return defaultLifecycle;
57      } else {
58        if (LOG.isInfoEnabled()) {
59          LOG.info("getLifecycle(\"" + lifecycleId + "\")  -> other Lifecycle");
60        }
61        return factory.getLifecycle(lifecycleId);
62      }
63    }
64  
65    public Iterator getLifecycleIds() {
66      if (LOG.isInfoEnabled()) {
67        LOG.info("getLifecycleIds()");
68      }
69      return factory.getLifecycleIds();
70    }
71  }