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.logging.LogUtil; 50 import com.rhi.architecture.logging.Logger; 51 import com.rhi.architecture.config.ConfigurationException; 52 import com.rhi.architecture.resource.InitializationException; 53 import com.rhi.architecture.xa.Transaction; 54 55 import java.util.Collection; 56 import java.util.Properties; 57 58 /*** 59 * Audit Agent is responsible for performing all audits for a 60 * specific concrete application. All auditing is deferred to 61 * this class. 62 * 63 * @author Pete McKinstry 64 * @copyright 2002, Robert Half Int'l., Inc. All rights reserved. 65 * 66 * @since 1.0 67 */ 68 public abstract class AuditAgent { 69 70 /*** 71 * log 72 */ 73 private static Logger log = null; 74 75 /*** 76 * private constructor - use the getInstance factory method to build 77 * an audit agent. 78 * 79 * @since 1.0 80 */ 81 protected AuditAgent() { 82 super(); 83 } 84 85 /*** 86 * Initialization Logic 87 * 88 * @param p config properties for audit agent. 89 * @throws InitializationException 90 * @since 1.0 91 */ 92 public abstract void init(Properties p) 93 throws InitializationException; 94 95 /*** 96 * Create an appropriate audit /control record. This 97 * method should create a record w/ only a unprocessed 98 * count > 0. The auditCollection method will be called 99 * as records are passed through the pipeline & this 100 * method will modify the counts; subtracting from the 101 * unprocesed, and adding to the errored, valid, or 102 * duplicate counts. 103 * 104 * @param c the collection that will be audited. (all source records) 105 * @throws AuditException - thrown if the audits can't be created. 106 * @since 1.0 107 */ 108 public abstract void createAudits(Collection c) 109 throws AuditException; 110 111 /*** 112 * Audit the given collection. This method should 113 * subtract the given collection.size() from the un- 114 * processed count for this audit set & add the 115 * collection.size() in some manner to the processed 116 * columns (valid,errored,duplicate,other) 117 * 118 * @param c - records to be audited. 119 * @param t - the transaction to use when auditing. 120 * @throws AuditException thrown if the collection audit fails. 121 * @since 1.0 122 */ 123 public abstract void auditCollection(Collection c, Transaction t) 124 throws AuditException; 125 126 /*** 127 * Mark complete & close the current audit record. This 128 * method may or may not do anything. 129 * 130 * @throws AuditException thrown if the commit fails. 131 * @since 1.0 132 */ 133 public abstract void commitAudits() throws AuditException; 134 135 /*** 136 * Factory method allowing the framework to load any audit agent 137 * as long as it's in the classpath. 138 * 139 * @param className - fully qualified class name for a concrete audit 140 * agent class. 141 * @return AuditAgent - an instance of the audit agent class. 142 * @throws InitializationException - failure creating audit agent. 143 * 144 * @since 1.0 145 */ 146 public static AuditAgent getInstance(String className) 147 throws InitializationException { 148 if (log == null) { 149 try { 150 log = LogUtil.getLogger(); 151 } 152 catch (ConfigurationException e) { 153 throw new InitializationException(e.toString(), e); 154 } 155 } 156 157 AuditAgent agent = null; 158 try { 159 if (className == null) { 160 throw new InitializationException("AuditAgent className == null"); 161 } 162 Class type = Class.forName(className); 163 Object obj = type.newInstance(); 164 agent = (AuditAgent) obj; 165 } 166 catch (ClassCastException cce) { 167 log.error( 168 "invalid entry for audit agent in configuration file. " + 169 "(cast exception)"); 170 throw new InitializationException(cce.toString(), cce); 171 } 172 catch (ClassNotFoundException cnfe) { 173 log.error( 174 "invalid entry for audit agent in configuration file. " + 175 "(class not found)"); 176 throw new InitializationException(cnfe.toString(), cnfe); 177 } 178 catch (InstantiationException ie) { 179 log.error( 180 "instantiation exception loading audit agent. probably " + 181 "configuration error."); 182 throw new InitializationException(ie.toString(), ie); 183 } 184 catch (IllegalAccessException iae) { 185 log.error( 186 "illegal access loading audit agent. configuration error."); 187 throw new InitializationException(iae.toString(), iae); 188 } 189 return agent; 190 } 191 192 }

This page was automatically generated by Maven