View Javadoc

1   /*
2    * Copyright 2005 by Mark Vollmann Hamburg, Germany. All rights reserved.
3    * 
4    * mail to mark.vollmann@web.de
5    * 
6    * Created on 05.07.2005
7    */
8   package de.keepondreaming.xml;
9   
10  import java.lang.reflect.Method;
11  
12  /***
13   *	Instances of this class provide a {@link de.keepondreaming.xml.XmlConverter}
14   *	with lookup methods to receive metadata information not obtainable
15   *	by runtime class information
16   * 
17   * $Author: wintermond $
18   * $Date: 2005/07/10 18:38:07 $
19   * $Log: AnnotationStrategy.java,v $
20   * Revision 1.1  2005/07/10 18:38:07  wintermond
21   * Renamed ParserStrategy to AnnotationStrategy
22   * Added support to annotate date format patterns
23   *
24   * Revision 1.3  2005/07/09 09:58:29  wintermond
25   * javadoc
26   *
27   */
28  public interface AnnotationStrategy
29  {
30      /***
31       * This method is called whenever the {@link XmlConverter} wants to set contents read 
32       * by the {@link org.xml.sax.ContentHandler#characters(char[], int, int)}-method.
33       * The {@link XmlConverter} needs the attribute name designated for the content to lookup
34       * the corresponding setter method.
35       * <p>
36       * <code>clazz</code> is guaranteed to be not null
37       * 
38       * @param clazz  Name of the current class, never null
39       * @param object  The current objct processed
40       * 
41       * @return The name of the method set receives the untagged contents
42       */
43      public String getContentAttribute(Class clazz, Object object);
44      
45      /***
46       * Called by the {@link XmlConverter} if an entry has to be set in a {@link java.util.Map}.
47       * <p>
48       * The name of the attribute containing the key identifier gets returned.
49       * <p>
50       * <b>Note: At the moment the key attribute must be of type {@link String} and the attribute must
51       * be read as an attribute, not as a sub tag!</b>
52       * <p>
53       * This means that
54       * <p>
55       * &lt;myTag&gt;&lt;myKeyAttribute&gt;myKeyValue&lt;/myKeyAttribute&gt;&lt;/myTag&gt; will not work, use instead 
56       * <p>
57       * &lt;myTag myKeyAttribute="myKeyValue"&gt;
58       * 
59       * @param method Method returning a {@link java.util.Map}
60       * 
61       * @return The attribute name of the Class storing the key-value 
62       */
63      public String getKeyAttribute(Method method);
64      
65      /***
66       * This method is called whenever the {@link XmlConverter} wants to set the contents 
67       * of a {@link java.util.Collection}- or {@link java.util.Map}-return type.
68       * <p> 
69       * The method returns the base class all stored elements must be assignable to.
70       * <p>
71       * <b>Note that the {@link ProxyObjectStrategy}
72       * requires the returned class types to be interfaces</b>.  
73       * 
74       * @param method Getter method returning a{@link java.util.Collection} or {@link java.util.Map}
75       * 
76       * @return An class of the element classes stored within.
77       */
78      public Class getGenericReturnType(Method method);
79  
80     /***
81      * This method is called whenever the {@link XmlConverter} reads a String
82      * for a method returning a {@link java.util.Date} or one of its subclasses. 
83      * Values can be either longs or formatted strings, which have to be converted to
84      * longs.
85      * <p>
86      * This method returns the formatting string, or null if values are expected as longs
87      * 
88      * @param method Getter method returning a {@link java.util.Date} or one of its subclasses
89      * 
90      * @return A Date format string or null
91      */
92      public String getDateFormatPattern(Method method);
93  
94      /***
95       * Restore initial state
96       */
97      public void init();
98      
99  }