roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r539785 - in /roller/branches/roller_guice: ./ nbproject/ src/org/apache/roller/business/ src/org/apache/roller/business/hibernate/ src/org/apache/roller/business/search/ tools/lib/ web/WEB-INF/classes/
Date Sat, 19 May 2007 18:05:03 GMT
Author: snoopdave
Date: Sat May 19 11:04:58 2007
New Revision: 539785

URL: http://svn.apache.org/viewvc?view=rev&rev=539785
Log:
Working Roller/Guice implementation

Added:
    roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateModule.java
    roller/branches/roller_guice/tools/lib/guice-1.0.jar   (with props)
Modified:
    roller/branches/roller_guice/nbproject/project.xml
    roller/branches/roller_guice/properties.xmlf
    roller/branches/roller_guice/src/org/apache/roller/business/Roller.java
    roller/branches/roller_guice/src/org/apache/roller/business/RollerFactory.java
    roller/branches/roller_guice/src/org/apache/roller/business/RollerImpl.java
    roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateAutoPingManagerImpl.java
    roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateBookmarkManagerImpl.java
    roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernatePersistenceStrategy.java
    roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernatePingQueueManagerImpl.java
    roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernatePingTargetManagerImpl.java
    roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernatePropertiesManagerImpl.java
    roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateRefererManagerImpl.java
    roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateRollerImpl.java
    roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateThreadManagerImpl.java
    roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateUserManagerImpl.java
    roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java
    roller/branches/roller_guice/src/org/apache/roller/business/search/IndexManager.java
    roller/branches/roller_guice/src/org/apache/roller/business/search/IndexManagerImpl.java
    roller/branches/roller_guice/web/WEB-INF/classes/roller.properties

Modified: roller/branches/roller_guice/nbproject/project.xml
URL: http://svn.apache.org/viewvc/roller/branches/roller_guice/nbproject/project.xml?view=diff&rev=539785&r1=539784&r2=539785
==============================================================================
--- roller/branches/roller_guice/nbproject/project.xml (original)
+++ roller/branches/roller_guice/nbproject/project.xml Sat May 19 11:04:58 2007
@@ -4,7 +4,7 @@
     <configuration>
         <general-data xmlns="http://www.netbeans.org/ns/freeform-project/1">
             <!--Do not use Project Properties customizer when editing this file manually.-->
-            <name>roller_trunk</name>
+            <name>roller_guice</name>
             <!--
             <properties>
                 <property name="src.dir">../src</property>
@@ -211,7 +211,7 @@
                 <package-root>sandbox/scripting/bsf/src</package-root>
                 <package-root>custom/src</package-root>
                 <package-root>sandbox/scripting/jruby/src</package-root>
-                <classpath mode="compile">tools/buildtime/junit-3.8.1.jar:tools/lib/concurrent-1.3.2.jar:tools/lib/log4j-1.2.4.jar:tools/lib/lucene-1.4.3.jar:tools/lib/taglibs-string.jar:tools/struts-1.2.4/lib/antlr.jar:tools/struts-1.2.4/lib/commons-beanutils.jar:tools/struts-1.2.4/lib/commons-digester.jar:tools/struts-1.2.4/lib/commons-fileupload.jar:tools/struts-1.2.4/lib/commons-validator.jar:tools/struts-1.2.4/lib/jakarta-oro.jar:tools/struts-1.2.4/lib/struts-el.jar:tools/struts-1.2.4/lib/struts.jar:tools/buildtime/mockrunner-0.35/lib/mockrunner-servlet.jar:tools/buildtime/mockrunner-0.35/lib/mockrunner-struts.jar:tools/buildtime/mockrunner-0.35/lib/mockrunner.jar:tools/buildtime/mockrunner-0.35/lib/nekohtml.jar:tools/standard-1.0.3/lib/jaxen-full.jar:tools/standard-1.0.3/lib/jstl.jar:tools/standard-1.0.3/lib/standard.jar:tools/buildtime/tomcat-5.0.28/servlet-api.jar:tools/buildtime/tomcat-5.0.28/jsp-api.jar:tools/lib/jdom.jar:tools/spring-1.2/acegi-security-0.9.0.jar:t
 ools/spring-1.2/spring.jar:tools/lib/rome-0.8.jar:tools/lib/rome-fetcher-0.8.jar:tools/lib/commons-codec-1.3.jar:tools/hibernate-3.1/hibernate3.jar:contrib/lib/textile4j-1.20.jar:tools/buildtime/derby.jar:tools/buildtime/ant-1.6.2/ant.jar:tools/buildtime/derbynet.jar:tools/lib/rome-0.9.jar:tools/lib/rome-fetcher-0.9.jar:tools/buildtime/activation.jar:tools/buildtime/mail.jar:tools/spring-1.2/spring.jar:../../../../../../Applications/Java/groovy/embeddable/groovy-all-1.0.jar:sandbox/scripting/bsf/lib/bsf.jar:tools/lib/commons-collections-3.1.jar:tools/lib/commons-lang-2.1.jar:tools/lib/commons-logging-1.0.4.jar:tools/lib/velocity-1.5.jar:tools/lib/velocity-dep-1.5.jar:tools/xmlrpc-3.0/lib/ws-commons-util-1.0.1.jar:tools/xmlrpc-3.0/lib/xmlrpc-client-3.0.jar:tools/xmlrpc-3.0/lib/xmlrpc-common-3.0.jar:tools/xmlrpc-3.0/lib/xmlrpc-server-3.0.jar:tools/spring-1.2/acegi-security-1.0.3.jar:tools/struts-2.0.6/lib/antlr-2.7.2.jar:tools/struts-2.0.6/lib/commons-beanutils-1.6.jar:tools/s
 truts-2.0.6/lib/commons-chain-1.1.jar:tools/struts-2.0.6/lib/commons-fileupload-1.2.jar:tools/struts-2.0.6/lib/commons-io-1.3.1.jar:tools/struts-2.0.6/lib/commons-validator-1.3.0.jar:tools/struts-2.0.6/lib/freemarker-2.3.8.jar:tools/struts-2.0.6/lib/ognl-2.6.11.jar:tools/struts-2.0.6/lib/oro-2.0.8.jar:tools/struts-2.0.6/lib/struts2-core-2.0.6.jar:tools/struts-2.0.6/lib/struts2-spring-plugin-2.0.6.jar:tools/struts-2.0.6/lib/struts2-tiles-plugin-2.0.6.jar:tools/struts-2.0.6/lib/tiles-api-2.0-20070207.130156-4.jar:tools/struts-2.0.6/lib/tiles-core-2.0-20070207.130156-4.jar:tools/struts-2.0.6/lib/xwork-2.0.1.jar</classpath>
