[jboss-svn-commits] JBL Code SVN: r10051 - labs/jbossesb/workspace/rsheridan/trunk/product/core/rosetta/src/org/jboss/soa/esb/notification.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Mar 7 17:35:28 EST 2007
Author: rex.sheridan
Date: 2007-03-07 17:35:27 -0500 (Wed, 07 Mar 2007)
New Revision: 10051
Added:
labs/jbossesb/workspace/rsheridan/trunk/product/core/rosetta/src/org/jboss/soa/esb/notification/NotificationTarget.java
Log:
Commit of bean configuration capabilities
Added: labs/jbossesb/workspace/rsheridan/trunk/product/core/rosetta/src/org/jboss/soa/esb/notification/NotificationTarget.java
===================================================================
--- labs/jbossesb/workspace/rsheridan/trunk/product/core/rosetta/src/org/jboss/soa/esb/notification/NotificationTarget.java (rev 0)
+++ labs/jbossesb/workspace/rsheridan/trunk/product/core/rosetta/src/org/jboss/soa/esb/notification/NotificationTarget.java 2007-03-07 22:35:27 UTC (rev 10051)
@@ -0,0 +1,159 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.notification;
+
+import java.lang.reflect.Constructor;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.util.BeanConfigurator;
+
+/**
+ * Abstract class to define expected behaviour of all NotificationTargets and
+ * provide some common functionality to all of them
+ * <p>
+ * Description:
+ * </p>
+ * <p>
+ * Heuristica - Buenos Aires - Argentina
+ * </p>
+ *
+ * @version 1.0
+ */
+public abstract class NotificationTarget
+{
+ /**
+ * Derived classes must implement this method to do what has to be done to
+ * trigger that specific type of notification event
+ *
+ * @param p_o
+ * Object - The toString() method of this object will be the
+ * actual notification content
+ * @throws NotificationException -
+ * invoke Exception.getMessage() at runtime for this object
+ * @see ConfigTree
+ */
+ public abstract void sendNotification (java.io.Serializable p_o)
+ throws NotificationException;
+
+ private static final String NOTIF_PFX = NotificationTarget.class
+ .getPackage().getName();
+
+ public static final String PRM_NOTIF_CLASS = "class";
+
+ /**
+ * Common object to hold details of object's information - Each derived
+ * class will hold it's own needs
+ */
+ protected ConfigTree m_oParms;
+
+ /**
+ * Instantiate an empty NotificationTarget object
+ */
+ protected NotificationTarget ()
+ {
+ }
+
+ /**
+ * Instantiate a NotificationTarget object with the information contained in
+ * <arg 1>
+ *
+ * @param p_oP
+ * ConfigTree - Holds details to instantiate this object
+ */
+ protected NotificationTarget (ConfigTree p_oP)
+ {
+ m_oParms = p_oP;
+ } // __________________________________
+
+ /**
+ * A typical Factory.getInstance() method
+ *
+ * @param p_oP
+ * ConfigTree - Contents of this argument will determine the type
+ * (derived class) of NotificationTarget returned
+ * @throws ConfigurationException -
+ * Arg 1 does not contain a valid structure for currently
+ * implemented NotificationTarget subclasses - invoke
+ * Exception.getMessage() at runtime for details
+ * @return NotificationTarget - An object that instantiates the
+ * NotificationTarget abstract class
+ */
+ public static NotificationTarget fromParams (ConfigTree p_oP)
+ throws ConfigurationException
+ {
+ String sClass = p_oP.getAttribute(PRM_NOTIF_CLASS);
+ if (null == sClass)
+ throw new IllegalArgumentException(
+ "Missing '" + PRM_NOTIF_CLASS + "' attribute in parameters");
+ Class oCls = null;
+ try
+ {
+ oCls = Class.forName(NOTIF_PFX + "." + sClass);
+ }
+ catch (Exception e)
+ {
+ try
+ {
+ oCls = Class.forName(sClass);
+ }
+ catch (Exception e1)
+ {/* oCls will be null */
+ }
+ }
+ if (null == oCls)
+ throw new ConfigurationException(
+ "Invalid class <" + sClass + ">, or missing library");
+
+ Constructor oCons = null;
+ Object oRet = null;
+ try
+ {
+ oCons = oCls.getConstructor(new Class[] { ConfigTree.class });
+
+ try
+ {
+ oRet = oCons.newInstance(new Object[] { p_oP });
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ catch (Exception e)
+ {
+ try {
+ oCons = oCls.getConstructor(new Class[] {});
+ oRet = oCons.newInstance(new Object[] {});
+ BeanConfigurator configurator = new BeanConfigurator(p_oP, oRet);
+ configurator.configure();
+ } catch(Exception e1) {
+ throw new ConfigurationException("Unable to configure NotificationTarget as a bean. class="+oCls.getName(), e1);
+ }
+ }
+ if (null == oRet || (!(oRet instanceof NotificationTarget)))
+ throw new ConfigurationException(sClass + " does not extend NotificationTarget");
+
+ return (NotificationTarget) oRet;
+ } // __________________________________
+} // ____________________________________________________________________________
More information about the jboss-svn-commits
mailing list