Package org.exolab.castor.xml

Examples of org.exolab.castor.xml.Marshaller


     * @param writer
     *            the Writer to serialize the mapping to
     * @throws MappingException if writing the mapping information fails
     */
    public void write(final Writer writer) throws MappingException {
        Marshaller marshal;
        MappingRoot mapping;
        Enumeration enumeration;

        try {
            mapping = new MappingRoot();
            mapping.setDescription("Castor generated mapping file");
            enumeration = _mappings.elements();
            while (enumeration.hasMoreElements()) {
                mapping.addClassMapping((ClassMapping) enumeration.nextElement());
            }
            marshal = new Marshaller(writer);
            marshal.setNamespaceMapping(null, "http://castor.exolab.org/");
            marshal.setNamespaceMapping("cst", "http://castor.exolab.org/");
            marshal.marshal(mapping);
        } catch (Exception except) {
            throw new MappingException(except);
        }
    } // -- write
View Full Code Here


        public void saveHistory() {
            // write back the history to file
            try {
                FileWriter writer = new FileWriter("queryhistory.xml");
                Marshaller marshaller = new Marshaller(writer);
                marshaller.setMapping(_mapping);
                marshaller.marshal(_qhistory);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
View Full Code Here

        test.setElement1(el1);
        test.setElement2(el2);
        test.setElement3(el3);
        test.setElementRef(elRef);
        StringWriter out = new StringWriter();
        Marshaller marshaller = new Marshaller(out);
        marshaller.setValidation(true);
        marshaller.marshal(test);
    }
View Full Code Here

        test.setElement3(el3);
        test.setElementRef(elRef);
       
        try {
            StringWriter out = new StringWriter();
            Marshaller marshaller = new Marshaller(out);
            marshaller.setValidation(true);
            marshaller.marshal(test);
        } catch (Exception e) {
            // assertTrue(e.getCause() instanceof ValidationException);
        }
    }
View Full Code Here

        test.setElement3(el3);
        test.setElementRef(elRef);
       
        try {
            StringWriter out = new StringWriter();
            Marshaller marshaller = new Marshaller(out);
            marshaller.setValidation(true);
            marshaller.marshal(test);
        } catch (Exception e) {
            // assertTrue(e.getCause() instanceof ValidationException);
        }
    }   
View Full Code Here

           
            file = new File(DEFAULT_OUTPUT);
            FileWriter writer = new FileWriter(file);

            xmlContext.setProperty(XMLProperties.USE_INDENTATION, true);
            Marshaller marshaller = xmlContext.createMarshaller();
            marshaller.setWriter(writer);
           
            marshaller.setRootElement("changelog");
            marshaller.setSuppressXSIType(true);
            marshaller.marshal(changelog);
           
        }
        catch(Exception ex) {
          ex.printStackTrace();
        }
