Search in sources :

Example 1 with Zoo

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;
}
Also used : HashMap(java.util.HashMap) Animal(org.apache.cxf.demo.aegis.types.Animal) Zoo(org.apache.cxf.demo.aegis.types.Zoo)

Example 2 with 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();
}
Also used : IndentingXMLStreamWriter(javanet.staxutils.IndentingXMLStreamWriter) AegisType(org.apache.cxf.aegis.type.AegisType) QName(javax.xml.namespace.QName) AegisContext(org.apache.cxf.aegis.AegisContext) AegisType(org.apache.cxf.aegis.type.AegisType) IndentingXMLStreamWriter(javanet.staxutils.IndentingXMLStreamWriter) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) FileOutputStream(java.io.FileOutputStream) Zoo(org.apache.cxf.demo.aegis.types.Zoo) HashSet(java.util.HashSet)

Example 3 with Zoo

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());
    }
}
Also used : Type(java.lang.reflect.Type) XMLStreamReader(javax.xml.stream.XMLStreamReader) Animal(org.apache.cxf.demo.aegis.types.Animal) AegisContext(org.apache.cxf.aegis.AegisContext) Zoo(org.apache.cxf.demo.aegis.types.Zoo) Map(java.util.Map) FileInputStream(java.io.FileInputStream) HashSet(java.util.HashSet)

Aggregations

Zoo (org.apache.cxf.demo.aegis.types.Zoo)3 HashSet (java.util.HashSet)2 AegisContext (org.apache.cxf.aegis.AegisContext)2 Animal (org.apache.cxf.demo.aegis.types.Animal)2 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 Type (java.lang.reflect.Type)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 IndentingXMLStreamWriter (javanet.staxutils.IndentingXMLStreamWriter)1 QName (javax.xml.namespace.QName)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 AegisType (org.apache.cxf.aegis.type.AegisType)1