Java Code Examples for org.apache.ws.commons.schema.XmlSchemaComplexType#setParticle()

The following examples show how to use org.apache.ws.commons.schema.XmlSchemaComplexType#setParticle() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MapType.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public void writeSchema(XmlSchema root) {
    XmlSchemaComplexType complex = new XmlSchemaComplexType(root, true);
    complex.setName(getSchemaType().getLocalPart());
    XmlSchemaSequence sequence = new XmlSchemaSequence();
    complex.setParticle(sequence);

    AegisType kType = getKeyType();
    AegisType vType = getValueType();

    XmlSchemaElement element = new XmlSchemaElement(root, false);
    sequence.getItems().add(element);
    element.setName(getEntryName().getLocalPart());
    element.setMinOccurs(0);
    element.setMaxOccurs(Long.MAX_VALUE);

    XmlSchemaComplexType evType = new XmlSchemaComplexType(root, false);
    element.setType(evType);

    XmlSchemaSequence evSequence = new XmlSchemaSequence();
    evType.setParticle(evSequence);

    createElement(root, evSequence, getKeyName(), kType, false);
    createElement(root, evSequence, getValueName(), vType, true);
}
 
Example 2
Source File: BindingHelper.java    From syndesis with Apache License 2.0 5 votes vote down vote up
private static List<XmlSchemaSequenceMember> getXmlSchemaElement(XmlSchema schema, XmlSchema parentSchema,
                                                          List<XmlSchemaSequenceMember> parentSequence,
                                                          String name, boolean topLevel) {
    // element
    final XmlSchemaElement element = new XmlSchemaElement(schema, topLevel);
    element.setName(name);

    // complex type
    final XmlSchemaComplexType complexType = new XmlSchemaComplexType(schema, false);
    element.setType(complexType);

    // sequence
    final XmlSchemaSequence sequence = new XmlSchemaSequence();
    complexType.setParticle(sequence);

    // need to add new element to a parent sequence?
    if(parentSequence != null) {
        final XmlSchemaElement child;
        if (!topLevel && schema.equals(parentSchema)) {
            // local element in parent schema, add as direct child to sequence
            child = element;
        } else {
            // add as ref in parent schema
            XmlSchemaElement refElement = new XmlSchemaElement(parentSchema, false);
            refElement.getRef().setTargetQName(element.getQName());
            child = refElement;
        }

        // add element or ref to parent sequence
        parentSequence.add(child);
    }

    return sequence.getItems();
}
 
Example 3
Source File: ArrayVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private XmlSchemaComplexType generateSchemaArray(Scope scopedName, Long size,
                                                 XmlSchemaType type, Scope fQName) {
    XmlSchemaComplexType complexType = new XmlSchemaComplexType(schema, true);
    complexType.setName(mapper.mapToQName(scopedName));

    XmlSchemaSequence sequence = new XmlSchemaSequence();

    XmlSchemaElement element = new XmlSchemaElement(schema, false);
    element.setMinOccurs(size);
    element.setMaxOccurs(size);
    element.setName(ELEMENT_NAME);
    if (type != null) {
        element.setSchemaTypeName(type.getQName());
        if (type.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
            element.setNillable(true);
        }
    } else {
        ArrayDeferredAction arrayAction =
            new ArrayDeferredAction(element);
        wsdlVisitor.getDeferredActions().add(fQName, arrayAction);
    }

    sequence.getItems().add(element);

    complexType.setParticle(sequence);

    return complexType;
}
 
Example 4
Source File: SequenceVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private XmlSchemaType generateSchemaType(XmlSchemaType stype, Scope scopedName,
                                         long bound, Scope fullyQualifiedName) {
    XmlSchemaComplexType ct = new XmlSchemaComplexType(schema, true);
    ct.setName(mapper.mapToQName(scopedName));
    XmlSchemaSequence sequence = new XmlSchemaSequence();
    XmlSchemaElement el = new XmlSchemaElement(schema, false);
    el.setName(ELEMENT_NAME);
    el.setMinOccurs(0);
    if (bound != -1) {
        el.setMaxOccurs(bound);
    } else {
        el.setMaxOccurs(Long.MAX_VALUE);
    }
    if (stype != null) {
        el.setSchemaTypeName(stype.getQName());
        if (stype.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
            el.setNillable(true);
        }
    } else {
        SequenceDeferredAction elementAction =
            new SequenceDeferredAction(el);
        wsdlVisitor.getDeferredActions().add(fullyQualifiedName, elementAction);
    }
    sequence.getItems().add(el);
    ct.setParticle(sequence);
    return ct;
}
 
