Package org.apache.cxf.aegis

Examples of org.apache.cxf.aegis.Context


        globalContext.setTypeMapping(mapping);
        return new Context(globalContext);
    }

    public <T> T readWriteReadRef(String file, Class<T> typeClass) throws XMLStreamException {
        Context context = getContext();
       
        AegisType type = mapping.getType(typeClass);
        assertNotNull("no type found for " + typeClass.getName());

        // read file
View Full Code Here


            throw new RuntimeException(e);
        }
    }

    public Object readRef(ElementReader root) throws XMLStreamException {
        Context context = getContext();

        // get AegisType based on the element qname
        MessageReader reader = root.getNextElementReader();
        AegisType type = this.mapping.getType(reader.getName());
        assertNotNull("type is null", type);
View Full Code Here

        // we should not add the out namespace here, as it is not a part of root element
        /*for (Map.Entry<String, String> entry : getNamespaces().entrySet()) {
            namespaces.addNamespace(entry.getKey(), entry.getValue());
        }*/
        ElementWriter rootWriter = getElementWriter(element, namespaces);
        Context context = getContext();

        // get AegisType based on the object instance
        assertNotNull("type is null", type);

        // write the ref
View Full Code Here

    public void verifyInvalid(String resourceName, Class<?> expectedType) throws XMLStreamException {
        AegisType type = mapping.getType(expectedType);
        assertNotNull("type is null", type);

        Context context = getContext();

        ElementReader reader = new ElementReader(getClass().getResourceAsStream(resourceName));
        try {
            type.readObject(reader, context);
            fail("expected DatabindingException");
View Full Code Here

        }
        if (type == null) {
            throw new Fault(new Message("NO_MESSAGE_FOR_PART", LOG, part));
        }
       
        Context context = new Context(databinding.getAegisContext());
       
        context.setAttachments(attachments);
        type = TypeUtil.getWriteType(databinding.getAegisContext(), obj, type);
       
        /*
         * We arrive here with a 'type' of the inner type if isWriteOuter is null.
         * However, in that case, the original type is available.
View Full Code Here

        tm.register(type);

        Element root = new Element("root");
        JDOMWriter writer = new JDOMWriter(root);

        type.writeObject(smallEnum.VALUE1, writer, new Context());

        assertEquals("VALUE1", root.getValue());

        JDOMReader reader = new JDOMReader(root);
        Object value = type.readObject(reader, new Context());

        assertEquals(smallEnum.VALUE1, value);
    }
View Full Code Here

        tm.register(type);

        Element root = new Element("root");
        JDOMWriter writer = new JDOMWriter(root);

        type.writeObject(new EnumBean(), writer, new Context());

        JDOMReader reader = new JDOMReader(root);
        Object value = type.readObject(reader, new Context());

        assertTrue(value instanceof EnumBean);
        EnumBean bean = (EnumBean)value;
        assertNull(bean.getCurrency());
    }
View Full Code Here

        type.setSchemaType(new QName("urn:Bean", "bean"));

        // Test reading
        ElementReader reader = new ElementReader(getResourceAsStream("bean1.xml"));

        SimpleBean bean = (SimpleBean)type.readObject(reader, new Context());
        assertEquals("bleh", bean.getBleh());
        assertEquals("howdy", bean.getHowdy());

        reader.getXMLStreamReader().close();

        // Test reading with extra elements
        reader = new ElementReader(getResourceAsStream("bean2.xml"));
        bean = (SimpleBean)type.readObject(reader, new Context());
        assertEquals("bleh", bean.getBleh());
        assertEquals("howdy", bean.getHowdy());
        reader.getXMLStreamReader().close();

        // test <bleh/> element
        reader = new ElementReader(getResourceAsStream("bean7.xml"));
        bean = (SimpleBean)type.readObject(reader, new Context());
        assertEquals("", bean.getBleh());
        assertEquals("howdy", bean.getHowdy());
        reader.getXMLStreamReader().close();

        bean.setBleh("bleh");

        // Test writing
        Element element = new Element("root", "b", "urn:Bean");
        new Document(element);
        type.writeObject(bean, new JDOMWriter(element), new Context());

        assertValid("/b:root/b:bleh[text()='bleh']", element);
        assertValid("/b:root/b:howdy[text()='howdy']", element);
    }
View Full Code Here

        type.setSchemaType(new QName("urn:Bean", "bean"));

        // Test reading
        ElementReader reader = new ElementReader(getResourceAsStream("bean9.xml"));

        Context ctx = new Context();
        ctx.setReadXsiTypes(false);

        SimpleBean bean = (SimpleBean)type.readObject(reader, ctx);
        assertEquals("bleh", bean.getBleh());
        assertEquals("howdy", bean.getHowdy());

        reader.getXMLStreamReader().close();

        // Test writing
        Element element = new Element("root", "b", "urn:Bean");
        new Document(element);
        type.writeObject(bean, new JDOMWriter(element), new Context());

        assertValid("/b:root/b:bleh[text()='bleh']", element);
        assertValid("/b:root/b:howdy[text()='howdy']", element);
    }
View Full Code Here

        type.setTypeMapping(mapping);
        type.setSchemaType(new QName("urn:Bean", "bean"));

        ElementReader reader = new ElementReader(getResourceAsStream("bean3.xml"));

        SimpleBean bean = (SimpleBean)type.readObject(reader, new Context());
        assertEquals("howdy", bean.getHowdy());
        assertNull(bean.getBleh());

        reader.getXMLStreamReader().close();

        // Test writing
        Element element = new Element("root", "b", "urn:Bean");
        new Document(element);
        type.writeObject(bean, new JDOMWriter(element), new Context());

        assertInvalid("/b:root/b:bleh", element);
        assertValid("/b:root/b:howdycustom[text()='howdy']", element);
    }
View Full Code Here

TOP

Related Classes of org.apache.cxf.aegis.Context

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.