File Source: GuiceWebloggerProvider.java
/*
P/P * Method: org.apache.roller.weblogger.business.GuiceWebloggerProvider__static_init
*/
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */
18
19 package org.apache.roller.weblogger.business;
20
21 import com.google.inject.Guice;
22 import com.google.inject.Injector;
23 import com.google.inject.Module;
24 import org.apache.roller.weblogger.config.WebloggerConfig;
25
26
27 /**
28 * A Guice specific implementation of a WebloggerProvider.
29 */
30 public class GuiceWebloggerProvider implements WebloggerProvider {
31
32 // Guice injector
33 protected final Injector injector;
34
35 // maintain our own singleton instance of Weblogger
36 protected Weblogger webloggerInstance = null;
37
38
39 /**
40 * Instantiate a new GuiceWebloggerProvider using default guice module
41 * configured in WebloggerConfig via 'guice.backend.module' property.
42 */
/*
P/P * Method: void org.apache.roller.weblogger.business.GuiceWebloggerProvider()
*
* Preconditions:
* org/apache/roller/weblogger/config/WebloggerConfig.config != null
* org/apache/roller/weblogger/config/WebloggerConfig.log != null
*
* Presumptions:
* java.lang.Class:forName(...)@51 != null
*
* Postconditions:
* init'ed(this.injector)
* this.webloggerInstance == null
*/
43 public GuiceWebloggerProvider() {
44
45 String moduleClassname = WebloggerConfig.getProperty("guice.backend.module");
+ 46 if(moduleClassname == null) {
47 throw new NullPointerException("unable to lookup default guice module via property 'guice.backend.module'");
48 }
49
50 try {
51 Class moduleClass = Class.forName(moduleClassname);
52 Module module = (Module)moduleClass.newInstance();
53 injector = Guice.createInjector(module);
54 } catch (Throwable e) {
55 // Fatal misconfiguration, cannot recover
56 throw new RuntimeException("Error instantiating backend module " + moduleClassname, e);
57 }
58 }
59
60
61 /**
62 * Instantiate a new GuiceWebloggerProvider using the given Guice module.
63 *
64 * @param moduleClassname The full classname of the Guice module to use.
65 */
/*
P/P * Method: void org.apache.roller.weblogger.business.GuiceWebloggerProvider(String)
*
* Preconditions:
* moduleClassname != null
*
* Presumptions:
* java.lang.Class:forName(...)@73 != null
*
* Postconditions:
* init'ed(this.injector)
* this.webloggerInstance == null
*/
66 public GuiceWebloggerProvider(String moduleClassname) {
67
68 if(moduleClassname == null) {
69 throw new NullPointerException("moduleClassname cannot be null");
70 }
71
72 try {
73 Class moduleClass = Class.forName(moduleClassname);
74 Module module = (Module)moduleClass.newInstance();
75 injector = Guice.createInjector(module);
76 } catch (Throwable e) {
77 // Fatal misconfiguration, cannot recover
78 throw new RuntimeException("Error instantiating backend module " + moduleClassname, e);
79 }
80 }
81
82
83 /**
84 * @inheritDoc
85 */
86 public void bootstrap() {
/*
P/P * Method: void bootstrap()
*
* Preconditions:
* this.injector != null
*
* Postconditions:
* init'ed(this.webloggerInstance)
*/
87 webloggerInstance = injector.getInstance(Weblogger.class);
88 }
89
90
91 /**
92 * @inheritDoc
93 */
94 public Weblogger getWeblogger() {
/*
P/P * Method: Weblogger getWeblogger()
*
* Preconditions:
* init'ed(this.webloggerInstance)
*
* Postconditions:
* return_value == this.webloggerInstance
* init'ed(return_value)
*/
95 return webloggerInstance;
96 }
97
98 }
SofCheck Inspector Build Version : 2.18479
| GuiceWebloggerProvider.java |
2009-Jan-02 14:25:24 |
| GuiceWebloggerProvider.class |
2009-Sep-04 03:12:30 |