Search in sources :

Example 31 with XmlSchemaComplexType

use of org.apache.ws.commons.schema.XmlSchemaComplexType in project cxf by apache.

the class BeanTest method testByteMappings.

@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(new Byte((byte) 0xfe));
    bean.setLittleByte((byte) 0xfd);
    Element element = writeObjectToElement(type, bean, getContext());
    Byte bb = new Byte((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();
}
Also used : XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) Element(org.w3c.dom.Element) XmlElement(javax.xml.bind.annotation.XmlElement) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchema(org.apache.ws.commons.schema.XmlSchema) SimpleBean(org.apache.cxf.aegis.services.SimpleBean) XmlSchemaSequenceMember(org.apache.ws.commons.schema.XmlSchemaSequenceMember) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) ElementReader(org.apache.cxf.aegis.xml.stax.ElementReader) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest) Test(org.junit.Test)

Example 32 with XmlSchemaComplexType

use of org.apache.ws.commons.schema.XmlSchemaComplexType in project cxf by apache.

the class BeanTest method testAttributeMap.

@Test
public void testAttributeMap() throws Exception {
    defaultContext();
    BeanTypeInfo info = new BeanTypeInfo(SimpleBean.class, "urn:Bean");
    info.mapAttribute("howdy", new QName("urn:Bean", "howdy"));
    info.mapAttribute("bleh", new QName("urn:Bean", "bleh"));
    info.setTypeMapping(mapping);
    BeanType type = new BeanType(info);
    type.setTypeClass(SimpleBean.class);
    type.setTypeMapping(mapping);
    type.setSchemaType(new QName("urn:Bean", "bean"));
    ElementReader reader = new ElementReader(getResourceAsStream("bean4.xml"));
    SimpleBean bean = (SimpleBean) type.readObject(reader, getContext());
    assertEquals("bleh", bean.getBleh());
    assertEquals("howdy", bean.getHowdy());
    reader.getXMLStreamReader().close();
    // Test writing
    Element element = writeObjectToElement(type, bean, getContext());
    assertValid("/b:root[@b:bleh='bleh']", element);
    assertValid("/b:root[@b:howdy='howdy']", element);
    XmlSchema schema = newXmlSchema("urn:Bean");
    type.writeSchema(schema);
    XmlSchemaComplexType stype = (XmlSchemaComplexType) schema.getTypeByName("bean");
    boolean howdy = false;
    boolean bleh = false;
    for (int x = 0; x < stype.getAttributes().size(); x++) {
        XmlSchemaObject o = stype.getAttributes().get(x);
        if (o instanceof XmlSchemaAttribute) {
            XmlSchemaAttribute a = (XmlSchemaAttribute) o;
            if ("howdy".equals(a.getName())) {
                howdy = true;
            }
            if ("bleh".equals(a.getName())) {
                bleh = true;
            }
        }
    }
    assertTrue(howdy);
    assertTrue(bleh);
}
Also used : XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) XmlSchema(org.apache.ws.commons.schema.XmlSchema) QName(javax.xml.namespace.QName) SimpleBean(org.apache.cxf.aegis.services.SimpleBean) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) Element(org.w3c.dom.Element) XmlElement(javax.xml.bind.annotation.XmlElement) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlSchemaAttribute(org.apache.ws.commons.schema.XmlSchemaAttribute) ElementReader(org.apache.cxf.aegis.xml.stax.ElementReader) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest) Test(org.junit.Test)

Example 33 with XmlSchemaComplexType

use of org.apache.ws.commons.schema.XmlSchemaComplexType in project cxf by apache.

the class BeanTest method testNullProperties.

