use of org.apache.cxf.aegis.AegisContext in project cxf by apache.
the class NoNamespaceAegisElementProvider method getAegisContext.
@Override
protected AegisContext getAegisContext(Class<?> plainClass, Type genericType) {
AegisContext context = new AegisContext();
context.setWriteXsiTypes(writeXsiType);
context.setReadXsiTypes(readXsiType);
TypeCreationOptions tco = new TypeCreationOptions();
tco.setQualifyElements(false);
Set<java.lang.reflect.Type> rootClasses = new HashSet<java.lang.reflect.Type>();
rootClasses.add(genericType);
context.setTypeCreationOptions(tco);
context.setRootClasses(rootClasses);
TypeMapping baseMapping = DefaultTypeMapping.createSoap11TypeMapping(true, false, false);
DefaultTypeMapping mapping = new DefaultTypeMapping(Constants.URI_2001_SCHEMA_XSD, baseMapping);
TypeCreator stockTypeCreator = createTypeCreator(tco);
mapping.setTypeCreator(stockTypeCreator);
context.setTypeMapping(mapping);
context.initialize();
return context;
}
use of org.apache.cxf.aegis.AegisContext in project cxf by apache.
the class ReadZoo method go.
private void go() throws Exception {
AegisContext context;
context = new AegisContext();
Set<Type> rootClasses = new HashSet<>();
rootClasses.add(Zoo.class);
context.setRootClasses(rootClasses);
context.initialize();
AegisReader<XMLStreamReader> reader = context.createXMLStreamReader();
FileInputStream input = new FileInputStream(inputPathname);
XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(input);
Zoo zoo = (Zoo) reader.read(xmlReader);
System.out.println("Name " + zoo.getName());
System.out.println("Founder " + zoo.getFounder());
for (Map.Entry<String, Animal> e : zoo.getAnimals().entrySet()) {
System.out.println(e.getKey() + " -> " + e.getValue().getName());
}
}
use of org.apache.cxf.aegis.AegisContext in project cxf by apache.
the class AegisDatabinding method initialize.
/**
* {@inheritDoc} Set up the data binding for a service.
*/
public void initialize(Service s) {
// We want to support some compatibility configuration properties.
if (aegisContext == null) {
aegisContext = new AegisContext();
Object val = s.get("mtom-enabled");
if ("true".equals(val) || Boolean.TRUE.equals(val) || mtomEnabled) {
setMtomEnabled(true);
aegisContext.setMtomEnabled(true);
}
if (mtomUseXmime) {
aegisContext.setMtomUseXmime(true);
}
Map<Class<?>, String> implMap = new HashMap<>();
// now for a really annoying case, the .implementation objects.
for (String key : s.keySet()) {
if (key.endsWith(".implementation")) {
String className = key.substring(0, key.length() - ".implementation".length());
Class<?> clazz = null;
try {
clazz = ClassLoaderUtils.loadClass(className, getClass());
} catch (ClassNotFoundException e) {
Message message = new Message("MAPPED_CLASS_NOT_FOUND", LOG, className, key);
LOG.warning(message.toString());
continue;
}
String implClassName = (String) s.get(key);
implMap.put(clazz, implClassName);
}
}
if (overrideTypes != null) {
aegisContext.setRootClassNames(overrideTypes);
}
if (configuration != null) {
aegisContext.setTypeCreationOptions(configuration);
}
if (!implMap.isEmpty()) {
aegisContext.setBeanImplementationMap(implMap);
}
}
aegisContext.setMappingNamespaceURI(s.getServiceInfos().get(0).getInterface().getName().getNamespaceURI());
aegisContext.initialize();
this.service = s;
s.getInInterceptors().add(new StaxSchemaValidationInInterceptor());
Set<AegisType> deps = new HashSet<>();
for (ServiceInfo info : s.getServiceInfos()) {
for (OperationInfo opInfo : info.getInterface().getOperations()) {
if (opInfo.isUnwrappedCapable()) {
initializeOperation(s, aegisContext.getTypeMapping(), opInfo.getUnwrappedOperation(), deps);
} else {
initializeOperation(s, aegisContext.getTypeMapping(), opInfo, deps);
}
}
}
Collection<AegisType> additional = aegisContext.getRootTypes();
if (additional != null) {
for (AegisType t : additional) {
if (!deps.contains(t)) {
deps.add(t);
}
addDependencies(deps, t);
}
}
createSchemas(s, deps);
for (ServiceInfo info : s.getServiceInfos()) {
for (OperationInfo opInfo : info.getInterface().getOperations()) {
if (opInfo.isUnwrappedCapable()) {
initializeOperationTypes(info, opInfo.getUnwrappedOperation());
} else {
initializeOperationTypes(info, opInfo);
}
}
}
}
use of org.apache.cxf.aegis.AegisContext in project cxf by apache.
the class XMLStreamReaderMappingTest method getContext.
protected Context getContext() {
AegisContext globalContext = new AegisContext();
globalContext.initialize();
globalContext.setTypeMapping(mapping);
return new Context(globalContext);
}
use of org.apache.cxf.aegis.AegisContext in project cxf by apache.
the class TestDateMapping method testWriteSqlDateAsDate.
@Test
public void testWriteSqlDateAsDate() throws Exception {
context = new AegisContext();
Set<java.lang.reflect.Type> rootClasses = new HashSet<java.lang.reflect.Type>();
rootClasses.add(BeanWithDate.class);
context.setRootClasses(rootClasses);
context.initialize();
BeanWithDate bean = new BeanWithDate();
java.sql.Date date = new java.sql.Date(0);
bean.setFig(date);
AegisType sbType = context.getTypeMapping().getType(bean.getClass());
AegisWriter<XMLStreamWriter> writer = context.createXMLStreamWriter();
StringWriter stringWriter = new StringWriter();
XMLStreamWriter xmlWriter = xmlOutputFactory.createXMLStreamWriter(stringWriter);
writer.write(bean, new QName("urn:test", "beanWithDate"), false, xmlWriter, sbType);
xmlWriter.close();
// an absence of exception is success here.
}
Aggregations