001/*
002 * Copyright 2002-2016 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.oxm;
018
019import java.io.IOException;
020import javax.xml.transform.Result;
021
022/**
023 * Defines the contract for Object XML Mapping Marshallers. Implementations of this interface
024 * can serialize a given Object to an XML Stream.
025 *
026 * <p>Although the {@code marshal} method accepts a {@code java.lang.Object} as its
027 * first parameter, most {@code Marshaller} implementations cannot handle arbitrary
028 * {@code Object}s. Instead, a object class must be registered with the marshaller,
029 * or have a common base class.
030 *
031 * @author Arjen Poutsma
032 * @since 3.0
033 * @see Unmarshaller
034 */
035public interface Marshaller {
036
037        /**
038         * Indicate whether this marshaller can marshal instances of the supplied type.
039         * @param clazz the class that this marshaller is being asked if it can marshal
040         * @return {@code true} if this marshaller can indeed marshal instances of the supplied class;
041         * {@code false} otherwise
042         */
043        boolean supports(Class<?> clazz);
044
045        /**
046         * Marshal the object graph with the given root into the provided {@link Result}.
047         * @param graph the root of the object graph to marshal
048         * @param result the result to marshal to
049         * @throws IOException if an I/O error occurs
050         * @throws XmlMappingException if the given object cannot be marshalled to the result
051         */
052        void marshal(Object graph, Result result) throws IOException, XmlMappingException;
053
054}