/*
 * Orika - simpler, better and faster Java bean mapping
 * 
 * Copyright (C) 2011 Orika authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package ma.glasnost.orika;

import java.util.HashMap;
import java.util.Map;

public class MappingContext {

	private final Map<Class<?>, Class<?>> mapping;
	private final Map<Object, Object> cache;

	public MappingContext() {
		mapping = new HashMap<Class<?>, Class<?>>();
		cache = new HashMap<Object, Object>();
	}

	@SuppressWarnings("unchecked")
	public <S, D> Class<? extends D> getConcreteClass(Class<S> sourceClass, Class<D> destinationClass) {

		Class<?> clazz = mapping.get(sourceClass);
		if (clazz != null && destinationClass.isAssignableFrom(clazz)) {
			return (Class<? extends D>) clazz;
		}
		return null;
	}

	public <S, D> void cacheMappedObject(S source, D destination) {
		cache.put(source, destination);
	}

	public <S> boolean isAlreadyMapped(S source) {
		return cache.containsKey(source);
	}

	public Object getMappedObject(Object source) {
		return cache.get(source);
	}
}

@@ -787,19 +787,26 @@
 text %7B%0D%0A
-%0D%0A%09
+    %0D%0A    
 private 
@@ -845,17 +845,20 @@
 pping;%0D%0A
-%09
+    
 private 
@@ -891,19 +891,26 @@
 cache;%0D%0A
-%0D%0A%09
+    %0D%0A    
 public M
@@ -928,18 +928,24 @@
 xt() %7B%0D%0A
-%09%09
+        
 mapping 
@@ -982,18 +982,24 @@
 ?%3E%3E();%0D%0A
-%09%09
+        
 cache = 
@@ -1030,23 +1030,33 @@
 ct%3E();%0D%0A
-%09%7D%0D%0A%0D%0A%09
+    %7D%0D%0A    %0D%0A    
 @Suppres
@@ -1079,17 +1079,20 @@
 cked%22)%0D%0A
-%09
+    
 public %3C
@@ -1185,20 +1185,34 @@
 ass) %7B%0D%0A
-%0D%0A%09%09
+        %0D%0A        
 Class%3C?%3E
@@ -1247,18 +1247,24 @@
 lass);%0D%0A
-%09%09
+        
 if (claz
@@ -1325,11 +1325,20 @@
  %7B%0D%0A
-%09%09%09
+            
 retu
@@ -1373,36 +1373,210 @@
 z;%0D%0A
-%09%09%7D%0D%0A%09%09return null;%0D%0A%09%7D%0D%0A%0D%0A%09
+        %7D%0D%0A        return null;%0D%0A    %7D%0D%0A    %0D%0A    public void registerConcreteClass(Class%3C?%3E subjectClass, Class%3C?%3E concreteClass) %7B%0D%0A        mapping.put(subjectClass, concreteClass);%0D%0A    %7D%0D%0A    %0D%0A    
 publ
@@ -1636,18 +1636,24 @@
 ion) %7B%0D%0A
-%09%09
+        
 cache.pu
@@ -1673,31 +1673,41 @@
 tination);%0D%0A
-%09%7D%0D%0A%0D%0A%09
+    %7D%0D%0A    %0D%0A    
 public %3CS%3E b
@@ -1734,34 +1734,40 @@
 ed(S source) %7B%0D%0A
-%09%09
+        
 return cache.con
@@ -1789,15 +1789,25 @@
 );%0D%0A
-%09%7D%0D%0A%0D%0A%09
+    %7D%0D%0A    %0D%0A    
 publ
@@ -1854,10 +1854,16 @@
  %7B%0D%0A
-%09%09
+        
 retu
@@ -1889,9 +1889,12 @@
 );%0D%0A
-%09
+    
 %7D%0D%0A%7D

Add register a concrete class for one mapping operation