@Test
public void testNullProperties() throws Exception {
    defaultContext();
    BeanTypeInfo info = new BeanTypeInfo(SimpleBean.class, "urn:Bean");
    info.setTypeMapping(mapping);
    info.mapAttribute("howdy", new QName("urn:Bean", "howdy"));
    info.mapElement("bleh", new QName("urn:Bean", "bleh"));
    BeanType type = new BeanType(info);
    type.setTypeClass(SimpleBean.class);
    type.setTypeMapping(mapping);
    type.setSchemaType(new QName("urn:Bean", "bean"));
    SimpleBean bean = new SimpleBean();
    // Test writing
    Element element = writeObjectToElement(type, bean, getContext());
    assertInvalid("/b:root[@b:howdy]", element);
    assertValid("/b:root/b:bleh[@xsi:nil='true']", element);
    XmlSchema schema = newXmlSchema("urn:Bean");
    type.writeSchema(schema);
    XmlSchemaComplexType stype = (XmlSchemaComplexType) schema.getTypeByName("bean");
    XmlSchemaSequence seq = (XmlSchemaSequence) stype.getParticle();
    boolean howdy = false;
    boolean bleh = false;
    for (int x = 0; x < seq.getItems().size(); x++) {
        XmlSchemaSequenceMember o = seq.getItems().get(x);
        if (o instanceof XmlSchemaElement) {
            XmlSchemaElement a = (XmlSchemaElement) o;
            if ("bleh".equals(a.getName())) {
                bleh = true;
            }
        }
    }
    for (int x = 0; x < stype.getAttributes().size(); x++) {
        XmlSchemaObject o = stype.getAttributes().get(x);
        if (o instanceof XmlSchemaAttribute) {
            XmlSchemaAttribute a = (XmlSchemaAttribute) o;
            if ("howdy".equals(a.getName())) {
                howdy = true;
            }
        }
    }
    assertTrue(howdy);
    assertTrue(bleh);
}
Also used : QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) Element(org.w3c.dom.Element) XmlElement(javax.xml.bind.annotation.XmlElement) XmlSchemaAttribute(org.apache.ws.commons.schema.XmlSchemaAttribute) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) XmlSchema(org.apache.ws.commons.schema.XmlSchema) SimpleBean(org.apache.cxf.aegis.services.SimpleBean) XmlSchemaSequenceMember(org.apache.ws.commons.schema.XmlSchemaSequenceMember) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest) Test(org.junit.Test)

Example 34 with XmlSchemaComplexType

use of org.apache.ws.commons.schema.XmlSchemaComplexType in project cxf by apache.

the class BeanTest method testNillableIntMinOccurs1.

@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);
}
Also used : XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaSequenceMember(org.apache.ws.commons.schema.XmlSchemaSequenceMember) AegisContext(org.apache.cxf.aegis.AegisContext) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) TypeCreationOptions(org.apache.cxf.aegis.type.TypeCreationOptions) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest) Test(org.junit.Test)

Example 35 with XmlSchemaComplexType

use of org.apache.ws.commons.schema.XmlSchemaComplexType in project cxf by apache.

the class MapType method writeSchema.

@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);
}
Also used : XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) AegisType(org.apache.cxf.aegis.type.AegisType) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType)

Aggregations

XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)88 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)60 QName (javax.xml.namespace.QName)45 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)38 XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)25 XmlSchemaType (org.apache.ws.commons.schema.XmlSchemaType)25 XmlSchema (org.apache.ws.commons.schema.XmlSchema)24 Test (org.junit.Test)18 XmlSchemaComplexContentExtension (org.apache.ws.commons.schema.XmlSchemaComplexContentExtension)13 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)12 XmlSchemaParticle (org.apache.ws.commons.schema.XmlSchemaParticle)12 XmlSchemaObjectCollection (org.apache.ws.commons.schema.XmlSchemaObjectCollection)11 XmlSchemaSequenceMember (org.apache.ws.commons.schema.XmlSchemaSequenceMember)11 XmlSchemaGroupBase (org.apache.ws.commons.schema.XmlSchemaGroupBase)10 FeatureMetacardType (org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType)8 ParameterInfo (org.talend.designer.webservice.ws.wsdlinfo.ParameterInfo)8 ArrayList (java.util.ArrayList)7 AbstractAegisTest (org.apache.cxf.aegis.AbstractAegisTest)7 XmlSchemaAttribute (org.apache.ws.commons.schema.XmlSchemaAttribute)7 XmlSchemaComplexContentRestriction (org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction)6