Java Code Examples for org.apache.ws.commons.schema.XmlSchemaElement#setSchemaTypeName()

The following examples show how to use org.apache.ws.commons.schema.XmlSchemaElement#setSchemaTypeName() . 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: ExceptionVisitor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private XmlSchemaElement createElementType(AST memberNode, XmlSchemaType stype,
                                           Scope fqName) {
    // xmlschema:member
    XmlSchemaElement member = new XmlSchemaElement(schema, false);
    String memberName = memberNode.toString();
    member.setName(memberName);
    if (stype != null) {
        member.setSchemaType(stype);
        member.setSchemaTypeName(stype.getQName());
        if (stype.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
            member.setNillable(true);
        }
    } else {
        wsdlVisitor.getDeferredActions().
            add(fqName, new ExceptionDeferredAction(member));
    }
    return member;
}
 
Example 2
Source File: StructVisitor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private XmlSchemaElement createXmlSchemaElement(AST memberNode,
                                                XmlSchemaType schemaType,
                                                Scope fqName) {
    // xmlschema:member
    XmlSchemaElement member = new XmlSchemaElement(schema, false);
    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;
}
 
Example 3
Source File: OperationVisitor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private XmlSchemaElement addElement(XmlSchemaSequence schemaSequence,
                                    XmlSchemaType schemaType,
                                    Scope fqName,
                                    String name) {
    XmlSchemaElement element = new XmlSchemaElement(schema, false);
    element.setName(name);
    if (schemaType != null) {
        element.setSchemaTypeName(schemaType.getQName());
        if (schemaType.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
            element.setNillable(true);
        }
    } else {
        wsdlVisitor.getDeferredActions().
            add(fqName, new OperationDeferredAction(element));
    }
    schemaSequence.getItems().add(element);

    return element;
}
 
Example 4
Source File: JAXBSchemaInitializer.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void buildGenericElements(XmlSchema schema, XmlSchemaSequence seq, Field f) {
    XmlSchemaComplexType generics = new XmlSchemaComplexType(schema, true);
    Type type = f.getGenericType();
    String rawType = ((ParameterizedType)type).getRawType().toString();
    String typeName = StringUtils.uncapitalize(rawType.substring(rawType.lastIndexOf('.') + 1));
    generics.setName(typeName);

    Class<?> genericsClass = f.getType();
    buildGenericSeq(schema, generics, genericsClass);

    String name = Character.toLowerCase(f.getName().charAt(0)) + f.getName().substring(1);
    XmlSchemaElement newel = new XmlSchemaElement(schema, false);
    newel.setName(name);
    newel.setSchemaTypeName(generics.getQName());
    newel.setMinOccurs(0);
    if (!seq.getItems().contains(newel)) {
        seq.getItems().add(newel);
    }
}
 
Example 5
Source File: JAXBSchemaInitializer.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void addExceptionMessage(Class<?> cls, XmlSchema schema, XmlSchemaSequence seq) {
    try {
        //a subclass could mark the message method as transient
        Method m = cls.getMethod("getMessage");
        if (!m.isAnnotationPresent(XmlTransient.class)
            && m.getDeclaringClass().equals(Throwable.class)) {
            JAXBBeanInfo beanInfo = getBeanInfo(java.lang.String.class);
            XmlSchemaElement exEle = new XmlSchemaElement(schema, false);
            exEle.setName("message");
            exEle.setSchemaTypeName(getTypeName(beanInfo));
            exEle.setMinOccurs(0);
            seq.getItems().add(exEle);
        }
    } catch (Exception e) {
        //ignore, just won't have the message element
    }
}
 
Example 6
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 7
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 8
Source File: XsdEmitter.java    From legstar-core2 with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Create an XML Schema element from a COBOL data item.
 * 
 * @param xsdDataItem COBOL data item decorated with XSD attributes
 * @return the XML schema element
 */
