private NeutralSchema parseElement(XmlSchemaElement element, XmlSchema schema) {

    QName elementTypeName = element.getSchemaTypeName();

    // Derive Element Schema
    XmlSchemaType elementSchemaType = element.getSchemaType();

    // Element annotations override type annotations.
    if (element.getAnnotation() != null) {
      elementSchemaType.setAnnotation(element.getAnnotation());
    }

    NeutralSchema elementSchema = null;
    if (elementSchemaType != null) {
      if (elementSchemaType.getName() != null) {
        elementSchema = this.parse(elementSchemaType, schema);
      } else {
        elementSchema = this.parse(elementSchemaType, element.getName(), schema);
      }
    } else if (elementTypeName != null) {
      elementSchema = getSchemaFactory().createSchema(elementTypeName);
    }

    if (elementSchema != null) {

      // List Schema
      if (element.getMaxOccurs() > 1) {
        ListSchema listSchema = (ListSchema) getSchemaFactory().createSchema("list");
        listSchema.getList().add(elementSchema);
        listSchema.updateAnnotations();
        elementSchema = listSchema;
      }
    }

    Long min = element.getMinOccurs();
    Long max = element.getMaxOccurs();
    QName type = element.getSchemaTypeName();

    if (min != null) {
      elementSchema.getProperties().put("minCardinality", min);
    }
    if (max != null) {
      elementSchema.getProperties().put("maxCardinality", max);
    }
    if (type != null) {
      elementSchema.getProperties().put("elementType", type.toString());
    }

    return elementSchema;
  }
Exemplo n.º 2
0
 private XmlSchemaElement createXmlSchemaElement(
     AST memberNode, XmlSchemaType schemaType, Scope fqName) {
   // xmlschema:member
   XmlSchemaElement member = new XmlSchemaElement();
   String memberName = memberNode.toString();
   member.setName(memberName);
   member.setSchemaType(schemaType);
   if (schemaType != null) {
     member.setSchemaTypeName(schemaType.getQName());
     if (schemaType.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
       member.setNillable(true);
     }
   } else {
     wsdlVisitor.getDeferredActions().add(fqName, new StructDeferredAction(member));
   }
   return member;
 }
 private XmlSchemaComplexType getComplexBaseType(
     XmlSchemaComplexContentExtension schemaComplexContent, XmlSchema schema) {
   XmlSchemaComplexType complexBaseType = null;
   QName baseTypeName = schemaComplexContent.getBaseTypeName();
   XmlSchemaType baseType = schema.getTypeByName(baseTypeName);
   if (baseType != null) {
     if (baseType instanceof XmlSchemaComplexType) {
       complexBaseType = (XmlSchemaComplexType) baseType;
     } else {
       throw new RuntimeException(
           "Unsupported complex base type: " + baseType.getClass().getCanonicalName());
     }
   } else {
     throw new RuntimeException("Schema complex base type not found: " + baseTypeName);
   }
   return complexBaseType;
 }
  private XmlSchemaSimpleType getSimpleBaseType(QName simpleBaseTypeName, XmlSchema schema) {
    XmlSchemaSimpleType simpleBaseType = null;
    if (simpleBaseTypeName != null) {
      XmlSchemaType baseType = schema.getTypeByName(simpleBaseTypeName);
      if (baseType != null) {
        if (baseType instanceof XmlSchemaSimpleType) {
          simpleBaseType = (XmlSchemaSimpleType) baseType;
        } else {
          throw new RuntimeException(
              "Unsupported simple base type: " + baseType.getClass().getCanonicalName());
        }
      } else {
        throw new RuntimeException("Schema simple base type not found: " + simpleBaseTypeName);
      }
    }

    return simpleBaseType;
  }
  private void parseAnnotations(NeutralSchema neutralSchema, XmlSchemaType schemaType) {

    if (neutralSchema == null || schemaType == null || schemaType.getAnnotation() == null) {
      return;
    }

    parseDocumentation(neutralSchema, schemaType);
    parseAppInfo(neutralSchema, schemaType);
  }
  private void parseDocumentation(NeutralSchema neutralSchema, XmlSchemaType schemaType) {
    XmlSchemaObjectCollection annotations = schemaType.getAnnotation().getItems();
    for (int annotationIdx = 0; annotationIdx < annotations.getCount(); ++annotationIdx) {

      XmlSchemaObject annotation = annotations.getItem(annotationIdx);
      if (annotation instanceof XmlSchemaDocumentation) {
        XmlSchemaDocumentation docs = (XmlSchemaDocumentation) annotation;
        neutralSchema.addAnnotation(new Documentation(docs.getMarkup()));
      }
    }
  }
  private void parseAppInfo(NeutralSchema neutralSchema, XmlSchemaType schemaType) {

    XmlSchemaObjectCollection annotations = schemaType.getAnnotation().getItems();
    for (int annotationIdx = 0; annotationIdx < annotations.getCount(); ++annotationIdx) {

      XmlSchemaObject annotation = annotations.getItem(annotationIdx);
      if (annotation instanceof XmlSchemaAppInfo) {
        XmlSchemaAppInfo info = (XmlSchemaAppInfo) annotation;
        neutralSchema.addAnnotation(new AppInfo(info.getMarkup()));
      }
    }
  }
  private NeutralSchema parse(XmlSchemaType type, String name, XmlSchema schema) {
    NeutralSchema prior = partialSchemas.get(type);
    if (prior != null) {
      // we already have a schema of this type
      NeutralSchema nSchema = getSchemaFactory().copySchema(prior);
      return nSchema;
    }
    if (type instanceof XmlSchemaComplexType) {
      NeutralSchema complexSchema = getSchemaFactory().createSchema(name);
      partialSchemas.put(type, complexSchema); // avoid infinite recursion in self-referential
      // schemas
      return parseComplexType((XmlSchemaComplexType) type, complexSchema, schema);

    } else if (type instanceof XmlSchemaSimpleType) {
      return parseSimpleType((XmlSchemaSimpleType) type, schema, name);

    } else {
      throw new RuntimeException("Unsupported schema type: " + type.getClass().getCanonicalName());
    }
  }
