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 * A marshaller that wraps an unmarshaller to convert the unmarshaller for type T into a marshaller for type S 023 * @param <S> source type 024 * @param <T> output type for the marshaller 025 */ 026public class UnmarshallerToMarshaller<S, T> implements ToMarshaller<S, T> { 027 028 private FromUnmarshaller<T, S> unmarshaller; 029 030 /** 031 * Create a new instance of a {@link ToMarshaller} wrapping the given {@link FromUnmarshaller} 032 * @param unmarshaller The FromUnmarshaller to wrap 033 */ 034 public UnmarshallerToMarshaller(FromUnmarshaller<T, S> unmarshaller) { 035 this.unmarshaller = unmarshaller; 036 } 037 038 /** 039 * {@inheritDoc} 040 */ 041 /* @Override */ 042 public T marshal(S object) { 043 return unmarshaller.unmarshal(object); 044 } 045 046 /** 047 * {@inheritDoc} 048 */ 049 /* @Override */ 050 public Class<S> getBoundClass() { 051 return unmarshaller.getTargetClass(); 052 } 053 054 /** 055 * {@inheritDoc} 056 */ 057 /* @Override */ 058 public Class<T> getTargetClass() { 059 return unmarshaller.getBoundClass(); 060 } 061}