Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ConfigBeanFactory |
|
| 1.8;1.8 |
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one or more | |
3 | * contributor license agreements. See the NOTICE file distributed with | |
4 | * this work for additional information regarding copyright ownership. | |
5 | * The ASF licenses this file to you under the Apache License, Version 2.0 | |
6 | * (the "License"); you may not use this file except in compliance with | |
7 | * the License. You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, software | |
12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | * See the License for the specific language governing permissions and | |
15 | * limitations under the License. | |
16 | */ | |
17 | ||
18 | /* | |
19 | * $Id: ConfigBeanFactory.java 464373 2006-10-16 04:21:54Z rahul $ | |
20 | */ | |
21 | package org.apache.shale.clay.config.beans; | |
22 | ||
23 | import java.util.Collection; | |
24 | import java.util.Iterator; | |
25 | import java.util.TreeSet; | |
26 | ||
27 | /** | |
28 | * <p>This is an abstract factory that contains a ordered collection of | |
29 | * object pools {@link ConfigBean}. The configuration beans are registered on | |
30 | * application startup by the {@link ClayConfigListener}. | |
31 | * </p> | |
32 | */ | |
33 | public final class ConfigBeanFactory { | |
34 | ||
35 | /** | |
36 | * <p>Hide constructor on a factory class.</p> | |
37 | */ | |
38 | private ConfigBeanFactory() { | |
39 | super(); | |
40 | } | |
41 | ||
42 | /** | |
43 | * <p>A static ordered set of {@link ConfigBean} instances.</p> | |
44 | */ | |
45 | 1 | private static Collection configBeans = new TreeSet(); |
46 | ||
47 | /** | |
48 | * <p>This method is invoked to register a class instance implementing | |
49 | * {@link ConfigBean} interface. | |
50 | * </p> | |
51 | * | |
52 | * @param config {@link ConfigBean} collection of faces component metadata | |
53 | */ | |
54 | public static void register(ConfigBean config) { | |
55 | 144 | configBeans.add(config); |
56 | 144 | } |
57 | ||
58 | /** | |
59 | * <p>This method will return a {@link ConfigBean} that can be used | |
60 | * to return component metadata. The suffix of the parameter is used to | |
61 | * find a <code>ConfigBean</code> that has the metadata. | |
62 | * </p> | |
63 | * | |
64 | * @param id jsfid | |
65 | * @return config bean | |
66 | */ | |
67 | public static ConfigBean findConfig(String id) { | |
68 | 962 | Iterator ci = configBeans.iterator(); |
69 | 962 | ConfigBean config = null; |
70 | 985 | while (ci.hasNext()) { |
71 | 985 | config = (ConfigBean) ci.next(); |
72 | 985 | if (config.validMoniker(id)) { |
73 | 962 | break; |
74 | } | |
75 | } | |
76 | ||
77 | 962 | return config; |
78 | } | |
79 | ||
80 | /** | |
81 | * <p>Invoked by the context listener {@link org.apache.shale.clay.config.ClayConfigureListener} on | |
82 | * application shutdown to clean up cached resources. | |
83 | * </p> | |
84 | */ | |
85 | public static void destroy() { | |
86 | 48 | Iterator ci = configBeans.iterator(); |
87 | 48 | ConfigBean config = null; |
88 | 192 | while (ci.hasNext()) { |
89 | 144 | config = (ConfigBean) ci.next(); |
90 | 144 | config.destroy(); |
91 | ||
92 | 144 | } |
93 | 48 | configBeans.clear(); |
94 | 48 | } |
95 | ||
96 | ||
97 | /** | |
98 | * <p>This method should be called from key points in the application to invoke | |
99 | * automatic reloading of the configuration files if they have been modified since | |
100 | * last reloaded. If the XML files have changed, all files have to be reloaded. | |
101 | * This includes HTML template files. | |
102 | * </p> | |
103 | */ | |
104 | public static void refresh() { | |
105 | Iterator ci = configBeans.iterator(); | |
106 | //the logic assumes the ComponentConfigBean will be first | |
107 | //in the ordered list. If the XML files are dirty, the | |
108 | //template cache must be reestablished. | |
109 | boolean wasDirty = false; | |
110 | while (ci.hasNext()) { | |
111 | ConfigBean config = (ConfigBean) ci.next(); | |
112 | wasDirty = config.refresh(wasDirty); | |
113 | } | |
114 | } | |
115 | ||
116 | } |