View Javadoc

1   /*
2    * Copyright 2005 Mark Vollmann Hamburg, Germany. All rights reserved.
3    * 
4    * Created on 08.07.2005
5    */
6   package de.keepondreaming.xml.annotations;
7   
8   import java.lang.reflect.Method;
9   
10  import de.keepondreaming.xml.AnnotationStrategy;
11  
12  /***
13   *	Resolves annotations needed by the {@link de.keepondreaming.xml.XmlConverter}
14   *	by using the {@link java.lang.annotation.Annotation} mechanism, introduced
15   *	with Java 1.5, eg. Java 5 or also called Tiger
16   * 
17   * $Author: wintermond $
18   * $Date: 2005/07/10 18:34:58 $
19   * $Log: JavaAnnotationsStrategy.java,v $
20   * Revision 1.1  2005/07/10 18:34:58  wintermond
21   * Renamed from AnnotationsParserStrategy
22   * javadoc
23   *
24   */
25  public class JavaAnnotationsStrategy implements AnnotationStrategy
26  {
27  
28      /***
29       *  Default constructor 
30       */
31      public JavaAnnotationsStrategy()
32      {
33          super();
34          init();
35      }
36  
37      /* (non-Javadoc)
38       * @see de.keepondreaming.xml.AnnotationStrategy#getContentAttribute(java.lang.Class, java.lang.Object)
39       */
40      @SuppressWarnings({"unchecked"})
41      public String getContentAttribute(Class unused, Object object)
42      {
43          String result = "Content";
44          ContentAttribute contentAttribute = (ContentAttribute) object.getClass().getInterfaces()[0].getAnnotation(ContentAttribute.class);
45          
46          if(contentAttribute != null)
47          {
48              result = contentAttribute.contentMethod();
49          }
50          return result;
51  
52      }
53  
54      /* (non-Javadoc)
55       * @see de.keepondreaming.xml.AnnotationStrategy#getKeyAttribute(java.lang.reflect.Method)
56       */
57      public String getKeyAttribute(Method method)
58      {
59          String result = null;
60          if(method.isAnnotationPresent(SetKeyAttribute.class))
61          {
62              result = method.getAnnotation(SetKeyAttribute.class).keyAttribute();
63          }
64          return result;
65  
66      }
67  
68      /* (non-Javadoc)
69       * @see de.keepondreaming.xml.AnnotationStrategy#getGenericReturnType(java.lang.reflect.Method)
70       */
71      public Class getGenericReturnType(Method method)
72      {
73          Class result = null;
74          if(method.isAnnotationPresent(ReturnTypeAnnotation.class))
75          {
76              result = method.getAnnotation(ReturnTypeAnnotation.class).genericClass();
77          }
78          return result;
79      }
80  
81  	/* (non-Javadoc)
82  	 * @see de.keepondreaming.xml.AnnotationStrategy#getDateFormatPattern(java.lang.reflect.Method)
83  	 */
84  	public String getDateFormatPattern(Method method)
85  	{
86  		String result = null;
87  		if(method.isAnnotationPresent(DateFormat.class))
88          {
89              result = method.getAnnotation(DateFormat.class).formatString();
90          }
91  		return result;
92  	}
93  
94  	/* (non-Javadoc)
95  	 * @see de.keepondreaming.xml.AnnotationStrategy#init()
96  	 */
97  	public void init()
98  	{
99  		// nothing to do		
100 	}
101 
102 
103 
104 }