org.apache.ws.commons.schema.XmlSchemaSequenceMember Java Examples

The following examples show how to use org.apache.ws.commons.schema.XmlSchemaSequenceMember. 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: BindingHelper.java    From syndesis with Apache License 2.0 6 votes vote down vote up
private void createRpcEnvelope(XmlSchemaExtractor schemaExtractor, QName operationWrapper) throws ParserException {

        // create soap envelope
        final XmlSchema soapSchema = schemaExtractor.getTargetSchemas().getSchemaByTargetNamespace(soapVersion.getNamespace());
        final List<XmlSchemaSequenceMember> soapEnvelope = getSoapEnvelope(soapSchema);

        if (headerParts != null) {
            // soap header
            final List<XmlSchemaSequenceMember> soapHeader = getXmlSchemaElement(soapSchema, soapEnvelope,
                soapVersion.getHeader());
            // add header elements
            soapHeader.addAll(getPartElements(schemaExtractor, soapSchema, headerParts));
        }

        // soap body
        final List<XmlSchemaSequenceMember> soapBody = getXmlSchemaElement(soapSchema, soapEnvelope, soapVersion.getBody());

        // top-level operation wrapper element
        final String namespaceURI = operationWrapper.getNamespaceURI();
        final XmlSchema operationSchema = schemaExtractor.getOrCreateTargetSchema(namespaceURI);
        final List<XmlSchemaSequenceMember> bodySequence = getXmlSchemaElement(operationSchema, soapSchema,
            soapBody, operationWrapper.getLocalPart(), true);

        // add bodyParts to wrapper element
        bodySequence.addAll(getPartElements(schemaExtractor, operationSchema, bodyParts));
    }
 
Example #2
Source File: BindingHelper.java    From syndesis with Apache License 2.0 6 votes vote down vote up
private void createDocumentEnvelope(XmlSchemaExtractor schemaExtractor, List<XmlSchemaElement> headerElements,
                                    List<XmlSchemaElement> bodyElements) {
    // envelope element
    final XmlSchema soapSchema = schemaExtractor.getTargetSchemas().getSchemaByTargetNamespace(soapVersion.getNamespace());
    final List<XmlSchemaSequenceMember> envelope = getSoapEnvelope(soapSchema);

    // check if there is a header included
    if (headerElements != null) {
        final List<XmlSchemaSequenceMember> headers = getXmlSchemaElement(soapSchema, envelope, soapVersion.getHeader());
        headers.addAll(headerElements);
    }

    // add body wrapper
    final List<XmlSchemaSequenceMember> bodySequence = getXmlSchemaElement(soapSchema, envelope, soapVersion.getBody());
    bodySequence.addAll(bodyElements);
}
 
Example #3
Source File: WSDLParameter.java    From cxf with Apache License 2.0 6 votes vote down vote up
private boolean isWrappableSequence(XmlSchemaComplexType type) {
    if (type.getParticle() instanceof XmlSchemaSequence) {
        XmlSchemaSequence seq = (XmlSchemaSequence)type.getParticle();
        List<XmlSchemaSequenceMember> items = seq.getItems();

        for (XmlSchemaSequenceMember member : items) {
            if (!(member instanceof XmlSchemaElement)) {
                return false;
            }
        }

        return true;
    } else if (type.getParticle() == null) {
        return true;
    }
    return false;
}
 
Example #4
Source File: ProcessorUtil.java    From cxf with Apache License 2.0 6 votes vote down vote up
private static List<WrapperElement> createWrappedElements(XmlSchemaSequence seq) {

        List<WrapperElement> qnames = new ArrayList<>();
        if (seq != null) {

            List<XmlSchemaSequenceMember> items = seq.getItems();

            for (XmlSchemaSequenceMember seqMember : items) {
                XmlSchemaElement subElement = (XmlSchemaElement)seqMember;

                if (subElement.getQName() != null) {
                    qnames.add(new WrapperElement(subElement.getWireName(), subElement.getSchemaTypeName()));
                } else {
                    qnames.add(new WrapperElement(subElement.getRef().getTargetQName(),
                                                  subElement.getSchemaTypeName()));
                }
            }
        }
        return qnames;
    }
 
