1 | /* |
2 | * Copyright 2007 brunella ltd |
3 | * |
4 | * Licensed under the LGPL Version 3 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * |
7 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
8 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
9 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
10 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
11 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
12 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
13 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
14 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
15 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
16 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
17 | * THE POSSIBILITY OF SUCH DAMAGE. |
18 | */ |
19 | package sf.qof.customizer; |
20 | |
21 | import static sf.qof.codegen.Constants.TYPE_ArrayList; |
22 | import static sf.qof.codegen.Constants.TYPE_HashMap; |
23 | import static sf.qof.codegen.Constants.TYPE_HashSet; |
24 | |
25 | import org.objectweb.asm.Type; |
26 | |
27 | import sf.qof.session.UseSessionContext; |
28 | |
29 | /** |
30 | * Provides the default implementation to customize the generation process. |
31 | * |
32 | * @see Customizer |
33 | */ |
34 | public class DefaultCustomizer implements Customizer { |
35 | /** |
36 | * Customizes the type of <code>List</code> implementations. |
37 | * |
38 | * @return <code>ArrayList</code> type |
39 | * |
40 | * @see java.util.List |
41 | */ |
42 | public Type getListType() { |
43 | return TYPE_ArrayList; |
44 | } |
45 | |
46 | /** |
47 | * Customizes the type of <code>Map</code> implementations. |
48 | * |
49 | * @return <code>HashMap</code> type |
50 | * |
51 | * @see java.util.Map |
52 | */ |
53 | public Type getMapType() { |
54 | return TYPE_HashMap; |
55 | } |
56 | |
57 | /** |
58 | * Customizes the type of <code>Set</code> implementations. |
59 | * |
60 | * @return <code>HashSet</code> type |
61 | * |
62 | * @see java.util.Set |
63 | */ |
64 | public Type getSetType() { |
65 | return TYPE_HashSet; |
66 | } |
67 | |
68 | /** |
69 | * Customizes the class name of the generated query object. |
70 | * |
71 | * @param queryDefinitionClass query definition class or interface |
72 | * @return class name of the query definition class with "$Impl" appended |
73 | * @see Customizer#getClassName(Class) |
74 | */ |
75 | public String getClassName(Class<?> queryDefinitionClass) { |
76 | return queryDefinitionClass.getName() + "$Impl"; |
77 | } |
78 | |
79 | /** |
80 | * Customizes the implementation of getConnection() and setConnection() |
81 | * methods. |
82 | * |
83 | * @param queryDefinitionClass query definition class or interface |
84 | * @return a ConnectionFactoryCustomizer |
85 | * @see Customizer#getConnectionFactoryCustomizer(Class) |
86 | * @see ConnectionFactoryCustomizer |
87 | */ |
88 | public ConnectionFactoryCustomizer getConnectionFactoryCustomizer(Class<?> queryDefinitionClass) { |
89 | if (queryDefinitionClass.isAnnotationPresent(UseSessionContext.class)) { |
90 | return new SessionContextConnectionFactoryCustomizer(); |
91 | } else { |
92 | return new DefaultConnectionFactoryCustomizer(); |
93 | } |
94 | } |
95 | |
96 | } |