use of org.apache.cxf.aegis.type.TypeMapping in project cxf by apache.
the class QualificationTest method testAnnotatedDefaultQualifiedAttribute.
@Test
public void testAnnotatedDefaultQualifiedAttribute() throws Exception {
AegisContext context = new AegisContext();
TypeCreationOptions typeCreationOptions = new TypeCreationOptions();
typeCreationOptions.setQualifyAttributes(true);
context.setTypeCreationOptions(typeCreationOptions);
context.initialize();
TypeMapping mapping = context.getTypeMapping();
AegisType type = mapping.getTypeCreator().createType(AttributeBean.class);
type.setSchemaType(new QName("urn:Bean", "bean"));
Context messageContext = new Context(context);
AttributeBean bean = new AttributeBean();
Element element = writeObjectToElement(type, bean, messageContext);
assertValid("/b:root[@xyzzy:attrExplicitString]", element);
assertXPathEquals("/b:root/@xyzzy:attrExplicitString", "attrExplicit", element);
assertValid("/b:root[@pkg:attrPlainString]", element);
assertXPathEquals("/b:root/@pkg:attrPlainString", "attrPlain", element);
}
use of org.apache.cxf.aegis.type.TypeMapping in project cxf by apache.
the class QualificationTest method testAnnotatedDefaultUnqualifiedAttribute.
@Test
public void testAnnotatedDefaultUnqualifiedAttribute() throws Exception {
AegisContext context = new AegisContext();
context.initialize();
TypeMapping mapping = context.getTypeMapping();
AegisType type = mapping.getTypeCreator().createType(AttributeBean.class);
type.setSchemaType(new QName("urn:Bean", "bean"));
Context messageContext = new Context(context);
AttributeBean bean = new AttributeBean();
Element element = writeObjectToElement(type, bean, messageContext);
assertValid("/b:root[@xyzzy:attrExplicitString]", element);
assertXPathEquals("/b:root/@xyzzy:attrExplicitString", "attrExplicit", element);
assertValid("/b:root[@attrPlainString]", element);
assertXPathEquals("/b:root/@attrPlainString", "attrPlain", element);
}
use of org.apache.cxf.aegis.type.TypeMapping in project cxf by apache.
the class SoapArrayType method readObject.
@Override
public Object readObject(MessageReader reader, Context context) throws DatabindingException {
try {
// get the encoded array type info
TypeMapping tm = context.getTypeMapping();
if (tm == null) {
tm = getTypeMapping();
}
ArrayTypeInfo arrayTypeInfo = new ArrayTypeInfo(reader, tm);
// verify arrayType dimensions are the same as this type class's array dimensions
if (getDimensions() != arrayTypeInfo.getTotalDimensions()) {
throw new DatabindingException("In " + getSchemaType() + " expected array with " + getDimensions() + " dimensions, but arrayType has " + arrayTypeInfo.getTotalDimensions() + " dimensions: " + arrayTypeInfo.toString());
}
// calculate max size
int maxSize = 1;
for (int dimension : arrayTypeInfo.getDimensions()) {
maxSize *= dimension;
}
// verify offset doesn't exceed maximum size
if (arrayTypeInfo.getOffset() >= maxSize) {
throw new DatabindingException("The array offset " + arrayTypeInfo.getOffset() + " in " + getSchemaType() + " exceeds the expecte size of " + maxSize);
}
// read the values
List<Object> values = readCollection(reader, context, arrayTypeInfo, maxSize - arrayTypeInfo.getOffset());
// if it is a partially transmitted array offset the array values
if (arrayTypeInfo.getOffset() > 0) {
List<Object> list = new ArrayList<>(values.size() + arrayTypeInfo.getOffset());
list.addAll(Collections.nCopies(arrayTypeInfo.getOffset(), null));
list.addAll(values);
values = list;
}
// check bounds
if (values.size() > maxSize) {
throw new DatabindingException("The number of elements " + values.size() + " in " + getSchemaType() + " exceeds the expecte size of " + maxSize);
}
if (values.size() < maxSize) {
values.addAll(Collections.nCopies(maxSize - values.size(), null));
// todo is this an error?
// throw new DatabindingException("The number of elements in " + getSchemaType() +
// " is less then the expected size of " + expectedSize);
}
if (values.size() != maxSize) {
throw new IllegalStateException("Internal error: Expected values collection to contain " + maxSize + " elements but it contains " + values.size() + " elements");
}
// create the array
return makeArray(values, arrayTypeInfo.getDimensions(), getTypeClass().getComponentType());
} catch (IllegalArgumentException e) {
throw new DatabindingException("Illegal argument.", e);
}
}
use of org.apache.cxf.aegis.type.TypeMapping in project cxf by apache.
the class ExplicitPrefixTest method setupService.
private ServiceAndMapping setupService(Class<?> seiClass, Map<String, String> namespaces) {
AegisDatabinding db = new AegisDatabinding();
db.setNamespaceMap(namespaces);
Server s = createService(seiClass, null, db);
ServiceAndMapping serviceAndMapping = new ServiceAndMapping();
serviceAndMapping.setServer(s);
serviceAndMapping.setService(s.getEndpoint().getService());
serviceAndMapping.setTypeMapping((TypeMapping) serviceAndMapping.getService().get(TypeMapping.class.getName()));
return serviceAndMapping;
}
use of org.apache.cxf.aegis.type.TypeMapping in project qi4j-sdk by Qi4j.
the class ValueCompositeCxfType method getOrCreateNonQi4jType.
private AegisType getOrCreateNonQi4jType(Object value) {
AegisType type;
TypeMapping mapping = getTypeMapping();
Class<?> javaType = value.getClass();
type = mapping.getType(javaType);
if (type == null) {
// This might be wrong and instead the ultimate top parent should be used. This works, since
// we know that we are the top parent.
type = getTypeMapping().getTypeCreator().createType(javaType);
mapping.register(type);
}
return type;
}
Aggregations