1 package org.snipsnap.container; 2 3 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 ; 60 import java.util.Iterator ; 61 62 public class Components { 63 public final static String DEFAULT_ENGINE = "defaultRenderEngine"; 64 65 private static PicoContainer container; 66 67 public static synchronized PicoContainer getContainer() { 68 if (null == container) { 69 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 82 Globals globals = ConfigurationProxy.getInstance(); 83 String 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 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 nc.registerComponentImplementation(MessageService.class); 120 nc.registerComponentImplementation(ApplicationManager.class); 121 nc.registerComponentImplementation(LabelManager.class); 122 123 nc.registerComponentImplementation(FeederRepository.class, BasicFeederRepository.class); 125 126 nc.registerComponentImplementation(VersionManager.class, DefaultVersionManager.class); 128 nc.registerComponentImplementation(DifferenceService.class, CookbookDifferenceService.class); 129 130 Iterator iterator = Service.providerClasses(Component.class); 131 while (iterator.hasNext()) { 132 Class component = (Class ) iterator.next(); 133 nc.registerComponentImplementation(component); 134 } 135 136 container = nc; 139 } catch (Exception e) { 140 e.printStackTrace(); 141 } 142 } 144 145 return container; 146 } 147 148 public static Object getComponent(Class c) { 149 return getContainer().getComponentInstance(c); 150 } 151 152 } 153 | Popular Tags |