View Javadoc
1 /* ====================================================================
2 * License:
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. The end-user documentation included with the redistribution,
17 * if any, must include the following acknowledgment:
18 * "This product includes software developed by
19 * Robert Half International (http://www.rhi.com/)."
20 * Alternately, this acknowledgment may appear in the software itself,
21 * if and wherever such third-party acknowledgments normally appear.
22 *
23 * 4. The names "Parc", "RHI", and "Robert Half International" must
24 * not be used to endorse or promote products derived from this
25 * software without prior written permission. For written
26 * permission, please contact pete.mckinstry@rhi.com.
27 *
28 * 5. Products derived from this software may not be called "PARC",
29 * nor may "PARC" appear in their name, without prior written
30 * permission of Robert Half International.
31 *
32 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
33 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
34 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
35 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
36 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
37 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
38 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
39 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
40 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
41 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
42 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43 * SUCH DAMAGE.
44 * ====================================================================
45 *
46 */
47 package com.rhi.architecture.batch;
48
49 import com.rhi.architecture.resource.InitializationException;
50 import com.rhi.architecture.config.ConfigurationException;
51 import com.rhi.architecture.logging.Logger;
52 import com.rhi.architecture.logging.LogUtil;
53
54 /***
55 * This class provides a partial implementation of
56 * the application interface for use by sub-classes.
57 * Basically an execute() method following the Template
58 * GOF pattern is used to call the initialization &
59 * cleanup methods on the applications object.
60 * <p />
61 * Resources should be allocated & configured in the init()
62 * method. The same resources should be deallocated in the
63 * cleanup() method, and the processing logic should be
64 * performed w/in the run() method.
65 *
66 * @author Pete McKinstry
67 * @copyright 2002, Robert Half Int'l., Inc. All rights reserved.
68 *
69 * @since 1.0
70 */
71 public abstract class AbstractApplication implements Application {
72
73 /***
74 * logger
75 */
76 private static Logger log = null;
77
78 /***
79 * Start application. Initialize any common framework components,
80 * and then call the abstract run() method to allow sub-classes to
81 * do the real processing.
82 *
83 * @param args commandline arguments.
84 * @throws ApplicationException fatal error
85 * @since 1.0
86 */
87 public final void execute(String args[]) throws ApplicationException {
88 try {
89 init(args);
90 run();
91 }
92 catch (InitializationException ie) {
93 if (log() != null) {
94 log().fatal("InitializationException thrown.");
95 log().fatal("exception = " + ie, ie);
96 }
97 throw new ApplicationException(
98 "InitializationException thrown. " + "e = " + ie.toString(),
99 ie,
100 Application.FATAL_EXCEPTION);
101 }
102 catch (ApplicationException ae) {
103 if (log() != null) {
104 log().fatal("Application exception occured during processing.");
105 log().fatal("exception = " + ae, ae);
106 }
107 throw ae;
108 }
109 finally {
110 cleanup();
111 }
112 }
113
114 /***
115 * Perform initialization required by the application
116 * framework. This should include allocation and configuration
117 * of resources if possible.
118 *
119 * @param args commandline arguments
120 * @throws InitializationException error initializing the process.
121 *
122 * @since 1.0
123 */
124 protected abstract void init(String args[]) throws InitializationException;
125
126 /***
127 * Perform any cleanup required by the application framework.
128 *
129 * @since 1.0
130 */
131 protected abstract void cleanup();
132
133 /***
134 * The run() method is expected to be overriden by concrete
135 * sub-classes. This method should include or call the
136 * processing logic represented by this application.
137 *
138 * @throws ApplicationException a fatal error occured during processing.
139 * @since 1.0
140 */
141 protected abstract void run() throws ApplicationException;
142
143 /***
144 * Logs a msg. Ignores if logger not properly initialized.
145 *
146 * @return Logger
147 */
148 public Logger log() {
149 if (log == null) {
150 try {
151 log = LogUtil.getLogger();
152 }
153 catch (ConfigurationException e) {
154 /*
155 * don't set member variable because the logging may
156 * be initialized later & we don't want to store
157 * this in that case.
158 */
159 return LogUtil.getDefaultLogger();
160 }
161 }
162 return log;
163 }
164
165 }
This page was automatically generated by Maven