%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.torque.avalon.TorqueComponent |
|
|
1 | package org.apache.torque.avalon; |
|
2 | ||
3 | /* |
|
4 | * Licensed to the Apache Software Foundation (ASF) under one |
|
5 | * or more contributor license agreements. See the NOTICE file |
|
6 | * distributed with this work for additional information |
|
7 | * regarding copyright ownership. The ASF licenses this file |
|
8 | * to you under the Apache License, Version 2.0 (the |
|
9 | * "License"); you may not use this file except in compliance |
|
10 | * with the License. You may obtain a copy of the License at |
|
11 | * |
|
12 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
13 | * |
|
14 | * Unless required by applicable law or agreed to in writing, |
|
15 | * software distributed under the License is distributed on an |
|
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|
17 | * KIND, either express or implied. See the License for the |
|
18 | * specific language governing permissions and limitations |
|
19 | * under the License. |
|
20 | */ |
|
21 | ||
22 | import java.io.File; |
|
23 | import java.util.Iterator; |
|
24 | import java.util.Map; |
|
25 | ||
26 | import org.apache.avalon.framework.activity.Disposable; |
|
27 | import org.apache.avalon.framework.activity.Initializable; |
|
28 | import org.apache.avalon.framework.configuration.Configurable; |
|
29 | import org.apache.avalon.framework.configuration.Configuration; |
|
30 | import org.apache.avalon.framework.configuration.ConfigurationException; |
|
31 | import org.apache.avalon.framework.context.Context; |
|
32 | import org.apache.avalon.framework.context.ContextException; |
|
33 | import org.apache.avalon.framework.context.Contextualizable; |
|
34 | import org.apache.avalon.framework.logger.LogEnabled; |
|
35 | import org.apache.avalon.framework.logger.Logger; |
|
36 | import org.apache.avalon.framework.thread.SingleThreaded; |
|
37 | import org.apache.commons.lang.StringUtils; |
|
38 | import org.apache.torque.TorqueInstance; |
|
39 | ||
40 | /** |
|
41 | * Avalon component for Torque. |
|
42 | * |
|
43 | * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a> |
|
44 | * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> |
|
45 | * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a> |
|
46 | * @version $Id: TorqueComponent.java 493492 2007-01-06 15:57:44Z tv $ |
|
47 | */ |
|
48 | 7 | public class TorqueComponent |
49 | extends TorqueInstance |
|
50 | implements Torque, |
|
51 | LogEnabled, |
|
52 | Configurable, |
|
53 | Initializable, |
|
54 | Contextualizable, |
|
55 | Disposable, |
|
56 | SingleThreaded |
|
57 | 17 | { |
58 | /** The Avalon Application Root */ |
|
59 | 6 | private String appRoot = null; |
60 | 17 | |
61 | /** The Avalon Logger */ |
|
62 | 6 | private Logger logger = null; |
63 | 17 | |
64 | /** The configuration file name. */ |
|
65 | 6 | private String configFile = null; |
66 | ||
67 | /* |
|
68 | * ======================================================================== |
|
69 | * |
|
70 | * Avalon Component Interfaces |
|
71 | 17 | * |
72 | * ======================================================================== |
|
73 | */ |
|
74 | 17 | |
75 | 17 | /** |
76 | * @see org.apache.avalon.framework.logger.LogEnabled#enableLogging(org.apache.avalon.framework.logger.Logger) |
|
77 | */ |
|
78 | public void enableLogging(Logger aLogger) |
|
79 | { |
|
80 | 6 | this.logger = aLogger; |
81 | 6 | } |
82 | ||
83 | /** |
|
84 | * Convenience method to provide the Avalon logger the way AbstractLogEnabled does. |
|
85 | */ |
|
86 | public Logger getLogger() |
|
87 | { |
|
88 | 36 | return logger; |
89 | } |
|
90 | 17 | |
91 | 17 | /** |
92 | * @see |
|
93 | * org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration) |
|
94 | */ |
|
95 | public void configure(Configuration configuration) |
|
96 | throws ConfigurationException |
|
97 | { |
|
98 | 125 | getLogger().debug("configure(" + configuration + ")"); |
99 | ||
100 | 6 | String configurationFile |
101 | 1 | = configuration.getChild("configfile").getValue(); |
102 | ||
103 | 6 | if (StringUtils.isNotEmpty(appRoot)) |
104 | { |
|
105 | 6 | if (configurationFile.startsWith("/")) |
106 | { |
|
107 | 6 | configurationFile = configurationFile.substring(1); |
108 | 24 | getLogger().debug("Config File changes to " |
109 | 1 | + configurationFile); |
110 | 17 | } |
111 | ||
112 | 6 | StringBuffer sb = new StringBuffer(); |
113 | 23 | sb.append(appRoot); |
114 | 6 | sb.append(File.separator); |
115 | 23 | sb.append(configurationFile); |
116 | ||
117 | 23 | configurationFile = sb.toString(); |
118 | 17 | } |
119 | ||
120 | 6 | getLogger().debug("Config File is " + configurationFile); |
121 | ||
122 | 23 | this.configFile = configurationFile; |
123 | 23 | } |
124 | 17 | |
125 | 17 | /** |
126 | * @see org.apache.avalon.framework.context.Contextualizable |
|
127 | 17 | */ |
128 | public void contextualize(Context context) |
|
129 | throws ContextException |
|
130 | 17 | { |
131 | // check context Merlin and YAAFI style |
|
132 | 17 | try |
133 | 17 | { |
134 | 6 | appRoot = ((File) context.get("urn:avalon:home")).getAbsolutePath(); |
135 | } |
|
136 | 0 | catch (ContextException ce) |
137 | { |
|
138 | 0 | appRoot = null; |
139 | 5 | } |
140 | ||
141 | 6 | if (appRoot == null) |
142 | { |
|
143 | // check context old ECM style, let exception flow if not available |
|
144 | 17 | appRoot = (String) context.get("componentAppRoot"); |
145 | } |
|
146 | ||
147 | 6 | if (StringUtils.isNotEmpty(appRoot)) |
148 | { |
|
149 | 23 | if (appRoot.endsWith("/")) |
150 | { |
|
151 | 17 | appRoot = appRoot.substring(0, appRoot.length() - 1); |
152 | 0 | getLogger().debug("Application Root changed to " + appRoot); |
153 | } |
|
154 | } |
|
155 | 6 | } |
156 | ||
157 | 17 | /** |
158 | * @see org.apache.avalon.framework.activity.Initializable#initialize() |
|
159 | 17 | */ |
160 | public void initialize() |
|
161 | throws Exception |
|
162 | { |
|
163 | 6 | getLogger().debug("initialize()"); |
164 | ||
165 | 23 | TorqueInstance instance = org.apache.torque.Torque.getInstance(); |
166 | ||
167 | // Check if another singleton is already running |
|
168 | 6 | if (instance.isInit()) |
169 | { |
|
170 | 0 | Map mapBuilders = instance.getMapBuilders(); |
171 | ||
172 | // Copy the registered MapBuilders and take care that they will be built again |
|
173 | 17 | for (Iterator i = mapBuilders.keySet().iterator(); i.hasNext();) |
174 | 17 | { |
175 | 17 | String className = (String)i.next(); |
176 | 0 | registerMapBuilder(className); |
177 | 0 | } |
178 | } |
|
179 | ||
180 | // Provide the singleton instance to the static accessor |
|
181 | 6 | org.apache.torque.Torque.setInstance(this); |
182 | 17 | |
183 | 23 | init(configFile); |
184 | 6 | } |
185 | ||
186 | /** |
|
187 | * @see org.apache.avalon.framework.activity.Disposable#dispose() |
|
188 | */ |
|
189 | public void dispose() |
|
190 | 17 | { |
191 | 6 | getLogger().debug("dispose()"); |
192 | try |
|
193 | 17 | { |
194 | 6 | shutdown(); |
195 | 17 | } |
196 | 6 | catch (Exception e) |
197 | 17 | { |
198 | 6 | getLogger().error("Error while stopping Torque", e); |
199 | 17 | } |
200 | 6 | } |
201 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |