/**
   * Sets the job name.
   *
   * <p>
   *
   * @param jobName the job name to set
   */
  public void setJobName(String jobName) {

    checkFrozen();
    if (CmsStringUtil.isEmpty(jobName) || !jobName.trim().equals(jobName)) {
      throw new CmsIllegalArgumentException(
          Messages.get().container(Messages.ERR_BAD_JOB_NAME_1, jobName));
    }
    m_jobName = jobName;
  }
  /**
   * Sets the context information for the user executing the job.
   *
   * <p>This will also "freeze" the context information that is set.
   *
   * <p>
   *
   * @param contextInfo the context information for the user executing the job
   * @see CmsContextInfo#freeze()
   */
  public void setContextInfo(CmsContextInfo contextInfo) {

    checkFrozen();
    if (contextInfo == null) {
      throw new CmsIllegalArgumentException(
          Messages.get().container(Messages.ERR_BAD_CONTEXT_INFO_0));
    }
    m_context = contextInfo;
  }
  /**
   * Sets the job parameters.
   *
   * <p>
   *
   * @param parameters the parameters to set
   */
  public void setParameters(SortedMap<String, String> parameters) {

    checkFrozen();
    if (parameters == null) {
      throw new CmsIllegalArgumentException(
          Messages.get().container(Messages.ERR_BAD_JOB_PARAMS_0));
    }
    // make sure the parameters are a sorted map
    m_parameters = new TreeMap<String, String>(parameters);
  }
  /**
   * Sets the cron expression for this job entry.
   *
   * <p>
   *
   * @param cronExpression the cron expression to set
   */
  public void setCronExpression(String cronExpression) {

    checkFrozen();

    try {
      // check if the cron expression is valid
      new CronTrigger().setCronExpression(cronExpression);
    } catch (Exception e) {
      throw new CmsIllegalArgumentException(
          Messages.get()
              .container(Messages.ERR_BAD_CRON_EXPRESSION_2, getJobName(), cronExpression));
    }

    m_cronExpression = cronExpression;
  }
  /**
   * @see
   *     org.opencms.configuration.I_CmsConfigurationParameterHandler#addConfigurationParameter(java.lang.String,
   *     java.lang.String)
   */
  public void addConfigurationParameter(String paramName, String paramValue) {

    checkFrozen();
    // add the configured parameter
    m_parameters.put(paramName, paramValue);
    if (LOG.isDebugEnabled()) {
      LOG.debug(
          org.opencms.configuration.Messages.get()
              .getBundle()
              .key(
                  org.opencms.configuration.Messages.LOG_ADD_CONFIG_PARAM_3,
                  paramName,
                  paramValue,
                  this));
    }
  }
  /**
   * Sets the name of the class to schedule.
   *
   * <p>
   *
   * @param className the class name to set
   */
  public void setClassName(String className) {

    checkFrozen();
    if (!CmsStringUtil.isValidJavaClassName(className)) {
      CmsMessageContainer message =
          Messages.get().container(Messages.ERR_BAD_JOB_CLASS_NAME_1, className);
      if (OpenCms.getRunLevel() > OpenCms.RUNLEVEL_2_INITIALIZING) {
        throw new CmsIllegalArgumentException(message);
      } else {
        LOG.warn(message.key());
      }
    } else {
      Class<?> jobClass;
      try {
        jobClass = Class.forName(className);
        if (!I_CmsScheduledJob.class.isAssignableFrom(jobClass)) {
          CmsMessageContainer message =
              Messages.get()
                  .container(
                      Messages.ERR_JOB_CLASS_BAD_INTERFACE_2,
                      className,
                      I_CmsScheduledJob.class.getName());

          if (OpenCms.getRunLevel() > OpenCms.RUNLEVEL_2_INITIALIZING) {
            throw new CmsIllegalArgumentException(message);
          } else {
            LOG.warn(message.key());
          }
        }
      } catch (ClassNotFoundException e) {
        CmsMessageContainer message =
            Messages.get().container(Messages.ERR_JOB_CLASS_NOT_FOUND_1, className);
        if (OpenCms.getRunLevel() > OpenCms.RUNLEVEL_2_INITIALIZING) {
          throw new CmsIllegalArgumentException(message);
        } else {
          LOG.warn(message.key());
        }
      }
    }
    m_className = className;
    if (getJobName() == null) {
      // initialize job name with class name as default
      setJobName(className);
    }
  }
  /**
   * Sets the Quartz trigger used for scheduling this job.
   *
   * <p>This is an internal operation that should only by performed by the <code>
   * {@link CmsScheduleManager}</code>, never by using this API directly.
   *
   * <p>
   *
   * @param trigger the Quartz trigger to set
   */
  protected void setTrigger(Trigger trigger) {

    checkFrozen();
    m_trigger = trigger;
  }
  /**
   * Sets the is used for scheduling this job.
   *
   * <p>This is an internal operation that should only by performed by the <code>
   * {@link CmsScheduleManager}</code>, never by using this API directly.
   *
   * <p>
   *
   * @param id the id to set
   */
  protected void setId(String id) {

    checkFrozen();
    m_id = id;
  }
  /**
   * Controls if the job instance class is reused for this job, of if a new instance is generated
   * every time the job is run.
   *
   * <p>
   *
   * @param reuseInstance must be true if the job instance class is to be reused
   */
  public void setReuseInstance(boolean reuseInstance) {

    checkFrozen();
    m_reuseInstance = reuseInstance;
  }
Пример #10
0
  /**
   * Sets the active state of this job.
   *
   * <p>
   *
   * @param active the active state to set
   */
  public void setActive(boolean active) {

    checkFrozen();
    m_active = active;
  }