File Source: WebloggerFactory.java
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 org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.apache.roller.weblogger.business.startup.WebloggerStartup;
24 import org.apache.roller.weblogger.config.WebloggerConfig;
25
26
27 /**
28 * Provides access to the Weblogger instance and bootstraps the business tier.
29 */
30 public final class WebloggerFactory {
31
/*
P/P * Method: org.apache.roller.weblogger.business.WebloggerFactory__static_init
*
* Postconditions:
* init'ed(log)
* webloggerProvider == null
*/
32 private static final Log log = LogFactory.getLog(WebloggerFactory.class);
33
34 // our configured weblogger provider
35 private static WebloggerProvider webloggerProvider = null;
36
37
38 // non-instantiable
/*
P/P * Method: void org.apache.roller.weblogger.business.WebloggerFactory()
*/
39 private WebloggerFactory() {
40 // hello all you beautiful people
41 }
42
43
44 /**
45 * True if bootstrap process has been completed, False otherwise.
46 */
47 public static boolean isBootstrapped() {
/*
P/P * Method: bool isBootstrapped()
*
* Preconditions:
* init'ed(webloggerProvider)
*
* Postconditions:
* init'ed(return_value)
*/
48 return (webloggerProvider != null);
49 }
50
51
52 /**
53 * Accessor to the Weblogger Weblogger business tier.
54 *
55 * @return Weblogger An instance of Weblogger.
56 * @throws IllegalStateException If the app has not been properly bootstrapped yet.
57 */
58 public static final Weblogger getWeblogger() {
/*
P/P * Method: Weblogger getWeblogger()
*
* Preconditions:
* webloggerProvider != null
* init'ed(webloggerProvider.webloggerInstance)
*
* Postconditions:
* return_value == webloggerProvider.webloggerInstance
* init'ed(return_value)
*/
59 if (webloggerProvider == null) {
60 throw new IllegalStateException("Roller Weblogger has not been bootstrapped yet");
61 }
62
63 return webloggerProvider.getWeblogger();
64 }
65
66
67 /**
68 * Bootstrap the Roller Weblogger business tier, uses default WebloggerProvider.
69 *
70 * Bootstrapping the application effectively instantiates all the necessary
71 * pieces of the business tier and wires them together so that the app is
72 * ready to run.
73 *
74 * @throws IllegalStateException If the app has not been properly prepared yet.
75 * @throws BootstrapException If an error happens during the bootstrap process.
76 */
77 public static final void bootstrap() throws BootstrapException {
78
79 // if the app hasn't been properly started so far then bail
/*
P/P * Method: void bootstrap()
*
* Preconditions:
* org/apache/roller/weblogger/business/startup/WebloggerStartup.prepared == 1
* org/apache/roller/weblogger/config/WebloggerConfig.config != null
* org/apache/roller/weblogger/config/WebloggerConfig.log != null
*
* Presumptions:
* defaultProvider.injector@90 != null
* java.lang.Class:forName(...)@89 != null
*
* Postconditions:
* webloggerProvider != null
* webloggerProvider.webloggerInstance != null
*/
80 if (!WebloggerStartup.isPrepared()) {
81 throw new IllegalStateException("Cannot bootstrap until application has been properly prepared");
82 }
83
84 // lookup our default provider and instantiate it
85 WebloggerProvider defaultProvider;
86 String providerClassname = WebloggerConfig.getProperty("weblogger.provider.class");
+ 87 if(providerClassname != null) {
88 try {
89 Class providerClass = Class.forName(providerClassname);
90 defaultProvider = (WebloggerProvider) providerClass.newInstance();
91 } catch (Exception ex) {
92 throw new BootstrapException("Error instantiating default provider: "+providerClassname, ex);
93 }
94 } else {
95 throw new NullPointerException("No provider specified in config property 'weblogger.provider.class'");
96 }
97
98 // now just bootstrap using our default provider
99 bootstrap(defaultProvider);
100 }
101
102
103 /**
104 * Bootstrap the Roller Weblogger business tier, uses specified WebloggerProvider.
105 *
106 * Bootstrapping the application effectively instantiates all the necessary
107 * pieces of the business tier and wires them together so that the app is
108 * ready to run.
109 *
110 * @param provider A WebloggerProvider to use for bootstrapping.
111 * @throws IllegalStateException If the app has not been properly prepared yet.
112 * @throws BootstrapException If an error happens during the bootstrap process.
113 */
114 public static final void bootstrap(WebloggerProvider provider)
115 throws BootstrapException {
116
117 // if the app hasn't been properly started so far then bail
/*
P/P * Method: void bootstrap(WebloggerProvider)
*
* Preconditions:
* org/apache/roller/weblogger/business/startup/WebloggerStartup.prepared == 1
* provider != null
* provider.injector != null
*
* Presumptions:
* com.google.inject.Injector:getInstance(...)@87 != null
* java.lang.Object:getClass(...)@128 != null
* org.apache.commons.logging.LogFactory:getLog(...)@32 != null
*
* Postconditions:
* (soft) provider.webloggerInstance != null
* webloggerProvider.webloggerInstance == provider.webloggerInstance
* webloggerProvider == provider
* webloggerProvider != null
*/
118 if (!WebloggerStartup.isPrepared()) {
119 throw new IllegalStateException("Cannot bootstrap until application has been properly prepared");
120 }
121
122 if (provider == null) {
123 throw new NullPointerException("WebloggerProvider is null");
124 }
125
126 log.info("Bootstrapping Roller Weblogger business tier");
127
128 log.info("Weblogger Provider = "+provider.getClass().getName());
129
130 // save reference to provider
131 webloggerProvider = provider;
132
133 // bootstrap weblogger provider
134 webloggerProvider.bootstrap();
135
136 // make sure we are all set
137 if(webloggerProvider.getWeblogger() == null) {
138 throw new BootstrapException("Bootstrapping failed, Weblogger instance is null");
139 }
140
141 log.info("Roller Weblogger business tier successfully bootstrapped");
142 log.info(" Version: " + webloggerProvider.getWeblogger().getVersion());
143 log.info(" Revision: " + webloggerProvider.getWeblogger().getRevision());
144 }
145
146 }
SofCheck Inspector Build Version : 2.18479
| WebloggerFactory.java |
2009-Jan-02 14:24:54 |
| WebloggerFactory.class |
2009-Sep-04 03:12:30 |