Package com.sos.scheduler.model

Source Code of com.sos.scheduler.model.SchedulerHotFolder

/********************************************************* 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;

import org.apache.log4j.Logger;

import com.sos.JSHelper.Exceptions.JobSchedulerException;
import com.sos.VirtualFileSystem.Interfaces.ISOSVfsFileTransfer;
import com.sos.VirtualFileSystem.Interfaces.ISOSVirtualFile;
import com.sos.scheduler.model.objects.JSObjBase;
import com.sos.scheduler.model.objects.JSObjJob;
import com.sos.scheduler.model.objects.JSObjJobChain;
import com.sos.scheduler.model.objects.JSObjLock;
import com.sos.scheduler.model.objects.JSObjOrder;
import com.sos.scheduler.model.objects.JSObjParams;
import com.sos.scheduler.model.objects.JSObjProcessClass;
import com.sos.scheduler.model.objects.JSObjSchedule;

/**
* \class SchedulerHotFolder
*
* \brief SchedulerHotFolder -
*
* \details
*
* \section SchedulerHotFolder.java_intro_sec Introduction
*
* \section SchedulerHotFolder.java_samples Some Samples
*
* \code
*   .... code goes here ...
* \endcode
*
* <p style="text-align:center">
* <br />---------------------------------------------------------------------------
* <br /> APL/Software GmbH - Berlin
* <br />##### generated by ClaviusXPress (http://www.sos-berlin.com) #########
* <br />---------------------------------------------------------------------------
* </p>
* \author oh
* @version $Id$
* \see reference
*
* Created on 10.02.2011 22:58:07
*/

/**
* @author oh
*
*/
public class SchedulerHotFolder extends JSObjBase {

  private final String        conClassName    = "SchedulerHotFolder";
  private static final Logger      logger        = Logger.getLogger(SchedulerHotFolder.class);
  private boolean            isLoaded      = false;
  private SchedulerHotFolderFileList  objHotFolderFileList = new SchedulerHotFolderFileList();
 
  public SchedulerHotFolder () {
    //
  }
 
  public SchedulerHotFolder(SchedulerObjectFactory schedulerObjectFactory) {
    objFactory  = schedulerObjectFactory;
  }
 
  public SchedulerHotFolder(SchedulerObjectFactory schedulerObjectFactory, ISOSVirtualFile pobjVirtualFile) {
    objFactory  = schedulerObjectFactory;
    setHotFolderSrc(pobjVirtualFile);
  }
 
  public SchedulerHotFolderFileList load() {
    if(isLoaded) {
      return getHotFolderFileList();
    }
    return load(this.getHotFolderSrc());
  }
 
  public SchedulerHotFolderFileList refresh() {
    return load(this.getHotFolderSrc());
  }
 
  private SchedulerHotFolderFileList load(ISOSVirtualFile pobjVirtualDir)  {
 
    final String  conMethodName  = conClassName + "::load";
    try {
      if(!pobjVirtualDir.isDirectory()) {
        throw new JobSchedulerException(String.format("%1$s isn't a directory", pobjVirtualDir.getName()));
      }
    }
    catch (Exception e) {
      e.printStackTrace();
      JobSchedulerException objJSException = new JobSchedulerException(conMethodName, e);
      logger.error("", objJSException);
      throw objJSException;
    }
    ISOSVfsFileTransfer objVFSHandler = pobjVirtualDir.getHandler();
    logger.debug("getFilelist from: "+pobjVirtualDir.getName());
    String[] filenames = objVFSHandler.getFilelist(pobjVirtualDir.getName(), ".*", 0, false);
    objHotFolderFileList.setHotFolderSrc(pobjVirtualDir);
    for (String filename : filenames) {
      ISOSVirtualFile objVirtualFile = objVFSHandler.getFileHandle(filename);
      String lowerFilename = filename.toLowerCase();
      try {
        if(objVirtualFile.isDirectory()) {
          logger.debug("load SchedulerHotFolder = " + filename);
          SchedulerHotFolder obj = objFactory.createSchedulerHotFolder(objVirtualFile);
          objHotFolderFileList.add(obj);
        }
        else if(lowerFilename.endsWith(JSObjJob.fileNameExtension)) {
          logger.debug("load JSObjJob = " + filename);
          JSObjJob obj = objFactory.createJob(objVirtualFile);
          objHotFolderFileList.add(obj);
        }
        else if(lowerFilename.endsWith(JSObjJobChain.fileNameExtension)) {
          logger.debug("load JSObjJobChain = " + filename);
          JSObjJobChain obj = objFactory.createJobChain(objVirtualFile);
          objHotFolderFileList.add(obj);
        }
        else if(lowerFilename.endsWith(JSObjOrder.fileNameExtension)) {
          logger.debug("load JSObjOrder = " + filename);
          JSObjOrder obj = objFactory.createOrder(objVirtualFile);
          objHotFolderFileList.add(obj);
        }
        else if(lowerFilename.endsWith(JSObjLock.fileNameExtension)) {
          logger.debug("load JSObjLock = " + filename);
          JSObjLock obj = objFactory.createLock(objVirtualFile);
          objHotFolderFileList.add(obj);
        }
        else if(lowerFilename.endsWith(JSObjProcessClass.fileNameExtension)) {
          logger.debug("load JSObjProcessClass = " + filename);
          JSObjProcessClass obj = objFactory.createProcessClass(objVirtualFile);
          objHotFolderFileList.add(obj);
        }
        else if(lowerFilename.endsWith(JSObjSchedule.fileNameExtension)) {
          logger.debug("load JSObjSchedule = " + filename);
          JSObjSchedule obj = objFactory.createSchedule(objVirtualFile);
          objHotFolderFileList.add(obj);
        }
        else if(lowerFilename.endsWith(JSObjParams.fileNameExtension)) {
          logger.debug("load JSObjParams = " + filename);
          JSObjParams obj = objFactory.createParams(objVirtualFile);
          objHotFolderFileList.add(obj);
        }
        else {
          continue;
        }
      }
      catch (Exception e) {
        e.printStackTrace();
        logger.error("", new JobSchedulerException(conMethodName, e));
        throw new JobSchedulerException(conMethodName, e);
      }
    }
//    Collections.sort(objHotFolderFileList.getFileList());
    isLoaded  = true;
    logger.debug(String.format("%1$s objects found in %2$s", objHotFolderFileList.getFileList().size(), pobjVirtualDir.getName()));
    return objHotFolderFileList;
  } //load
 
 
  public SchedulerHotFolderFileList getHotFolderFileList() {
        return objHotFolderFileList;
    }
 
 
 
}
TOP

Related Classes of com.sos.scheduler.model.SchedulerHotFolder

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.