View Javadoc

1   /*
2    * Copyright 2004-2007 the Seasar Foundation and the Others.
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, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.cubby.dxo.impl;
17  
18  import org.seasar.extension.dxo.converter.ConversionContext;
19  import org.seasar.extension.dxo.converter.Converter;
20  import org.seasar.extension.dxo.converter.ConverterFactory;
21  
22  public class RequestParameterConverterFactoryWrapper implements
23  		ConverterFactory {
24  
25  	private ConverterFactory converterFactory;
26  
27  	public void setConverterFactory(final ConverterFactory converterFactory) {
28  		this.converterFactory = converterFactory;
29  	}
30  
31  	@SuppressWarnings("unchecked")
32  	public Converter getConverter(final Class sourceClass, final Class destClass) {
33  		final Converter converter = converterFactory.getConverter(sourceClass,
34  				destClass);
35  		return new DisregardExceptionConverterWrapper(converter);
36  	}
37  
38  	static class DisregardExceptionConverterWrapper implements Converter {
39  
40  		private final Converter converter;
41  
42  		public DisregardExceptionConverterWrapper(final Converter converter) {
43  			this.converter = converter;
44  		}
45  
46  		@SuppressWarnings("unchecked")
47  		public Object convert(final Object source, final Class destClass,
48  				final ConversionContext context) {
49  			try {
50  				return converter.convert(source, destClass, context);
51  			} catch (final Exception e) {
52  				return null;
53  			}
54  		}
55  
56  		public void convert(final Object source, final Object dest,
57  				final ConversionContext context) {
58  			converter.convert(source, dest, context);
59  		}
60  
61  		@SuppressWarnings("unchecked")
62  		public Class getDestClass() {
63  			return converter.getDestClass();
64  		}
65  
66  		@SuppressWarnings("unchecked")
67  		public Class[] getSourceClasses() {
68  			return converter.getSourceClasses();
69  		}
70  
71  	}
72  
73  }