01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
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.geronimo.myfaces;
21:
22: import java.util.Map;
23: import java.util.concurrent.ConcurrentHashMap;
24:
25: import javax.faces.context.ExternalContext;
26:
27: import org.apache.myfaces.config.annotation.LifecycleProvider;
28: import org.apache.myfaces.config.annotation.LifecycleProviderFactory;
29:
30: /**
31: * @version $Rev: 518223 $ $Date: 2007-03-14 10:14:58 -0700 (Wed, 14 Mar 2007) $
32: */
33: public class ApplicationIndexedLifecycleProviderFactory extends
34: LifecycleProviderFactory {
35:
36: private final Map<ClassLoader, LifecycleProvider> providers = new ConcurrentHashMap<ClassLoader, LifecycleProvider>();
37:
38: public LifecycleProvider getLifecycleProvider(
39: ExternalContext externalContext) {
40: ClassLoader cl = Thread.currentThread().getContextClassLoader();
41: LifecycleProvider provider = providers.get(cl);
42: if (provider == null) {
43: throw new IllegalStateException(
44: "No LifecycleProvider registered for application classloader: "
45: + cl);
46: }
47: return provider;
48: }
49:
50: /**
51: * Register a lifecycle provider for an application classloader. This method is intended to be called
52: * by the container in which MyFaces is running, once for each application, during application startup before
53: * any other myfaces initialization has taken place.
54: *
55: * @param cl application classloader, used to index LifecycleProviders
56: * @param provider LifecycleProvider for the application.
57: */
58: public void registerLifecycleProvider(ClassLoader cl,
59: LifecycleProvider provider) {
60: providers.put(cl, provider);
61: }
62:
63: public void unregisterLifecycleProvider(ClassLoader cl) {
64: providers.remove(cl);
65: }
66:
67: public void release() {
68: providers.clear();
69: }
70:
71: }
|