KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > services > ServiceHelper


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 at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 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 JavaDoc loadModelClass(Service service, String JavaDoc configurationName)
41     throws InitializationException
42     {
43         String JavaDoc 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 JavaDoc 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 JavaDoc createObject(Class JavaDoc classe)
69     {
70         Object JavaDoc object = null;
71         try
72         {
73             object = classe.newInstance();
74         }
75         catch (Exception JavaDoc e)
76         {
77             log.error("Factory failed to create object: " + classe.getName(), e);
78         }
79         
80         return object;
81     }
82     
83 }
84
Popular Tags