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.orchestra;
21
22 import org.apache.myfaces.orchestra.conversation.ConversationContextFactory;
23 import org.apache.myfaces.orchestra.conversation.ConversationManagerFactory;
24 import org.apache.myfaces.orchestra.conversation.ConversationManagerFactoryImpl;
25 import org.apache.myfaces.orchestra.frameworkAdapter.FrameworkAdapter;
26
27 import org.apache.myfaces.orchestra.conversation.ConversationContextFactoryImpl;
28
29 /**
30 * A factory of factory classes, just like the JSF javax.faces.FactoryFinder class.
31 * <p>
32 * This class ensures that the user can configure their own instances of the critical
33 * orchestra factory classes by defining beans with appropriate names in the dependency
34 * injection framework. Orchestra code should always use the factory-finder methods
35 * here when creating object instances, instead of the "new" operator.
36 * <p>
37 * The factory classes returned here should all be thread-safe; they are effectively
38 * "application scoped" objects.
39 */
40 public class FactoryFinder
41 {
42 // The key of an optional bean that the user can define in the DI framework to override
43 // the settings of the ConversationManagerFactory used by Orchestra.
44 public static final String CONVERSATION_MANAGER_FACTORY_KEY
45 = ConversationManagerFactory.class.getName();
46
47 // The key of an optional bean that the user can define in the DI framework to override
48 // the settings of the ConversationContextFactory used by Orchestra.
49 public static final String CONVERSATION_CONTEXT_FACTORY_KEY
50 = ConversationContextFactory.class.getName();
51
52 private static final ConversationManagerFactory CONVERSATION_MANAGER_FACTORY_DFLT
53 = new ConversationManagerFactoryImpl();
54
55 private static final ConversationContextFactory CONVERSATION_CONTEXT_FACTORY_DFLT
56 = new ConversationContextFactoryImpl();
57
58 /**
59 * Return an object that implements interface ConversationManagerFactory.
60 * <p>
61 * Normally, the returned object will be an instance of ConversationManagerFactoryImpl.
62 */
63 public static ConversationManagerFactory getConversationManagerFactory()
64 {
65 FrameworkAdapter fa = FrameworkAdapter.getCurrentInstance();
66 ConversationManagerFactory factory = (ConversationManagerFactory) fa.getBean(
67 CONVERSATION_MANAGER_FACTORY_KEY);
68
69 if (factory == null)
70 {
71 factory = CONVERSATION_MANAGER_FACTORY_DFLT;
72 }
73
74 return factory;
75 }
76
77 /**
78 * Return an object that implements interface ConversationContextFactory.
79 * <p>
80 * Normally, the returned object will be an instance of ConversationContextFactoryImpl.
81 * However users can configure a bean in the DI framework to specify a different class - or to
82 * return an instance of ConversationContextFactoryImpl with a custom timeout value configured.
83 */
84 public static ConversationContextFactory getConversationContextFactory()
85 {
86 FrameworkAdapter fa = FrameworkAdapter.getCurrentInstance();
87 ConversationContextFactory factory = (ConversationContextFactory) fa.getBean(
88 CONVERSATION_CONTEXT_FACTORY_KEY);
89
90 if (factory == null)
91 {
92 factory = CONVERSATION_CONTEXT_FACTORY_DFLT;
93 }
94
95 return factory;
96 }
97 }