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

The following examples show how to use org.apache.ws.commons.schema.XmlSchemaElement#setName() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 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: 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 10
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 11
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 12
Source File: XmlSchemaExtractor.java    From syndesis with Apache License 2.0 5 votes vote down vote up
public XmlSchemaElement extract(QName name, XmlSchemaType type) throws ParserException {

        // find target schema
        final XmlSchema targetSchema = getOrCreateTargetSchema(name.getNamespaceURI());

        // create new element in target schema
        final XmlSchemaElement result = new XmlSchemaElement(targetSchema, true);
        result.setName(name.getLocalPart());

        // set element type to the provided type
        final QName typeQName = type.getQName();
        withNamespace(typeQName.getNamespaceURI(), () -> setTargetTypeQName(typeQName, result::setSchemaTypeName));
        return result;
    }
 
Example 13
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 14
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 15
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 16
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 17
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 18
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 19
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 20
Source File: ImportRepairTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void createImportedElement(XmlSchema elementSchema) {
    XmlSchemaElement importedElement = new XmlSchemaElement(elementSchema, true);
    importedElement.setName("importedElement");
    importedElement.setSchemaTypeName(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "string"));
}