001/*
002 *  Copyright 2011 Chris Pheby
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 *      http://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 */
016package org.jadira.bindings.core.general.adapter;
017
018import org.jadira.bindings.core.api.FromUnmarshaller;
019import org.jadira.bindings.core.api.ToMarshaller;
020
021/**
022 * An unmarshaller that wraps a marshaller to convert the marshaller for type T into an unmarshaller for type S
023 * @param <S> source type
024 * @param <T> output type for the marshaller
025 */
026public class MarshallerToUnmarshaller<S, T> implements FromUnmarshaller<S, T> {
027
028        private ToMarshaller<T, S> marshaller;
029
030        /**
031         * Create a new instance of a {@link FromUnmarshaller} wrapping the given {@link ToMarshaller}
032         * @param marshaller The ToMarshaller to wrap
033         */
034        public MarshallerToUnmarshaller(ToMarshaller<T, S> marshaller) {
035                this.marshaller = marshaller;
036        }
037
038        /**
039         * {@inheritDoc}
040         */
041        /* @Override */
042        public S unmarshal(T object) {
043                return marshaller.marshal(object);
044        }
045
046        /**
047         * {@inheritDoc}
048         */
049        /* @Override */
050        public Class<S> getBoundClass() {
051                return marshaller.getTargetClass();
052        }
053
054        /**
055         * {@inheritDoc}
056         */
057        /* @Override */
058        public Class<T> getTargetClass() {
059                return marshaller.getBoundClass();
060        }
061}