use of org.apache.cxf.aegis.type.AegisType in project cxf by apache.
the class AegisXMLStreamDataReader method read.
/**
* {@inheritDoc}
*/
public Object read(XMLStreamReader reader, AegisType desiredType) throws Exception {
setupReaderPosition(reader);
ElementReader elReader = new ElementReader(reader);
if (elReader.isXsiNil()) {
elReader.readToEnd();
return null;
}
AegisType type = TypeUtil.getReadTypeStandalone(reader, aegisContext, desiredType);
if (type == null) {
throw new DatabindingException(new Message("NO_MAPPING", LOG));
}
return type.readObject(elReader, context);
}
use of org.apache.cxf.aegis.type.AegisType in project cxf by apache.
the class AegisDatabinding method getSuggestedName.
public QName getSuggestedName(Service s, TypeMapping tm, OperationInfo op, int param) {
Method m = getMethod(s, op);
if (m == null) {
return null;
}
QName name = tm.getTypeCreator().getElementName(m, param);
// instead
if (name == null) {
AegisType type = tm.getTypeCreator().createType(m, param);
if (type.isComplex() && !type.isAbstract()) {
name = type.getSchemaType();
}
}
return name;
}
use of org.apache.cxf.aegis.type.AegisType in project cxf by apache.
the class AegisDatabinding method initializeMessage.
protected void initializeMessage(Service s, TypeMapping serviceTM, AbstractMessageContainer container, int partType, Set<AegisType> deps) {
if (container == null) {
return;
}
for (MessagePartInfo part : container.getMessageParts()) {
AegisType type = getParameterType(s, serviceTM, part, partType);
if (part.getXmlSchema() == null) {
// schema hasn't been filled in yet
if (type.isAbstract()) {
part.setTypeQName(type.getSchemaType());
} else {
part.setElementQName(type.getSchemaType());
}
}
Annotation[] anns = part.getProperty("parameter.annotations", Annotation[].class);
long miValue = -1;
if (type.hasMinOccurs()) {
miValue = type.getMinOccurs();
}
Integer i = AnnotationReader.getMinOccurs(anns);
if (i != null) {
miValue = i;
}
if (miValue > 0) {
part.setProperty("minOccurs", Long.toString(miValue));
}
// However, this if at least allow .aegis.xml files to get control.
if (part.getProperty("nillable") == null) {
boolean isNil = type.isNillable();
Boolean b = AnnotationReader.isNillable(anns);
if (b != null || (miValue != 0 && isNil)) {
part.setProperty("nillable", b == null ? isNil : b);
}
/*
if (miValue == -1 && (b == null ? isNil : b)) {
part.setProperty("minOccurs", "1");
}
*/
}
if (type.hasMaxOccurs()) {
String moValue;
long mo = type.getMaxOccurs();
if (mo != Long.MAX_VALUE) {
moValue = Long.toString(mo);
part.setProperty("maxOccurs", moValue);
}
}
part2Type.put(part, type);
// QName elName = getSuggestedName(service, op, param)
deps.add(type);
type.getTypeMapping().register(type);
addDependencies(deps, type);
}
}
use of org.apache.cxf.aegis.type.AegisType 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.AegisType in project cxf by apache.
the class CollectionType method writeObject.
@Override
public void writeObject(Object object, MessageWriter writer, Context context) throws DatabindingException {
if (object == null) {
return;
}
try {
Collection<?> list = (Collection<?>) object;
AegisType type = getComponentType();
if (type == null) {
throw new DatabindingException("Couldn't find component type for Collection.");
}
for (Iterator<?> itr = list.iterator(); itr.hasNext(); ) {
final String ns;
if (type.isAbstract()) {
ns = getSchemaType().getNamespaceURI();
} else {
ns = type.getSchemaType().getNamespaceURI();
}
writeValue(itr.next(), writer, context, type, type.getSchemaType().getLocalPart(), ns);
}
} catch (IllegalArgumentException e) {
throw new DatabindingException("Illegal argument.", e);
}
}
Aggregations