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.converter;
017
018import org.jadira.bindings.core.api.Converter;
019import org.jadira.bindings.core.api.ToMarshaller;
020
021/**
022 * A converter that wraps a marshaller to convert the marshaller for type S into a converter for type S to type S
023 * @param <S> input type
024 * @param <T> output type for the marshaller
025 */
026public class ToMarshallerConverter<S,T> implements Converter<S,T> {
027
028        private ToMarshaller<S,T> marshaller;
029
030        /**
031         * Create a new instance of a {@link Converter} wrapping the given {@link ToMarshaller}
032         * @param marshaller The ToMarshaller to wrap
033         */
034        public ToMarshallerConverter(ToMarshaller<S,T> marshaller) {
035                this.marshaller = marshaller;
036        }
037        
038        /**
039         * {@inheritDoc}
040         */
041        /* @Override */
042        public T convert(S inputObject) {
043                return marshaller.marshal(inputObject);
044        }
045
046        /**
047         * Get the wrapped marshaller
048         * @return the wrapped marshaller
049         */
050        public ToMarshaller<S, T> getMarshaller() {
051                return marshaller;
052        }
053
054        /**
055         * {@inheritDoc}
056         */
057        /* @Override */
058        public Class<S> getInputClass() {
059                return marshaller.getBoundClass();
060        }
061
062        /**
063         * {@inheritDoc}
064         */
065        /* @Override */
066        public Class<T> getOutputClass() {
067                return marshaller.getTargetClass();
068        }
069}