use of org.apache.cxf.aegis.type.TypeMapping in project cxf by apache.
the class ObjectType method determineType.
public AegisType determineType(Context context, Class<?> clazz) {
TypeMapping tm = context.getTypeMapping();
if (tm == null) {
tm = getTypeMapping();
}
AegisType type = tm.getType(clazz);
if (null != type) {
return type;
}
Class<?>[] interfaces = clazz.getInterfaces();
for (int i = 0; i < interfaces.length; i++) {
Class<?> anInterface = interfaces[i];
type = tm.getType(anInterface);
if (null != type) {
return type;
}
}
Class<?> superclass = clazz.getSuperclass();
if (null == superclass || Object.class.equals(superclass)) {
return null;
}
return determineType(context, superclass);
}
use of org.apache.cxf.aegis.type.TypeMapping in project cxf by apache.
the class ObjectType method readObject.
@Override
public Object readObject(MessageReader reader, Context context) throws DatabindingException {
if (isNil(reader.getAttributeReader(XSI_NIL))) {
while (reader.hasMoreElementReaders()) {
reader.getNextElementReader();
}
return null;
}
MessageReader typeReader = reader.getAttributeReader(XSI_TYPE);
if (null == typeReader && !readToDocument) {
throw new DatabindingException("Missing 'xsi:type' attribute");
}
String typeName = null;
if (typeReader != null) {
typeName = typeReader.getValue();
}
if (null == typeName && !readToDocument) {
throw new DatabindingException("Missing 'xsi:type' attribute value");
}
AegisType type = null;
QName typeQName = null;
if (typeName != null) {
typeName = typeName.trim();
typeQName = extractQName(reader, typeName);
} else {
typeQName = reader.getName();
}
TypeMapping tm = context.getTypeMapping();
if (tm == null) {
tm = getTypeMapping();
}
type = tm.getType(typeQName);
if (type == null) {
type = tm.getType(getSchemaType());
}
if (type == this) {
throw new DatabindingException("Could not determine how to read type: " + typeQName);
}
if (type == null && readToDocument) {
type = getTypeMapping().getType(Document.class);
}
if (null == type) {
throw new DatabindingException("No mapped type for '" + typeName + "' (" + typeQName + ")");
}
return type.readObject(reader, context);
}
use of org.apache.cxf.aegis.type.TypeMapping in project cxf by apache.
the class ObjectType method writeObject.
@Override
public void writeObject(Object object, MessageWriter writer, Context context) throws DatabindingException {
if (null == object) {
MessageWriter nilWriter = writer.getAttributeWriter(XSI_NIL);
nilWriter.writeValue("true");
nilWriter.close();
} else {
AegisType type = determineType(context, object.getClass());
if (null == type) {
TypeMapping tm = context.getTypeMapping();
if (tm == null) {
tm = getTypeMapping();
}
type = tm.getTypeCreator().createType(object.getClass());
tm.register(type);
}
writer.writeXsiType(type.getSchemaType());
boolean nextIsBeanType = type instanceof BeanType;
if (nextIsBeanType) {
((BeanType) type).writeObjectFromObjectType(object, writer, context, true);
} else {
type.writeObject(object, writer, context);
}
}
}
use of org.apache.cxf.aegis.type.TypeMapping in project cxf by apache.
the class QualificationTest method testXmlDefaultUnqualifiedAttribute.
@Test
public void testXmlDefaultUnqualifiedAttribute() throws Exception {
AegisContext context = new AegisContext();
context.initialize();
TypeMapping mapping = context.getTypeMapping();
AegisType type = mapping.getTypeCreator().createType(XmlMappedAttributeBean.class);
type.setSchemaType(new QName("urn:Bean", "bean"));
Context messageContext = new Context(context);
XmlMappedAttributeBean bean = new XmlMappedAttributeBean();
Element element = writeObjectToElement(type, bean, messageContext);
assertValid("/b:root[@attrXmlString]", element);
assertXPathEquals("/b:root/@attrXmlString", "attrXml", element);
}
use of org.apache.cxf.aegis.type.TypeMapping in project cxf by apache.
the class AbstractEncodedTest method setUp.
@Before
public void setUp() throws Exception {
super.setUp();
addNamespace("b", "urn:Bean");
addNamespace("a", "urn:anotherns");
addNamespace("xsi", Constants.URI_2001_SCHEMA_XSI);
addNamespace("soapenc", Soap11.getInstance().getSoapEncodingStyle());
AegisContext context = new AegisContext();
// create a different mapping than the context creates.
TypeMapping baseMapping = DefaultTypeMapping.createSoap11TypeMapping(true, false, false);
mapping = new DefaultTypeMapping(Constants.URI_2001_SCHEMA_XSD, baseMapping);
mapping.setTypeCreator(context.createTypeCreator());
context.setTypeMapping(mapping);
context.initialize();
// serialization root type
trailingBlocks = new TrailingBlocks();
}
Aggregations