01: /*
02: * Copyright 2007 Hippo.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package nl.hippo.cms.brokenlinkchecker.avalon;
17:
18: import org.apache.avalon.framework.logger.Logger;
19: import org.apache.avalon.framework.service.ServiceManager;
20:
21: /**
22: * <p>
23: * A utility class to help with cleaning up Avalon components.
24: * </p>
25: */
26: public class ComponentCleanup {
27: /**
28: * <p>
29: * The only and private constructor to prevent instantiation of this
30: * class.
31: * </p>
32: */
33: private ComponentCleanup() {
34: super ();
35: }
36:
37: /**
38: * <p>
39: * Release the Avalon component without throwing exceptions. If the
40: * releasing of the component throws an exception, the exception is
41: * logged.
42: * </p>
43: *
44: * @param serviceManager
45: * the service manager from which the component was
46: * looked up.
47: * @param component
48: * the component to release.
49: * @param role
50: * the role of the component.
51: * @param logger
52: * the logger to which to log a messge if releasing the
53: * component throws an exception.
54: */
55: public static void release(ServiceManager serviceManager,
56: Object component, String role, Logger logger) {
57: try {
58: serviceManager.release(component);
59: } catch (Exception e) {
60: if (logger.isWarnEnabled()) {
61: logger.warn(
62: "Error occurred while releasing component: "
63: + role, e);
64: }
65: }
66: }
67: }
|