Search in sources :

Example 36 with XmlSchema

use of org.apache.ws.commons.schema.XmlSchema 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 37 with XmlSchema

use of org.apache.ws.commons.schema.XmlSchema 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 38 with XmlSchema

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

the class EnumTypeTest method testWsdlFromJaxbAnnotations.

/**
 * {@link https://issues.apache.org/jira/browse/CXF-7188}
 */
@Test
public void testWsdlFromJaxbAnnotations() throws Exception {
    AegisType type = tm.getTypeCreator().createType(JaxbTestEnum.class);
    XmlSchema schema = newXmlSchema("urn:test");
    type.writeSchema(schema);
    XmlSchemaSerializer ser = new XmlSchemaSerializer();
    Document doc = ser.serializeSchema(schema, false)[0];
    addNamespace("xsd", Constants.URI_2001_SCHEMA_XSD);
    assertValid("//xsd:simpleType[@name='bar']/xsd:restriction[@base='xsd:string']", doc);
    assertValid("//xsd:restriction[@base='xsd:string']/xsd:enumeration[@value='Value1']", doc);
    assertValid("//xsd:restriction[@base='xsd:string']/xsd:enumeration[@value='VALUE2']", doc);
}
Also used : AegisType(org.apache.cxf.aegis.type.AegisType) XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaSerializer(org.apache.ws.commons.schema.XmlSchemaSerializer) Document(org.w3c.dom.Document) Test(org.junit.Test) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest)

Example 39 with XmlSchema

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

the class AbstractAegisTest method newXmlSchema.

protected XmlSchema newXmlSchema(String targetNamespace) {
    XmlSchema s = new XmlSchema();
    s.setTargetNamespace(targetNamespace);
    NamespaceMap xmlsNamespaceMap = new NamespaceMap();
    s.setNamespaceContext(xmlsNamespaceMap);
    // tns: is conventional, and besides we have unit tests that are hardcoded to it.
    xmlsNamespaceMap.add(WSDLConstants.CONVENTIONAL_TNS_PREFIX, targetNamespace);
    // ditto for xsd: instead of just namespace= for the schema schema.
    xmlsNamespaceMap.add("xsd", Constants.URI_2001_SCHEMA_XSD);
    return s;
}
Also used : XmlSchema(org.apache.ws.commons.schema.XmlSchema) NamespaceMap(org.apache.ws.commons.schema.utils.NamespaceMap)

Example 40 with XmlSchema

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

the class CorbaUtils method isAttributeFormQualified.

// Change this method to access the XmlSchemaCollection.
public static boolean isAttributeFormQualified(ServiceInfo serviceInfo, String uri) {
    if (uri != null) {
        SchemaInfo schemaInfo = serviceInfo.getSchema(uri);
        if (schemaInfo != null) {
            return schemaInfo.isAttributeFormQualified();
        }
        Iterator<SchemaInfo> it = serviceInfo.getSchemas().iterator();
        while (it.hasNext()) {
            XmlSchema schema = it.next().getSchema();
            return isAttributeFormQualified(schema, uri);
        }
    }
    return false;
}
Also used : XmlSchema(org.apache.ws.commons.schema.XmlSchema) SchemaInfo(org.apache.cxf.service.model.SchemaInfo)

Aggregations

XmlSchema (org.apache.ws.commons.schema.XmlSchema)116 QName (javax.xml.namespace.QName)61 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)52 Test (org.junit.Test)49 FeatureMetacardType (org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType)37 XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)32 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)23 XmlSchemaType (org.apache.ws.commons.schema.XmlSchemaType)18 SchemaInfo (org.apache.cxf.service.model.SchemaInfo)17 ArrayList (java.util.ArrayList)14 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)13 Element (org.w3c.dom.Element)12 AbstractAegisTest (org.apache.cxf.aegis.AbstractAegisTest)10 XmlSchemaCollection (org.apache.ws.commons.schema.XmlSchemaCollection)10 Document (org.w3c.dom.Document)10 HashMap (java.util.HashMap)9 Map (java.util.Map)8 NamespaceMap (org.apache.ws.commons.schema.utils.NamespaceMap)8 List (java.util.List)7 XmlSchemaSequenceMember (org.apache.ws.commons.schema.XmlSchemaSequenceMember)7