Package org.exolab.castor.xml

Examples of org.exolab.castor.xml.Marshaller


        // assertNotNull (entity);
       
        entity.getPartyOneElement().setId("");
       
        StringWriter out = new StringWriter();
        Marshaller marshaller = new Marshaller (out);
        marshaller.setValidation(true);
        try {
            marshaller.marshal(entity);
            // fail ("ValidationException expected");
        }
        catch (ValidationException e) {
            // nothing to check
        }
View Full Code Here


        // assertNotNull (entity);
       
        entity.getPartyOneElement().setId("ID000001");
       
        StringWriter out = new StringWriter();
        Marshaller marshaller = new Marshaller (out);
        marshaller.setValidation(true);
        try {
            marshaller.marshal(entity);
            // fail ("ValidationException expected");
        }
        catch (ValidationException e) {
            // nothing to check
        }
View Full Code Here

     * @throws Exception For any exception thrown.
     */
    public void testMarshalEntity() throws Exception {

        StringWriter out = new StringWriter();
        Marshaller marshaller = getXMLContext().createMarshaller();
        marshaller.setWriter(out);
       
        Entity entity = new Entity();
        entity.setId(new Integer(100));
        entity.setName("entity 100");
        marshaller.marshal(entity);
       
        System.out.println(out.toString());
    }
View Full Code Here

    public void testMarshalEntity() throws Exception {
        Mapping mapping = new Mapping();
        mapping.loadMapping(getClass().getResource(MAPPING_FILE).toExternalForm());
       
        StringWriter out = new StringWriter();
        Marshaller marshaller = getXMLContext().createMarshaller();
        marshaller.setWriter(out);
        marshaller.setMapping(mapping);
       
        Entity entity = new Entity();
        entity.setId(new Integer(100));
        entity.setName("entity 100");
       
        marshaller.marshal(entity);
       
        System.out.println(out.toString());
    }
View Full Code Here

            AssignmentNotification[] assignmentNotification = entity.getAssignmentNotification();
            // assertEquals(assignmentNotification[0].getPartyReference().getHref(), entity.getPartyTwo());
            assignmentNotification[0].getPartyReference().setHref(entity.getPartyOne());
           
            StringWriter out = new StringWriter();
            Marshaller marshaller = new Marshaller (out);
            marshaller.setValidation(true);
            marshaller.marshal(entity);
           
            // assertTrue(out.toString().indexOf("<assignmentNotification><partyReference href=\"ID000000\"/>")>-1);
           
        }
        catch (Exception e) {
View Full Code Here

            partyTwo.setPartyName("Other");
            partyTwo.setPartyId(entity.getPartyTwo().getPartyId());
            assignmentNotification[0].getPartyReference().setHref(partyTwo);
           
            StringWriter out = new StringWriter();
            Marshaller marshaller = new Marshaller (out);
            marshaller.setValidation(true);
            marshaller.marshal(entity);
           
            // fail ("Nested ValidationException expected.");
        }
        catch (Exception e) {
            // assertTrue(e.getCause() instanceof ValidationException);
View Full Code Here

           
            AssignmentNotification[] assignmentNotification = entity.getAssignmentNotification();
            assignmentNotification[0].getPartyReference().setHref(null);
           
            StringWriter out = new StringWriter();
            Marshaller marshaller = new Marshaller (out);
            marshaller.setValidation(true);
            marshaller.marshal(entity);
           
            // fail ("MarshalException expected, because partyReference/@href is use=\"required\"");
        }
        catch (Exception e) {
            // assertTrue(e instanceof ValidationException);
View Full Code Here

           
            AssignmentNotification[] assignmentNotification = entity.getAssignmentNotification();
            assignmentNotification[0].getPartyReference().setHref("bla");
           
            StringWriter out = new StringWriter();
            Marshaller marshaller = new Marshaller (out);
            marshaller.setValidation(true);
            marshaller.marshal(entity);
           
            // fail ("Nested ValidationException expected.");
        }
        catch (Exception e) {
            // assertTrue(e.getCause() instanceof ValidationException);
View Full Code Here

        verbose("--> Marshaling to: '" + fileName + "'");

        File marshalOutput = new File(_outputRootFile, fileName);

        try {
            Marshaller marshaller = createMarshaler(marshalOutput);
            marshaller.marshal(object);
        } catch (Exception e) {
            if (!checkExceptionWasExpected(e, FailureStepType.MARSHAL_TO_DISK)) {
                fail("Exception marshaling to disk " + e);
            }
            return null;
View Full Code Here

        return marshalOutput;
    }

    private Marshaller createMarshaler(final File marshalOutput) throws Exception {
        getXMLContext().getInternalContext().getXMLClassDescriptorResolver().cleanDescriptorCache();
        Marshaller marshaller = getXMLContext().createMarshaller();
        marshaller.setWriter(new FileWriter(marshalOutput));

        //-- Configuration for marshaler?  Use config from unit test case if available
        Configuration config = _unitTest.getConfiguration();
        if (config == null) {
            config = _configuration;
        }

        if (config != null) {
            ConfigurationType marshal = config.getMarshal();
            List returnValues = invokeEnumeratedMethods(marshaller, marshal);
            returnValues.clear(); // We don't care about the return values
        }//-- config != null

        if (_mapping != null) {
            marshaller.setMapping(_mapping);
        }

        if (_listener != null && _listener instanceof MarshalListener
                && _listenerType != TypeType.UNMARSHAL) {
            marshaller.setMarshalListener((MarshalListener)_listener);
        }
        return marshaller;
    }
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.