KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > util > ComponentLocator


1 /*
2  * Created on Dec 2, 2004
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Style - Code Templates
6  */

7 package org.tigris.scarab.util;
8
9 import org.apache.fulcrum.TurbineServices;
10 import org.apache.fulcrum.mimetype.MimeTypeService;
11 import org.apache.turbine.services.yaaficomponent.YaafiComponentService;
12 import org.tigris.scarab.tools.localization.L10NKeySet;
13
14 /**
15  * @author Eric Pugh
16  *
17  * TODO To change the template for this generated type comment go to Window -
18  * Preferences - Java - Code Style - Code Templates
19  */

20 public class ComponentLocator {
21     private static MimeTypeService mimeTypeService;
22
23     /**
24      * @return Returns the mimeTypeService.
25      */

26     public static MimeTypeService getMimeTypeService() {
27         if (mimeTypeService == null) {
28             mimeTypeService = (MimeTypeService) lookup(MimeTypeService.class);
29         }
30         return mimeTypeService;
31     }
32
33     /**
34      * @param mimeTypeService
35      * The mimeTypeService to set.
36      */

37     public static void setMimeTypeService(MimeTypeService mimeTypeService) {
38         ComponentLocator.mimeTypeService = mimeTypeService;
39     }
40
41     /**
42      * @param class1
43      * @return
44      */

45     private static Object JavaDoc lookup(Class JavaDoc clazz) {
46         YaafiComponentService yaafi = (YaafiComponentService) TurbineServices
47                 .getInstance().getService(YaafiComponentService.SERVICE_NAME);
48         try {
49             return yaafi.lookup(clazz.getName());
50         } catch (Exception JavaDoc e) {
51             throw new ScarabRuntimeException(
52                     L10NKeySet.ExceptionComponentLocator,
53                     clazz.getName(),
54                     e);
55         }
56     }
57 }
Popular Tags