+                <classpath mode="compile">tools/buildtime/junit-3.8.1.jar:tools/lib/concurrent-1.3.2.jar:tools/lib/log4j-1.2.4.jar:tools/lib/lucene-1.4.3.jar:tools/lib/taglibs-string.jar:tools/struts-1.2.4/lib/antlr.jar:tools/struts-1.2.4/lib/commons-beanutils.jar:tools/struts-1.2.4/lib/commons-digester.jar:tools/struts-1.2.4/lib/commons-fileupload.jar:tools/struts-1.2.4/lib/commons-validator.jar:tools/struts-1.2.4/lib/jakarta-oro.jar:tools/struts-1.2.4/lib/struts-el.jar:tools/struts-1.2.4/lib/struts.jar:tools/buildtime/mockrunner-0.35/lib/mockrunner-servlet.jar:tools/buildtime/mockrunner-0.35/lib/mockrunner-struts.jar:tools/buildtime/mockrunner-0.35/lib/mockrunner.jar:tools/buildtime/mockrunner-0.35/lib/nekohtml.jar:tools/standard-1.0.3/lib/jaxen-full.jar:tools/standard-1.0.3/lib/jstl.jar:tools/standard-1.0.3/lib/standard.jar:tools/buildtime/tomcat-5.0.28/servlet-api.jar:tools/buildtime/tomcat-5.0.28/jsp-api.jar:tools/lib/jdom.jar:tools/spring-1.2/acegi-security-0.9.0.jar:t
 ools/spring-1.2/spring.jar:tools/lib/rome-0.8.jar:tools/lib/rome-fetcher-0.8.jar:tools/lib/commons-codec-1.3.jar:tools/hibernate-3.1/hibernate3.jar:contrib/lib/textile4j-1.20.jar:tools/buildtime/derby.jar:tools/buildtime/ant-1.6.2/ant.jar:tools/buildtime/derbynet.jar:tools/lib/rome-0.9.jar:tools/lib/rome-fetcher-0.9.jar:tools/buildtime/activation.jar:tools/buildtime/mail.jar:tools/spring-1.2/spring.jar:../../../../../Applications/Java/groovy/embeddable/groovy-all-1.0.jar:sandbox/scripting/bsf/lib/bsf.jar:tools/lib/commons-collections-3.1.jar:tools/lib/commons-lang-2.1.jar:tools/lib/commons-logging-1.0.4.jar:tools/lib/velocity-1.5.jar:tools/lib/velocity-dep-1.5.jar:tools/xmlrpc-3.0/lib/ws-commons-util-1.0.1.jar:tools/xmlrpc-3.0/lib/xmlrpc-client-3.0.jar:tools/xmlrpc-3.0/lib/xmlrpc-common-3.0.jar:tools/xmlrpc-3.0/lib/xmlrpc-server-3.0.jar:tools/spring-1.2/acegi-security-1.0.3.jar:tools/struts-2.0.6/lib/antlr-2.7.2.jar:tools/struts-2.0.6/lib/commons-beanutils-1.6.jar:tools/stru
 ts-2.0.6/lib/commons-chain-1.1.jar:tools/struts-2.0.6/lib/commons-fileupload-1.2.jar:tools/struts-2.0.6/lib/commons-io-1.3.1.jar:tools/struts-2.0.6/lib/commons-validator-1.3.0.jar:tools/struts-2.0.6/lib/freemarker-2.3.8.jar:tools/struts-2.0.6/lib/ognl-2.6.11.jar:tools/struts-2.0.6/lib/oro-2.0.8.jar:tools/struts-2.0.6/lib/struts2-core-2.0.6.jar:tools/struts-2.0.6/lib/struts2-spring-plugin-2.0.6.jar:tools/struts-2.0.6/lib/struts2-tiles-plugin-2.0.6.jar:tools/struts-2.0.6/lib/tiles-api-2.0-20070207.130156-4.jar:tools/struts-2.0.6/lib/tiles-core-2.0-20070207.130156-4.jar:tools/struts-2.0.6/lib/xwork-2.0.1.jar:tools/lib/guice-1.0.jar</classpath>
                 <source-level>1.5</source-level>
             </compilation-unit>
         </java-data>

Modified: roller/branches/roller_guice/properties.xmlf
URL: http://svn.apache.org/viewvc/roller/branches/roller_guice/properties.xmlf?view=diff&rev=539785&r1=539784&r2=539785
==============================================================================
--- roller/branches/roller_guice/properties.xmlf (original)
+++ roller/branches/roller_guice/properties.xmlf Sat May 19 11:04:58 2007
@@ -96,6 +96,7 @@
     <include name="rome-0.9.jar"/>
     <include name="rome-fetcher-0.9.jar"/>
     <include name="velocity-1.5.jar"/>
+    <include name="guice-1.0.jar"/>
 </fileset>
 
 <fileset id="presentation.jars" dir="${ro.tools}/lib">

Modified: roller/branches/roller_guice/src/org/apache/roller/business/Roller.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_guice/src/org/apache/roller/business/Roller.java?view=diff&rev=539785&r1=539784&r2=539785
==============================================================================
--- roller/branches/roller_guice/src/org/apache/roller/business/Roller.java (original)
+++ roller/branches/roller_guice/src/org/apache/roller/business/Roller.java Sat May 19 11:04:58 2007
@@ -122,6 +122,12 @@
     
     
     /**
+     * Prepare all managers for first use.
+     */
+    public void init() throws RollerException;
+    
+    
+    /**
      * Flush object states.
      */
     public void flush() throws RollerException;
@@ -138,13 +144,22 @@
      */
     public void shutdown();
     
-    /** Roller version */
-    public String getVersion();    
     
-    /** Roller build time */
+    /** 
+     * Roller version 
+     */
+    public String getVersion();
+    
+    
+    /** 
+     * Roller build time 
+     */
     public String getBuildTime();
+    
         
-    /** Get username that built Roller */
+    /** 
+     * Get username that built Roller 
+     */
     public String getBuildUser();
 }
 

Modified: roller/branches/roller_guice/src/org/apache/roller/business/RollerFactory.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_guice/src/org/apache/roller/business/RollerFactory.java?view=diff&rev=539785&r1=539784&r2=539785
==============================================================================
--- roller/branches/roller_guice/src/org/apache/roller/business/RollerFactory.java (original)
+++ roller/branches/roller_guice/src/org/apache/roller/business/RollerFactory.java Sat May 19 11:04:58 2007
@@ -18,6 +18,10 @@
 
 package org.apache.roller.business;
 
+import com.google.inject.Binder;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Module;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.roller.config.RollerConfig;
@@ -26,76 +30,35 @@
 /**
  * Provides access to the Roller instance.
  */