View Full Code Here

    public void testMarshalSimpleBean() throws Exception {
        Mapping mapping = new Mapping();
        mapping.loadMapping(getClass().getResource(MAPPING_FILE).toExternalForm());
       
        StringWriter out = new StringWriter();
        Marshaller marshaller = new Marshaller(out);
        marshaller.setMapping(mapping);
       
        Bean bean = new Bean(new Integer(999), "element of 999", null);
       
        marshaller.marshal(bean);
       
        String output = out.toString();
       
        String expected
            = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
View Full Code Here

    public void testMarshalReferingBean() throws Exception {
        Mapping mapping = new Mapping();
        mapping.loadMapping(getClass().getResource(MAPPING_FILE).toExternalForm());
       
        StringWriter out = new StringWriter();
        Marshaller marshaller = new Marshaller(out);
        marshaller.setMapping(mapping);
       
        Bean refered = new Bean(new Integer(999), "element of 999", null);
        Bean referer = new Bean(new Integer(100), "element of 100", refered);
       
        marshaller.marshal(referer);
       
        String output = out.toString();
       
        String expected
            = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
View Full Code Here

       
        Mapping mapping = xmlContext.createMapping();
        mapping.loadMapping(getClass().getResource(MAPPING_FILE).toExternalForm());
       
        StringWriter out = new StringWriter();
        Marshaller marshaller = xmlContext.createMarshaller();
        marshaller.setWriter(out);
        marshaller.setMapping(mapping);
       
// Joachim 2007-09-04 before XMLContext was introduced it looked like:
//        Configuration config = LocalConfiguration.getInstance();
//        config.getProperties().setProperty(
//                XMLConfiguration.PROXY_INTERFACES, "net.sf.cglib.proxy.Factory");
//       
//        Mapping mapping = new Mapping();
//        mapping.loadMapping(getClass().getResource(MAPPING_FILE).toExternalForm());
//       
//        StringWriter out = new StringWriter();
//        Marshaller marshaller = new Marshaller(out);
//        marshaller.setMapping(mapping);
       
        Bean bean = new Bean(new Integer(999), "element of 999", null);
        Bean proxy = (Bean) Proxy.newInstance(bean);
       
        assertNotNull(proxy);
        assertEquals(Bean.class, proxy.getClass().getSuperclass());
        assertEquals(1, proxy.getClass().getInterfaces().length);
        assertEquals(Factory.class, proxy.getClass().getInterfaces()[0]);
       
        assertEquals(999, proxy.getAttribute().intValue());
        assertEquals("element of 999", proxy.getElement());
        assertNull(proxy.getReference());
       
        marshaller.marshal(proxy);
       
        String output = out.toString();

        String expected
            = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
View Full Code Here

       
        Mapping mapping = xmlContext.createMapping();
        mapping.loadMapping(getClass().getResource(MAPPING_FILE).toExternalForm());
       
        StringWriter out = new StringWriter();
        Marshaller marshaller = xmlContext.createMarshaller();
        marshaller.setWriter(out);
        marshaller.setMapping(mapping);
       
// Joachim 2007-09-04 before XMLContext was introduced it looked like:
//        Configuration config = LocalConfiguration.getInstance();
//        config.getProperties().setProperty(
//                XMLConfiguration.PROXY_INTERFACES, "net.sf.cglib.proxy.Factory");
//       
//        Mapping mapping = new Mapping();
//        mapping.loadMapping(getClass().getResource(MAPPING_FILE).toExternalForm());
//       
//        StringWriter out = new StringWriter();
//        Marshaller marshaller = new Marshaller(out);
//        marshaller.setMapping(mapping);
       
        Bean refered = new Bean(new Integer(999), "element of 999", null);
        Bean referedProxy = (Bean) Proxy.newInstance(refered);
       
        assertNotNull(referedProxy);
        assertEquals(Bean.class, referedProxy.getClass().getSuperclass());
        assertEquals(1, referedProxy.getClass().getInterfaces().length);
        assertEquals(Factory.class, referedProxy.getClass().getInterfaces()[0]);
       
        assertEquals(999, referedProxy.getAttribute().intValue());
        assertEquals("element of 999", referedProxy.getElement());
        assertNull(referedProxy.getReference());

        Bean referer = new Bean(new Integer(100), "element of 100", referedProxy);
        Bean refererProxy = (Bean) Proxy.newInstance(referer);
       
        assertNotNull(refererProxy);
        assertEquals(Bean.class, refererProxy.getClass().getSuperclass());
        assertEquals(1, refererProxy.getClass().getInterfaces().length);
        assertEquals(Factory.class, refererProxy.getClass().getInterfaces()[0]);
       
        assertEquals(100, refererProxy.getAttribute().intValue());
        assertEquals("element of 100", refererProxy.getElement());
        assertNotNull(refererProxy.getReference());

        marshaller.marshal(refererProxy);
       
        String output = out.toString();
       
        String expected
            = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
View Full Code Here

TOP

Related Classes of org.exolab.castor.xml.Marshaller

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.