Package com.sos.scheduler.model.events

Source Code of com.sos.scheduler.model.events.JSEvent

/********************************************************* begin of preamble
**
** Copyright (C) 2003-2010 Software- und Organisations-Service GmbH.
** All rights reserved.
**
** This file may be used under the terms of either the
**
**   GNU General Public License version 2.0 (GPL)
**
**   as published by the Free Software Foundation
**   http://www.gnu.org/licenses/gpl-2.0.txt and appearing in the file
**   LICENSE.GPL included in the packaging of this file.
**
** or the
** 
**   Agreement for Purchase and Licensing
**
**   as offered by Software- und Organisations-Service GmbH
**   in the respective terms of supply that ship with this file.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
** IS" AND ANY EXPRESS 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 COPYRIGHT OWNER OR 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.
********************************************************** end of preamble*/
package com.sos.scheduler.model.events;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Properties;
import org.apache.log4j.Logger;

import com.sos.scheduler.model.SchedulerObjectFactory;
import com.sos.scheduler.model.exceptions.JSUnknownEventException;
//import com.sos.scheduler.model.exceptions.JSUnknownEventException;

/**
* \file JSEventHotFolderChanged.java \brief Event fired if an element of the
* live folder was changed
*
* \class JSEventHotFolderChanged \brief Event fired if an element of the live
* folder was changed
*
* \details
*
* \code \endcode
*
* \author SS \version 1.0 - 20.04.2011 15:54:22 <div class="sos_branding">
* <p>
* (c) 2011 SOS GmbH - Berlin (<a style='color:silver'
* href='http://www.sos-berlin.com'>http://www.sos-berlin.com</a>)
* </p>
* </div>
*/
public class JSEvent extends Event {

  @SuppressWarnings("unused")
  private final String conClassName = "JSEvent";
  private static final Logger logger = Logger.getLogger(JSEvent.class);
  private final JSEventBase eventObject;

  public JSEvent(final SchedulerObjectFactory schedulerObjectFactory,
      String eventName) {

    objFactory = schedulerObjectFactory;
    setName(eventName);

    logger.debug("the event name is " + getName());

    String className = getClass().getPackage().getName() + ".JS" + eventName;
    JSEventBase o = null;
    logger.debug("create instance of class " + className );
    try {
      Method setMethod = getMethod("set" + eventName);      // the setter to store the event object
      o = createEventClass(className);
      setMethod.invoke(this, new Object[] {o});
    } catch (Exception e) {
       throw new JSUnknownEventException("the event " + eventName +
       " is not known (class " + className +
       " is missing)",e);
    }
    eventObject = o;

  }
 
  public JSEventBase getEventObject() {
    return eventObject;
  }
 
  private Method getMethod(String methodName) throws NoSuchMethodException {
    for (Method m : getClass().getMethods() ) {
      if (m.getName().equals(methodName)) return m;
    }
    throw new NoSuchMethodException("the method " + methodName + " does not exist in class " + getClass().getName() );
  }
 
  private JSEventBase createEventClass(String className) throws Exception {
    Class<?> cls = Class.forName(className);
    Constructor<?> cons = cls.getConstructor(new Class[] { SchedulerObjectFactory.class });
    return (JSEventBase) cons.newInstance(new Object[] { objFactory });
  }

}
TOP

Related Classes of com.sos.scheduler.model.events.JSEvent

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.