01: package com.coldcore.coloradoftp.factory;
02:
03: /**
04: * Object factory.
05: *
06: * Provides objects referred by name. Written as a static class this factory is available from all
07: * other objects in the same JVM. Configuration dictates what objects must be provided as singletons
08: * and wich must be not (every time a new object).
09: *
10: * This implementation delegates all calls to its internal factory which is responsible for
11: * finding requested objects.
12: *
13: *
14: * ColoradoFTP - The Open Source FTP Server (http://cftp.coldcore.com)
15: */
16: public class ObjectFactory {
17:
18: protected static InternalFactory internalFactory;
19:
20: private ObjectFactory() {
21: }
22:
23: /** Get internal factory
24: * @return Internal factory
25: */
26: public static InternalFactory getInternalFactory() {
27: return internalFactory;
28: }
29:
30: /** Set new internal factory
31: * @param internalFactory Internal factory
32: */
33: public static void setInternalFactory(
34: InternalFactory internalFactory) {
35: ObjectFactory.internalFactory = internalFactory;
36: }
37:
38: /** Get object by name
39: * @param name Object name
40: * @return Requested object (never returns NULL)
41: */
42: public static Object getObject(String name) {
43: if (internalFactory == null)
44: throw new IllegalStateException(
45: "Internal factory is not set");
46: Object o = internalFactory.getBean(name);
47: if (o == null)
48: throw new IllegalArgumentException("Object " + name
49: + " cannot be loaded");
50: return o;
51: }
52: }
|