use of org.apache.cxf.aegis.type.TypeMapping in project cxf by apache.
the class XMLStreamReaderMappingTest method setUp.
@Before
public void setUp() throws Exception {
super.setUp();
addNamespace("b", "urn:beanz");
addNamespace("xsi", Constants.URI_2001_SCHEMA_XSI);
context = new AegisContext();
// create a different mapping than the context creates.
TypeMapping baseMapping = DefaultTypeMapping.createSoap11TypeMapping(true, false, false);
mapping = new DefaultTypeMapping(Constants.URI_2001_SCHEMA_XSD, baseMapping);
mapping.register(XMLStreamReader.class, new QName("urn:Bean", "SimpleBean"), new XMLStreamReaderType());
mapping.setTypeCreator(context.createTypeCreator());
context.setTypeMapping(mapping);
context.initialize();
}
use of org.apache.cxf.aegis.type.TypeMapping in project cxf by apache.
the class AegisContext method initialize.
/**
* Initialize the context. The encodingStyleURI allows .aegis.xml files to have multiple mappings for,
* say, SOAP 1.1 versus SOAP 1.2. Passing null uses a default URI.
*
* @param mappingNamespaceURI URI to select mappings based on the encoding.
*/
public void initialize() {
// allow spring config of an alternative mapping.
if (configuration == null) {
configuration = new TypeCreationOptions();
}
if (typeMapping == null) {
boolean defaultNillable = configuration.isDefaultNillable();
TypeMapping baseTM = DefaultTypeMapping.createDefaultTypeMapping(defaultNillable, mtomUseXmime, enableJDOMMappings);
if (mappingNamespaceURI == null) {
mappingNamespaceURI = DefaultTypeMapping.DEFAULT_MAPPING_URI;
}
DefaultTypeMapping defaultTypeMapping = new DefaultTypeMapping(mappingNamespaceURI, baseTM);
defaultTypeMapping.setTypeCreator(createTypeCreator());
typeMapping = defaultTypeMapping;
}
processRootTypes();
}
use of org.apache.cxf.aegis.type.TypeMapping in project cxf by apache.
the class BeanType method getSuperType.
/**
* Return the AegisType for the superclass if this type's class, if any.
* @return
*/
public AegisType getSuperType() {
BeanTypeInfo inf = getTypeInfo();
Class<?> c = inf.getTypeClass();
if (c.isInterface() && c.getInterfaces().length == 1) {
c = c.getInterfaces()[0];
} else {
c = c.getSuperclass();
}
/*
* Don't dig any deeper than Object or Exception
*/
if (c != null && c != Object.class && c != Exception.class && c != RuntimeException.class && c != Enum.class && c != Serializable.class && c != Cloneable.class) {
TypeMapping tm = inf.getTypeMapping();
AegisType superType = tm.getType(c);
if (superType == null) {
// if we call createType, we know that we'll get a BeanType. */
superType = getTypeMapping().getTypeCreator().createType(c);
if (superType != null) {
tm.register(superType);
this.info.setExtension(true);
}
} else {
this.info.setExtension(true);
}
return superType;
}
return null;
}
use of org.apache.cxf.aegis.type.TypeMapping in project cxf by apache.
the class BeanTypeInfo method getType.
/**
* Get the type class for the field with the specified QName.
*/
public AegisType getType(QName name) {
// 1. Try a prexisting mapped type
AegisType type = mappedName2type.get(name);
// 2. Try to get the type by its name, if there is one
if (type == null) {
QName typeName = getMappedTypeName(name);
if (typeName != null) {
type = getTypeMapping().getType(typeName);
if (type != null) {
mapType(name, type);
}
}
}
// 3. Create the type from the property descriptor and map it
if (type == null) {
PropertyDescriptor desc;
try {
desc = getPropertyDescriptorFromMappedName(name);
} catch (Exception e) {
if (e instanceof DatabindingException) {
throw (DatabindingException) e;
}
throw new DatabindingException("Couldn't get properties.", e);
}
if (desc == null) {
return null;
}
try {
TypeMapping tm = getTypeMapping();
TypeCreator tc = tm.getTypeCreator();
type = tc.createType(desc);
} catch (DatabindingException e) {
e.prepend("Couldn't create type for property " + desc.getName() + " on " + getTypeClass());
throw e;
}
// second part is possible workaround for XFIRE-586
if (registerType(desc)) {
getTypeMapping().register(type);
}
mapType(name, type);
}
if (type == null) {
throw new DatabindingException("Couldn't find type for property " + name);
}
return type;
}
use of org.apache.cxf.aegis.type.TypeMapping in project cxf by apache.
the class QualificationTest method testXmlDefaultQualifiedAttribute.
@Test
public void testXmlDefaultQualifiedAttribute() 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(XmlMappedAttributeBean.class);
type.setSchemaType(new QName("urn:Bean", "bean"));
Context messageContext = new Context(context);
XmlMappedAttributeBean bean = new XmlMappedAttributeBean();
Element element = writeObjectToElement(type, bean, messageContext);
assertValid("/b:root[@pkg:attrXmlString]", element);
assertXPathEquals("/b:root/@pkg:attrXmlString", "attrXml", element);
}
Aggregations