use of org.apache.cxf.aegis.type.AegisType in project cxf by apache.
the class Java5TypeCreator method getOrCreateParameterizedType.
protected AegisType getOrCreateParameterizedType(TypeClassInfo generic, int index, boolean map) {
Type paramType;
Map<String, Type> pm = generic.getTypeVars();
if (map) {
if (pm == null) {
pm = new HashMap<>();
} else {
pm = new HashMap<>(pm);
}
paramType = getComponentTypeForMap(generic.getType(), pm, index == 0);
} else {
paramType = getComponentType(generic.getType(), index);
}
if (paramType instanceof WildcardType) {
WildcardType wct = (WildcardType) paramType;
paramType = wct.getUpperBounds()[0];
}
if (paramType instanceof TypeVariable) {
TypeVariable<?> v = (TypeVariable<?>) paramType;
LOG.log(Level.WARNING, "Could not map TypeVariable named {0} from {1} with initial mapping {2} to " + "a known class. Using Object.", new Object[] { v.getName(), generic.getType().toString(), generic.getTypeVars() });
}
if (paramType == null) {
return createObjectType();
}
/* null arises when the index-th parameter to generic is something list List<T> */
Class<?> clazz = TypeUtil.getTypeRelatedClass(paramType);
if (clazz == null) {
return createObjectType();
}
if (!Collection.class.isAssignableFrom(clazz) && !Map.class.isAssignableFrom(clazz)) {
return getTopCreator().createType(clazz);
}
TypeClassInfo info = createBasicClassInfo(clazz);
info.setDescription(clazz.toString());
info.setType(paramType, paramType instanceof ParameterizedType ? pm : null);
return createTypeForClass(info);
}
use of org.apache.cxf.aegis.type.AegisType 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");
}
final QName typeQName;
if (typeName != null) {
typeName = typeName.trim();
typeQName = extractQName(reader, typeName);
} else {
typeQName = reader.getName();
}
TypeMapping tm = context.getTypeMapping();
if (tm == null) {
tm = getTypeMapping();
}
AegisType 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.AegisType 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.AegisType 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.AegisType in project cxf by apache.
the class SoapArrayType method getComponentType.
/**
* Get the <code>AegisType</code> of the elements in the array. This is only used for writing an array.
* When reading the type is solely determined by the required arrayType soap attribute.
*/
public AegisType getComponentType() {
Class<?> compType = getTypeClass().getComponentType();
AegisType type;
if (componentName == null) {
type = getTypeMapping().getType(compType);
} else {
type = getTypeMapping().getType(componentName);
// below instead.
if (type == null) {
LOG.finest("Couldn't find array component type " + componentName + ". Creating one instead.");
}
}
if (type == null) {
type = getTypeMapping().getTypeCreator().createType(compType);
getTypeMapping().register(type);
}
return type;
}
Aggregations