Example #5
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 #6
Source File: BeanTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testNillableInt() throws Exception {
    defaultContext();
    BeanTypeInfo info = new BeanTypeInfo(IntBean.class, "urn:Bean");
    info.setTypeMapping(mapping);

    BeanType type = new BeanType(info);
    type.setTypeClass(IntBean.class);
    type.setTypeMapping(mapping);
    type.setSchemaType(new QName("urn:Bean", "bean"));

    XmlSchema schema = newXmlSchema("urn:Bean");
    type.writeSchema(schema);

    XmlSchemaComplexType btype = (XmlSchemaComplexType)schema.getTypeByName("bean");
    XmlSchemaSequence seq = (XmlSchemaSequence)btype.getParticle();
    boolean int1ok = false;
    boolean int2ok = false;
    for (int x = 0; x < seq.getItems().size(); x++) {
        XmlSchemaSequenceMember o = seq.getItems().get(x);
        if (o instanceof XmlSchemaElement) {
            XmlSchemaElement oe = (XmlSchemaElement) o;
            if ("int1".equals(oe.getName())) {
                int1ok = true;
                assertTrue(oe.isNillable());
                assertEquals(0, oe.getMinOccurs());
            } else if ("int2".equals(oe.getName())) {
                int2ok = true;
                assertEquals(0, oe.getMinOccurs());
                assertFalse(oe.isNillable());
            }
        }
    }
    assertTrue(int1ok);
    assertTrue(int2ok);
}
 
Example #7
Source File: BeanTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testNillableAnnotation() throws Exception {
    context = new AegisContext();
    TypeCreationOptions config = new TypeCreationOptions();
    config.setDefaultNillable(false);
    config.setDefaultMinOccurs(1);
    context.setTypeCreationOptions(config);
    context.initialize();
    mapping = context.getTypeMapping();

    BeanType type = (BeanType)mapping.getTypeCreator().createType(BeanWithNillableItem.class);
    type.setTypeClass(BeanWithNillableItem.class);
    type.setTypeMapping(mapping);

    XmlSchema schema = newXmlSchema("urn:Bean");
    type.writeSchema(schema);

    XmlSchemaComplexType btype = (XmlSchemaComplexType)schema.getTypeByName("BeanWithNillableItem");
    XmlSchemaSequence seq = (XmlSchemaSequence)btype.getParticle();
    boolean itemFound = false;
    boolean itemNotNillableFound = false;
    for (int x = 0; x < seq.getItems().size(); x++) {
        XmlSchemaSequenceMember o = seq.getItems().get(x);
        if (o instanceof XmlSchemaElement) {
            XmlSchemaElement oe = (XmlSchemaElement) o;
            if ("item".equals(oe.getName())) {
                itemFound = true;
                assertTrue(oe.isNillable());
                assertEquals(0, oe.getMinOccurs());
            } else if ("itemNotNillable".equals(oe.getName())) {
                itemNotNillableFound = true;
                assertFalse(oe.isNillable());
            }
        }
    }
    assertTrue(itemFound);
    assertTrue(itemNotNillableFound);
}
 
Example #8
Source File: BeanTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testNillableIntMinOccurs1() throws Exception {
    context = new AegisContext();
    TypeCreationOptions config = new TypeCreationOptions();
    config.setDefaultMinOccurs(1);
    config.setDefaultNillable(false);
    context.setTypeCreationOptions(config);
    context.initialize();
    mapping = context.getTypeMapping();

    BeanType type = (BeanType)mapping.getTypeCreator().createType(IntBean.class);
    type.setTypeClass(IntBean.class);
    type.setTypeMapping(mapping);

    XmlSchema schema = newXmlSchema("urn:Bean");
    type.writeSchema(schema);

    XmlSchemaComplexType btype = (XmlSchemaComplexType)schema.getTypeByName("IntBean");
    XmlSchemaSequence seq = (XmlSchemaSequence)btype.getParticle();
    boolean int1ok = false;
    for (int x = 0; x < seq.getItems().size(); x++) {
        XmlSchemaSequenceMember o = seq.getItems().get(x);
        if (o instanceof XmlSchemaElement) {
            XmlSchemaElement oe = (XmlSchemaElement) o;
            if ("int1".equals(oe.getName())) {
                int1ok = true;
                assertFalse(oe.isNillable());
                assertEquals(1, oe.getMinOccurs());
            }
        }
    }
    assertTrue(int1ok);
}
 
Example #9
Source File: BeanTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testCharMappings() throws Exception {
    defaultContext();

    BeanType type = (BeanType)mapping.getTypeCreator().createType(SimpleBean.class);
    type.setTypeClass(SimpleBean.class);
    type.setTypeMapping(mapping);

    XmlSchema schema = newXmlSchema("urn:Bean");
    type.writeSchema(schema);

    XmlSchemaComplexType btype = (XmlSchemaComplexType)schema.getTypeByName("SimpleBean");
    XmlSchemaSequence seq = (XmlSchemaSequence)btype.getParticle();
    boolean charok = false;

    for (int x = 0; x < seq.getItems().size(); x++) {
        XmlSchemaSequenceMember o = seq.getItems().get(x);
        if (o instanceof XmlSchemaElement) {
            XmlSchemaElement oe = (XmlSchemaElement) o;
            if ("character".equals(oe.getName())) {
                charok = true;
                assertNotNull(oe.getSchemaTypeName());
                assertTrue(oe.isNillable());
                assertEquals(CharacterAsStringType.CHARACTER_AS_STRING_TYPE_QNAME,
                             oe.getSchemaTypeName());
            }
        }
    }
    assertTrue(charok);
}
 
