예제 #1
0
파일: JobParser.java 프로젝트: knrc/jsr352
 private static Flow parseFlow(final XMLStreamReader reader) throws XMLStreamException {
   final Flow flow = new Flow(getAttributeValue(reader, XmlAttribute.ID, true));
   flow.setAttributeNext(getAttributeValue(reader, XmlAttribute.NEXT, false));
   while (reader.hasNext()) {
     final int eventType = reader.next();
     if (eventType != START_ELEMENT && eventType != END_ELEMENT) {
       continue;
     }
     final XmlElement element = XmlElement.forName(reader.getLocalName());
     switch (eventType) {
       case START_ELEMENT:
         switch (element) {
           case DECISION:
             flow.addJobElement(parseDecision(reader));
             break;
           case FLOW:
             flow.addJobElement(parseFlow(reader));
             break;
           case SPLIT:
             flow.addJobElement(parseSplit(reader));
             break;
           case STEP:
             flow.addJobElement(parseStep(reader));
             break;
           case NEXT:
             if (flow.getAttributeNext() != null) {
               throw BatchLogger.LOGGER.cannotHaveBothNextAttributeAndElement(
                   reader.getLocation(), flow.getAttributeNext());
             }
             flow.addTransitionElement(parseNext(reader));
             break;
           case FAIL:
             flow.addTransitionElement(parseFail(reader));
             break;
           case END:
             flow.addTransitionElement(parseEnd(reader));
             break;
           case STOP:
             flow.addTransitionElement(parseStop(reader));
             break;
           default:
             throw BatchLogger.LOGGER.unexpectedXmlElement(
                 reader.getLocalName(), reader.getLocation());
         }
         break;
       case END_ELEMENT:
         switch (element) {
           case FLOW:
             return flow;
           default:
             throw BatchLogger.LOGGER.unexpectedXmlElement(
                 reader.getLocalName(), reader.getLocation());
         }
     }
   }
   throw BatchLogger.LOGGER.unexpectedXmlElement(reader.getLocalName(), reader.getLocation());
 }
예제 #2
0
파일: JobParser.java 프로젝트: knrc/jsr352
  private static Step parseStep(final XMLStreamReader reader) throws XMLStreamException {
    final Step step = new Step(getAttributeValue(reader, XmlAttribute.ID, true));
    step.setStartLimit(getAttributeValue(reader, XmlAttribute.START_LIMIT, false));
    step.setAllowStartIfComplete(
        getAttributeValue(reader, XmlAttribute.ALLOW_START_IF_COMPLETE, false));
    step.setAttributeNext(getAttributeValue(reader, XmlAttribute.NEXT, false));

    while (reader.hasNext()) {
      final int eventType = reader.next();
      if (eventType != START_ELEMENT && eventType != END_ELEMENT) {
        continue;
      }
      final XmlElement element = XmlElement.forName(reader.getLocalName());
      switch (eventType) {
        case START_ELEMENT:
          switch (element) {
            case PROPERTIES:
              step.setProperties(parseProperties(reader));
              break;
            case LISTENERS:
              step.addListeners(parseListeners(reader));
              break;
            case BATCHLET:
              step.setBatchlet(parseRefArtifact(reader, XmlElement.BATCHLET));
              break;
            case CHUNK:
              step.setChunk(parseChunk(reader));
              break;
            case PARTITION:
              step.setPartition(parsePartition(reader));
              break;
            case NEXT:
              if (step.getAttributeNext() != null) {
                throw BatchLogger.LOGGER.cannotHaveBothNextAttributeAndElement(
                    reader.getLocation(), step.getAttributeNext());
              }
              step.addTransitionElement(parseNext(reader));
              break;
            case FAIL:
              step.addTransitionElement(parseFail(reader));
              break;
            case END:
              step.addTransitionElement(parseEnd(reader));
              break;
            case STOP:
              step.addTransitionElement(parseStop(reader));
              break;
            default:
              throw BatchLogger.LOGGER.unexpectedXmlElement(
                  reader.getLocalName(), reader.getLocation());
          }
          break;
        case END_ELEMENT:
          switch (element) {
            case STEP:
              return step;
            default:
              throw BatchLogger.LOGGER.unexpectedXmlElement(
                  reader.getLocalName(), reader.getLocation());
          }
      }
    }
    throw BatchLogger.LOGGER.unexpectedXmlElement(reader.getLocalName(), reader.getLocation());
  }