01: /*
02: * The contents of this file are subject to the Sapient Public License
03: * Version 1.0 (the "License"); you may not use this file except in compliance
04: * with the License. You may obtain a copy of the License at
05: * http://carbon.sf.net/License.html.
06: *
07: * Software distributed under the License is distributed on an "AS IS" basis,
08: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
09: * the specific language governing rights and limitations under the License.
10: *
11: * The Original Code is The Carbon Component Framework.
12: *
13: * The Initial Developer of the Original Code is Sapient Corporation
14: *
15: * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
16: */
17:
18: package org.sape.carbon.core.component;
19:
20: import org.sape.carbon.core.bootstrap.BootStrapper;
21:
22: /**
23: * <p>This class provides a singleton interface to the component subsystem.
24: * This class should be used by any client that needs a reference to a
25: * component</p>
26: *
27: * Copyright 2002 Sapient
28: * @since carbon 1.0
29: * @author Douglas Voet, January 2002
30: * @version $Revision: 1.13 $($Author: dvoet $ / $Date: 2003/05/05 21:21:11 $)
31: * @stereotype singleton
32: */
33: public class Lookup {
34: /** @link dependency */
35: /*#Component lnkComponent;*/
36:
37: /** @link dependency */
38: /*#BootStrapper lnkBootStrapper;*/
39:
40: /** Reference to the component keeper. */
41: private ComponentKeeper componentKeeper;
42:
43: /**
44: * Private constructor to ensure singleton.
45: */
46: private Lookup() {
47: }
48:
49: /**
50: * <p>Fetches a reference to a component. Delegates to the system's
51: * <code>ComponentKeeper</code>. If the <code>ComponentKeeper</code> has
52: * not been created yet, it calls the <code>BootStrapper</code>
53: * to get it.</p>
54: *
55: * @param logicalComponentName the name of the component
56: * @return a reference to the component specified by name
57: */
58: public Component fetchComponent(String logicalComponentName) {
59: return getComponentKeeper()
60: .fetchComponent(logicalComponentName);
61: }
62:
63: /**
64: * Gets the <code>ComponentKeeper</code> for the system.
65: * @return the <code>ComponentKeeper</code>
66: */
67: public ComponentKeeper getComponentKeeper() {
68: if (this .componentKeeper == null) {
69: this .componentKeeper = BootStrapper.getInstance()
70: .fetchComponentKeeper();
71: }
72:
73: return this .componentKeeper;
74: }
75:
76: /** Single statically instantiated instance of lookup. */
77: private static final Lookup INSTANCE = new Lookup();
78:
79: /**
80: * <p>
81: * Static factory method for getting a reference to the singleton
82: * <code>Lookup</code>.
83: * </p>
84: *
85: * @return Lookup
86: */
87: public static Lookup getInstance() {
88: return Lookup.INSTANCE;
89: }
90: }
|