public XmlSchemaElement createXmlSchemaElement(final XsdDataItem xsdDataItem) {

    // Let call add root elements if he needs to so for now pretend this is
    // not a root element
    XmlSchemaElement element = new XmlSchemaElement(getXsd(), false);
    element.setName(xsdDataItem.getXsdElementName());
    if (xsdDataItem.getMaxOccurs() != 1) {
        element.setMaxOccurs(xsdDataItem.getMaxOccurs());
    }
    if (xsdDataItem.getMinOccurs() != 1) {
        element.setMinOccurs(xsdDataItem.getMinOccurs());
    }

    /*
     * Create this element schema type, then if its a simple type set it as
     * an anonymous type. Otherwise, it is a named complex type, so
     * reference it by name.
     */
    XmlSchemaType xmlSchemaType = createXmlSchemaType(xsdDataItem);
    if (xmlSchemaType == null) {
        return null;
    }
    if (xmlSchemaType instanceof XmlSchemaSimpleType) {
        element.setSchemaType(xmlSchemaType);
    } else {
        element.setSchemaTypeName(xmlSchemaType.getQName());
    }
    if (getConfig().addLegStarAnnotations()) {
        element.setAnnotation(_annotationEmitter
                .createLegStarAnnotation(xsdDataItem));
    }
    return element;
}
 
Example 9
Source File: JAXBSchemaInitializer.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void addElement(XmlSchema schema,
                          XmlSchemaSequence seq, JAXBBeanInfo beanInfo,
                          QName name, boolean isArray, XmlElement xmlElementAnno) {
    XmlSchemaElement el = new XmlSchemaElement(schema, false);
    if (isArray) {
        el.setMinOccurs(0);
        el.setMaxOccurs(Long.MAX_VALUE);
    } else {
        if (xmlElementAnno == null) {
            el.setMinOccurs(0);
            el.setNillable(false);
        } else {
            el.setNillable(xmlElementAnno.nillable());
            int minOccurs = xmlElementAnno.required() ? 1 : 0;
            el.setMinOccurs(minOccurs);
        }
    }

    if (beanInfo.isElement()) {
        QName ename = new QName(beanInfo.getElementNamespaceURI(null),
                               beanInfo.getElementLocalName(null));
        XmlSchemaElement el2 = schemas.getElementByQName(ename);
        el.setNillable(false);
        el.getRef().setTargetQName(el2.getQName());
    } else {
        if (xmlElementAnno != null && !StringUtils.isEmpty(xmlElementAnno.name())) {
            el.setName(xmlElementAnno.name());
        } else {
            el.setName(name.getLocalPart());
        }
        Iterator<QName> itr = beanInfo.getTypeNames().iterator();
        if (!itr.hasNext()) {
            return;
        }
        QName typeName = itr.next();
        el.setSchemaTypeName(typeName);
    }

    seq.getItems().add(el);
}
 
Example 10
Source File: ParamDclVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private XmlSchemaElement addElement(XmlSchemaSequence schemaSequence,
                                    XmlSchemaType schemaType,
                                    String name,
                                    Scope fullyQualifiedName) {
    XmlSchemaElement element = new XmlSchemaElement(schema, false);
    element.setName(name);
    if (schemaType == null) {
        ParamDeferredAction elementAction;
        if (mapper.isDefaultMapping()) {
            elementAction = new ParamDeferredAction(element);
        } else {
            elementAction = new ParamDeferredAction(element,
                                                    fullyQualifiedName.getParent(),
                                                    schema,
                                                    schemas,
                                                    manager,
                                                    mapper);
        }
        wsdlVisitor.getDeferredActions().add(fullyQualifiedName, elementAction);

        //ParamDeferredAction elementAction =
        //    new ParamDeferredAction(element);
        //wsdlVisitor.getDeferredActions().add(fullyQualifiedName, elementAction);
    } else {
        element.setSchemaTypeName(schemaType.getQName());
        if (schemaType.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
            element.setNillable(true);
        }
    }
    schemaSequence.getItems().add(element);
    return element;
}
 
Example 11
Source File: BeanType.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void writeTypeReference(QName name, XmlSchemaElement element, AegisType type,
                                XmlSchema schemaRoot) {
    if (type.isAbstract()) {
        element.setName(name.getLocalPart());
        element.setSchemaTypeName(type.getSchemaType());
        XmlSchemaUtils.addImportIfNeeded(schemaRoot, type.getSchemaType().getNamespaceURI());

        /*
         * Here we have a semi-giant mess. If a parameter has a minOccurs > 1, it ends
         * up in the type info. However, it really got used in the array type.
         * All we really want to do here is manage 'optional' elements. If we
         * ever implement flat arrays, this will change. For now, we ignore
         * maxOccurs and we only look for 0's in the minOccurs.
         */
        long minOccurs = getTypeInfo().getMinOccurs(name);
        /* If it is 1, that's the default, and if it's greater than one, it means
         * that there is a real array at work here. So the only value we want to pay
         * attention to is 0.
         */
        if (minOccurs == 0) {
            element.setMinOccurs(minOccurs);
        }


        element.setNillable(getTypeInfo().isNillable(name));
    } else {
        element.getRef().setTargetQName(type.getSchemaType());
    }
}
 