Exemplo n.º 9
0
  private void processCaseNodes(
      AST caseNode, Scope scope, XmlSchemaChoice choice, Union corbaUnion) {
    while (caseNode != null) {
      AST typeNode = null;
      AST nameNode = null;
      AST labelNode = null;

      // xmlschema:element
      XmlSchemaElement element = new XmlSchemaElement();

      // corba:unionbranch
      Unionbranch unionBranch = new Unionbranch();

      if (caseNode.getType() == IDLTokenTypes.LITERAL_default) {
        // default:
        unionBranch.setDefault(true);

        typeNode = caseNode.getFirstChild();
        nameNode = typeNode.getNextSibling();
      } else {
        // case:
        createCase(caseNode, unionBranch);

        labelNode = caseNode.getFirstChild();
        if (labelNode.getType() == IDLTokenTypes.LITERAL_case) {
          labelNode = labelNode.getNextSibling();
        }

        typeNode = labelNode.getNextSibling();
        nameNode = typeNode.getNextSibling();
      }

      TypesVisitor visitor = new TypesVisitor(scope, definition, schema, wsdlVisitor, null);
      visitor.visit(typeNode);
      XmlSchemaType stype = visitor.getSchemaType();
      CorbaTypeImpl ctype = visitor.getCorbaType();
      Scope fullyQualifiedName = visitor.getFullyQualifiedName();

      // needed for anonymous arrays in unions
      if (ArrayVisitor.accept(nameNode)) {
        Scope anonScope = new Scope(scope, TypesUtils.getCorbaTypeNameNode(nameNode));
        ArrayVisitor arrayVisitor =
            new ArrayVisitor(anonScope, definition, schema, wsdlVisitor, null, fullyQualifiedName);
        arrayVisitor.setSchemaType(stype);
        arrayVisitor.setCorbaType(ctype);
        arrayVisitor.visit(nameNode);
        stype = arrayVisitor.getSchemaType();
        ctype = arrayVisitor.getCorbaType();
        fullyQualifiedName = visitor.getFullyQualifiedName();
      }

      // xmlschema:element
      element.setName(nameNode.toString());
      if (stype != null) {
        element.setSchemaTypeName(stype.getQName());
        if (stype.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
          element.setNillable(true);
        }
      } else {
        UnionDeferredAction elementAction = new UnionDeferredAction(element);
        wsdlVisitor.getDeferredActions().add(fullyQualifiedName, elementAction);
      }
      choice.getItems().add(element);

      // corba:unionbranch
      unionBranch.setName(nameNode.toString());
      if (ctype != null) {
        unionBranch.setIdltype(ctype.getQName());
      } else {
        // its type is forward declared.
        UnionDeferredAction unionBranchAction = new UnionDeferredAction(unionBranch);
        wsdlVisitor.getDeferredActions().add(fullyQualifiedName, unionBranchAction);
      }
      corbaUnion.getUnionbranch().add(unionBranch);

      caseNode = caseNode.getNextSibling();
    }
  }
 private NeutralSchema parse(XmlSchemaType type, XmlSchema schema) {
   return parse(type, type.getName(), schema);
 }