-public abstract class RollerFactory {
-    
+public abstract class RollerFactory implements Module {
     private static Log log = LogFactory.getLog(RollerFactory.class);
-    
-    private static final String DEFAULT_IMPL =
-            "org.apache.roller.business.hibernate.HibernateRollerImpl";
-    
-    private static Roller rollerInstance = null;
-    
-    
+    private static Injector injector = null;
+       
     
     // non-instantiable
     private RollerFactory() {
         // hello all you beautiful people
     }
     
+
+    static { 
+        String moduleClassname = RollerConfig.getProperty("guice.backend.module");
+        try {
+            Class moduleClass = Class.forName(moduleClassname);
+            Module module = (Module)moduleClass.newInstance();
+            injector = Guice.createInjector(module);
+        } catch (Throwable e) {                
+            // Fatal misconfiguration, cannot recover
+            throw new RuntimeException("Error instantiating backend module" + moduleClassname, e);
+        }
+    }
+    
     
     /**
-     * Static accessor for the instance of Roller.
+     * Static accessor for the instance of Roller
      */
     public static Roller getRoller() {
-        
-        // check to see if we need to instantiate
-        if(rollerInstance == null) {
-            
-            // lookup value for the roller classname to use
-            String roller_classname =
-                    RollerConfig.getProperty("persistence.roller.classname");
-            if(roller_classname == null || roller_classname.trim().length() < 1)
-                roller_classname = DEFAULT_IMPL;
-            
-            try {
-                Class rollerClass = Class.forName(roller_classname);
-                java.lang.reflect.Method instanceMethod =
-                        rollerClass.getMethod("instantiate", (Class[])null);
-                
-                // do the invocation
-                rollerInstance = (Roller) instanceMethod.invoke(rollerClass, (Object[])null);
-                
-                log.info("Using Roller Impl: " + roller_classname);
-                
-            } catch (Throwable e) {
-                
-                // uh oh
-                log.error("Error instantiating " + roller_classname, e);
-                
-                try {
-                    // if we didn't already try DEFAULT_IMPL then try it now
-                    if( ! DEFAULT_IMPL.equals(roller_classname)) {
-                        
-                        log.info("** Trying DEFAULT_IMPL "+DEFAULT_IMPL+" **");
-                        
-                        Class rollerClass = Class.forName(DEFAULT_IMPL);
-                        java.lang.reflect.Method instanceMethod =
-                                rollerClass.getMethod("instantiate", (Class[])null);
-                        
-                        // do the invocation
-                        rollerInstance = (Roller) instanceMethod.invoke(rollerClass, (Object[])null);
-                    } else {
-                        // we just do this so that the logger gets the message
-                        throw new Exception("Doh! Couldn't instantiate a roller class");
-                    }
-                    
-                } catch (Exception re) {
-                    log.fatal("Failed to instantiate fallback roller impl", re);
-                }
-            }
-        }
-        
-        return rollerInstance;
-    }
-    
+        return injector.getInstance(Roller.class);
+    }    
 }
+

Modified: roller/branches/roller_guice/src/org/apache/roller/business/RollerImpl.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_guice/src/org/apache/roller/business/RollerImpl.java?view=diff&rev=539785&r1=539784&r2=539785
==============================================================================
--- roller/branches/roller_guice/src/org/apache/roller/business/RollerImpl.java (original)
+++ roller/branches/roller_guice/src/org/apache/roller/business/RollerImpl.java Sat May 19 11:04:58 2007
@@ -16,49 +16,56 @@
  * directory of this distribution.
  */
 
+
 package org.apache.roller.business;
 
+import com.google.inject.Inject;
 import java.io.IOException;
 import java.util.Properties;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.roller.business.pings.AutoPingManager;
+import org.apache.roller.business.pings.PingQueueManager;
+import org.apache.roller.business.pings.PingTargetManager;
+import org.apache.roller.business.referrers.RefererManager;
 import org.apache.roller.business.referrers.ReferrerQueueManager;
-import org.apache.roller.business.referrers.ReferrerQueueManagerImpl;
-import org.apache.roller.business.runnable.ThreadManagerImpl;
-import org.apache.roller.business.search.IndexManagerImpl;
-import org.apache.roller.business.search.IndexManager;
 import org.apache.roller.business.runnable.ThreadManager;
+import org.apache.roller.business.search.IndexManager;
 import org.apache.roller.business.themes.ThemeManager;
