⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 schedulingmanager.java

📁 本系统有十分强大的功能
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*******************************************************************************
 * ***** BEGIN LICENSE BLOCK Version: MPL 1.1
 * 
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
 * 
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 * 
 * The Original Code is the OpenCustomer CRM.
 * 
 * The Initial Developer of the Original Code is Thomas Bader (Bader & Jene
 * Software-Ingenieurb黵o). Portions created by the Initial Developer are
 * Copyright (C) 2005 the Initial Developer. All Rights Reserved.
 * 
 * Contributor(s): Thomas Bader <thomas.bader@bader-jene.de>
 *                 Felix Breske <felix.breske@bader-jene.de>
 * 
 * ***** END LICENSE BLOCK *****
 */

package org.opencustomer.connector.scheduling;

import java.io.File;
import java.lang.reflect.Constructor;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.List;

import javax.mail.internet.AddressException;

import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import org.opencustomer.connector.mail.exception.NoValidSenderException;
import org.opencustomer.connector.mail.messages.JobReminderMail;
import org.opencustomer.connector.mail.messages.EventReminderMail;
import org.opencustomer.connector.scheduling.jobs.MailJob;
import org.opencustomer.db.dao.crm.JobDAO;
import org.opencustomer.db.dao.system.UserDAO;
import org.opencustomer.db.vo.crm.JobVO;
import org.opencustomer.db.vo.system.UserVO;
import org.opencustomer.util.configuration.UserConfiguration;
import org.opencustomer.webapp.Settings;
import org.opencustomer.webapp.module.calendar.util.EventBean;
import org.opencustomer.webapp.module.calendar.util.EventBeanCalculator;

import com.jtheory.jdring.AlarmEntry;
import com.jtheory.jdring.AlarmListener;
import com.jtheory.jdring.AlarmManager;
import com.jtheory.jdring.PastDateException;

/**
 * This class manages a single instance of AlarmManager, and loads alarm jobs from a xml file, or from the opencustomer databse.
 * 
 * @author fbreske
 * @see com.jtheory.jdring.AlarmManager
 *
 */
public class SchedulingManager
{
    private static Logger log = Logger.getLogger(SchedulingManager.class);
    
    private AlarmManager alarmManager;
    
    private static SchedulingManager schedulingManager;
    
    public SchedulingManager()
    {
        alarmManager = new AlarmManager();
        if(log.isDebugEnabled())
            log.debug("stating alarm manager");
    }
    
    public static SchedulingManager getInstance()
    {
        if(schedulingManager == null)
            schedulingManager = new SchedulingManager();
        return schedulingManager;
    }

    /**
     * Returns the managed instance of AlarmManager
     * @return instance of AlarmManager
     * @see com.jtheory.jdring.AlarmManager
     */
    public AlarmManager getAlarmManager()
    {
        return alarmManager;
    }
    
    /**
     * Reads alarm jobs from a xml configuration file, and adds the jobs to the AlarmManager.
     * @param file xml configuration file.
     */
    public void readXMLJobs(File file)
    {
        SAXReader reader = new SAXReader();
        Document document;
        try
        {
            document = reader.read(file);
        }
        catch (DocumentException e1)
        {
            log.warn("error parsing file " + file.getName());
            return;
        }
        Element root = document.getRootElement();
        Iterator iter = root.elementIterator();
        while(iter.hasNext())
        {
            Element element = (Element) iter.next();
            String type = element.valueOf("@type");
            String name = element.valueOf("@name");
            String className = element.valueOf("@class");
            AlarmListener alarm = null;
            
            try
            {
                Class cl = Class.forName(className);
                Constructor b = cl.getConstructor(new Class[]{});
                alarm = (AlarmListener) b.newInstance(new Object[]{});
            }
            catch (Exception e)
            {
                log.warn("unable to get class for event: " + name,e);
            }
                      
            if(alarm != null && type.equals("DATE"))
            {
                Node dateNode = root.selectSingleNode("//events/event/date");
                if(dateNode != null && dateNode.getText() != null)
                {
                    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm");
                    try
                    {
                        AlarmEntry alarmEntry = new AlarmEntry(name,sdf.parse(dateNode.getText()), alarm);
                        alarmEntry.setRingInNewThead();
                        if(log.isDebugEnabled())
                            log.debug("adding event: "+ alarmEntry);
                        alarmManager.addAlarm(alarmEntry);
                    }
                    catch (ParseException e)
                    {
                        log.warn("unparseable date format of event: " + name,e);
                    }
                    catch (PastDateException e)
                    {
                        if(log.isInfoEnabled())
                            log.info("ignoring old event: " + name);
                    }
                    
                } 
            }
            else if(alarm != null && type.equals("DELAY"))
            {
                Node minuteNode = root.selectSingleNode("//events/event/minute");
                if(minuteNode != null && minuteNode.getText() != null)
                {
                    int minute = Integer.parseInt(minuteNode.getText());
                    try
                    {
                        AlarmEntry alarmEntry = new AlarmEntry(name,minute,true,alarm);
                        alarmEntry.setRingInNewThead();
                        if(log.isDebugEnabled())
                            log.debug("adding event: "+ alarmEntry);
                        alarmManager.addAlarm(alarmEntry);
                    }
                    catch (PastDateException e)
                    {
                        if(log.isInfoEnabled())
                            log.info("ignoring old event: " + name);;
                    }
                }
            }
            else if(alarm != null && type.equals("CRON"))
            {
                //Minuten
                int minutes[] = getChildEntries(element, "minute");
                              
                //Stunden
                int hours[] = getChildEntries(element, "hour");
                
                //Tag des Monats
                int dayOfMonth[] = getChildEntries(element, "dayofmonth");
                
                //Monat
                int months[] = getChildEntries(element, "month");
                
                //Tag der Woche
                int dayOfWeek[] = getChildEntries(element, "dayofweek");
                

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -