示例#1
0
  private void processElement(SchemaParticle sp, XmlCursor xmlc, boolean mixed) {
    // cast as schema local element
    SchemaLocalElement element = (SchemaLocalElement) sp;

    // Add comment about type
    addElementTypeAndRestricionsComment(element, xmlc);

    // / ^ -> <elemenname></elem>^
    if (_soapEnc) xmlc.insertElement(element.getName().getLocalPart()); // soap
    // encoded?
    // drop
    // namespaces.
    else xmlc.insertElement(element.getName().getLocalPart(), element.getName().getNamespaceURI());
    // / -> <elem>^</elem>
    // processAttributes( sp.getType(), xmlc );

    xmlc.toPrevToken();
    // -> <elem>stuff^</elem>

    String[] values = null;
    if (multiValues != null) values = multiValues.get(element.getName());
    if (values != null) xmlc.insertChars(StringUtils.join(values, ","));
    else if (sp.isDefault()) xmlc.insertChars(sp.getDefaultText());
    else createSampleForType(element.getType(), xmlc);
    // -> <elem>stuff</elem>^
    xmlc.toNextToken();
  }
示例#2
0
 /*
  * Return a name for the element or the particle type to use in the comment
  * for minoccurs, max occurs
  */
 @SuppressWarnings("unused")
 private String getItemNameOrType(SchemaParticle sp, XmlCursor xmlc) {
   String elementOrTypeName = null;
   if (sp.getParticleType() == SchemaParticle.ELEMENT) {
     elementOrTypeName = "Element (" + sp.getName().getLocalPart() + ")";
   } else {
     elementOrTypeName = printParticleType(sp.getParticleType());
   }
   return elementOrTypeName;
 }
示例#3
0
  /**
   * Cursor position: Before this call: <outer><foo/>^</outer> (cursor at the ^) After this call:
   * <<outer><foo/><bar/>som text<etc/>^</outer>
   */
  private void processParticle(SchemaParticle sp, XmlCursor xmlc, boolean mixed) {
    int loop = determineMinMaxForSample(sp, xmlc);

    while (loop-- > 0) {
      switch (sp.getParticleType()) {
        case (SchemaParticle.ELEMENT):
          processElement(sp, xmlc, mixed);
          break;
        case (SchemaParticle.SEQUENCE):
          processSequence(sp, xmlc, mixed);
          break;
        case (SchemaParticle.CHOICE):
          processChoice(sp, xmlc, mixed);
          break;
        case (SchemaParticle.ALL):
          processAll(sp, xmlc, mixed);
          break;
        case (SchemaParticle.WILDCARD):
          processWildCard(sp, xmlc, mixed);
          break;
        default:
          // throw new Exception("No Match on Schema Particle Type: " +
          // String.valueOf(sp.getParticleType()));
      }
    }
  }
示例#4
0
 private void processSequence(SchemaParticle sp, XmlCursor xmlc, boolean mixed) {
   SchemaParticle[] spc = sp.getParticleChildren();
   for (int i = 0; i < spc.length; i++) {
     // / <parent>maybestuff^</parent>
     processParticle(spc[i], xmlc, mixed);
     // <parent>maybestuff...morestuff^</parent>
     if (mixed && i < spc.length - 1) xmlc.insertChars(pick(WORDS));
   }
 }
示例#5
0
  private void processChoice(SchemaParticle sp, XmlCursor xmlc, boolean mixed) {
    SchemaParticle[] spc = sp.getParticleChildren();
    if (!_skipComments)
      xmlc.insertComment(
          "You have a CHOICE of the next " + String.valueOf(spc.length) + " items at this level");

    for (int i = 0; i < spc.length; i++) {
      processParticle(spc[i], xmlc, mixed);
    }
  }
示例#6
0
  private void processAll(SchemaParticle sp, XmlCursor xmlc, boolean mixed) {
    SchemaParticle[] spc = sp.getParticleChildren();
    if (!_skipComments)
      xmlc.insertComment(
          "You may enter the following " + String.valueOf(spc.length) + " items in any order");

    for (int i = 0; i < spc.length; i++) {
      processParticle(spc[i], xmlc, mixed);
      if (mixed && i < spc.length - 1) xmlc.insertChars(pick(WORDS));
    }
  }
示例#7
0
  private int determineMinMaxForSample(SchemaParticle sp, XmlCursor xmlc) {
    int minOccurs = sp.getIntMinOccurs();
    int maxOccurs = sp.getIntMaxOccurs();

    if (minOccurs == maxOccurs) return minOccurs;

    if (minOccurs == 0 && ignoreOptional) return 0;

    int result = minOccurs;
    if (result == 0) result = 1;

    if (sp.getParticleType() != SchemaParticle.ELEMENT) return result;

    // it probably only makes sense to put comments in front of individual
    // elements that repeat

    if (!_skipComments) {
      if (sp.getMaxOccurs() == null) {
        // xmlc.insertComment("The next " + getItemNameOrType(sp, xmlc) + "
        // may
        // be repeated " + minOccurs + " or more times");
        if (minOccurs == 0) xmlc.insertComment("Zero or more repetitions:");
        else xmlc.insertComment(minOccurs + " or more repetitions:");
      } else if (sp.getIntMaxOccurs() > 1) {
        xmlc.insertComment(
            minOccurs + " to " + String.valueOf(sp.getMaxOccurs()) + " repetitions:");
      } else {
        xmlc.insertComment("Optional:");
      }
    }

    return result;
  }