use of org.apache.cxf.aegis.type.basic.ArrayType 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.basic.ArrayType in project cxf by apache.
the class XMLStreamDataReader method read.
public Object read(MessagePartInfo part, XMLStreamReader input) {
try {
AegisType type = part.getProperty("org.apache.cxf.aegis.outerType", AegisType.class);
if (type == null) {
type = databinding.getType(part);
return reader.read(input, type);
}
ArrayType arrayType = (ArrayType) type;
return reader.readFlatArray(input, arrayType, part.getConcreteName());
} catch (Exception e) {
throw new Fault(e);
}
}
use of org.apache.cxf.aegis.type.basic.ArrayType in project cxf by apache.
the class XMLStreamDataWriter method write.
public void write(Object obj, MessagePartInfo part, XMLStreamWriter output) {
AegisType type = databinding.getType(part);
if (type == null) {
type = databinding.getTypeFromClass(obj.getClass());
}
if (type == null) {
throw new Fault(new Message("NO_MESSAGE_FOR_PART", LOG, part));
}
Context context = new Context(databinding.getAegisContext());
context.setAttachments(attachments);
type = TypeUtil.getWriteType(databinding.getAegisContext(), obj, type);
/*
* We arrive here with a 'type' of the inner type if isWriteOuter is null.
* However, in that case, the original type is available.
*/
AegisType outerType = null;
if (part != null) {
outerType = part.getProperty("org.apache.cxf.aegis.outerType", AegisType.class);
}
try {
if (obj == null) {
if (part.getXmlSchema() instanceof XmlSchemaElement && ((XmlSchemaElement) part.getXmlSchema()).getMinOccurs() == 0) {
// skip writing minOccurs=0 stuff if obj is null
return;
} else if (type.isNillable()) {
ElementWriter writer = new ElementWriter(output);
MessageWriter w2 = writer.getElementWriter(part.getConcreteName());
w2.writeXsiNil();
w2.close();
return;
}
}
ElementWriter writer = new ElementWriter(output);
// outerType is only != null for a flat array.
if (outerType == null) {
MessageWriter w2 = writer.getElementWriter(part != null ? part.getConcreteName() : type.getSchemaType());
type.writeObject(obj, w2, context);
w2.close();
} else {
// it has better be an array (!)
ArrayType aType = (ArrayType) outerType;
// the part has to have a name or we can't do this.
aType.writeObject(obj, writer, context, part.getConcreteName());
}
} catch (DatabindingException e) {
throw new RuntimeException(e);
}
}
use of org.apache.cxf.aegis.type.basic.ArrayType in project cxf by apache.
the class AbstractTypeCreator method createArrayType.
protected AegisType createArrayType(TypeClassInfo info) {
ArrayType type = new ArrayType();
type.setTypeMapping(getTypeMapping());
type.setTypeClass(info.getType());
type.setSchemaType(createCollectionQName(info, type.getComponentType()));
if (info.getMinOccurs() != -1) {
type.setMinOccurs(info.getMinOccurs());
} else {
type.setMinOccurs(typeConfiguration.getDefaultMinOccurs());
}
if (info.getMaxOccurs() != -1) {
type.setMaxOccurs(info.getMaxOccurs());
}
type.setFlat(info.isFlat());
return type;
}
Aggregations