Example 5
Source File: StructVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void visitDeclaredStruct(AST identifierNode) {
    Scope structScope = new Scope(getScope(), identifierNode);

    // xmlschema:struct
    XmlSchemaComplexType complexType = new XmlSchemaComplexType(schema, true);
    complexType.setName(mapper.mapToQName(structScope));
    XmlSchemaSequence sequence = new XmlSchemaSequence();
    complexType.setParticle(sequence);

    // corba:struct
    Struct struct = new Struct();
    struct.setQName(new QName(typeMap.getTargetNamespace(), structScope.toString()));
    struct.setType(complexType.getQName());
    struct.setRepositoryID(structScope.toIDLRepositoryID());

    boolean recursiveAdd = addRecursiveScopedName(identifierNode);

    // struct members
    visitStructMembers(identifierNode, struct, sequence, structScope);

    if (recursiveAdd) {
        removeRecursiveScopedName(identifierNode);
    }

    // add corbaType
    typeMap.getStructOrExceptionOrUnion().add(struct);

    // REVISIT: are there assignment needed?
    setSchemaType(complexType);
    setCorbaType(struct);

    // Need to check if the struct was forward declared
    processForwardStructActions(structScope);

    // Once we've finished declaring the struct, we should make sure it has been removed from
    // the list of scopedNames so that we inidicate that is no longer simply forward declared.
    scopedNames.remove(structScope);
}
 
Example 6
Source File: DeclaratorVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private XmlSchemaComplexType duplicateXmlSchemaComplexType(Scope newScope) {
    XmlSchemaComplexType oldSchemaType = (XmlSchemaComplexType) getSchemaType();
    XmlSchemaComplexType newSchemaType = new XmlSchemaComplexType(schema, true);

    newSchemaType.setName(newScope.toString());
    newSchemaType.setParticle(oldSchemaType.getParticle());

    return newSchemaType;
}
 
Example 7
Source File: OperationVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private XmlSchemaElement generateWrapper(QName el, XmlSchemaSequence wrappingSequence) {
    XmlSchemaComplexType schemaComplexType = new XmlSchemaComplexType(schema, false);
    schemaComplexType.setParticle(wrappingSequence);

    XmlSchemaElement wrappingSchemaElement = new XmlSchemaElement(schema, true);
    wrappingSchemaElement.setName(el.getLocalPart());
    wrappingSchemaElement.setSchemaType(schemaComplexType);

    return wrappingSchemaElement;
}
 
Example 8
Source File: ArrayType.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public void writeSchema(XmlSchema root) {

    if (isFlat()) {
        return; // there is no extra level of type.
    }
    if (hasDefinedArray(root)) {
        return;
    }

    XmlSchemaComplexType complex = new XmlSchemaComplexType(root, true);
    complex.setName(getSchemaType().getLocalPart());

    XmlSchemaSequence seq = new XmlSchemaSequence();
    complex.setParticle(seq);

    AegisType componentType = getComponentType();
    XmlSchemaElement element = new XmlSchemaElement(root, false);
    element.setName(componentType.getSchemaType().getLocalPart());
    element.setSchemaTypeName(componentType.getSchemaType());

    seq.getItems().add(element);

    if (componentType.isNillable()) {
        element.setNillable(true);
    }

    element.setMinOccurs(getMinOccurs());
    element.setMaxOccurs(getMaxOccurs());

}
 
Example 9
Source File: ImportRepairTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void createTypeImportingElement(XmlSchema importingSchema) {
    XmlSchemaComplexType typeWithElementRef = new XmlSchemaComplexType(importingSchema, true);
    typeWithElementRef.setName("typeWithRef");
    XmlSchemaSequence sequence = new XmlSchemaSequence();
    typeWithElementRef.setParticle(sequence);
    XmlSchemaElement refElement = new XmlSchemaElement(importingSchema, false);
    refElement.getRef().setTargetQName(new QName(ELEMENT_SCHEMA, "importedElement"));
}
 
