Example #1
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;
  }
Example #2
0
  /**
   * Cursor position Before: <theElement>^</theElement> After: <theElement><lots of
   * stuff/>^</theElement>
   */
  public void createSampleForType(SchemaType stype, XmlCursor xmlc) {
    _exampleContent =
        SoapUI.getSettings().getBoolean(WsdlSettings.XML_GENERATION_TYPE_EXAMPLE_VALUE);
    _typeComment = SoapUI.getSettings().getBoolean(WsdlSettings.XML_GENERATION_TYPE_COMMENT_TYPE);
    _skipComments = SoapUI.getSettings().getBoolean(WsdlSettings.XML_GENERATION_SKIP_COMMENTS);

    QName nm = stype.getName();
    if (nm == null && stype.getContainerField() != null) nm = stype.getContainerField().getName();

    if (nm != null && excludedTypes.contains(nm)) {
      if (!_skipComments) xmlc.insertComment("Ignoring type [" + nm + "]");
      return;
    }

    if (_typeStack.contains(stype)) return;

    _typeStack.add(stype);

    try {
      if (stype.isSimpleType() || stype.isURType()) {
        processSimpleType(stype, xmlc);
        return;
      }

      // complex Type
      // <theElement>^</theElement>
      processAttributes(stype, xmlc);

      // <theElement attri1="string">^</theElement>
      switch (stype.getContentType()) {
        case SchemaType.NOT_COMPLEX_TYPE:
        case SchemaType.EMPTY_CONTENT:
          // noop
          break;
        case SchemaType.SIMPLE_CONTENT:
          {
            processSimpleType(stype, xmlc);
          }
          break;
        case SchemaType.MIXED_CONTENT:
          xmlc.insertChars(pick(WORDS) + " ");
          if (stype.getContentModel() != null) {
            processParticle(stype.getContentModel(), xmlc, true);
          }
          xmlc.insertChars(pick(WORDS));
          break;
        case SchemaType.ELEMENT_CONTENT:
          if (stype.getContentModel() != null) {
            processParticle(stype.getContentModel(), xmlc, false);
          }
          break;
      }
    } finally {
      _typeStack.remove(_typeStack.size() - 1);
    }
  }
Example #3
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);
    }
  }
Example #4
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));
    }
  }
Example #5
0
  private void addElementTypeAndRestricionsComment(SchemaLocalElement element, XmlCursor xmlc) {

    SchemaType type = element.getType();
    if (_typeComment && (type != null && type.isSimpleType())) {
      String info = "";

      XmlAnySimpleType[] values = type.getEnumerationValues();
      if (values != null && values.length > 0) {
        info = " - enumeration: [";
        for (int c = 0; c < values.length; c++) {
          if (c > 0) info += ",";

          info += values[c].getStringValue();
        }

        info += "]";
      }

      if (type.isAnonymousType()) xmlc.insertComment("anonymous type" + info);
      else xmlc.insertComment("type: " + type.getName().getLocalPart() + info);
    }
  }
Example #6
0
 private void processWildCard(SchemaParticle sp, XmlCursor xmlc, boolean mixed) {
   if (!_skipComments) xmlc.insertComment("You may enter ANY elements at this point");
   // xmlc.insertElement("AnyElement");
 }