1 package de.keepondreaming.xml;
2
3 import java.lang.reflect.Method;
4 import java.util.Map;
5 import java.util.Properties;
6
7 /***
8 * Obtains informations unavailable at runtime via a configuration object
9 * Property mappings are as follows:
10 * <ul>
11 * <li>Set date pattern: <Interface-name>.annotation.<method-name>.dateFormatPattern=<pattern in which {@link java.util.Date} attribute value is formated, <p>i.e. <code>de.keepondreaming.xml.example.Root.annotation.getEnd.dateFormatPattern=HH:mm:ss dd.MM.yyyy</code></li>
12 * <li>Set class type of {@link java.util.Collection}s and {@link Map}s:<interface-name>.annotation.<method name>.returnType, <p>i.e. <code>de.keepondreaming.xml.example.Root.annotation.getElements.returnType=de.keepondreaming.xml.example.Element</code></li>
13 * <li>Set key attribute used to add objects to {@link java.util.Map}:<interface-name>.annotation.<method-name>.keyAttribute<p> i.e. <code>de.keepondreaming.xml.example.Root.annotation.getElements.keyAttribute=string</code>
14 * <li>Specify attribute to set the contents read by {@link org.xml.sax.ContentHandler#characters(char[], int, int)}:<interface-name>.annotation.content=<attribute><p> i.e. <code>de.keepondreaming.xml.example.Remark.annotation.content=Remark</code>
15 * </ul>
16 *
17 * $Author: wintermond $
18 * $Date: 2005/07/10 18:39:35 $
19 * $Log: MappingAnnotationStrategy.java,v $
20 * Revision 1.1 2005/07/10 18:39:35 wintermond
21 * initial
22 *
23 */
24 public class MappingAnnotationStrategy implements AnnotationStrategy
25 {
26 /***
27 * mappings for needed informations
28 */
29 Properties mappingM;
30
31 /***
32 * Default constructor
33 *
34 * @param properties Must not be null
35 */
36 public MappingAnnotationStrategy(Properties properties)
37 {
38 if(properties == null)
39 {
40 throw new NullPointerException("properties is null");
41 }
42 mappingM = properties;
43 }
44
45
46
47
48 public String getContentAttribute(Class clazz, Object current)
49 {
50 String key = clazz.getName() + ".annotation.content";
51 String result = mappingM.getProperty(key);
52 return result;
53 }
54
55
56
57
58 public String getKeyAttribute(Method method)
59 {
60 String key = method.getDeclaringClass().getName()
61 + ".annotation."
62 + method.getName()
63 + ".keyAttribute";
64 String result = mappingM.getProperty(key);
65 return result;
66 }
67
68
69
70
71 public Class getGenericReturnType(Method method)
72 {
73 Class result = null;
74
75 String key = method.getDeclaringClass().getName()
76 + ".annotation."
77 + method.getName()
78 + ".returnType";
79 String className = mappingM.getProperty(key);
80
81 try
82 {
83 result = Class.forName(className);
84 }
85 catch (ClassNotFoundException ignore)
86 {
87
88 }
89 return result;
90 }
91
92
93
94
95 public String getDateFormatPattern(Method method)
96 {
97 String key = method.getDeclaringClass().getName()
98 + ".annotation."
99 + method.getName()
100 + ".dateFormatPattern";
101
102 String result = mappingM.getProperty(key);
103 return result;
104 }
105
106
107
108
109 public void init()
110 {
111
112
113 }
114
115 }