001/* 002 * Copyright 2010, 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.binding; 017 018import org.jadira.bindings.core.api.Binding; 019import org.jadira.bindings.core.api.FromUnmarshaller; 020 021/** 022 * Binding that supports a from contract but not to 023 * @param <S> Source type for the conversion 024 * @param <T> Target type 025 */ 026public class FromBinding<S, T> implements Binding<S, T> { 027 028 private final FromUnmarshaller<S, T> unmarshal; 029 030 /** 031 * Create a new instance of a {@link Binding} wrapping the given {@link FromUnmarshaller} instance 032 * @param unmarshal The FromUnmarshaller to wrap 033 */ 034 public FromBinding(FromUnmarshaller<S, T> unmarshal) { 035 036 if (unmarshal == null) { 037 throw new IllegalStateException("Unmarshaller may not be null"); 038 } 039 040 this.unmarshal = unmarshal; 041 } 042 043 /** 044 * {@inheritDoc} 045 */ 046 /* @Override */ 047 public T marshal(S object) throws UnsupportedOperationException { 048 throw new UnsupportedOperationException("FromBinding does not support marshalling"); 049 } 050 051 /** 052 * {@inheritDoc} 053 */ 054 /* @Override */ 055 public S unmarshal(T inputString) { 056 return unmarshal.unmarshal(inputString); 057 } 058 059 /** 060 * {@inheritDoc} 061 */ 062 /* @Override */ 063 public Class<S> getBoundClass() { 064 return unmarshal.getBoundClass(); 065 } 066 067 /** 068 * {@inheritDoc} 069 */ 070 /* @Override */ 071 public Class<T> getTargetClass() { 072 return unmarshal.getTargetClass(); 073 } 074}