From: Gautam J. <ga...@us...> - 2008-03-28 17:31:49
|
Update of /cvsroot/jaffa/JaffaCore/source/java/org/jaffa/soa/events In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv20049 Added Files: IProcessEvent.java Param.java ProcessEventGraph.java ProcessEventHandler.java Log Message: Committing these new files on behalf of PavitraM --- NEW FILE: IProcessEvent.java --- /* * ==================================================================== * JAFFA - Java Application Framework For All * * Copyright (C) 2002 JAFFA Development Group * * This library 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 library 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 library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Redistribution and use of this software and associated documentation ("Software"), * with or without modification, are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain copyright statements and notices. * Redistributions must also contain a copy of this document. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name "JAFFA" must not be used to endorse or promote products derived from * this Software without prior written permission. For written permission, * please contact mail to: jaf...@ya.... * 4. Products derived from this Software may not be called "JAFFA" nor may "JAFFA" * appear in their names without prior written permission. * 5. Due credit should be given to the JAFFA Project (http://jaffa.sourceforge.net). * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== */ package org.jaffa.soa.events; import org.jaffa.exceptions.ApplicationExceptions; import org.jaffa.exceptions.FrameworkException; import org.jaffa.persistence.UOW; /** Interface of ProcessEvent than can be used to * process events * * @author PavitraM */ public interface IProcessEvent { /** Called as in process of eventHandler. * @param uow. */ public void execute(UOW uow) throws FrameworkException, ApplicationExceptions; } --- NEW FILE: Param.java --- /* * ==================================================================== * JAFFA - Java Application Framework For All * * Copyright (C) 2002 JAFFA Development Group * * This library 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 library 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 library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Redistribution and use of this software and associated documentation ("Software"), * with or without modification, are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain copyright statements and notices. * Redistributions must also contain a copy of this document. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name "JAFFA" must not be used to endorse or promote products derived from * this Software without prior written permission. For written permission, * please contact mail to: jaf...@ya.... * 4. Products derived from this Software may not be called "JAFFA" nor may "JAFFA" * appear in their names without prior written permission. * 5. Due credit should be given to the JAFFA Project (http://jaffa.sourceforge.net). * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== */ package org.jaffa.soa.events; /** * * @author PavitraM */ public class Param { /** Holds value of property name. */ private String m_name; /** Holds value of property value. */ private String m_value; /** Getter for property value. * @return Value of property value. * */ public java.lang.String getValue() { return m_value; } /** Setter for property value. * @param value New value of property value. * */ public void setValue(java.lang.String value) { m_value = value; } /** Getter for property name. * @return Value of property name. * */ public java.lang.String getName() { return m_name; } /** Setter for property name. * @param name New value of property name. * */ public void setName(java.lang.String name) { m_name = name; } } --- NEW FILE: ProcessEventGraph.java --- /* * ==================================================================== * JAFFA - Java Application Framework For All * * Copyright (C) 2002 JAFFA Development Group * * This library 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 library 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 library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Redistribution and use of this software and associated documentation ("Software"), * with or without modification, are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain copyright statements and notices. * Redistributions must also contain a copy of this document. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name "JAFFA" must not be used to endorse or promote products derived from * this Software without prior written permission. For written permission, * please contact mail to: jaf...@ya.... * 4. Products derived from this Software may not be called "JAFFA" nor may "JAFFA" * appear in their names without prior written permission. * 5. Due credit should be given to the JAFFA Project (http://jaffa.sourceforge.net). * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== */ package org.jaffa.soa.events; /** * * @author PavitraM */ public class ProcessEventGraph { /** Holds value of property eventName. */ private String m_eventName; /** Holds value of property cancelEvent. */ private Boolean m_cancelEvent; /** Holds value of property params. */ private Param[] m_params; /** Getter for property eventName. * @return Value of property eventName. * */ public String getEventName() { return m_eventName; } /** Setter for property eventName. * @param params New value of property eventName. * */ public void setEventName(String eventName) { this.m_eventName = eventName; } /** Getter for property cancelEvent. * @return Value of property cancelEvent. * */ public Boolean getCancelEvent() { return m_cancelEvent; } /** Setter for property cancelEvent. * @param params New value of property cancelEvent. * */ public void setCancelEvent(Boolean cancelEvent) { this.m_cancelEvent = cancelEvent; } /** Getter for property params. * @return Value of property params. * */ public Param[] getParams() { return m_params; } /** Setter for property params. * @param params New value of property params. * */ public void setParams(Param[] params) { this.m_params = params; } } --- NEW FILE: ProcessEventHandler.java --- /* * ==================================================================== * JAFFA - Java Application Framework For All * * Copyright (C) 2002 JAFFA Development Group * * This library 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 library 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 library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Redistribution and use of this software and associated documentation ("Software"), * with or without modification, are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain copyright statements and notices. * Redistributions must also contain a copy of this document. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name "JAFFA" must not be used to endorse or promote products derived from * this Software without prior written permission. For written permission, * please contact mail to: jaf...@ya.... * 4. Products derived from this Software may not be called "JAFFA" nor may "JAFFA" * appear in their names without prior written permission. * 5. Due credit should be given to the JAFFA Project (http://jaffa.sourceforge.net). * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== */ package org.jaffa.soa.events; import java.io.IOException; import java.io.InputStream; import java.util.Properties; import org.apache.log4j.Logger; import org.jaffa.exceptions.ApplicationException; import org.jaffa.exceptions.ApplicationExceptions; import org.jaffa.exceptions.FrameworkException; import org.jaffa.persistence.UOW; import org.jaffa.util.BeanHelper; import org.jaffa.util.ExceptionHelper; import org.jaffa.util.URLHelper; /** ProcessEventHandler * * @author PavitraM * @version 1.0 */ public class ProcessEventHandler { private static Logger log = Logger.getLogger(ProcessEventHandler.class); private static final String SOA_EVENT_LOCATION = "resources/soa-event.properties"; public static String EXCEPTION_NO_EVENT_LOCATION_FILE = "exception." + ProcessEventHandler.class.getName() + ".noEventLocationFile"; public static String EXCEPTION_CANNOT_FIND_PROPERTY = "exception." + ProcessEventHandler.class.getName() + ".cannotFindProperty"; /* sets the parameters on the ProcessEvent class * and calls execute() method on processEvent * @param uow * @param processEventGraph the graph which contains values to be changed. */ public static void process(UOW uow, ProcessEventGraph processEventGraph) throws ApplicationExceptions, FrameworkException { if (processEventGraph.getEventName() == null) throw new ApplicationExceptions(new ApplicationException(EXCEPTION_CANNOT_FIND_PROPERTY, new String[]{"null"}) { }); try { Properties props = new Properties(); InputStream input = null; try { input = URLHelper.getInputStream(SOA_EVENT_LOCATION); if (input != null) { props.load(input); if (log.isDebugEnabled()) log.debug("Loaded " + props.size() + " rule(s) from " + SOA_EVENT_LOCATION); } else { throw new ApplicationExceptions(new ApplicationException(EXCEPTION_NO_EVENT_LOCATION_FILE, new String[]{SOA_EVENT_LOCATION}) { }); } } catch (IOException e) { throw new ApplicationExceptions(new ApplicationException(EXCEPTION_NO_EVENT_LOCATION_FILE, new String[]{SOA_EVENT_LOCATION}) { }); } finally { if (input != null) input.close(); } String className = props.getProperty(processEventGraph.getEventName()); if (className != null) { IProcessEvent processEvent = (IProcessEvent) Class.forName(className).newInstance(); if (processEventGraph.getParams() != null) { Param[] params = processEventGraph.getParams(); for (Param param : params) { BeanHelper.setField(processEvent, param.getName(), param.getValue()); } } processEvent.execute(uow); } else { throw new ApplicationExceptions(new ApplicationException(EXCEPTION_CANNOT_FIND_PROPERTY, new String[]{processEventGraph.getEventName()}) { }); } } catch (Exception e) { ExceptionHelper.throwAFR(e); } } } |