use of org.apache.cxf.aegis.type.AegisType in project cxf by apache.
the class SoapArrayType method readCollection.
protected List<Object> readCollection(MessageReader reader, Context context, ArrayTypeInfo arrayTypeInfo, int maxSize) throws DatabindingException {
List<Object> values = new ArrayList<>();
Boolean sparse = null;
while (reader.hasMoreElementReaders()) {
MessageReader creader = reader.getNextElementReader();
// if the first element contains a position attribute, this is a sparse array
// and all subsequent elements must contain the position attribute
String position = readAttributeValue(creader, SOAP_ARRAY_POSITION);
if (sparse == null) {
sparse = position != null;
}
// nested element names can specify a type
AegisType compType = getTypeMapping().getType(creader.getName());
if (compType == null) {
// use the type declared in the arrayType attribute
compType = arrayTypeInfo.getType();
}
// check for an xsi:type override
compType = TypeUtil.getReadType(creader.getXMLStreamReader(), context.getGlobalContext(), compType);
// wrap type with soap ref to handle hrefs
compType = new SoapRefType(compType);
// read the value
Object value;
if (creader.isXsiNil()) {
value = null;
creader.readToEnd();
} else {
value = compType.readObject(creader, context);
}
// add the value
if (!sparse) {
if (values.size() + 1 > maxSize) {
throw new DatabindingException("The number of elements in " + getSchemaType() + " exceeds the maximum size of " + maxSize);
}
values.add(value);
} else {
int valuesPosition = readValuesPosition(position, arrayTypeInfo.getDimensions());
if (valuesPosition > maxSize) {
throw new DatabindingException("Array position " + valuesPosition + " in " + getSchemaType() + " exceeds the maximum size of " + maxSize);
}
if (values.size() <= valuesPosition) {
values.addAll(Collections.nCopies(valuesPosition - values.size() + 1, null));
}
Object oldValue = values.set(valuesPosition, value);
if (oldValue != null) {
throw new DatabindingException("Array position " + valuesPosition + " in " + getSchemaType() + " is already assigned to value " + oldValue);
}
}
}
return values;
}
use of org.apache.cxf.aegis.type.AegisType in project cxf by apache.
the class MapType method writeSchema.
@Override
public void writeSchema(XmlSchema root) {
XmlSchemaComplexType complex = new XmlSchemaComplexType(root, true);
complex.setName(getSchemaType().getLocalPart());
XmlSchemaSequence sequence = new XmlSchemaSequence();
complex.setParticle(sequence);
AegisType kType = getKeyType();
AegisType vType = getValueType();
XmlSchemaElement element = new XmlSchemaElement(root, false);
sequence.getItems().add(element);
element.setName(getEntryName().getLocalPart());
element.setMinOccurs(0);
element.setMaxOccurs(Long.MAX_VALUE);
XmlSchemaComplexType evType = new XmlSchemaComplexType(root, false);
element.setType(evType);
XmlSchemaSequence evSequence = new XmlSchemaSequence();
evType.setParticle(evSequence);
createElement(root, evSequence, getKeyName(), kType, false);
createElement(root, evSequence, getValueName(), vType, true);
}
use of org.apache.cxf.aegis.type.AegisType in project cxf by apache.
the class MapType method writeObject.
@Override
public void writeObject(Object object, MessageWriter writer, Context context) throws DatabindingException {
if (object == null) {
return;
}
try {
Map<?, ?> map = (Map<?, ?>) object;
AegisType kType = getKeyType();
AegisType vType = getValueType();
for (Iterator<?> itr = map.entrySet().iterator(); itr.hasNext(); ) {
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) itr.next();
writeEntry(writer, context, kType, vType, entry);
}
} catch (IllegalArgumentException e) {
throw new DatabindingException("Illegal argument.", e);
}
}
use of org.apache.cxf.aegis.type.AegisType in project cxf by apache.
the class StructType method getElementType.
/**
* Returns a SoapRefType wrapping the actual type.
*/
@Override
protected AegisType getElementType(QName name, BeanTypeInfo beanTypeInfo, MessageReader reader, Context context) {
// nested elements use unqualified names
name = qualifyName(name);
AegisType type = super.getElementType(name, beanTypeInfo, reader, context);
if (type != null) {
type = new SoapRefType(type);
}
return type;
}
use of org.apache.cxf.aegis.type.AegisType in project cxf by apache.
the class XMLBeanTypeInfo method mapProperty.
@Override
protected void mapProperty(PropertyDescriptor pd) {
Element e = getPropertyElement(pd.getName());
String style = null;
QName mappedName = null;
if (e != null) {
String ignore = DOMUtils.getAttributeValueEmptyNull(e, "ignore");
if ("true".equals(ignore)) {
return;
}
LOG.finest("Found mapping for property " + pd.getName());
style = DOMUtils.getAttributeValueEmptyNull(e, "style");
}
if (style == null) {
style = "element";
}
boolean element = "element".equals(style);
boolean qualify;
if (element) {
qualify = isQualifyElements();
} else {
qualify = isQualifyAttributes();
}
String namespace = null;
if (qualify) {
namespace = getDefaultNamespace();
}
if (e != null) {
mappedName = NamespaceHelper.createQName(e, DOMUtils.getAttributeValueEmptyNull(e, "mappedName"), namespace);
}
if (mappedName == null) {
mappedName = createMappedName(pd, qualify);
}
if (e != null) {
QName mappedType = NamespaceHelper.createQName(e, DOMUtils.getAttributeValueEmptyNull(e, "typeName"), getDefaultNamespace());
if (mappedType != null) {
mapTypeName(mappedName, mappedType);
}
/*
* Whenever we create a type object, it has to have a schema type. If we created a custom type
* object out of thin air here, we've may have a problem. If "typeName" was specified, then then
* we know the mapping. But if mappedName was not specified, then the typeName will come from the
* type mapping, so we have to ask it. And if some other type creator has something to say about
* it, we'll get it wrong.
*/
String explicitTypeName = DOMUtils.getAttributeValueEmptyNull(e, "type");
if (explicitTypeName != null) {
try {
Class<?> typeClass = ClassLoaderUtils.loadClass(explicitTypeName, XMLBeanTypeInfo.class);
AegisType customTypeObject = (AegisType) typeClass.newInstance();
mapType(mappedName, customTypeObject);
QName schemaType = mappedType;
if (schemaType == null) {
schemaType = getTypeMapping().getTypeQName(pd.getPropertyType());
}
customTypeObject.setTypeClass(typeClass);
customTypeObject.setSchemaType(schemaType);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e1) {
//
}
}
String nillableVal = DOMUtils.getAttributeValueEmptyNull(e, "nillable");
if (nillableVal != null && nillableVal.length() > 0) {
ensurePropertyInfo(mappedName).setNillable(Boolean.parseBoolean(nillableVal));
}
String minOccurs = DOMUtils.getAttributeValueEmptyNull(e, "minOccurs");
if (minOccurs != null && minOccurs.length() > 0) {
ensurePropertyInfo(mappedName).setMinOccurs(Integer.parseInt(minOccurs));
}
String maxOccurs = DOMUtils.getAttributeValueEmptyNull(e, "maxOccurs");
if (maxOccurs != null && maxOccurs.length() > 0) {
ensurePropertyInfo(mappedName).setMinOccurs(Integer.parseInt(maxOccurs));
}
}
try {
// name " + mappedName);
if ("element".equals(style)) {
mapElement(pd.getName(), mappedName);
} else if ("attribute".equals(style)) {
mapAttribute(pd.getName(), mappedName);
} else {
throw new DatabindingException("Invalid style: " + style);
}
} catch (DatabindingException ex) {
ex.prepend("Couldn't create type for property " + pd.getName() + " on " + getTypeClass());
throw ex;
}
}
Aggregations