示例#1
0
 public static boolean isParticleArray(XmlSchemaParticle particle) {
   return particle.getMaxOccurs() > 1;
 }
示例#2
0
 public static boolean isParticleOptional(XmlSchemaParticle particle) {
   return particle.getMinOccurs() == 0 && particle.getMaxOccurs() == 1;
 }
  private void parseParticle(
      XmlSchemaParticle particle, NeutralSchema complexSchema, XmlSchema schema) {

    if (particle != null) {
      if (particle instanceof XmlSchemaElement) {
        XmlSchemaElement element = (XmlSchemaElement) particle;

        NeutralSchema elementSchema = parseElement(element, schema);

        String elementName = element.getName();

        // Required Elements
        if (!element.isNillable() && (element.getMinOccurs() > 0)) {
          AppInfo info = elementSchema.getAppInfo();
          if (info == null) {
            info = new AppInfo(null);
          }
          info.put(REQUIRED_USE.getValue(), "true");
          elementSchema.addAnnotation(info);
        }

        // Update Neutral Schema Field
        complexSchema.addField(elementName, elementSchema);

        // DE840 address.addressLines were not being encrypted
        for (Map.Entry<String, NeutralSchema> entry : elementSchema.getFields().entrySet()) {
          String fieldName = entry.getKey();
          NeutralSchema fieldSchema = entry.getValue();
          fieldSchema.inheritAnnotations(complexSchema.getAppInfo());
        }

      } else if (particle instanceof XmlSchemaSequence) {
        XmlSchemaSequence schemaSequence = (XmlSchemaSequence) particle;
        for (int i = 0; i < schemaSequence.getItems().getCount(); i++) {
          XmlSchemaObject item = schemaSequence.getItems().getItem(i);
          if (item instanceof XmlSchemaParticle) {
            parseParticle((XmlSchemaParticle) item, complexSchema, schema);
          } else {
            throw new RuntimeException(
                "Unsupported XmlSchemaSequence item: " + item.getClass().getCanonicalName());
          }
        }
      } else if (particle instanceof XmlSchemaChoice) {

        XmlSchemaChoice xmlSchemaChoice = (XmlSchemaChoice) particle;

        ChoiceSchema choiceSchema =
            (ChoiceSchema) getSchemaFactory().createSchema(NeutralSchemaType.CHOICE.name());

        choiceSchema.setMinOccurs(xmlSchemaChoice.getMinOccurs());
        choiceSchema.setMaxOccurs(xmlSchemaChoice.getMaxOccurs());

        XmlSchemaObjectCollection choices = xmlSchemaChoice.getItems();
        for (int i = 0; i < choices.getCount(); ++i) {
          XmlSchemaObject item = xmlSchemaChoice.getItems().getItem(i);
          if (item instanceof XmlSchemaParticle) {
            parseParticle((XmlSchemaParticle) item, choiceSchema, schema);
          }
        }

        complexSchema.addField("choice_" + choiceCount++, choiceSchema);

      } else {
        throw new RuntimeException(
            "Unsupported XmlSchemaParticle item: " + particle.getClass().getCanonicalName());
      }
    }
  }