示例#1
0
  @Test
  public void testModelValidate() throws Exception {

    JAXBContext ctx = JAXBContext.newInstance("jsr352.batch.jsl");

    Unmarshaller u = ctx.createUnmarshaller();
    u.setSchema(ValidatorHelper.getXJCLSchema());
    XJCLValidationEventHandler handler = new XJCLValidationEventHandler();
    u.setEventHandler(handler);
    URL url = this.getClass().getResource("/job1.xml");

    // Use this for anonymous type
    // Job job = (Job)u.unmarshal(url.openStream());

    // Use this for named complex type
    Object elem = u.unmarshal(url.openStream());
    assertFalse("XSD invalid, see sysout", handler.eventOccurred());

    JSLJob job = (JSLJob) ((JAXBElement) elem).getValue();

    assertEquals("job1", job.getId());
    assertEquals(1, job.getExecutionElements().size());
    Step step = (Step) job.getExecutionElements().get(0);
    assertEquals("step1", step.getId());
    Batchlet b = step.getBatchlet();
    assertEquals("step1Ref", b.getRef());
  }
 private ExecutionElement getExecutionElementByID(String id) {
   if (id != null) {
     for (ExecutionElement elem : job.getExecutionElements()) {
       if (elem.getId().equals(id)) {
         return elem;
       }
     }
   }
   return null;
 }
  @Override
  public ExecutionElement getFirstExecutionElement(String restartOn) {
    final String method = "getFirstExecutionElement";

    if (logger.isLoggable(Level.FINE)) {
      logger.fine(method + " , restartOn = " + restartOn);
    }

    ExecutionElement startElement = null;

    if (restartOn != null) {
      startElement = getExecutionElementByID(restartOn);
      if (startElement == null) {
        throw new IllegalStateException(
            "Didn't find an execution element maching restart-on designated element: " + restartOn);
      }
    } else {
      if (job.getExecutionElements().size() > 0) {
        startElement = job.getExecutionElements().get(0);
      } else {
        if (logger.isLoggable(Level.FINE)) {
          logger.fine(method + " , Job appears to contain no execution elements.  Returning.");
        }
        return null;
      }
    }

    if (logger.isLoggable(Level.FINE)) {
      logger.fine(method + " , Found start element: " + startElement);
    }

    if (startElement instanceof Step) {
      return (Step) startElement;
    } else if (startElement instanceof Flow) {
      return (Flow) startElement;
    } else if (startElement instanceof Split) {
      return (Split) startElement;
    } else {
      throw new IllegalStateException(
          "Didn't get this far yet implementing.\nOnly support <step> as first execution element.");
    }
  }
示例#4
0
  @Test
  public void testModelNoValidate() throws Exception {

    JAXBContext ctx = JAXBContext.newInstance("jsr352.batch.jsl");

    Unmarshaller u = ctx.createUnmarshaller();
    URL url = this.getClass().getResource("/job1.xml");

    // Use this for anonymous type
    // Job job = (Job)u.unmarshal(url.openStream());

    // Use this for named complex type
    Object elem = u.unmarshal(url.openStream());
    JSLJob job = (JSLJob) ((JAXBElement) elem).getValue();

    assertEquals("job1", job.getId());
    assertEquals(1, job.getExecutionElements().size());
    Step step = (Step) job.getExecutionElements().get(0);
    assertEquals("step1", step.getId());
    Batchlet b = step.getBatchlet();
    assertEquals("step1Ref", b.getRef());
  }
  /*


  private static String buildRegExFromJSLStringPattern(String jslPattern) {
  	String asterisk = "*";
  	String asteriskRegEx = ".*";
  	String questionMark = "?";
  	String questionMarkRegEx = ".?";

  	String newString = jslPattern;
  	newString = newString.replace(asterisk, asteriskRegEx);
  	newString = newString.replace(questionMark, questionMarkRegEx);

  	return newString;
  }
   */
  public String getId() {
    return job.getId();
  }