use of org.apache.cxf.aegis.type.TypeClassInfo in project cxf by apache.
the class AegisDatabinding method getParameterType.
private AegisType getParameterType(Service s, TypeMapping tm, MessagePartInfo param, int paramtype) {
AegisType type = tm.getType(param.getTypeQName());
if (type != null && type.getTypeClass() != param.getTypeClass()) {
type = null;
}
int offset = 0;
if (paramtype == OUT_PARAM) {
offset = 1;
}
TypeCreator typeCreator = tm.getTypeCreator();
if (type == null) {
// Current author doesn't know how type can be non-null here.
boolean usingComponentType = false;
OperationInfo op = param.getMessageInfo().getOperation();
Method m = getMethod(s, op);
TypeClassInfo info;
if (paramtype != FAULT_PARAM && m != null) {
info = typeCreator.createClassInfo(m, param.getIndex() - offset);
} else {
info = typeCreator.createBasicClassInfo(param.getTypeClass());
}
Boolean nillable = info.getNillable();
/*
* Note that, for types from the mapping, the minOccurs, maxOccurs, and nillable from the 'info'
* will be ignored by createTypeForClass below. So we need to override.
*/
type = typeCreator.createTypeForClass(info);
// if not writing outer, we don't need anything special.
if (param.getMessageInfo().getOperation().isUnwrapped() && param.getTypeClass().isArray() && type.isWriteOuter()) {
/*
* The service factory expects arrays going into the wrapper to be mapped to the array
* component type and will then add min=0/max=unbounded. That doesn't work for Aegis where we
* already created a wrapper ArrayType so we'll let it know we want the default.
*/
param.setProperty("minOccurs", "1");
param.setProperty("maxOccurs", "1");
if (nillable == null) {
nillable = Boolean.TRUE;
}
param.setProperty("nillable", nillable);
} else {
if (nillable != null) {
param.setProperty("nillable", nillable);
}
/*
* TypeClassInfo uses -1 to mean 'not specified'
*/
if (info.getMinOccurs() != -1) {
param.setProperty("minOccurs", Long.toString(info.getMinOccurs()));
}
if (info.getMaxOccurs() != -1) {
param.setProperty("maxOccurs", Long.toString(info.getMaxOccurs()));
}
if ((type instanceof ArrayType) && !type.isWriteOuter()) {
param.setProperty("org.apache.cxf.aegis.outerType", type);
ArrayType aType = (ArrayType) type;
type = aType.getComponentType();
usingComponentType = true;
}
}
if (info.getMappedName() != null) {
param.setConcreteName(info.getMappedName());
param.setName(info.getMappedName());
}
if (!usingComponentType) {
// param setting above?
if (info.nonDefaultAttributes()) {
tm.register(type);
}
type.setTypeMapping(tm);
}
part2Type.put(param, type);
}
return type;
}
use of org.apache.cxf.aegis.type.TypeClassInfo in project cxf by apache.
the class Java5TypeCreator method createClassInfo.
@Override
public TypeClassInfo createClassInfo(Method m, int index) {
if (index >= 0) {
TypeClassInfo info;
Type genericType = m.getGenericParameterTypes()[index];
if (genericType instanceof Class) {
info = nextCreator.createClassInfo(m, index);
} else {
info = new TypeClassInfo();
info.setDescription("method " + m.getName() + " parameter " + index);
info.setType(genericType);
}
Class<?> paramTypeClass = annotationReader.getParamType(m, index);
info.setAegisTypeClass(castToAegisTypeClass(paramTypeClass));
String paramName = annotationReader.getParamTypeName(m, index);
if (paramName != null) {
info.setTypeName(createQName(m.getParameterTypes()[index], genericType, paramName, annotationReader.getParamNamespace(m, index)));
}
return info;
}
Type genericReturnType = m.getGenericReturnType();
TypeClassInfo info;
if (genericReturnType instanceof Class) {
info = nextCreator.createClassInfo(m, index);
} else {
info = new TypeClassInfo();
info.setDescription("method " + m.getName() + " parameter " + index);
info.setType(genericReturnType);
}
if (m.getParameterAnnotations() != null && m.getAnnotations().length > 0) {
info.setAnnotations(m.getAnnotations());
}
info.setAegisTypeClass(castToAegisTypeClass(annotationReader.getReturnType(m)));
String returnName = annotationReader.getReturnTypeName(m);
if (returnName != null) {
info.setTypeName(createQName(m.getReturnType(), genericReturnType, returnName, annotationReader.getReturnNamespace(m)));
}
return info;
}
use of org.apache.cxf.aegis.type.TypeClassInfo 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.TypeClassInfo in project cxf by apache.
the class Java5TypeCreator method createClassInfo.
/*
* Apparently, this callers must notice collection types and not call this.
*/
@Override
public TypeClassInfo createClassInfo(PropertyDescriptor pd) {
Type genericType = pd.getReadMethod().getGenericReturnType();
TypeClassInfo info = createBasicClassInfo(pd.getPropertyType());
// override basicClassInfo's of the type.
info.setType(genericType);
info.setAnnotations(pd.getReadMethod().getAnnotations());
info.setAegisTypeClass(castToAegisTypeClass(annotationReader.getType(pd.getReadMethod())));
info.setFlat(annotationReader.isFlat(pd.getReadMethod().getAnnotations()));
return info;
}
Aggregations