-import org.apache.roller.business.themes.ThemeManagerImpl;
-
 
 /**
- * The abstract version of the Roller implementation.
- *
- * Here we put code that pertains to *all* implementations of the Roller
- * interface, regardless of their persistence strategy.
+ * Roller implementation designed for Dependency Injection
  */
 public abstract class RollerImpl implements Roller {
-    
-    private static Log mLogger = LogFactory.getLog(RollerImpl.class);
-    
-    private FileManager   fileManager = null;
-    private IndexManager  indexManager = null;
-    private ThreadManager threadManager = null;
-    private ThemeManager  themeManager = null;
-    private PluginManager pluginManager = null;
-            
+    private static Log log = LogFactory.getLog(RollerImpl.class);
+
     private String version = null;
     private String buildTime = null;
     private String buildUser = null;
     
+    private AutoPingManager      autopingManager;
+    private BookmarkManager      bookmarkManager;
+    private FileManager          fileManager;
+    private IndexManager         indexManager;
+    private PluginManager        pagePluginManager;
+    private PingQueueManager     pingQueueManager;
+    private PingTargetManager    pingTargetManager;
+    private PropertiesManager    propertiesManager;
+    private RefererManager       refererManager;
+    private ReferrerQueueManager referrerQueueManager;
+    private ThemeManager         themeManager;
+    private ThreadManager        threadManager;
+    private UserManager          userManager;
+    private WeblogManager        weblogManager;
+    
+    
     public RollerImpl() {
                 
         Properties props = new Properties();
         try {
             props.load(getClass().getResourceAsStream("/version.properties"));
         } catch (IOException e) {
-            mLogger.error("version.properties not found", e);
+            log.error("version.properties not found", e);
         }
         
         version = props.getProperty("ro.version", "UNKNOWN");
@@ -66,107 +73,149 @@
         buildUser = props.getProperty("ro.buildUser", "UNKNOWN");
     }
     
+    public AutoPingManager getAutopingManager() {
+        return autopingManager;
+    }
     
-    /**
-     * @see org.apache.roller.model.Roller#getFileManager()
-     */
-    public FileManager getFileManager() {
-        if (fileManager == null) {
-            fileManager = new FileManagerImpl();
-        }
-        return fileManager;
+    @Inject
+    public void setAutopingManager(AutoPingManager autopingManager) {
+        this.autopingManager = autopingManager;
     }
     
+    public BookmarkManager getBookmarkManager() {
+        return bookmarkManager;
+    }
     
-    /**
-     * @see org.apache.roller.model.Roller#getThreadManager()
-     */
-    public ThreadManager getThreadManager() {
-        if (threadManager == null) {
-            threadManager = new ThreadManagerImpl();
-        }
-        return threadManager;
+    @Inject
+    public void setBookmarkManager(BookmarkManager bookmarkManager) {
+        this.bookmarkManager = bookmarkManager;
+    }
+    
+    public FileManager getFileManager() {
+        return fileManager;
     }
     
+    @Inject
+    public void setFileManager(FileManager fileManager) {
+        this.fileManager = fileManager;
+    }
     
-    /**
-     * @see org.apache.roller.model.Roller#getIndexManager()
-     */
     public IndexManager getIndexManager() {
-        if (indexManager == null) {
-            indexManager = new IndexManagerImpl();
-        }
         return indexManager;
     }
     
+    @Inject
+    public void setIndexManager(IndexManager indexManager) {
+        this.indexManager = indexManager;
+    }
     
-    /**
-     * @see org.apache.roller.model.Roller#getThemeManager()
-     */
-    public ThemeManager getThemeManager() {
-        if (themeManager == null) {
-            themeManager = new ThemeManagerImpl();
-        }
-        return themeManager;
+    public PluginManager getPagePluginManager() {
+        return pagePluginManager;
     }
     
+    @Inject
+    public void setPagePluginManager(PluginManager pagePluginManager) {
+        this.pagePluginManager = pagePluginManager;
+    }
+    
+    public PingQueueManager getPingQueueManager() {
+        return pingQueueManager;
+    }
+        
+    @Inject
+    public void setPingQueueManager(PingQueueManager pingQueueManager) {
+        this.pingQueueManager = pingQueueManager;
+    }
+    
+    public PingTargetManager getPingTargetManager() {
+        return pingTargetManager;
+    }
+
+    @Inject
+    public void setPingTargetManager(PingTargetManager pingTargetManager) {
+        this.pingTargetManager = pingTargetManager;
+    }
+
+    public PropertiesManager getPropertiesManager() {
+        return propertiesManager;
+    }
+    
+    @Inject
+    public void setPropertiesManager(PropertiesManager propertiesManager) {
+        this.propertiesManager = propertiesManager;
+    }
+    
+    public RefererManager getRefererManager() {
+        return refererManager;
+    }
+    
+    @Inject
+    public void setRefererManager(RefererManager refererManager) {
+        this.refererManager = refererManager;
+    }
     
-    /**
-     * @see org.apache.roller.business.referrers.ReferrerQueueManager
-     */
     public ReferrerQueueManager getReferrerQueueManager() {
-        return ReferrerQueueManagerImpl.getInstance();
+        return referrerQueueManager;
     }
     
+    @Inject
+    public void setReferrerQueueManager(ReferrerQueueManager referrerQueueManager) {
+        this.referrerQueueManager = referrerQueueManager;
+    }
     
-    /**
-     * @see org.apache.roller.model.Roller#getPluginManager()
-     */
-    public PluginManager getPagePluginManager() {
-        if (pluginManager == null) {
-            pluginManager = new PluginManagerImpl();
-        }
-        return pluginManager;
+    public ThemeManager getThemeManager() {
+        return themeManager;
     }
     
+    @Inject
+    public void setThemeManager(ThemeManager themeManager) {
+        this.themeManager = themeManager;
+    }
     
-    public void release() {
-        try {
-            if (fileManager != null) fileManager.release();
-            if (threadManager != null) threadManager.release();
-            if (pluginManager != null) pluginManager.release();
-        } catch(Throwable e) {
-            mLogger.error("Error calling Roller.release()", e);
-        }
+    public ThreadManager getThreadManager() {
+        return threadManager;
     }
     
+    @Inject
+    public void setThreadManager(ThreadManager threadManager) {
+        this.threadManager = threadManager;
+    }
     
-    public void shutdown() {
-        try {
-            HitCountQueue.getInstance().shutdown();
-            if (getReferrerQueueManager() != null) getReferrerQueueManager().shutdown();
-            if (indexManager != null) indexManager.shutdown();
-            if (threadManager != null) threadManager.shutdown();
-        } catch(Throwable e) {
-            mLogger.error("Error calling Roller.shutdown()", e);
-        }
+    public UserManager getUserManager() {
+        return userManager;
     }
     
+    @Inject
+    public void setUserManager(UserManager userManager) {
+        this.userManager = userManager;
+    }
+        
+    public WeblogManager getWeblogManager() {
+        return weblogManager;
+    }
+
+    @Inject
+    public void setWeblogManager(WeblogManager weblogManager) {
+        this.weblogManager = weblogManager;
+    }
+    
+    public void init() {
+        this.indexManager.init();
+    }
+
     /** Roller version */
     public String getVersion() {
         return version;
     }
     
-    
     /** Roller build time */
     public String getBuildTime() {
         return buildTime;
-    }
-    
+    }    
     
     /** Get username that built Roller */
     public String getBuildUser() {
         return buildUser;
     }
-    
+
 }

Modified: roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateAutoPingManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateAutoPingManagerImpl.java?view=diff&rev=539785&r1=539784&r2=539785
==============================================================================
--- roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateAutoPingManagerImpl.java (original)
+++ roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateAutoPingManagerImpl.java Sat May 19 11:04:58 2007
@@ -18,6 +18,7 @@
 
 package org.apache.roller.business.hibernate;
 
+import com.google.inject.Inject;
 import org.hibernate.Criteria;
 import org.hibernate.HibernateException;
 import org.hibernate.Session;
@@ -33,10 +34,10 @@
 import java.util.List;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.roller.business.Roller;
 import org.apache.roller.config.PingConfig;
 import org.apache.roller.business.pings.AutoPingManager;
 import org.apache.roller.business.pings.PingQueueManager;
-import org.apache.roller.business.RollerFactory;
 
 
 /**
@@ -46,14 +47,16 @@
  */
 public class HibernateAutoPingManagerImpl implements AutoPingManager {
     
+    private Roller roller;
+    
     static final long serialVersionUID = 5420615676256979199L;
     
     private static Log log = LogFactory.getLog(HibernateAutoPingManagerImpl.class);
     
     private HibernatePersistenceStrategy strategy = null;
     
-    
-    public HibernateAutoPingManagerImpl(HibernatePersistenceStrategy strat) {
+    @Inject
+    public HibernateAutoPingManagerImpl(HibernatePersistenceStrategy strat, Roller roller) {
         this.strategy = strat;
     }
     
@@ -122,7 +125,7 @@
         }
         
         // TODO: new manager method for addQueueEntries(list)?
-        PingQueueManager pingQueueMgr = RollerFactory.getRoller().getPingQueueManager();
+        PingQueueManager pingQueueMgr = roller.getPingQueueManager();
         List applicableAutopings = getApplicableAutoPings(changedWeblogEntry);
         for (Iterator i = applicableAutopings.iterator(); i.hasNext(); ) {
             AutoPingData autoPing = (AutoPingData) i.next();

Modified: roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateBookmarkManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateBookmarkManagerImpl.java?view=diff&rev=539785&r1=539784&r2=539785
==============================================================================
--- roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateBookmarkManagerImpl.java (original)
+++ roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateBookmarkManagerImpl.java Sat May 19 11:04:58 2007
@@ -18,6 +18,7 @@
 
 package org.apache.roller.business.hibernate;
 
+import com.google.inject.Inject;
 import java.io.StringReader;
 import org.hibernate.Criteria;
 import org.hibernate.HibernateException;
@@ -28,7 +29,6 @@
 import org.apache.roller.pojos.FolderData;
 import org.apache.roller.pojos.WebsiteData;
 import java.util.Iterator;
-import java.util.LinkedList;
 import java.util.List;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -36,27 +36,23 @@
 import org.jdom.Element;
 import org.jdom.input.SAXBuilder;
 import org.apache.roller.business.BookmarkManager;
-import org.apache.roller.business.RollerFactory;
-import org.apache.roller.util.Utilities;
-
+import org.apache.roller.business.Roller;
 
 /**
  * Hibernate implementation of the BookmarkManager.
  */
 public class HibernateBookmarkManagerImpl implements BookmarkManager {
     
+    private Roller roller;
+    
     static final long serialVersionUID = 5286654557062382772L;
     
     private static Log log = LogFactory.getLog(HibernateBookmarkManagerImpl.class);
     
     private HibernatePersistenceStrategy strategy = null;
     
-    
-    /**
-     * @param pstrategy
-     * @param roller
-     */
-    public HibernateBookmarkManagerImpl(HibernatePersistenceStrategy strat) {
+    @Inject
+    public HibernateBookmarkManagerImpl(HibernatePersistenceStrategy strat, Roller roller) {
         log.debug("Instantiating Hibernate Bookmark Manager");
         
         this.strategy = strat;
@@ -67,7 +63,7 @@
         this.strategy.store(bookmark);
         
         // update weblog last modified date.  date updated by saveWebsite()
-        RollerFactory.getRoller().getUserManager().saveWebsite(bookmark.getWebsite());
+        roller.getUserManager().saveWebsite(bookmark.getWebsite());
     }
     
     
@@ -86,7 +82,7 @@
         //Now remove it from database
         this.strategy.remove(bookmark);
         // update weblog last modified date.  date updated by saveWebsite()
-        RollerFactory.getRoller().getUserManager()
+        roller.getUserManager()
                 .saveWebsite(bookmark.getWebsite());
     }
     
@@ -100,7 +96,7 @@
         this.strategy.store(folder);
         
         // update weblog last modified date.  date updated by saveWebsite()
-        RollerFactory.getRoller().getUserManager().saveWebsite(folder.getWebsite());
+        roller.getUserManager().saveWebsite(folder.getWebsite());
     }
     
     
@@ -109,7 +105,7 @@
         this.strategy.remove(folder);
         
         // update weblog last modified date.  date updated by saveWebsite()
-        RollerFactory.getRoller().getUserManager().saveWebsite(folder.getWebsite());
+        roller.getUserManager().saveWebsite(folder.getWebsite());
     }
     
     

Added: roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateModule.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateModule.java?view=auto&rev=539785
==============================================================================
--- roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateModule.java (added)
+++ roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateModule.java Sat May 19 11:04:58 2007
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.business.hibernate;
+
+import com.google.inject.Binder;
+import com.google.inject.Module;
+import org.apache.roller.business.BookmarkManager;
+import org.apache.roller.business.FileManager;
+import org.apache.roller.business.FileManagerImpl;
+import org.apache.roller.business.PluginManager;
+import org.apache.roller.business.PluginManagerImpl;
+import org.apache.roller.business.PropertiesManager;
+import org.apache.roller.business.Roller;
+import org.apache.roller.business.UserManager;
+import org.apache.roller.business.WeblogManager;
+import org.apache.roller.business.pings.AutoPingManager;
+import org.apache.roller.business.pings.PingQueueManager;
+import org.apache.roller.business.pings.PingTargetManager;
+import org.apache.roller.business.referrers.RefererManager;
+import org.apache.roller.business.referrers.ReferrerQueueManager;
+import org.apache.roller.business.referrers.ReferrerQueueManagerImpl;
+import org.apache.roller.business.runnable.ThreadManager;
+import org.apache.roller.business.runnable.ThreadManagerImpl;
+import org.apache.roller.business.search.IndexManager;
+import org.apache.roller.business.search.IndexManagerImpl;
+import org.apache.roller.business.themes.ThemeManager;
+import org.apache.roller.business.themes.ThemeManagerImpl;
+
+/**
+ * Guice module for configuring Hibernate as Roller-backend.
+ */
+public class HibernateModule implements Module {
+
+    public void configure(Binder binder) {
+        
+        binder.bind(Roller.class).to(HibernateRollerImpl.class);
+        
+        binder.bind(AutoPingManager.class).to(     HibernateAutoPingManagerImpl.class);   
+        binder.bind(BookmarkManager.class).to(     HibernateBookmarkManagerImpl.class);  
+        binder.bind(PingQueueManager.class).to(    HibernatePingQueueManagerImpl.class);   
+        binder.bind(PingTargetManager.class).to(   HibernatePingTargetManagerImpl.class); 
+        binder.bind(PropertiesManager.class).to(   HibernatePropertiesManagerImpl.class);   
+        binder.bind(RefererManager.class).to(      HibernateRefererManagerImpl.class);
+        binder.bind(UserManager.class).to(         HibernateUserManagerImpl.class);   
+        binder.bind(WeblogManager.class).to(       HibernateWeblogManagerImpl.class);   
+        
+        binder.bind(ReferrerQueueManager.class).to(ReferrerQueueManagerImpl.class); 
+        binder.bind(FileManager.class).to(         FileManagerImpl.class);   
+        binder.bind(IndexManager.class).to(        IndexManagerImpl.class);
+        binder.bind(PluginManager.class).to(       PluginManagerImpl.class);    
+        binder.bind(ThemeManager.class).to(        ThemeManagerImpl.class);  
+        binder.bind(ThreadManager.class).to(       ThreadManagerImpl.class);  
+    }    
+}
+

Modified: roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernatePersistenceStrategy.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernatePersistenceStrategy.java?view=diff&rev=539785&r1=539784&r2=539785
==============================================================================
--- roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernatePersistenceStrategy.java (original)
+++ roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernatePersistenceStrategy.java Sat May 19 11:04:58 2007
@@ -18,10 +18,12 @@
 
 package org.apache.roller.business.hibernate;
 
+import com.google.inject.Singleton;
 import java.io.StringBufferInputStream;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hibernate.HibernateException;
@@ -30,6 +32,7 @@
 import org.hibernate.Transaction;
 import org.hibernate.cfg.Configuration;
 import org.apache.roller.RollerException;
+import org.apache.roller.config.RollerConfig;
 import org.jdom.Attribute;
 import org.jdom.Document;
 import org.jdom.Element;
@@ -47,6 +50,7 @@
  * that can be easily reused.
  *
  */
+@Singleton
 public class HibernatePersistenceStrategy {
     
     static final long serialVersionUID = 2561090040518169098L;
@@ -61,9 +65,29 @@
             return new InputSource(new StringBufferInputStream(""));
         }
     };
-    
-    
-    public HibernatePersistenceStrategy() {
+        
+    public HibernatePersistenceStrategy() throws RollerException {
+        try {
+            if (StringUtils.isNotEmpty(RollerConfig.getProperty("jdbc.driverClass"))) {
+                // create and configure for JDBC access
+                initViaJDBCProperties(
+                    RollerConfig.getProperty("hibernate.configResource"),
+                    RollerConfig.getProperty("hibernate.dialect"),
+                    RollerConfig.getProperty("jdbc.driverClass"),
+                    RollerConfig.getProperty("jdbc.connectionURL"),
+                    RollerConfig.getProperty("jdbc.username"),
+                    RollerConfig.getProperty("jdbc.password"));
+            } else {
+                // create an configure via config resource only
+                initViaDataSource(
+                    RollerConfig.getProperty("hibernate.configResource"),
+                    RollerConfig.getProperty("hibernate.dialect"));
+            }
+        } catch(Throwable t) {
+            // if this happens then we are screwed
+            log.fatal("Error initializing Hibernate", t);
+            throw new RollerException(t);
+        }
     }   
 
     /** 
@@ -71,7 +95,7 @@
      * @param configResouce Classpath-based path to Hibernate config file (e.g. "/hibernate.cgf.xml")
      * @parma dialect Classname of Hibernate dialect to be used (overriding any specified in the configResource)
      */
-    public HibernatePersistenceStrategy(
+    private void initViaDataSource(
             String configResource,
             String dialect) throws Exception {
 
@@ -118,7 +142,7 @@
      * @param configResouce Classpath-based path to Hibernate config file (e.g. "/hibernate.cgf.xml")
      * @parma dialect Classname of Hibernate dialect to be used (or null to use one specified in configResource)
      */
-    public HibernatePersistenceStrategy(
+    private void initViaJDBCProperties(
             String configResource,
             String dialect,
             String driverClass,

Modified: roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernatePingQueueManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernatePingQueueManagerImpl.java?view=diff&rev=539785&r1=539784&r2=539785
==============================================================================
--- roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernatePingQueueManagerImpl.java (original)
+++ roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernatePingQueueManagerImpl.java Sat May 19 11:04:58 2007
@@ -19,6 +19,7 @@
 
 package org.apache.roller.business.hibernate;
 
+import com.google.inject.Inject;
 import org.hibernate.Criteria;
 import org.hibernate.HibernateException;
 import org.hibernate.Session;
@@ -47,7 +48,7 @@
     
     private HibernatePersistenceStrategy strategy = null;
     
-    
+    @Inject    
     public HibernatePingQueueManagerImpl(HibernatePersistenceStrategy strat) {
         this.strategy = strat;
     }

Modified: roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernatePingTargetManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernatePingTargetManagerImpl.java?view=diff&rev=539785&r1=539784&r2=539785
==============================================================================
--- roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernatePingTargetManagerImpl.java (original)
+++ roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernatePingTargetManagerImpl.java Sat May 19 11:04:58 2007
@@ -18,6 +18,7 @@
 
 package org.apache.roller.business.hibernate;
 
+import com.google.inject.Inject;
 import java.net.InetAddress;
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -35,9 +36,9 @@
 import java.util.Collection;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.roller.business.Roller;
 import org.apache.roller.business.pings.AutoPingManager;
 import org.apache.roller.business.pings.PingTargetManager;
-import org.apache.roller.business.RollerFactory;
 import org.apache.roller.pojos.AutoPingData;
 import org.apache.roller.pojos.PingQueueEntryData;
 
@@ -48,6 +49,7 @@
  * @author <a href="mailto:anil@busybuddha.org">Anil Gangolli</a>
  */
 public class HibernatePingTargetManagerImpl implements PingTargetManager {
+    private Roller roller = null;
     
     static final long serialVersionUID = 121008492583382718L;
     
@@ -56,7 +58,8 @@
     private HibernatePersistenceStrategy strategy = null;
     
     
-    public HibernatePingTargetManagerImpl(HibernatePersistenceStrategy strat) {
+    @Inject
+    public HibernatePingTargetManagerImpl(HibernatePersistenceStrategy strat, Roller roller) {
         this.strategy = strat;
     }
     
@@ -87,7 +90,7 @@
         }
         
         // Remove the website's auto ping configurations
-        AutoPingManager autoPingMgr = RollerFactory.getRoller().getAutopingManager();
+        AutoPingManager autoPingMgr = roller.getAutopingManager();
         List autopings = autoPingMgr.getAutoPingsByTarget(ping);
         Iterator it = autopings.iterator();
         while(it.hasNext()) {

Modified: roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernatePropertiesManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernatePropertiesManagerImpl.java?view=diff&rev=539785&r1=539784&r2=539785
==============================================================================
--- roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernatePropertiesManagerImpl.java (original)
+++ roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernatePropertiesManagerImpl.java Sat May 19 11:04:58 2007
@@ -18,6 +18,7 @@
 
 package org.apache.roller.business.hibernate;
 
+import com.google.inject.Inject;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -34,9 +35,6 @@
 import org.apache.roller.config.runtime.PropertyDef;
 import org.apache.roller.config.runtime.RuntimeConfigDefs;
 import org.apache.roller.business.PropertiesManager;
-import org.apache.roller.business.Roller;
-import org.apache.roller.business.RollerFactory;
-import org.apache.roller.pojos.RollerConfigData;
 import org.apache.roller.pojos.RollerPropertyData;
 
 
@@ -55,6 +53,7 @@
     /** 
      * Creates a new instance of HibernatePropertiesManagerImpl
      */
+    @Inject
     public HibernatePropertiesManagerImpl(HibernatePersistenceStrategy strat) {
         
         log.debug("Instantiating Hibernate Properties Manager");

Modified: roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateRefererManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateRefererManagerImpl.java?view=diff&rev=539785&r1=539784&r2=539785
==============================================================================
--- roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateRefererManagerImpl.java (original)
+++ roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateRefererManagerImpl.java Sat May 19 11:04:58 2007
@@ -18,6 +18,7 @@
 
 package org.apache.roller.business.hibernate;
 
+import com.google.inject.Inject;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
@@ -46,7 +47,6 @@
 import org.hibernate.engine.SessionFactoryImplementor;
 import org.hibernate.dialect.Dialect;
 import org.apache.roller.business.Roller;
-import org.apache.roller.business.RollerFactory;
 import org.apache.roller.business.UserManager;
 import org.apache.roller.business.WeblogManager;
 import org.apache.roller.pojos.StatCount;
@@ -60,6 +60,8 @@
  */
 public class HibernateRefererManagerImpl implements RefererManager {
     
+    private Roller roller = null;
+    
     static final long serialVersionUID = -4966091850482256435L;
     
     private static Log log = LogFactory.getLog(HibernateRefererManagerImpl.class);
@@ -71,6 +73,7 @@
     private Date mRefDate = new Date();
     
         
+    @Inject
     public HibernateRefererManagerImpl(HibernatePersistenceStrategy strat) {
         
         log.debug("Instantiating Hibernate Referer Manager");
@@ -527,13 +530,13 @@
         
         // lookup the weblog now
         try {
-            UserManager userMgr = RollerFactory.getRoller().getUserManager();
+            UserManager userMgr = roller.getUserManager();
             weblog = userMgr.getWebsiteByHandle(weblogHandle);
             if (weblog == null) return;
             
             // now lookup weblog entry if possible
             if (entryAnchor != null) {
-                WeblogManager weblogMgr = RollerFactory.getRoller().getWeblogManager();
+                WeblogManager weblogMgr = roller.getWeblogManager();
                 entry = weblogMgr.getWeblogEntryByAnchor(weblog, entryAnchor);
             }
         } catch (RollerException re) {
@@ -629,8 +632,7 @@
                     // Launch thread to extract referer linkback
                     
                     try {
-                        Roller mRoller = RollerFactory.getRoller();
-                        mRoller.getThreadManager().executeInBackground(
+                        roller.getThreadManager().executeInBackground(
                                 new LinkbackExtractorRunnable(ref));
                     } catch (InterruptedException e) {
                         log.warn("Interrupted during linkback extraction",e);

Modified: roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateRollerImpl.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateRollerImpl.java?view=diff&rev=539785&r1=539784&r2=539785
==============================================================================
--- roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateRollerImpl.java (original)
+++ roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateRollerImpl.java Sat May 19 11:04:58 2007
@@ -18,86 +18,30 @@
 
 package org.apache.roller.business.hibernate;
 
-import org.apache.commons.lang.StringUtils;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.roller.RollerException;
 import org.apache.roller.business.RollerImpl;
-import org.apache.roller.config.RollerConfig;
-import org.apache.roller.business.BookmarkManager;
-import org.apache.roller.business.pings.AutoPingManager;
-import org.apache.roller.business.pings.PingQueueManager;
-import org.apache.roller.business.pings.PingTargetManager;
-import org.apache.roller.business.PropertiesManager;
-import org.apache.roller.business.referrers.RefererManager;
-import org.apache.roller.business.Roller;
-import org.apache.roller.business.UserManager;
-import org.apache.roller.business.WeblogManager;
-import org.apache.roller.business.runnable.ThreadManager;
-
 
 /**
  * A Hibernate specific implementation of the Roller business layer.
  */
-public class HibernateRollerImpl extends RollerImpl {
+@Singleton
+public class HibernateRollerImpl extends RollerImpl { 
     
     static final long serialVersionUID = 5256135928578074652L;
     
-    private static Log mLogger = LogFactory.getLog(HibernateRollerImpl.class);
-    
-    // our singleton instance
-    private static HibernateRollerImpl me = null;
+    private static Log log = LogFactory.getLog(HibernateRollerImpl.class);
     
     // a persistence utility class
     private HibernatePersistenceStrategy strategy = null;
-    
-    // references to the managers we maintain
-    private BookmarkManager bookmarkManager = null;
-    private PropertiesManager propertiesManager = null;
-    private RefererManager refererManager = null;
-    private UserManager userManager = null;
-    private WeblogManager weblogManager = null;
-    private PingQueueManager pingQueueManager = null;
-    private AutoPingManager autoPingManager = null;
-    private PingTargetManager pingTargetManager = null;
-    private ThreadManager threadManager = null;
-    
-    
-    protected HibernateRollerImpl() throws RollerException {
-        try {
-            if (StringUtils.isNotEmpty(RollerConfig.getProperty("jdbc.driverClass"))) {
-                // create and configure for JDBC access
-                strategy = new HibernatePersistenceStrategy(
-                    RollerConfig.getProperty("hibernate.configResource"),
-                    RollerConfig.getProperty("hibernate.dialect"),
-                    RollerConfig.getProperty("jdbc.driverClass"),
-                    RollerConfig.getProperty("jdbc.connectionURL"),
-                    RollerConfig.getProperty("jdbc.username"),
-                    RollerConfig.getProperty("jdbc.password"));
-            } else {
-                // create an configure via config resource only
-                strategy = new HibernatePersistenceStrategy(
-                    RollerConfig.getProperty("hibernate.configResource"),
-                    RollerConfig.getProperty("hibernate.dialect"));
-            }
-        } catch(Throwable t) {
-            // if this happens then we are screwed
-            mLogger.fatal("Error initializing Hibernate", t);
-            throw new RollerException(t);
-        }
-    }
-    
-    
-    /**
-     * Instantiates and returns an instance of HibernateRollerImpl.
-     */
-    public static Roller instantiate() throws RollerException {
-        if (me == null) {
-            mLogger.debug("Instantiating HibernateRollerImpl");
-            me = new HibernateRollerImpl();
-        }
         
-        return me;
+    
+    @Inject
+    public HibernateRollerImpl(HibernatePersistenceStrategy strategy) throws RollerException {
+        this.strategy = strategy;
     }
     
     
@@ -106,132 +50,24 @@
     }
     
     
-    public void release() {
-        
+    public void release() {        
         // release our own stuff first
-        if (bookmarkManager != null) bookmarkManager.release();
-        if (refererManager != null) refererManager.release();
-        if (userManager != null) userManager.release();
-        if (weblogManager != null) weblogManager.release();
-        if (pingTargetManager != null) pingTargetManager.release();
-        if (pingQueueManager != null) pingQueueManager.release();
-        if (autoPingManager != null) autoPingManager.release();
-        if( threadManager != null) threadManager.release();
+        getBookmarkManager().release();
+        getRefererManager().release();
+        getUserManager().release();
+        getWeblogManager().release();
+        getPingTargetManager().release();
+        getPingQueueManager().release();
+        getAutopingManager().release();
+        getThreadManager().release();
         
         // tell Hibernate to close down
         this.strategy.release();
-        
-        // then let parent do its thing
-        super.release();
     }
     
     
-    public void shutdown() {
-        
+    public void shutdown() {        
         // do our own shutdown first
         this.release();
-        
-        // then let parent do its thing
-        super.shutdown();
-    }
-    
-    
-    /**
-     * @see org.apache.roller.model.Roller#getUserManager()
-     */
-    public UserManager getUserManager() {
-        if ( userManager == null ) {
-            userManager = new HibernateUserManagerImpl(strategy);
-        }
-        return userManager;
-    }
-    
-    
-    /**
-     * @see org.apache.roller.model.Roller#getBookmarkManager()
-     */
-    public BookmarkManager getBookmarkManager() {
-        if ( bookmarkManager == null ) {
-            bookmarkManager = new HibernateBookmarkManagerImpl(strategy);
-        }
-        return bookmarkManager;
-    }
-    
-    
-    /**
-     * @see org.apache.roller.model.Roller#getWeblogManager()
-     */
-    public WeblogManager getWeblogManager() {
-        if ( weblogManager == null ) {
-            weblogManager = new HibernateWeblogManagerImpl(strategy);
-        }
-        return weblogManager;
-    }
-    
-    
-    /**
-     * @see org.apache.roller.model.Roller#getRefererManager()
-     */
-    public RefererManager getRefererManager() {
-        if ( refererManager == null ) {
-            refererManager = new HibernateRefererManagerImpl(strategy);
-        }
-        return refererManager;
-    }
-    
-    
-    /**
-     * @see org.apache.roller.model.Roller#getPropertiesManager()
-     */
-    public PropertiesManager getPropertiesManager() {
-        if (propertiesManager == null) {
-            propertiesManager = new HibernatePropertiesManagerImpl(strategy);
-        }
-        return propertiesManager;
-    }
-    
-    
-    /**
-     * @see org.apache.roller.model.Roller#getPingTargetManager()
-     */
-    public PingQueueManager getPingQueueManager() {
-        if (pingQueueManager == null) {
-            pingQueueManager = new HibernatePingQueueManagerImpl(strategy);
-        }
-        return pingQueueManager;
-    }
-    
-    
-    /**
-     * @see org.apache.roller.model.Roller#getPingTargetManager()
-     */
-    public AutoPingManager getAutopingManager() {
-        if (autoPingManager == null) {
-            autoPingManager = new HibernateAutoPingManagerImpl(strategy);
-        }
-        return autoPingManager;
-    }
-    
-    
-    /**
-     * @see org.apache.roller.model.Roller#getPingTargetManager()
-     */
-    public PingTargetManager getPingTargetManager() {
-        if (pingTargetManager == null) {
-            pingTargetManager = new HibernatePingTargetManagerImpl(strategy);
-        }
-        return pingTargetManager;
-    }
-    
-    
-    /**
-     * @see org.apache.roller.model.Roller#getThreadManager()
-     */
-    public ThreadManager getThreadManager() {
-        if (threadManager == null) {
-            threadManager = new HibernateThreadManagerImpl(strategy);
-        }
-        return threadManager;
-    }
-    
+    }   
 }

Modified: roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateThreadManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateThreadManagerImpl.java?view=diff&rev=539785&r1=539784&r2=539785
==============================================================================
--- roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateThreadManagerImpl.java (original)
+++ roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateThreadManagerImpl.java Sat May 19 11:04:58 2007
@@ -18,6 +18,7 @@
 
 package org.apache.roller.business.hibernate;
 
+import com.google.inject.Inject;
 import java.util.Date;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -46,6 +47,7 @@
     private HibernatePersistenceStrategy strategy = null;
     
     
+    @Inject
     public HibernateThreadManagerImpl(HibernatePersistenceStrategy strat) {
         super();
         
@@ -67,7 +69,7 @@
             
             if(taskLock == null) {
                 // insert an empty record, then we will actually acquire the
-                // lease below using an update statement 
+                // lease below using an update statement
                 taskLock = new TaskLockData();
                 taskLock.setName(task.getName());
                 taskLock.setTimeAquired(new Date(0));

Modified: roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateUserManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateUserManagerImpl.java?view=diff&rev=539785&r1=539784&r2=539785
==============================================================================
--- roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateUserManagerImpl.java (original)
+++ roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateUserManagerImpl.java Sat May 19 11:04:58 2007
@@ -18,9 +18,9 @@
 
 package org.apache.roller.business.hibernate;
 
+import com.google.inject.Inject;
 import java.util.ArrayList;
 import java.util.Date;
-import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
@@ -79,6 +79,7 @@
     // cached mapping of userNames -> userIds
     private Map userNameToIdMap = new Hashtable();
         
+    @Inject
     public HibernateUserManagerImpl(HibernatePersistenceStrategy strat) {
         log.debug("Instantiating Hibernate User Manager");
         

Modified: roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java?view=diff&rev=539785&r1=539784&r2=539785
==============================================================================
--- roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java (original)
+++ roller/branches/roller_guice/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java Sat May 19 11:04:58 2007
@@ -18,6 +18,7 @@
 
 package org.apache.roller.business.hibernate;
 
+import com.google.inject.Inject;
 import java.sql.Timestamp;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -36,6 +37,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.roller.RollerException;
+import org.apache.roller.business.Roller;
 import org.apache.roller.business.RollerFactory;
 import org.apache.roller.business.WeblogManagerImpl;
 import org.apache.roller.pojos.CommentData;
@@ -72,6 +74,7 @@
     private static Log log = LogFactory.getLog(HibernateWeblogManagerImpl.class);
     
     private HibernatePersistenceStrategy strategy = null;
+    private Roller roller = null;
     
     // cached mapping of entryAnchors -> entryIds
     private Hashtable entryAnchorToIdMap = new Hashtable();
@@ -81,7 +84,9 @@
     
     private Comparator tagStatComparator = new TagStatComparator();
     
-    public HibernateWeblogManagerImpl(HibernatePersistenceStrategy strat) {
+    
+    @Inject
+    public HibernateWeblogManagerImpl(HibernatePersistenceStrategy strat, Roller roller) {
         log.debug("Instantiating Hibernate Weblog Manager");
         
         this.strategy = strat;

Modified: roller/branches/roller_guice/src/org/apache/roller/business/search/IndexManager.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_guice/src/org/apache/roller/business/search/IndexManager.java?view=diff&rev=539785&r1=539784&r2=539785
==============================================================================
--- roller/branches/roller_guice/src/org/apache/roller/business/search/IndexManager.java (original)
+++ roller/branches/roller_guice/src/org/apache/roller/business/search/IndexManager.java Sat May 19 11:04:58 2007
@@ -47,6 +47,8 @@
     /** Execute operation immediately */
     public abstract void executeIndexOperationNow(final IndexOperation op);
     
+    public void init();
+    
     /**
      * Release all resources associated with Roller session.
      */

Modified: roller/branches/roller_guice/src/org/apache/roller/business/search/IndexManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_guice/src/org/apache/roller/business/search/IndexManagerImpl.java?view=diff&rev=539785&r1=539784&r2=539785
==============================================================================
--- roller/branches/roller_guice/src/org/apache/roller/business/search/IndexManagerImpl.java (original)
+++ roller/branches/roller_guice/src/org/apache/roller/business/search/IndexManagerImpl.java Sat May 19 11:04:58 2007
@@ -44,9 +44,8 @@
 
 import EDU.oswego.cs.dl.util.concurrent.ReadWriteLock;
 import EDU.oswego.cs.dl.util.concurrent.WriterPreferenceReadWriteLock;
+import com.google.inject.Inject;
 import org.apache.roller.config.RollerConfig;
-import org.apache.roller.business.RollerFactory;
-import org.apache.commons.lang.StringUtils;
 
 /**
  * Lucene implementation of IndexManager. This is the central entry point 
@@ -55,6 +54,9 @@
  * @author mraible (formatting and making indexDir configurable)
  */
 public class IndexManagerImpl implements IndexManager {
+    private Roller roller; 
+    
+    
     //~ Static fields/initializers
     // =============================================
     
@@ -92,7 +94,13 @@
      * @param indexDir -
      *            the path to the index directory
      */
-    public IndexManagerImpl() {
+    @Inject
+    public IndexManagerImpl(Roller roller) {
+        this.roller = roller;
+    }
+    
+    public void init() {
+        
         // check config to see if the internal search is enabled
         String enabled = RollerConfig.getProperty("search.enabled");
         if("false".equalsIgnoreCase(enabled))
@@ -221,7 +229,7 @@
             // only if search is enabled
             if(this.searchEnabled) {
                 mLogger.debug("Starting scheduled index operation: "+op.getClass().getName());
-                RollerFactory.getRoller().getThreadManager().executeInBackground(op);
+                roller.getThreadManager().executeInBackground(op);
             }
         } catch (InterruptedException e) {
             mLogger.error("Error executing operation", e);
@@ -236,7 +244,7 @@
             // only if search is enabled
             if(this.searchEnabled) {
                 mLogger.debug("Executing index operation now: "+op.getClass().getName());
-                RollerFactory.getRoller().getThreadManager().executeInForeground(op);
+                roller.getThreadManager().executeInForeground(op);
             }
         } catch (InterruptedException e) {
             mLogger.error("Error executing operation", e);

Added: roller/branches/roller_guice/tools/lib/guice-1.0.jar
URL: http://svn.apache.org/viewvc/roller/branches/roller_guice/tools/lib/guice-1.0.jar?view=auto&rev=539785
==============================================================================
Binary file - no diff available.

Propchange: roller/branches/roller_guice/tools/lib/guice-1.0.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: roller/branches/roller_guice/web/WEB-INF/classes/roller.properties
URL: http://svn.apache.org/viewvc/roller/branches/roller_guice/web/WEB-INF/classes/roller.properties?view=diff&rev=539785&r1=539784&r2=539785
==============================================================================
--- roller/branches/roller_guice/web/WEB-INF/classes/roller.properties (original)
+++ roller/branches/roller_guice/web/WEB-INF/classes/roller.properties Sat May 19 11:04:58 2007
@@ -329,8 +329,10 @@
 #----------------------------------
 # Persistence settings
 
-persistence.roller.classname=org.apache.roller.business.hibernate.HibernateRollerImpl
-persistence.filemanager.classname=org.apache.roller.business.FileManagerImpl
+#persistence.roller.classname=org.apache.roller.business.hibernate.HibernateRollerImpl
+#persistence.filemanager.classname=org.apache.roller.business.FileManagerImpl
+
+guice.backend.module=org.apache.roller.business.hibernate.HibernateModule
 
 #----------------------------------
 # comment authentication



Mime
View raw message