Example 10
Source File: ExceptionVisitor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void visit(AST node) {
    // <exception_dcl> ::= "exception" <identifier> "{" <member>* "}"
    // <member> ::= <type_spec> <declarators> ";"

    // <type_spec> visited by TypesVisitor

    // Following should be visited by a separate visitor
    // <declarators> ::= <declarator> { "," <declarator> }*
    // <declarator> ::= <simple_declarator>
    //                | <complex_declarator>
    // <simple_declarator> ::= <identifier>
    // <complex_declarator> ::= <array_declarator>
    // <array_declarator> ::= <identifier> <fixed_array_size>+
    // <fixed_array_size> ::= "[" <positive_int_const> "]"


    AST identifierNode = node.getFirstChild();
    Scope exceptionScope = new Scope(getScope(), identifierNode);

    // xmlschema:exception
    Scope scopedName = new Scope(getScope(), identifierNode);
    String exceptionName = mapper.mapToQName(scopedName);
    XmlSchemaElement element = new XmlSchemaElement(schema, true);
    element.setName(mapper.mapToQName(scopedName));

    String exceptionTypeName = exceptionName + TYPE_SUFFIX;

    XmlSchemaComplexType complexType = new XmlSchemaComplexType(schema, true);
    complexType.setName(exceptionTypeName);
    //complexType.setQName(new QName(schema.getTargetNamespace(), exceptionTypeName));
    XmlSchemaSequence sequence = new XmlSchemaSequence();
    complexType.setParticle(sequence);

    element.setSchemaTypeName(complexType.getQName());

    // corba:exception
    org.apache.cxf.binding.corba.wsdl.Exception exception
        = new org.apache.cxf.binding.corba.wsdl.Exception();
    exception.setQName(new QName(typeMap.getTargetNamespace(), exceptionName));
    exception.setType(complexType.getQName());
    exception.setRepositoryID(scopedName.toIDLRepositoryID());


    // exception members
    AST memberTypeNode = identifierNode.getNextSibling();
    while (memberTypeNode != null) {
        AST memberNode = TypesUtils.getCorbaTypeNameNode(memberTypeNode);

        TypesVisitor visitor = new TypesVisitor(exceptionScope,
                                                definition,
                                                schema,
                                                wsdlVisitor,
                                                null);
        visitor.visit(memberTypeNode);
        XmlSchemaType stype = visitor.getSchemaType();
        CorbaType ctype = visitor.getCorbaType();
        Scope fullyQualifiedName = visitor.getFullyQualifiedName();

        // needed for anonymous arrays in exceptions
        if (ArrayVisitor.accept(memberNode)) {
            Scope anonScope = new Scope(exceptionScope,
                                        TypesUtils.getCorbaTypeNameNode(memberTypeNode));
            ArrayVisitor arrayVisitor = new ArrayVisitor(anonScope,
                                                         definition,
                                                         schema,
                                                         wsdlVisitor,
                                                         null,
                                                         fullyQualifiedName);
            arrayVisitor.setSchemaType(stype);
            arrayVisitor.setCorbaType(ctype);
            arrayVisitor.visit(memberNode);
            stype = arrayVisitor.getSchemaType();
            ctype = arrayVisitor.getCorbaType();
        }


        XmlSchemaElement member = createElementType(memberNode, stype,
                                                    fullyQualifiedName);
        sequence.getItems().add(member);

        MemberType memberType = createMemberType(memberNode, ctype,
                                                 fullyQualifiedName);
        exception.getMember().add(memberType);


        memberTypeNode = memberNode.getNextSibling();
    }

    // add exception to corba typemap
    typeMap.getStructOrExceptionOrUnion().add(exception);

    setSchemaType(complexType);
    setCorbaType(exception);
    createFaultMessage(element.getQName());
}
 
Example 11
Source File: AttributeVisitor.java    From cxf with Apache License 2.0 4 votes vote down vote up
/** Generate a wrapped doc style XmlSchemaElement containing one element.
 *
 * I.e.: generateWrappedDocElement(null, "foo", "bar");
 * <xs:element name="foo">
 *   <xs:complexType>
 *     <xs:sequence>
 *     </xs:sequence>
 *   </xs:complexType>
 * </xs:element>
 *
 * i.e.: generateWrappedDocElement(type, "foo", "bar");
 * <xs:element name="foo">
 *   <xs:complexType>
 *     <xs:sequence>
 *       <xs:element name="bar" type="xs:short">
 *       </xs:element>
 *     </xs:sequence>
 *   </xs:complexType>
 * </xs:element>

 *
 * @param typeNode is the type of the element wrapped in the sequence, no element is created if null.
 * @param name is the name of the wrapping element.
 * @param paramName is the name of the  wrapping element.
 * @return the wrapping element.
 */