Example 12
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 13
Source File: MapType.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a element in a sequence for the key type and the value type.
 */
private void createElement(XmlSchema schema, XmlSchemaSequence seq, QName name,
                           AegisType type, boolean optional) {
    XmlSchemaElement element = new XmlSchemaElement(schema, false);
    seq.getItems().add(element);
    element.setName(name.getLocalPart());
    element.setSchemaTypeName(type.getSchemaType());
    if (optional) {
        element.setMinOccurs(0);
    } else {
        element.setMinOccurs(1);
    }
    element.setMaxOccurs(1);
}
 
Example 14
Source File: JAXBSchemaInitializer.java    From cxf with Apache License 2.0 5 votes vote down vote up
private XmlSchemaElement createXsElement(XmlSchema schema,
                                         MessagePartInfo part,
                                         QName typeName, SchemaInfo schemaInfo) {
    XmlSchemaElement el = new XmlSchemaElement(schema, true);
    el.setName(part.getElementQName().getLocalPart());
    el.setNillable(true);
    el.setSchemaTypeName(typeName);
    part.setXmlSchema(el);
    schemaInfo.setElement(null);
    return el;
}
 
Example 15
Source File: ReflectionServiceFactoryBean.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected void createBareMessage(ServiceInfo serviceInfo, OperationInfo opInfo, boolean isOut) {

        MessageInfo message = isOut ? opInfo.getOutput() : opInfo.getInput();

        final List<MessagePartInfo> messageParts = message.getMessageParts();
        if (messageParts.isEmpty()) {
            return;
        }

        Method method = (Method)opInfo.getProperty(METHOD);
        int paraNumber = 0;
        for (MessagePartInfo mpi : messageParts) {
            SchemaInfo schemaInfo = null;
            XmlSchema schema = null;

            QName qname = (QName)mpi.getProperty(ELEMENT_NAME);
            if (messageParts.size() == 1 && qname == null) {
                qname = !isOut ? getInParameterName(opInfo, method, -1)
                        : getOutParameterName(opInfo, method, -1);

                if (qname.getLocalPart().startsWith("arg") || qname.getLocalPart().startsWith("return")) {
                    qname = isOut
                        ? new QName(qname.getNamespaceURI(), method.getName() + "Response") : new QName(qname
                            .getNamespaceURI(), method.getName());
                }
            } else if (isOut && messageParts.size() > 1 && qname == null) {
                while (!isOutParam(method, paraNumber)) {
                    paraNumber++;
                }
                qname = getOutParameterName(opInfo, method, paraNumber);
            } else if (qname == null) {
                qname = getInParameterName(opInfo, method, paraNumber);
            }

            for (SchemaInfo s : serviceInfo.getSchemas()) {
                if (s.getNamespaceURI().equals(qname.getNamespaceURI())) {
                    schemaInfo = s;
                    break;
                }
            }

            if (schemaInfo == null) {
                schemaInfo = getOrCreateSchema(serviceInfo, qname.getNamespaceURI(), true);
                schema = schemaInfo.getSchema();
            } else {
                schema = schemaInfo.getSchema();
                if (schema != null && schema.getElementByName(qname) != null) {
                    mpi.setElement(true);
                    mpi.setElementQName(qname);
                    mpi.setXmlSchema(schema.getElementByName(qname));
                    paraNumber++;
                    continue;
                }
            }

            schemaInfo.setElement(null); //cached element is now invalid
            XmlSchemaElement el = new XmlSchemaElement(schema, true);
            el.setName(qname.getLocalPart());
            el.setNillable(true);

            if (mpi.isElement()) {
                XmlSchemaElement oldEl = (XmlSchemaElement)mpi.getXmlSchema();
                if (null != oldEl && !oldEl.getQName().equals(qname)) {
                    el.setSchemaTypeName(oldEl.getSchemaTypeName());
                    el.setSchemaType(oldEl.getSchemaType());
                    if (oldEl.getSchemaTypeName() != null) {
                        addImport(schema, oldEl.getSchemaTypeName().getNamespaceURI());
                    }
                }
                mpi.setElement(true);
                mpi.setXmlSchema(el);
                mpi.setElementQName(qname);
                mpi.setConcreteName(qname);
                continue;
            }
            if (null == mpi.getTypeQName() && mpi.getXmlSchema() == null) {
                throw new ServiceConstructionException(new Message("UNMAPPABLE_PORT_TYPE", LOG,
                                                                   method.getDeclaringClass().getName(),
                                                                   method.getName(),
                                                                   mpi.getName()));
            }
            if (mpi.getTypeQName() != null) {
                el.setSchemaTypeName(mpi.getTypeQName());
            } else {
                el.setSchemaType((XmlSchemaType)mpi.getXmlSchema());
            }
            mpi.setXmlSchema(el);
            mpi.setConcreteName(qname);
            if (mpi.getTypeQName() != null) {
                addImport(schema, mpi.getTypeQName().getNamespaceURI());
            }

            mpi.setElement(true);
            mpi.setElementQName(qname);
            paraNumber++;
        }
    }
 