Example #10
Source File: JAXBSchemaInitializer.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void sortItems(final XmlSchemaSequence seq, final String[] propertyOrder) {
    final List<String> propList = Arrays.asList(propertyOrder);
    Collections.sort(seq.getItems(), new Comparator<XmlSchemaSequenceMember>() {
        public int compare(XmlSchemaSequenceMember o1, XmlSchemaSequenceMember o2) {
            XmlSchemaElement element1 = (XmlSchemaElement)o1;
            XmlSchemaElement element2 = (XmlSchemaElement)o2;
            int index1 = propList.indexOf(element1.getName());
            int index2 = propList.indexOf(element2.getName());
            return index1 - index2;
        }

    });
}
 
Example #11
Source File: JAXBSchemaInitializer.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void sort(final XmlSchemaSequence seq) {
    Collections.sort(seq.getItems(), new Comparator<XmlSchemaSequenceMember>() {
        public int compare(XmlSchemaSequenceMember o1, XmlSchemaSequenceMember o2) {
            XmlSchemaElement element1 = (XmlSchemaElement)o1;
            XmlSchemaElement element2 = (XmlSchemaElement)o2;
            return element1.getName().compareTo(element2.getName());
        }

    });
}
 
Example #12
Source File: SchemaCollection.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void addCrossImports(XmlSchema schema, XmlSchemaSequence sequence) {
    for (XmlSchemaSequenceMember seqMember : sequence.getItems()) {
        if (seqMember instanceof XmlSchemaElement) {
            addElementCrossImportsElement(schema, (XmlSchemaElement)seqMember);
        }
    }
}
 
Example #13
Source File: BindingHelper.java    From syndesis with Apache License 2.0 4 votes vote down vote up
private List<XmlSchemaSequenceMember> getSoapEnvelope(XmlSchema soapSchema) {
    return getXmlSchemaElement(soapSchema, null, null,
        soapVersion.getEnvelope().getLocalPart(), true);
}
 
Example #14
Source File: BindingHelper.java    From syndesis with Apache License 2.0 4 votes vote down vote up
private static List<XmlSchemaSequenceMember> getXmlSchemaElement(XmlSchema schema,
                                                          List<XmlSchemaSequenceMember> parentSequence,
                                                          QName name) {
    return getXmlSchemaElement(schema, schema, parentSequence, name.getLocalPart(), false);
}
 
Example #15
Source File: BeanTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testByteMappings() throws Exception {
    defaultContext();

    BeanType type = (BeanType)mapping.getTypeCreator().createType(SimpleBean.class);
    type.setTypeClass(SimpleBean.class);
    type.setTypeMapping(mapping);

    XmlSchema schema = newXmlSchema("urn:Bean");
    type.writeSchema(schema);

    XmlSchemaComplexType btype = (XmlSchemaComplexType)schema.getTypeByName("SimpleBean");
    XmlSchemaSequence seq = (XmlSchemaSequence)btype.getParticle();
    boolean littleByteOk = false;
    boolean bigByteOk = false;

    for (int x = 0; x < seq.getItems().size(); x++) {
        XmlSchemaSequenceMember o = seq.getItems().get(x);
        if (o instanceof XmlSchemaElement) {
            XmlSchemaElement oe = (XmlSchemaElement) o;
            if ("littleByte".equals(oe.getName())) {
                littleByteOk = true;
                assertNotNull(oe.getSchemaTypeName());
                assertEquals(Constants.XSD_BYTE, oe.getSchemaTypeName());
            } else if ("bigByte".equals(oe.getName())) {
                bigByteOk = true;
                assertNotNull(oe.getSchemaTypeName());
                assertEquals(Constants.XSD_BYTE, oe.getSchemaTypeName());
            }
        }
    }
    assertTrue(littleByteOk);
    assertTrue(bigByteOk);

    SimpleBean bean = new SimpleBean();
    bean.setBigByte(Byte.valueOf((byte)0xfe));
    bean.setLittleByte((byte)0xfd);
    Element element = writeObjectToElement(type, bean, getContext());
    Byte bb = Byte.valueOf((byte)0xfe);
    String bbs = bb.toString();
    assertValid("/b:root/bz:bigByte[text()='" + bbs + "']", element);

    // Test reading
    ElementReader reader = new ElementReader(getResourceAsStream("byteBeans.xml"));
    bean = (SimpleBean)type.readObject(reader, getContext());
    assertEquals(-5, bean.getLittleByte());
    assertEquals(25, bean.getBigByte().byteValue());

    reader.getXMLStreamReader().close();

}