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

The following examples show how to use org.apache.ws.commons.schema.XmlSchemaElement#setMinOccurs() . 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: 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 3
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 4
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 5
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 6
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 7
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 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: 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 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);
}