Example 16
Source File: ImportRepairTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void createElementWithImportedType(XmlSchema importingSchema) {
    XmlSchemaElement elementWithImportedType = new XmlSchemaElement(importingSchema, true);
    elementWithImportedType.setName("elementWithImportedType");
    elementWithImportedType.setSchemaTypeName(new QName(ELEMENT_TYPE_SCHEMA, "importedElementType"));
}
 
Example 17
Source File: ObjectReferenceVisitor.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void isDuplicateReference(QName referenceName, QName bindingName, Scope refScope,
                                  XmlSchemaType wsaType, AST node) {
    XmlSchema refSchema = null;
    if (!mapper.isDefaultMapping()) {
        String tns = mapper.map(refScope.getParent());
        String refSchemaFileName = getWsdlVisitor().getOutputDir()
            + System.getProperty("file.separator")
            + refScope.getParent().toString("_") + ".xsd";
        refSchema = manager.getXmlSchema(tns);
        if (refSchema == null) {
            refSchema = manager.createXmlSchema(tns, wsdlVisitor.getSchemas());
        }
        addWSAddressingImport(refSchema);
        manager.addXmlSchemaImport(schema, refSchema, refSchemaFileName);
    } else {
        refSchema = schema;
    }

    // Check to see if we have already defined an element for this reference type.  If
    // we have, then there is no need to add it to the schema again.
    if (!isReferenceSchemaTypeDefined(referenceName, refSchema)) {
        // We need to add a new element definition to the schema section of our WSDL.
        // For custom endpoint types, this should contain an annotation which points
        // to the binding which will be used for this endpoint type.
        XmlSchemaElement refElement = new XmlSchemaElement(schema, true);
        refElement.setName(referenceName.getLocalPart());
        refElement.setSchemaType(wsaType);
        refElement.setSchemaTypeName(wsaType.getQName());

        // Create an annotation which contains the CORBA binding for the element
        XmlSchemaAnnotation annotation = new XmlSchemaAnnotation();
        XmlSchemaAppInfo appInfo = new XmlSchemaAppInfo();
        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
            dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);

            DocumentBuilder db = dbf.newDocumentBuilder();
            Document doc = db.newDocument();
            Element el = doc.createElement("appinfo");
            el.setTextContent("corba:binding=" + bindingName.getLocalPart());
            // TODO: This is correct but the appinfo markup is never added to the
            // schema.  Investigate.
            appInfo.setMarkup(el.getChildNodes());
        } catch (ParserConfigurationException ex) {
            throw new RuntimeException("[ObjectReferenceVisitor: error creating endpoint schema]");
        }

        annotation.getItems().add(appInfo);

        refElement.setAnnotation(annotation);
    }
}
 
Example 18
Source File: UnionVisitor.java    From cxf with Apache License 2.0 4 votes vote down vote up
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(schema, false);

        // 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();
        CorbaType 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();
    }
}
 
Example 19
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 20
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());
}