View Javadoc

1   /*
2       Copyright (C) 2004 PjEr
3       
4       This program is free software; you can redistribute it and/or modify
5       it under the terms of the GNU General Public License as published by
6       the Free Software Foundation; either version 2 of the License, or
7       (at your option) any later version.
8       
9       This program is distributed in the hope that it will be useful,
10      but WITHOUT ANY WARRANTY; without even the implied warranty of
11      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12      GNU General Public License for more details.
13      
14      You should have received a copy of the GNU General Public License
15      along with this program; if not, write to the Free Software
16      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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