use of org.apache.cxf.aegis.type.AegisType in project cxf by apache.
the class EnumTypeTest method testAutoCreation.
@Test
public void testAutoCreation() throws Exception {
AegisType type = tm.getTypeCreator().createType(SmallEnum.class);
assertTrue(type instanceof EnumType);
}
use of org.apache.cxf.aegis.type.AegisType in project cxf by apache.
the class XFireXmlParamTypeTest method testType.
@Test
public void testType() throws Exception {
Method m = CustomTypeService.class.getMethod("doFoo", new Class[] { String.class });
AegisType type = creator.createType(m, 0);
tm.register(type);
assertTrue(type instanceof CustomStringType);
assertEquals(new QName("urn:xfire:foo", "custom"), type.getSchemaType());
type = creator.createType(m, -1);
tm.register(type);
assertTrue(type instanceof CustomStringType);
assertEquals(new QName("urn:xfire:foo", "custom"), type.getSchemaType());
}
use of org.apache.cxf.aegis.type.AegisType in project cxf by apache.
the class AegisElementProvider method writeTo.
public void writeTo(T obj, Class<?> type, Type genericType, Annotation[] anns, MediaType m, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException {
if (type == null) {
type = obj.getClass();
}
if (genericType == null) {
genericType = type;
}
AegisContext context = getAegisContext(type, genericType);
AegisType aegisType = context.getTypeMapping().getType(genericType);
AegisWriter<XMLStreamWriter> aegisWriter = context.createXMLStreamWriter();
try {
String enc = HttpUtils.getSetEncoding(m, headers, StandardCharsets.UTF_8.name());
XMLStreamWriter xmlStreamWriter = createStreamWriter(aegisType.getSchemaType(), enc, os);
// use type qname as element qname?
xmlStreamWriter.writeStartDocument();
aegisWriter.write(obj, aegisType.getSchemaType(), false, xmlStreamWriter, aegisType);
xmlStreamWriter.writeEndDocument();
xmlStreamWriter.close();
} catch (Exception e) {
throw ExceptionUtils.toInternalServerErrorException(e, null);
}
}
use of org.apache.cxf.aegis.type.AegisType in project cxf by apache.
the class AegisContext method processRootTypes.
/**
* Examine a list of override classes, and register all of them.
*/
private void processRootTypes() {
rootTypes = new HashSet<>();
// app may have already supplied classes.
if (rootClasses == null) {
rootClasses = new HashSet<>();
}
rootTypeQNames = new HashSet<>();
if (this.rootClassNames != null) {
for (String typeName : rootClassNames) {
try {
rootClasses.add(ClassLoaderUtils.loadClass(typeName, TypeUtil.class));
} catch (ClassNotFoundException e) {
throw new DatabindingException("Could not find override type class: " + typeName, e);
}
}
}
// 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.AegisType in project cxf by apache.
the class ElementDataWriter method write.
public void write(Object obj, MessagePartInfo part, Element output) {
AegisType type = databinding.getType(part);
if (type == null) {
throw new Fault(new Message("NO_MESSAGE_FOR_PART", LOG));
}
Context context = new Context(databinding.getAegisContext());
context.setAttachments(attachments);
type = TypeUtil.getWriteType(databinding.getAegisContext(), obj, type);
try {
W3CDOMStreamWriter domWriter = new W3CDOMStreamWriter(output);
ElementWriter writer = new ElementWriter(domWriter);
MessageWriter w2 = writer.getElementWriter(part.getConcreteName());
if (type.isNillable() && type.isWriteOuter() && obj == null) {
w2.writeXsiNil();
w2.close();
return;
}
type.writeObject(obj, w2, context);
w2.close();
} catch (DatabindingException e) {
throw new RuntimeException(e);
}
}
Aggregations