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;
020
021import javax.xml.transform.Source;
022
023/**
024 * Defines the contract for Object XML Mapping unmarshallers. Implementations of this
025 * interface can deserialize a given XML Stream to an Object graph.
026 *
027 * @author Arjen Poutsma
028 * @since 3.0
029 * @see Marshaller
030 */
031public interface Unmarshaller {
032
033        /**
034         * Indicate whether this unmarshaller can unmarshal instances of the supplied type.
035         * @param clazz the class that this unmarshaller is being asked if it can marshal
036         * @return {@code true} if this unmarshaller can indeed unmarshal to the supplied class;
037         * {@code false} otherwise
038         */
039        boolean supports(Class<?> clazz);
040
041        /**
042         * Unmarshal the given {@link Source} into an object graph.
043         * @param source the source to marshal from
044         * @return the object graph
045         * @throws IOException if an I/O error occurs
046         * @throws XmlMappingException if the given source cannot be mapped to an object
047         */
048        Object unmarshal(Source source) throws IOException, XmlMappingException;
049
050}