/********************************************************* 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.objects;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import com.sos.JSHelper.Exceptions.JobSchedulerException;
import com.sos.VirtualFileSystem.Interfaces.ISOSVirtualFile;
import com.sos.scheduler.model.SchedulerObjectFactory;
/**
* \class JSObjectJob
*
* \brief JSObjectJob -
*
* \details
*
* \section JSObjectJob.java_intro_sec Introduction
*
* \section JSObjectJob.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$03.02.2011
* \see reference
*
* Created on 03.02.2011 16:35:42
*/
/**
* @author oh
*
*/
public class JSObjJob extends Job {
private final String conClassName = "JSObjectJob";
private static final Logger logger = Logger.getLogger(JSObjJob.class);
// TODO should be defined as enum at the Attribute visible
public static enum enuVisibilityTypes {
enuIsVisible, enuIsNotVisible, enuIsNeverVisible;
private static String[] strVisibilityText = new String[] { "", "yes", "no", "never" };
public static boolean IsMandatory = false;
public static String I18nKey = "job.visible";
public static String[] getTexts() {
return strVisibilityText;
} // public static String getTexts
}
public final static String fileNameExtension = ".job.xml";
public JSObjJob(final SchedulerObjectFactory schedulerObjectFactory) {
objFactory = schedulerObjectFactory;
}
public JSObjJob(final SchedulerObjectFactory schedulerObjectFactory, final Job origOrder) {
objFactory = schedulerObjectFactory;
setObjectFieldsFrom(origOrder);
afterUnmarshal();
}
public JSObjJob(final SchedulerObjectFactory schedulerObjectFactory, final ISOSVirtualFile pobjVirtualFile) {
objFactory = schedulerObjectFactory;
final Job objJob = (Job) unMarshal(pobjVirtualFile);
setObjectFieldsFrom(objJob);
setHotFolderSrc(pobjVirtualFile);
afterUnmarshal();
}
private void afterUnmarshal() {
@SuppressWarnings("unused")
final String conMethodName = conClassName + "::afterUnmarchal";
if (this.getDescription() != null) {
removeEmptyContentsFrom(this.getDescription().getContent());
}
if (this.getScript() != null) {
removeEmptyContentsFrom(this.getScript().getContent());
}
if (this.getMonitor() != null) {
for (final Job.Monitor objMonitor : this.getMonitor()) {
if (objMonitor.getScript() != null) {
removeEmptyContentsFrom(objMonitor.getScript().getContent());
}
}
}
} // public afterUnmarchal
/**
*
* \brief removeEmptyContentsFrom
*
* \details
* Some objects contain cdata as well as other objects, so that
* unmarshalling creates for every spaces around the other objects
* empty cdata nodes. These empty cdata nodes are removed.
*
* \return void
*
* @param objList
*/
private void removeEmptyContentsFrom(final List<Object> objList) {
@SuppressWarnings("unused")
final String conMethodName = conClassName + "::removeEmptyContentsFrom";
final List<String> emptyContents = new ArrayList<String>();
for (final Object listItem : objList) {
if (listItem instanceof String && ((String) listItem).trim().length() == 0) {
emptyContents.add(((String) listItem));
}
}
objList.removeAll(emptyContents);
} // private removeEmptyContentsFrom
/**
*
* \brief setOrder
*
* \details
*
* \return void
*
* @param pflgIsOrder
*/
public void setOrder(final boolean pflgIsOrder) {
@SuppressWarnings("unused")
final String conMethodName = conClassName + "::setOrder";
if (pflgIsOrder == true) {
this.setOrder("yes");
}
else {
this.setOrder("no");
}
} // public void setOrder
/**
*
* \brief setStopOnError
*
* \details
*
* \return void
*
* @param pflgIsStoppingOnError
*/
public void setStopOnError(final boolean pflgIsStoppingOnError) {
@SuppressWarnings("unused")
final String conMethodName = conClassName + "::setStopOnError";
if (pflgIsStoppingOnError == true) {
this.setStopOnError("yes");
}
else {
this.setStopOnError("no");
}
} // public void setStopOnError
/**
*
* \brief setForceIdleTimeout
*
* \details
*
* \return void
*
* @param pflgIsForcedIdleTimeout
*/
public void setForceIdleTimeout(final boolean pflgIsForcedIdleTimeout) {
@SuppressWarnings("unused")
final String conMethodName = conClassName + "::setForceIdleTimeout";
if (pflgIsForcedIdleTimeout == true) {
this.setForceIdleTimeout("yes");
}
else {
this.setForceIdleTimeout("no");
}
} // public void setForceIdleTimeout
/**
*
* \brief setTemporary
*
* \details
*
* \return void
*
* @param pflgIsTemporary
*/
public void setTemporary(final boolean pflgIsTemporary) {
@SuppressWarnings("unused")
final String conMethodName = conClassName + "::setTemporary";
if (pflgIsTemporary == true) {
this.setTemporary("yes");
}
else {
this.setTemporary("no");
}
} // public void setTemporary
public boolean hasScript() {
@SuppressWarnings("unused")
final String conMethodName = conClassName + "::hasScript";
final Script objScript = getScript();
if (objScript == null) {
final JobSchedulerException objJSException = new JobSchedulerException("Job has no script.");
logger.error("", objJSException);
throw objJSException;
}
//TODO else if (objScript.getLanguage()... ) {
// }
return true;
}
}