//# 1 errors, 71 messages
//#
/*
    //#GuiceWebloggerProvider.java:1:1: class: org.apache.roller.weblogger.business.GuiceWebloggerProvider
    //#GuiceWebloggerProvider.java:1:1: method: org.apache.roller.weblogger.business.GuiceWebloggerProvider.org.apache.roller.weblogger.business.GuiceWebloggerProvider__static_init
 * 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.weblogger.business;

import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module;
import org.apache.roller.weblogger.config.WebloggerConfig;


/**
 * A Guice specific implementation of a WebloggerProvider.
 */
public class GuiceWebloggerProvider implements WebloggerProvider {
    
    // Guice injector
    protected final Injector injector;
    
    // maintain our own singleton instance of Weblogger
    protected Weblogger webloggerInstance = null;
    
    
    /**
     * Instantiate a new GuiceWebloggerProvider using default guice module 
     * configured in WebloggerConfig via 'guice.backend.module' property.
     */
    public GuiceWebloggerProvider() {
    //#GuiceWebloggerProvider.java:43: method: void org.apache.roller.weblogger.business.GuiceWebloggerProvider.org.apache.roller.weblogger.business.GuiceWebloggerProvider()
    //#input(void org.apache.roller.weblogger.business.GuiceWebloggerProvider()): "="._tainted
    //#input(void org.apache.roller.weblogger.business.GuiceWebloggerProvider()): "Error instantiating backend module "._tainted
    //#input(void org.apache.roller.weblogger.business.GuiceWebloggerProvider()): "Fetching property ["._tainted
    //#input(void org.apache.roller.weblogger.business.GuiceWebloggerProvider()): "]"._tainted
    //#input(void org.apache.roller.weblogger.business.GuiceWebloggerProvider()): "guice.backend.module"._tainted
    //#input(void org.apache.roller.weblogger.business.GuiceWebloggerProvider()): org/apache/roller/weblogger/config/WebloggerConfig.config
    //#input(void org.apache.roller.weblogger.business.GuiceWebloggerProvider()): org/apache/roller/weblogger/config/WebloggerConfig.log
    //#input(void org.apache.roller.weblogger.business.GuiceWebloggerProvider()): this
    //#output(void org.apache.roller.weblogger.business.GuiceWebloggerProvider()): this.injector
    //#output(void org.apache.roller.weblogger.business.GuiceWebloggerProvider()): this.webloggerInstance
    //#pre[1] (void org.apache.roller.weblogger.business.GuiceWebloggerProvider()): org/apache/roller/weblogger/config/WebloggerConfig.config != null
    //#pre[2] (void org.apache.roller.weblogger.business.GuiceWebloggerProvider()): org/apache/roller/weblogger/config/WebloggerConfig.log != null
    //#presumption(void org.apache.roller.weblogger.business.GuiceWebloggerProvider()): java.lang.Class:forName(...)@51 != null
    //#post(void org.apache.roller.weblogger.business.GuiceWebloggerProvider()): init'ed(this.injector)
    //#post(void org.apache.roller.weblogger.business.GuiceWebloggerProvider()): this.webloggerInstance == null
    //#unanalyzed(void org.apache.roller.weblogger.business.GuiceWebloggerProvider()): Effects-of-calling:java.lang.StringBuilder
    //#unanalyzed(void org.apache.roller.weblogger.business.GuiceWebloggerProvider()): Effects-of-calling:java.lang.StringBuilder:append
    //#unanalyzed(void org.apache.roller.weblogger.business.GuiceWebloggerProvider()): Effects-of-calling:java.lang.StringBuilder:toString
    //#unanalyzed(void org.apache.roller.weblogger.business.GuiceWebloggerProvider()): Effects-of-calling:java.lang.String:trim
    //#unanalyzed(void org.apache.roller.weblogger.business.GuiceWebloggerProvider()): Effects-of-calling:org.apache.commons.logging.Log:debug
    //#unanalyzed(void org.apache.roller.weblogger.business.GuiceWebloggerProvider()): Effects-of-calling:java.util.Properties:getProperty
        
        String moduleClassname = WebloggerConfig.getProperty("guice.backend.module");
        if(moduleClassname == null) {
    //#GuiceWebloggerProvider.java:46: ?NullPointerException check
    //#    moduleClassname != null
    //#    severity: LOW
    //#    class: org.apache.roller.weblogger.business.GuiceWebloggerProvider
    //#    method: void org.apache.roller.weblogger.business.GuiceWebloggerProvider()
    //#    basic block: Entry_BB_1
    //#    assertion: moduleClassname != null
    //#    VN: getProperty(...) == null
    //#    Expected: {0}
    //#    Bad: {1}
    //#    Attribs:  Int  Exp in +/-1000  Exp singleton  Bad singleton  Bad overlaps +/-1000  Bad > Exp
            throw new NullPointerException("unable to lookup default guice module via property 'guice.backend.module'");
        }
        
        try {
            Class moduleClass = Class.forName(moduleClassname);
            Module module = (Module)moduleClass.newInstance();
            injector = Guice.createInjector(module);
    //#GuiceWebloggerProvider.java:53: Warning: method not available
    //#    -- call on Injector com.google.inject.Guice:createInjector(Module[])
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.business.GuiceWebloggerProvider
    //#    method: void org.apache.roller.weblogger.business.GuiceWebloggerProvider()
    //#    unanalyzed callee: Injector com.google.inject.Guice:createInjector(Module[])
        } catch (Throwable e) {                
            // Fatal misconfiguration, cannot recover
            throw new RuntimeException("Error instantiating backend module " + moduleClassname, e);
        }
    }
    //#GuiceWebloggerProvider.java:58: end of method: void org.apache.roller.weblogger.business.GuiceWebloggerProvider.org.apache.roller.weblogger.business.GuiceWebloggerProvider()
    
    
    /**
     * Instantiate a new GuiceWebloggerProvider using the given Guice module.
     *
     * @param moduleClassname The full classname of the Guice module to use.
     */
    public GuiceWebloggerProvider(String moduleClassname) {
    //#GuiceWebloggerProvider.java:66: method: void org.apache.roller.weblogger.business.GuiceWebloggerProvider.org.apache.roller.weblogger.business.GuiceWebloggerProvider(String)
    //#input(void org.apache.roller.weblogger.business.GuiceWebloggerProvider(String)): "Error instantiating backend module "._tainted
    //#input(void org.apache.roller.weblogger.business.GuiceWebloggerProvider(String)): moduleClassname
    //#input(void org.apache.roller.weblogger.business.GuiceWebloggerProvider(String)): moduleClassname._tainted
    //#input(void org.apache.roller.weblogger.business.GuiceWebloggerProvider(String)): this
    //#output(void org.apache.roller.weblogger.business.GuiceWebloggerProvider(String)): this.injector
    //#output(void org.apache.roller.weblogger.business.GuiceWebloggerProvider(String)): this.webloggerInstance
    //#pre[1] (void org.apache.roller.weblogger.business.GuiceWebloggerProvider(String)): moduleClassname != null
    //#presumption(void org.apache.roller.weblogger.business.GuiceWebloggerProvider(String)): java.lang.Class:forName(...)@73 != null
    //#post(void org.apache.roller.weblogger.business.GuiceWebloggerProvider(String)): init'ed(this.injector)
    //#post(void org.apache.roller.weblogger.business.GuiceWebloggerProvider(String)): this.webloggerInstance == null
        
        if(moduleClassname == null) {
            throw new NullPointerException("moduleClassname cannot be null");
        }
        
        try {
            Class moduleClass = Class.forName(moduleClassname);
            Module module = (Module)moduleClass.newInstance();
            injector = Guice.createInjector(module);
    //#GuiceWebloggerProvider.java:75: Warning: method not available
    //#    -- call on Injector com.google.inject.Guice:createInjector(Module[])
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.business.GuiceWebloggerProvider
    //#    method: void org.apache.roller.weblogger.business.GuiceWebloggerProvider(String)
    //#    unanalyzed callee: Injector com.google.inject.Guice:createInjector(Module[])
        } catch (Throwable e) {                
            // Fatal misconfiguration, cannot recover
            throw new RuntimeException("Error instantiating backend module " + moduleClassname, e);
        }
    }
    //#GuiceWebloggerProvider.java:80: end of method: void org.apache.roller.weblogger.business.GuiceWebloggerProvider.org.apache.roller.weblogger.business.GuiceWebloggerProvider(String)
    
    
    /**
     * @inheritDoc
     */
    public void bootstrap() {
        webloggerInstance =  injector.getInstance(Weblogger.class);
    //#GuiceWebloggerProvider.java:87: method: void org.apache.roller.weblogger.business.GuiceWebloggerProvider.bootstrap()
    //#GuiceWebloggerProvider.java:87: Warning: method not available
    //#    -- call on Object com.google.inject.Injector:getInstance(Class)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.business.GuiceWebloggerProvider
    //#    method: void bootstrap()
    //#    unanalyzed callee: Object com.google.inject.Injector:getInstance(Class)
    //#input(void bootstrap()): org/apache/roller/weblogger/business/Weblogger.__Descendant_Table[org/apache/roller/weblogger/business/WebloggerImpl]
    //#input(void bootstrap()): org/apache/roller/weblogger/business/Weblogger.__Descendant_Table[org/apache/roller/weblogger/business/Weblogger]
    //#input(void bootstrap()): org/apache/roller/weblogger/business/Weblogger.__Descendant_Table[org/apache/roller/weblogger/business/jpa/JPAWebloggerImpl]
    //#input(void bootstrap()): org/apache/roller/weblogger/business/Weblogger.__Descendant_Table[others]
    //#input(void bootstrap()): this
    //#input(void bootstrap()): this.injector
    //#output(void bootstrap()): this.webloggerInstance
    //#pre[2] (void bootstrap()): this.injector != null
    //#presumption(void bootstrap()): com.google.inject.Injector:getInstance(...).__Tag@87 in {org/apache/roller/weblogger/business/Weblogger, org/apache/roller/weblogger/business/WebloggerImpl, org/apache/roller/weblogger/business/jpa/JPAWebloggerImpl}
    //#post(void bootstrap()): init'ed(this.webloggerInstance)
    }
    //#GuiceWebloggerProvider.java:88: end of method: void org.apache.roller.weblogger.business.GuiceWebloggerProvider.bootstrap()
    
    
    /**
     * @inheritDoc
     */
    public Weblogger getWeblogger() {
        return webloggerInstance;
    //#GuiceWebloggerProvider.java:95: method: Weblogger org.apache.roller.weblogger.business.GuiceWebloggerProvider.getWeblogger()
    //#input(Weblogger getWeblogger()): this
    //#input(Weblogger getWeblogger()): this.webloggerInstance
    //#output(Weblogger getWeblogger()): return_value
    //#pre[2] (Weblogger getWeblogger()): init'ed(this.webloggerInstance)
    //#post(Weblogger getWeblogger()): return_value == this.webloggerInstance
    //#post(Weblogger getWeblogger()): init'ed(return_value)
    //#GuiceWebloggerProvider.java:95: end of method: Weblogger org.apache.roller.weblogger.business.GuiceWebloggerProvider.getWeblogger()
    }
    
}
    //#output(org.apache.roller.weblogger.business.GuiceWebloggerProvider__static_init): __Descendant_Table[org/apache/roller/weblogger/business/GuiceWebloggerProvider]
    //#output(org.apache.roller.weblogger.business.GuiceWebloggerProvider__static_init): __Dispatch_Table.bootstrap()V
    //#output(org.apache.roller.weblogger.business.GuiceWebloggerProvider__static_init): __Dispatch_Table.getWeblogger()Lorg/apache/roller/weblogger/business/Weblogger;
    //#output(org.apache.roller.weblogger.business.GuiceWebloggerProvider__static_init): org/apache/roller/weblogger/business/WebloggerProvider.__Descendant_Table[org/apache/roller/weblogger/business/GuiceWebloggerProvider]
    //#post(org.apache.roller.weblogger.business.GuiceWebloggerProvider__static_init): __Descendant_Table[org/apache/roller/weblogger/business/GuiceWebloggerProvider] == &__Dispatch_Table
    //#post(org.apache.roller.weblogger.business.GuiceWebloggerProvider__static_init): org/apache/roller/weblogger/business/WebloggerProvider.__Descendant_Table[org/apache/roller/weblogger/business/GuiceWebloggerProvider] == &__Dispatch_Table
    //#post(org.apache.roller.weblogger.business.GuiceWebloggerProvider__static_init): __Dispatch_Table.bootstrap()V == &bootstrap
    //#post(org.apache.roller.weblogger.business.GuiceWebloggerProvider__static_init): __Dispatch_Table.getWeblogger()Lorg/apache/roller/weblogger/business/Weblogger; == &getWeblogger
    //#GuiceWebloggerProvider.java:: end of method: org.apache.roller.weblogger.business.GuiceWebloggerProvider.org.apache.roller.weblogger.business.GuiceWebloggerProvider__static_init
    //#GuiceWebloggerProvider.java:: end of class: org.apache.roller.weblogger.business.GuiceWebloggerProvider
