|
From: Donahue S. <dc...@us...> - 2004-08-19 06:11:41
|
Update of /cvsroot/ebxmlms/ebxmlms/src/hk/hku/cecid/phoenix/message/handler In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30423 Added Files: DeliveryManager.java Log Message: DeliveryManager is a singleton within Hermes for which plays with DeliveryHandler --- NEW FILE: DeliveryManager.java --- /* * Copyright(c) 2002 Center for E-Commerce Infrastructure Development, The * University of Hong Kong (HKU). All Rights Reserved. * * This software is licensed under the Academic Free License Version 1.0 * * Academic Free License * Version 1.0 * * This Academic Free License applies to any software and associated * documentation (the "Software") whose owner (the "Licensor") has placed the * statement "Licensed under the Academic Free License Version 1.0" immediately * after the copyright notice that applies to the Software. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of the Software (1) to use, copy, modify, merge, publish, perform, * distribute, sublicense, and/or sell copies of the Software, and to permit * persons to whom the Software is furnished to do so, and (2) under patent * claims owned or controlled by the Licensor that are embodied in the Software * as furnished by the Licensor, to make, use, sell and offer for sale the * Software and derivative works thereof, subject to the following conditions: * * - Redistributions of the Software in source code form must retain all * copyright notices in the Software as furnished by the Licensor, this list * of conditions, and the following disclaimers. * - Redistributions of the Software in executable form must reproduce all * copyright notices in the Software as furnished by the Licensor, this list * of conditions, and the following disclaimers in the documentation and/or * other materials provided with the distribution. * - Neither the names of Licensor, nor the names of any contributors to the * Software, nor any of their trademarks or service marks, may be used to * endorse or promote products derived from this Software without express * prior written permission of the Licensor. * * DISCLAIMERS: LICENSOR WARRANTS THAT THE COPYRIGHT IN AND TO THE SOFTWARE IS * OWNED BY THE LICENSOR OR THAT THE SOFTWARE IS DISTRIBUTED BY LICENSOR UNDER * A VALID CURRENT LICENSE. EXCEPT AS EXPRESSLY STATED IN THE IMMEDIATELY * PRECEDING SENTENCE, THE SOFTWARE IS PROVIDED BY THE LICENSOR, CONTRIBUTORS * AND COPYRIGHT OWNERS "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE * LICENSOR, CONTRIBUTORS OR COPYRIGHT OWNERS BE LIABLE FOR ANY CLAIM, DAMAGES * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE. * * This license is Copyright (C) 2002 Lawrence E. Rosen. All rights reserved. * Permission is hereby granted to copy and distribute this license without * modification. This license may not be modified without the express written * permission of its copyright owner. */ /* ===== * * $Header: /cvsroot/ebxmlms/ebxmlms/src/hk/hku/cecid/phoenix/message/handler/DeliveryManager.java,v 1.1 2004/08/19 06:11:31 dcmsze Exp $ * * Code authored by: * * dcmsze Jun 28, 2004 * * Code reviewed by: * * username [YYYY-MM-DD] * * Remarks: * * ===== */ package hk.hku.cecid.phoenix.message.handler; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import hk.hku.cecid.phoenix.common.util.Property; import org.apache.log4j.Logger; /** * DeliveryManager * * @author dcmsze * @version $Revision: 1.1 $ */ public final class DeliveryManager { /** * logger for DeliveryManager class. */ private static Logger logger = Logger.getLogger(DeliveryManager.class); /** * The Delivery Handler for the Application. */ private static DeliveryHandler applicationDeliveryHandler; /** * The Retry Interval of Delivery Handler for the Application. */ private static String applicationDeliveryHandlerRetryInterval; /** * The Maximum Retry of Delivery Handler for the Application. */ private static String applicationDeliveryHandlerMaximumRetry; /** * Flag indicating if the class has been configured. */ private static boolean isConfigured = false; /** * Configure the class if and only if it has not been configred. * * @param prop <code>Property</code> object. * @thros InitializationExcpetion thrown when there is error on * configurating the DevlieryManager */ static synchronized void configure(final Property prop) throws InitializationException { if (isConfigured) { return; } String applicationDeliveryHandlerClassName = prop.get(Constants.PROPERTY_DELIVERYHANDLER); applicationDeliveryHandlerRetryInterval = prop.get(Constants.PROPERTY_RETRYINTERVAL); applicationDeliveryHandlerMaximumRetry = prop.get(Constants.PROPERTY_MAXIMUMRETRY); if (applicationDeliveryHandlerClassName != null && applicationDeliveryHandlerRetryInterval != null && applicationDeliveryHandlerMaximumRetry != null) { logger.info( "Use customize application delivery handler : " + applicationDeliveryHandlerClassName); try { applicationDeliveryHandler = createDeliveryHandlerInstance( applicationDeliveryHandlerClassName, applicationDeliveryHandlerRetryInterval, applicationDeliveryHandlerMaximumRetry, prop); logger.debug("Successful to create Delivery Handler Instance"); } catch (Exception e) { logger.error(e.toString()); String err = ErrorMessages.getMessage( ErrorMessages.ERR_HERMES_INIT_ERROR, e, "Cannot load application delivery handler"); logger.error(err); throw new InitializationException(err); } } isConfigured = true; } /** * private constructor to prevent constructor of the class */ public DeliveryManager() { super(); } /** * create the Delivery Handler based on the inputted className. * If the className is null, it will create the Delivery Handler using * the defaultHandlerClass. * @param defaultHandlerClass the default Handler class to load if the * className is null * @param className the class name of the Delivery Handler to load * @return The Delivery Handler instance * @throws Exception thrown when there is error occur on creating the * instance. */ private static DeliveryHandler createDeliveryHandlerInstance( final String className, final String retryInterval, final String maximumRetry, final Property property) throws ClassNotFoundException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { Class handlerClass = Class.forName(className); Constructor[] constructors = handlerClass.getConstructors(); Object result = null; result = handlerClass.newInstance(); if (result instanceof DeliveryHandler) { return (DeliveryHandler) result; } else { throw new IllegalArgumentException("Specify class is not an instance of DeliveryHandler"); } } /** * get the Application Delivery Handler. * @return the Application Delivery Handler */ public static DeliveryHandler getApplicationDeliveryHandler() { return applicationDeliveryHandler; } /** * get the Application Delivery Handler Retry Interval. * @return the Application Delivery Handler Retry Interval */ public static String getApplicationDeliveryHandlerRetryInterval() { return applicationDeliveryHandlerRetryInterval; } /** * get the Application Delivery Handler Maximum Retry. * @return the Application Delivery Handler Maximum Retry */ public static String getApplicationDeliveryHandlerMaxmiumRetry() { return applicationDeliveryHandlerMaximumRetry; } } |