View Javadoc

1   /*
2    * Copyright 2008-2009 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.entropysoft.transmorph;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  import net.entropysoft.transmorph.context.ConvertedObjectPool;
22  import net.entropysoft.transmorph.context.UsedConverters;
23  
24  /**
25   * The conversion context.
26   * 
27   * <p>
28   * You can add custom objects to the context using add method.
29   * </p>
30   * 
31   * @author Cedric Chabanois (cchabanois at gmail.com)
32   * 
33   */
34  public class ConversionContext {
35  	private ConvertedObjectPool convertedObjectPool = new ConvertedObjectPool();
36  	private Map<String, Object> map = new HashMap<String, Object>();
37  	private UsedConverters usedConverters = new UsedConverters();
38  	private boolean storeUsedConverters = false;
39  
40  	public boolean isStoreUsedConverters() {
41  		return storeUsedConverters;
42  	}
43  
44  	public void setStoreUsedConverters(boolean storeUsedConverters) {
45  		this.storeUsedConverters = storeUsedConverters;
46  	}
47  
48  	/**
49  	 * get the pool of converted objects
50  	 * 
51  	 * @return
52  	 */
53  	public ConvertedObjectPool getConvertedObjectPool() {
54  		return convertedObjectPool;
55  	}
56  
57  	/**
58  	 * get the converters that have been used for conversion
59  	 * 
60  	 * @return
61  	 */
62  	public UsedConverters getUsedConverters() {
63  		return usedConverters;
64  	}
65  
66  	/**
67  	 * add an object to the context
68  	 * 
69  	 * @param key
70  	 * @param value
71  	 */
72  	public void add(String key, Object value) {
73  		map.put(key, value);
74  	}
75  
76  	/**
77  	 * get object from the context
78  	 * 
79  	 * @param key
80  	 */
81  	public void get(String key) {
82  		map.get(key);
83  	}
84  
85  	/**
86  	 * remove object from the context
87  	 * 
88  	 * @param key
89  	 */
90  	public void remove(String key) {
91  		map.remove(key);
92  	}
93  
94  }