1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package ca.pjer.cm.main;
19
20 import ca.pjer.cm.api.cmf.ContentManagementService;
21 import org.apache.hivemind.ClassResolver;
22 import org.apache.hivemind.Registry;
23 import org.apache.hivemind.impl.DefaultClassResolver;
24 import org.apache.hivemind.impl.RegistryBuilder;
25
26 import java.util.Locale;
27
28 /***
29 * This class is the main entry into the content management framework.<br />
30 * <br />
31 * $Id: ContentManagementFramework.java,v 1.1 2004/05/18 12:57:09 pjer Exp $<br />
32 * <br />
33 * $RCSfile: ContentManagementFramework.java,v $<br />
34 * $Revision: 1.1 $<br />
35 * $Author: pjer $<br />
36 * $Date: 2004/05/18 12:57:09 $<br />
37 */
38 public final class ContentManagementFramework {
39 private static final short STATE_UNDEFINED = 0;
40 private static final short STATE_INIT = 1;
41 private static final short STATE_SHUTDOWN = 2;
42
43 private static ContentManagementFramework me;
44
45 private Registry registry;
46 private short state;
47
48 /***
49 * Get the instance of ContentManagementFramework.
50 *
51 * @return The instance of ContentManagementFramework.
52 */
53 public static synchronized ContentManagementFramework getInstance() {
54 if (me == null) {
55 me = new ContentManagementFramework();
56 }
57 return me;
58 }
59
60 private ContentManagementFramework() {
61 state = STATE_UNDEFINED;
62 }
63
64 /***
65 * This method initialize the Content Management Framework.
66 */
67 public synchronized void init() {
68 if (state == STATE_INIT) {
69 throw new IllegalStateException("Allready initialized.");
70 }
71 ClassResolver classResolver = new DefaultClassResolver();
72 RegistryBuilder registryBuilder = new RegistryBuilder();
73 registryBuilder.processModules(classResolver);
74 registry = registryBuilder.constructRegistry(Locale.getDefault());
75 state = STATE_INIT;
76 }
77
78 /***
79 * This method returns the ContentManagementService.
80 *
81 * @return The ContentManagementService.
82 */
83 public ContentManagementService getContentManagementService() {
84 if (state != STATE_INIT) {
85 throw new IllegalStateException("Not initialized.");
86 }
87 return (ContentManagementService)
88 registry.getService("ca.pjer.cm.ContentManagementService", ContentManagementService.class);
89 }
90
91 /***
92 * This method shut down the ContentManagementFramework.
93 */
94 public synchronized void shutdown() {
95 if (state == STATE_SHUTDOWN) {
96 throw new IllegalStateException("Allready shutted down.");
97 }
98 registry.shutdown();
99 state = STATE_SHUTDOWN;
100 }
101 }
102