private XmlSchemaElement generateWrappedDocElement(AST typeNode, String name,
                                                   String paramName) {
    XmlSchemaElement element = new XmlSchemaElement(schema, false);
    if (typeNode != null) {
        ParamTypeSpecVisitor visitor = new ParamTypeSpecVisitor(getScope(),
                                                                definition,
                                                                schema,
                                                                wsdlVisitor);
        visitor.visit(typeNode);
        XmlSchemaType stype = visitor.getSchemaType();
        Scope fqName = visitor.getFullyQualifiedName();

        if (stype != null) {
            element.setSchemaTypeName(stype.getQName());
            if (stype.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
                element.setNillable(true);
            }
        } else {
            wsdlVisitor.getDeferredActions().
                add(fqName, new AttributeDeferredAction(element));
        }

        element.setName(paramName);
    }

    XmlSchemaSequence sequence = new XmlSchemaSequence();
    if (typeNode != null) {
        sequence.getItems().add(element);
    }

    XmlSchemaComplexType complex = new XmlSchemaComplexType(schema, false);
    complex.setParticle(sequence);

    QName qName = new QName(definition.getTargetNamespace(), name);

    XmlSchemaElement result = new XmlSchemaElement(schema, true);
    result.setSchemaType(complex);

    if (duplicateTypeTrackerMap.containsKey(qName.toString())) {
        result.setName(getScope().toString() + "." + name);
        qName = new QName(definition.getTargetNamespace(), getScope().toString() + "." + name);
    } else {
        result.setName(name);
    }

    duplicateTypeTrackerMap.put(qName.toString(), name);

    return result;
}
 
Example 12
Source File: UnionVisitor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void visitDeclaredUnion(AST identifierNode) {

        Scope unionScope = new Scope(getScope(), identifierNode);
        AST discriminatorNode = identifierNode.getNextSibling();
        AST caseNode = discriminatorNode.getNextSibling();
        // xmlschema:union
        XmlSchemaComplexType unionSchemaComplexType = new XmlSchemaComplexType(schema, true);
        unionSchemaComplexType.setName(mapper.mapToQName(unionScope));

        // REVISIT
        // TEMPORARILY
        // using TypesVisitor to visit <const_type>
        // it should be visited by a SwitchTypeSpecVisitor
        TypesVisitor visitor = new TypesVisitor(getScope(), definition, schema, wsdlVisitor, null);
        visitor.visit(discriminatorNode);
        CorbaType ctype = visitor.getCorbaType();
        Scope fullyQualifiedName = visitor.getFullyQualifiedName();

        XmlSchemaChoice choice = new XmlSchemaChoice();
        choice.setMinOccurs(1);
        choice.setMaxOccurs(1);
        unionSchemaComplexType.setParticle(choice);


        // corba:union
        Union corbaUnion = new Union();
        corbaUnion.setQName(new QName(typeMap.getTargetNamespace(), unionScope.toString()));
        corbaUnion.setRepositoryID(unionScope.toIDLRepositoryID());
        corbaUnion.setType(unionSchemaComplexType.getQName());
        if (ctype != null) {
            corbaUnion.setDiscriminator(ctype.getQName());
        } else {
            // Discriminator type is forward declared.
            UnionDeferredAction unionDiscriminatorAction =
                new UnionDeferredAction(corbaUnion);
            wsdlVisitor.getDeferredActions().add(fullyQualifiedName, unionDiscriminatorAction);
        }

        boolean recursiveAdd = addRecursiveScopedName(identifierNode);

        processCaseNodes(caseNode, unionScope, choice, corbaUnion);

        if (recursiveAdd) {
            removeRecursiveScopedName(identifierNode);
        }

        // add corbaType
        typeMap.getStructOrExceptionOrUnion().add(corbaUnion);

        // REVISIT: are these assignments needed?
        setSchemaType(unionSchemaComplexType);
        setCorbaType(corbaUnion);

        // Need to check if the union was forward declared
        processForwardUnionActions(unionScope);

        // Once we've finished declaring the union, we should make sure it has been removed from
        // the list of scopedNames so that we indicate that is no longer simply forward declared.
        scopedNames.remove(unionScope);
    }
 
Example 13
Source File: ImportRepairTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void createTypeImportedByElement(XmlSchema elementTypeSchema) {
    XmlSchemaComplexType elementImportedType = new XmlSchemaComplexType(elementTypeSchema, true);
    elementImportedType.setName("importedElementType");
    elementImportedType.setParticle(new XmlSchemaSequence());
}
 
Example 14
Source File: ImportRepairTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
private XmlSchemaComplexType createBaseType2(XmlSchema baseTypeSchema2) {
    XmlSchemaComplexType baseType2 = new XmlSchemaComplexType(baseTypeSchema2, true);
    baseType2.setName("baseType2");
    baseType2.setParticle(new XmlSchemaSequence());
    return baseType2;
}
 
Example 15
Source File: ImportRepairTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void createBaseType1(XmlSchema baseTypeSchema1) {
    XmlSchemaComplexType baseType1 = new XmlSchemaComplexType(baseTypeSchema1, true);
    baseType1.setName("baseType1");
    baseType1.setParticle(new XmlSchemaSequence());
}