View Javadoc

1   /*
2    * Copyright 2004-2008 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 java.lang.reflect.Method;
19  import java.util.Map;
20  
21  import org.seasar.cubby.action.FormatPattern;
22  import org.seasar.cubby.controller.CubbyConfiguration;
23  import org.seasar.cubby.controller.ThreadContext;
24  import org.seasar.extension.dxo.annotation.AnnotationReader;
25  import org.seasar.extension.dxo.annotation.AnnotationReaderFactory;
26  import org.seasar.framework.util.StringUtil;
27  
28  /**
29   * 
30   * @author baba
31   * 
32   */
33  public class RequestParameterAnnotationReaderFactoryWrapper implements
34  		AnnotationReaderFactory {
35  
36  	private AnnotationReaderFactory annotationReaderFactory;
37  
38  	public void setAnnotationReaderFactory(
39  			final AnnotationReaderFactory annotationReaderFactory) {
40  		this.annotationReaderFactory = annotationReaderFactory;
41  	}
42  
43  	public AnnotationReader getAnnotationReader() {
44  		final AnnotationReader annotationReader = annotationReaderFactory
45  				.getAnnotationReader();
46  		final CubbyConfiguration configuration = ThreadContext
47  				.getConfiguration();
48  		return new CubbyAnnotationReaderWrapper(annotationReader, configuration
49  				.getFormatPattern());
50  	}
51  
52  	static class CubbyAnnotationReaderWrapper implements AnnotationReader {
53  
54  		private final AnnotationReader annotationReader;
55  
56  		private final FormatPattern formatPattern;
57  
58  		public CubbyAnnotationReaderWrapper(
59  				final AnnotationReader annotationReader,
60  				final FormatPattern formatPattern) {
61  			this.annotationReader = annotationReader;
62  			this.formatPattern = formatPattern;
63  		}
64  
65  		@SuppressWarnings("unchecked")
66  		public String getDatePattern(final Class dxoClass, final Method method) {
67  			String datePattern = annotationReader.getDatePattern(dxoClass,
68  					method);
69  			if (StringUtil.isEmpty(datePattern) && formatPattern != null) {
70  				datePattern = formatPattern.getDatePattern();
71  			}
72  			return datePattern;
73  		}
74  
75  		@SuppressWarnings("unchecked")
76  		public String getTimePattern(final Class dxoClass, final Method method) {
77  			String timePattern = annotationReader.getTimePattern(dxoClass,
78  					method);
79  			if (StringUtil.isEmpty(timePattern) && formatPattern != null) {
80  				timePattern = formatPattern.getTimePattern();
81  			}
82  			return timePattern;
83  		}
84  
85  		@SuppressWarnings("unchecked")
86  		public String getTimestampPattern(final Class dxoClass,
87  				final Method method) {
88  			String timestampPattern = annotationReader.getTimestampPattern(
89  					dxoClass, method);
90  			if (StringUtil.isEmpty(timestampPattern) && formatPattern != null) {
91  				timestampPattern = formatPattern.getTimestampPattern();
92  			}
93  			return timestampPattern;
94  		}
95  
96  		@SuppressWarnings("unchecked")
97  		public String getConversionRule(final Class dxoClass,
98  				final Method method) {
99  			return annotationReader.getConversionRule(dxoClass, method);
100 		}
101 
102 		@SuppressWarnings("unchecked")
103 		public boolean isExcludeNull(final Class dxoClass, final Method method) {
104 			return annotationReader.isExcludeNull(dxoClass, method);
105 		}
106 
107 		@SuppressWarnings("unchecked")
108 		public Map getConverters(final Class destClass) {
109 			return annotationReader.getConverters(destClass);
110 		}
111 
112 		@SuppressWarnings("unchecked")
113 		public String getSourcePrefix(final Class dxoClass, final Method method) {
114 			return annotationReader.getSourcePrefix(dxoClass, method);
115 		}
116 
117 		@SuppressWarnings("unchecked")
118 		public String getDestPrefix(final Class dxoClass, final Method method) {
119 			return annotationReader.getDestPrefix(dxoClass, method);
120 		}
121 
122 	}
123 
124 }