1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.jetspeed.services;
17
18 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
19 import org.apache.jetspeed.services.logging.JetspeedLogger;
20 import org.apache.turbine.services.InitializationException;
21 import org.apache.turbine.services.Service;
22
23 /***
24 * ServiceHelper
25 *
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 */
29 public class ServiceHelper
30 {
31 private static final JetspeedLogger log = JetspeedLogFactoryService.getLogger(ServiceHelper.class.getName());
32
33 /***
34 * Load an implementation class from the configuration.
35 *
36 * @param configurationName
37 * @return
38 * @throws CPSInitializationException
39 */
40 static public Class loadModelClass(Service service, String configurationName)
41 throws InitializationException
42 {
43 String className = service.getConfiguration().getString(configurationName, null);
44 if (null == className)
45 {
46 throw new InitializationException(configurationName + " implementation configuration not found.");
47 }
48 try
49 {
50 return Class.forName(className);
51
52 }
53 catch (ClassNotFoundException e)
54 {
55 throw new InitializationException("Could not preload " + className + " implementation class.", e);
56 }
57 }
58
59 /***
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 object
65 * @return the newly created object
66 * @throws ContentManagementException
67 */
68 public static Object createObject(Class classe)
69 {
70 Object object = null;
71 try
72 {
73 object = classe.newInstance();
74 }
75 catch (Exception e)
76 {
77 log.error("Factory failed to create object: " + classe.getName(), e);
78 }
79
80 return object;
81 }
82
83 }