KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snipsnap > container > Components


1 package org.snipsnap.container;
2
3 /*
4  * This file is part of "SnipSnap Wiki/Weblog".
5  *
6  * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
7  * All Rights Reserved.
8  *
9  * Please visit http://snipsnap.org/ for updates and contact.
10  *
11  * --LICENSE NOTICE--
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25  * --LICENSE NOTICE--
26  */

27
28 import org.codehaus.nanning.config.AspectSystem;
29 import org.nanocontainer.nanning.NanningComponentAdapterFactory;
30 import org.picocontainer.PicoContainer;
31 import org.picocontainer.defaults.DefaultComponentAdapterFactory;
32 import org.picocontainer.defaults.DefaultPicoContainer;
33 import org.radeox.util.Service;
34 import org.snipsnap.app.ApplicationManager;
35 import org.snipsnap.app.ApplicationStorage;
36 import org.snipsnap.app.JDBCApplicationStorage;
37 import org.snipsnap.app.PropertyFileApplicationStorage;
38 import org.snipsnap.config.ConfigurationProxy;
39 import org.snipsnap.config.Globals;
40 import org.snipsnap.interceptor.custom.MissingSnipAspect;
41 import org.snipsnap.interceptor.custom.SnipSpaceACLAspect;
42 import org.snipsnap.jdbc.LazyDataSource;
43 import org.snipsnap.notification.MessageService;
44 import org.snipsnap.render.PlainTextRenderEngine;
45 import org.snipsnap.render.SnipRenderEngine;
46 import org.snipsnap.snip.SnipSpace;
47 import org.snipsnap.snip.SnipSpaceImpl;
48 import org.snipsnap.snip.attachment.storage.FileAttachmentStorage;
49 import org.snipsnap.snip.attachment.storage.AttachmentStorage;
50 import org.snipsnap.snip.label.LabelManager;
51 import org.snipsnap.snip.storage.*;
52 import org.snipsnap.user.*;
53 import org.snipsnap.versioning.*;
54 import org.snipsnap.versioning.cookbook.CookbookDifferenceService;
55 import org.snipsnap.xmlrpc.*;
56 import org.snipsnap.feeder.FeederRepository;
57 import org.snipsnap.feeder.BasicFeederRepository;
58
59 import javax.sql.DataSource JavaDoc;
60 import java.util.Iterator JavaDoc;
61
62 public class Components {
63   public final static String JavaDoc DEFAULT_ENGINE = "defaultRenderEngine";
64
65   private static PicoContainer container;
66
67   public static synchronized PicoContainer getContainer() {
68     if (null == container) {
69       //System.out.println("Creating PicoContainer ...");
70
DefaultPicoContainer nc = new DefaultPicoContainer(
71         new NanningComponentAdapterFactory(
72           new AspectSystem(),
73           new DefaultComponentAdapterFactory()));
74
75       nc.registerComponentImplementation(MissingSnipAspect.class);
76       nc.registerComponentImplementation(SnipSpaceACLAspect.class);
77       nc.getComponentInstances();
78
79 // StringRegistrationNanoContainer c =
80
// new StringRegistrationNanoContainerImpl(pc, Components.class.getClassLoader(), new StringToObjectConverter());
81

82       Globals globals = ConfigurationProxy.getInstance();
83       String JavaDoc database = globals.getDatabase();
84       try {
85         if("file".equals(database)) {
86           nc.registerComponentImplementation(UserStorage.class, PropertyFileUserStorage.class);
87           nc.registerComponentImplementation(SnipStorage.class, PropertyFileSnipStorage.class);
88           nc.registerComponentImplementation(VersionStorage.class, PropertyFileSnipStorage.class);
89           nc.registerComponentImplementation(ApplicationStorage.class, PropertyFileApplicationStorage.class);
90         } else {
91           nc.registerComponentInstance(DataSource.class, new LazyDataSource());
92           nc.registerComponentImplementation(SnipStorage.class, JDBCSnipStorage.class);
93           nc.registerComponentImplementation(UserStorage.class, JDBCUserStorage.class);
94           nc.registerComponentImplementation(VersionStorage.class, JDBCVersionStorage.class);
95           nc.registerComponentImplementation(ApplicationStorage.class, JDBCApplicationStorage.class);
96         }
97         nc.registerComponentImplementation(AttachmentStorage.class, FileAttachmentStorage.class);
98         nc.registerComponentImplementation(PermissionManager.class, DefaultPermissionManager.class);
99         nc.registerComponentImplementation(UserManager.class, DefaultUserManager.class);
100         nc.registerComponentImplementation(AuthenticationService.class, DefaultAuthenticationService.class);
101         nc.registerComponentImplementation(PasswordService.class);
102         nc.registerComponentImplementation(SessionService.class, DefaultSessionService.class);
103         nc.registerComponentImplementation(DEFAULT_ENGINE, SnipRenderEngine.class);
104         nc.registerComponentImplementation(PlainTextRenderEngine.class);
105         nc.registerComponentImplementation(SnipSpace.class, SnipSpaceImpl.class);
106
107         // Sec
108
// XML-RPC Handlers
109
nc.registerComponentImplementation(BloggerAPI.class, BloggerHandler.class);
110         nc.registerComponentImplementation(MetaWeblogAPI.class, MetaWeblogHandler.class);
111
112         nc.registerComponentImplementation(WeblogsPingHandler.class);
113         nc.registerComponentImplementation(GeneratorHandler.class);
114         nc.registerComponentImplementation(WeblogHandler.class);
115         nc.registerComponentImplementation(SnipSnapHandler.class);
116
117         //Others
118
//nc.registerComponentImplementation(RegexService.class);
119
nc.registerComponentImplementation(MessageService.class);
120         nc.registerComponentImplementation(ApplicationManager.class);
121         nc.registerComponentImplementation(LabelManager.class);
122
123         // Feeders
124
nc.registerComponentImplementation(FeederRepository.class, BasicFeederRepository.class);
125
126         // Versioning
127
nc.registerComponentImplementation(VersionManager.class, DefaultVersionManager.class);
128         nc.registerComponentImplementation(DifferenceService.class, CookbookDifferenceService.class);
129
130         Iterator JavaDoc iterator = Service.providerClasses(Component.class);
131         while (iterator.hasNext()) {
132           Class JavaDoc component = (Class JavaDoc) iterator.next();
133           nc.registerComponentImplementation(component);
134         }
135
136 // Component component = (MessageLogService) nc.getComponentInstance(MessageLogService.class);
137
// System.out.println("keys="+nc.getComponentKeys());
138
container = nc;
139       } catch (Exception JavaDoc e) {
140         e.printStackTrace();
141       }
142       //System.out.println(" PicoContainer ok.");
143
}
144
145     return container;
146   }
147
148   public static Object JavaDoc getComponent(Class JavaDoc c) {
149     return getContainer().getComponentInstance(c);
150   }
151
152 }
153
Popular Tags