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);
}
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);
}
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);
}
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;
}
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;
}
Aggregations