1/*2 * Copyright 2000-2004 The Apache Software Foundation.3 * 4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * limitations under the License.15 */16packageorg.apache.jetspeed.services;
1718import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
19import org.apache.jetspeed.services.logging.JetspeedLogger;
20import org.apache.turbine.services.InitializationException;
21import org.apache.turbine.services.Service;
2223/***24 * ServiceHelper25 *26 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>27 * @version $Id: ServiceHelper.java,v 1.2 2004/02/23 04:00:57 jford Exp $28 */29publicclassServiceHelper30 {
31privatestaticfinalJetspeedLogger log = JetspeedLogFactoryService.getLogger(ServiceHelper.class.getName());
3233/***34 * Load an implementation class from the configuration.35 * 36 * @param configurationName37 * @return38 * @throws CPSInitializationException39 */40staticpublic Class loadModelClass(Service service, String configurationName)
41 throws InitializationException
42 {
43 String className = service.getConfiguration().getString(configurationName, null);
44if (null == className)
45 {
46thrownew InitializationException(configurationName + " implementation configuration not found.");
47 }
48try49 {
50return Class.forName(className);
5152 }
53catch (ClassNotFoundException e)
54 {
55thrownew InitializationException("Could not preload " + className + " implementation class.", e);
56 }
57 }
5859/***60 * Creates objects given the class. 61 * Throws exceptions if the class is not found in the default class path, 62 * or the class is not an instance of CmsObject.63 * 64 * @param classe the class of object65 * @return the newly created object66 * @throws ContentManagementException67 */68publicstatic Object createObject(Class classe)
69 {
70 Object object = null;
71try72 {
73 object = classe.newInstance();
74 }
75catch (Exception e)
76 {
77 log.error("Factory failed to create object: " + classe.getName(), e);
78 }
7980return object;
81 }
8283 }