use of org.apache.cxf.aegis.type.basic.BeanType in project cxf by apache.
the class JaxbTypeTest method testNillableAndMinOccurs.
@Test
public void testNillableAndMinOccurs() {
BeanType type = (BeanType) tm.getTypeCreator().createType(JaxbBean4.class);
AnnotatedTypeInfo info = (AnnotatedTypeInfo) type.getTypeInfo();
Iterator<QName> elements = info.getElements().iterator();
assertTrue(elements.hasNext());
// nillable first
QName element = elements.next();
if ("minOccursProperty".equals(element.getLocalPart())) {
assertEquals(1, info.getMinOccurs(element));
} else {
assertFalse(info.isNillable(element));
}
assertTrue(elements.hasNext());
// minOccurs = 1 second
element = elements.next();
if ("minOccursProperty".equals(element.getLocalPart())) {
assertEquals(1, info.getMinOccurs(element));
} else {
assertFalse(info.isNillable(element));
}
}
use of org.apache.cxf.aegis.type.basic.BeanType in project cxf by apache.
the class StructType method writeElement.
/**
* Writes a nested element with an unqualified name.
*/
@Override
protected void writeElement(QName name, Object value, AegisType type, MessageWriter writer, Context context) {
// Nested elements are unqualified
name = new QName("", name.getLocalPart());
MessageWriter cwriter = writer.getElementWriter(name);
if (type instanceof BeanType || type instanceof SoapArrayType) {
String refId = MarshalRegistry.get(context).getInstanceId(value);
SoapEncodingUtil.writeRef(cwriter, refId);
} else {
type.writeObject(value, cwriter, context);
}
cwriter.close();
}
use of org.apache.cxf.aegis.type.basic.BeanType in project cxf by apache.
the class AegisContext method processRootTypes.
/**
* Examine a list of override classes, and register all of them.
*
* @param tm type manager for this binding
* @param classes list of class names
*/
private void processRootTypes() {
rootTypes = new HashSet<>();
// app may have already supplied classes.
if (rootClasses == null) {
rootClasses = new HashSet<java.lang.reflect.Type>();
}
rootTypeQNames = new HashSet<>();
if (this.rootClassNames != null) {
for (String typeName : rootClassNames) {
Class<?> c = null;
try {
c = ClassLoaderUtils.loadClass(typeName, TypeUtil.class);
} catch (ClassNotFoundException e) {
throw new DatabindingException("Could not find override type class: " + typeName, e);
}
rootClasses.add(c);
}
}
// This is a list of AegisType rather than Class so that it can set up for generic collections.
// When we see a generic, we process both the generic outer class and each parameter class.
// This is not the same thing as allowing mappings of arbitrary x<q> types.
Set<Class<?>> rootMappableClassSet = rootMappableClasses();
/*
* First loop: process non-Class roots, creating full types for them
* and registering them.
*/
for (java.lang.reflect.Type reflectType : rootClasses) {
if (!(reflectType instanceof Class)) {
// if it's not a Class, it can't be mapped from Class to type in the mapping.
// so we create
AegisType aegisType = typeMapping.getTypeCreator().createType(reflectType);
typeMapping.register(aegisType);
// note: we don't handle arbitrary generics, so no BeanType
// check here.
rootTypeQNames.add(aegisType.getSchemaType());
}
}
/*
* Second loop: process Class roots, including those derived from
* generic types, creating when not in the default mappings.
*/
for (Class<?> c : rootMappableClassSet) {
AegisType t = typeMapping.getType(c);
if (t == null) {
t = typeMapping.getTypeCreator().createType(c);
typeMapping.register(t);
}
rootTypeQNames.add(t.getSchemaType());
if (t instanceof BeanType) {
BeanType bt = (BeanType) t;
bt.getTypeInfo().setExtension(true);
rootTypes.add(bt);
}
}
}
use of org.apache.cxf.aegis.type.basic.BeanType in project cxf by apache.
the class AnnotatedTypeTest method testNillableAndMinOccurs.
@Test
public void testNillableAndMinOccurs() {
BeanType type = (BeanType) tm.getTypeCreator().createType(AnnotatedBean4.class);
AnnotatedTypeInfo info = (AnnotatedTypeInfo) type.getTypeInfo();
Iterator<QName> elements = info.getElements().iterator();
assertTrue(elements.hasNext());
// nillable first
QName element = elements.next();
if ("minOccursProperty".equals(element.getLocalPart())) {
assertEquals(1, info.getMinOccurs(element));
} else {
assertFalse(info.isNillable(element));
}
assertTrue(elements.hasNext());
// minOccurs = 1 second
element = elements.next();
if ("minOccursProperty".equals(element.getLocalPart())) {
assertEquals(1, info.getMinOccurs(element));
} else {
assertFalse(info.isNillable(element));
}
}
use of org.apache.cxf.aegis.type.basic.BeanType in project cxf by apache.
the class AnnotatedTypeTest method testGetSetRequired.
@Test
public void testGetSetRequired() throws Exception {
BeanType type = new BeanType(new AnnotatedTypeInfo(tm, BadBean.class, "urn:foo", new TypeCreationOptions()));
type.setSchemaType(new QName("urn:foo", "BadBean"));
assertFalse(type.getTypeInfo().getElements().iterator().hasNext());
}
Aggregations