use of org.apache.cxf.demo.aegis.types.Zoo in project cxf by apache.
the class WriteZoo method populateZoo.
private Zoo populateZoo() {
Zoo zoo = new Zoo();
zoo.setFounder("Noah");
zoo.setName("The Original Zoo");
Map<String, Animal> animals = new HashMap<>();
Animal a = new Animal();
a.setName("lion");
animals.put("lion", a);
a = new Animal();
a.setName("tiger");
animals.put("tiger", a);
a = new Animal();
a.setName("bear");
animals.put("bear", a);
zoo.setAnimals(animals);
return zoo;
}
use of org.apache.cxf.demo.aegis.types.Zoo in project cxf by apache.
the class WriteZoo method go.
private void go() throws Exception {
AegisContext context;
context = new AegisContext();
context.setWriteXsiTypes(true);
Set<java.lang.reflect.Type> rootClasses = new HashSet<java.lang.reflect.Type>();
rootClasses.add(Zoo.class);
context.setRootClasses(rootClasses);
context.initialize();
AegisWriter<XMLStreamWriter> writer = context.createXMLStreamWriter();
FileOutputStream output = new FileOutputStream(outputPathname);
XMLStreamWriter xmlWriter = outputFactory.createXMLStreamWriter(output);
IndentingXMLStreamWriter indentWriter = new IndentingXMLStreamWriter(xmlWriter);
Zoo zoo = populateZoo();
AegisType aegisType = context.getTypeMapping().getType(zoo.getClass());
writer.write(zoo, new QName("urn:aegis:demo", "zoo"), false, indentWriter, aegisType);
xmlWriter.close();
output.close();
}
use of org.apache.cxf.demo.aegis.types.Zoo 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());
}
}
Aggregations