Show last authors
1 |(% style="color:#337ab7" %){{icon name="info-circle"/}} This page applied to GeDA **v.2.0.1+**, specifically module geda.spring-integration.
2
3 This short article briefly explains use of regex match and nomatch attribute of annotation driven tag.
4
5 == Overview ==
6
7 GeDA 2.0.1 offers a way to fine tune the advices method matching by providing two new attributes. A sample configuration may look something like this:
8
9 (((
10 {{code language="XML"}}
11 <beans xmlns="http://www.springframework.org/schema/beans"
12 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
13 xmlns:geda="http://geda-genericdto.svn.sourceforge.net/svnroot/geda-genericdto/schema"
14 xsi:schemaLocation="http://www.springframework.org/schema/beans
15 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
16 http://geda-genericdto.svn.sourceforge.net/svnroot/geda-genericdto/schema
17 http://geda-genericdto.svn.sourceforge.net/svnroot/geda-genericdto/schema/geda-spring-integration-1.1.xsd">
18
19 <geda:annotation-driven dto-factory="dtoFactory"
20 dto-adapters-registrar="adapterRegistrar"
21 use-bean-preprocessor="true"
22 pointcut-match-regex="com.inspiresoftware.lib.dto.geda.test.impl.TestService.*"/>
23
24 <bean id="dtoFactory" class="com.inspiresoftware.lib.dto.geda.impl.DTOFactoryImpl">
25 <constructor-arg>
26 <map>
27 <entry key="entityKey" value="com.inspiresoftware.lib.dto.geda.test.impl.DomainObjectImpl"/>
28 <entry key="dtoKey" value="com.inspiresoftware.lib.dto.geda.test.impl.ExtendedDataTransferObjectImpl"/>
29 <entry key="filterKey" value="com.inspiresoftware.lib.dto.geda.test.impl.DataTransferObjectImpl"/>
30 </map>
31 </constructor-arg>
32 </bean>
33
34 <bean id="simpleTransferableService"
35 class="com.inspiresoftware.lib.dto.geda.test.impl.TestServiceImpl"/>
36 <bean id="simpleTransferableNoMatchService"
37 class="com.inspiresoftware.lib.dto.geda.test.impl.TestNoMatchServiceImpl"/>
38
39 <bean id="adapterRegistrar" class="com.inspiresoftware.lib.dto.geda.test.impl.ExposedDTOAdaptersRegistrarImpl">
40 <constructor-arg>
41 <map>
42 <entry key="vc" value-ref="adapterValueConverter"/>
43 <entry key="er" value-ref="adapterEntityRetriever"/>
44 <entry key="ma" value-ref="adapterMatcher"/>
45 </map>
46 </constructor-arg>
47 </bean>
48
49 <bean id="adapterValueConverter" class="com.inspiresoftware.lib.dto.geda.test.impl.ValueConverterImpl"/>
50 <bean id="adapterEntityRetriever" class="com.inspiresoftware.lib.dto.geda.test.impl.EntityRetrieverImpl"/>
51 <bean id="adapterMatcher" class="com.inspiresoftware.lib.dto.geda.test.impl.DtoToEntityMatcherImpl"/>
52
53 </beans>
54 {{/code}}
55 )))
56
57 In the above example the match regex is set to:pointcut-match-regex="com.inspiresoftware.lib.dto.geda.test.impl.TestService.*"
58
59 Which means that in this particular case on service bean with id "simpleTransferableService" will be eligible to be enriched with AOP advice. The service bean with id "simpleTransferableNoMatchService" will not however even though the underlaying implementation has the same annotations that the simpleTransferableService does (see junit of the module).
60
61 |(% style="color:#337ab7" %){{icon name="info-circle"/}} Therefore we are able to fine tune which bean we need to support DTO transfer and which ones should not.
62 **This is especially useful in complex Spring applications when different AOP advices may be in conflict or where GeDA advice will produce adverse effect of starting transactions, say with hibernate lazy objects**
63
64 Similarly we can use the "pointcut-nomatch-regex" property to **exclude** whatever get captures by the "pointcut-match-regex".
65
66 |(% style="color:red" %){{icon name="times-circle"/}} "pointcut-nomatch-regex" only has effect when "pointcut-match-regex" is specified. This is by design and is a limitation imposed by the Spring AOP framework.
67
68 Here is an example of nomatch configuration:
69
70 (((
71 {{code language="XML"}}
72 <beans xmlns="http://www.springframework.org/schema/beans"
73 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
74 xmlns:geda="http://geda-genericdto.svn.sourceforge.net/svnroot/geda-genericdto/schema"
75 xsi:schemaLocation="http://www.springframework.org/schema/beans
76 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
77 http://geda-genericdto.svn.sourceforge.net/svnroot/geda-genericdto/schema
78 http://geda-genericdto.svn.sourceforge.net/svnroot/geda-genericdto/schema/geda-spring-integration-1.1.xsd">
79
80 <geda:annotation-driven dto-factory="dtoFactory"
81 dto-adapters-registrar="adapterRegistrar"
82 use-bean-preprocessor="true"
83 pointcut-match-regex="com.inspiresoftware.lib.dto.geda.test.*"
84 pointcut-nomatch-regex="com.inspiresoftware.lib.dto.geda.test.impl.TestNoMatch.*,com.inspiresoftware.lib.dto.geda.test.TestNoMatch.*"/>
85
86 <bean id="dtoFactory" class="com.inspiresoftware.lib.dto.geda.impl.DTOFactoryImpl">
87 <constructor-arg>
88 <map>
89 <entry key="entityKey" value="com.inspiresoftware.lib.dto.geda.test.impl.DomainObjectImpl"/>
90 <entry key="dtoKey" value="com.inspiresoftware.lib.dto.geda.test.impl.ExtendedDataTransferObjectImpl"/>
91 <entry key="filterKey" value="com.inspiresoftware.lib.dto.geda.test.impl.DataTransferObjectImpl"/>
92 </map>
93 </constructor-arg>
94 </bean>
95
96 <bean id="simpleTransferableService"
97 class="com.inspiresoftware.lib.dto.geda.test.impl.TestServiceImpl"/>
98 <bean id="simpleTransferableNoMatchService"
99 class="com.inspiresoftware.lib.dto.geda.test.impl.TestNoMatchServiceImpl"/>
100
101 <bean id="adapterRegistrar" class="com.inspiresoftware.lib.dto.geda.test.impl.ExposedDTOAdaptersRegistrarImpl">
102 <constructor-arg>
103 <map>
104 <entry key="vc" value-ref="adapterValueConverter"/>
105 <entry key="er" value-ref="adapterEntityRetriever"/>
106 <entry key="ma" value-ref="adapterMatcher"/>
107 </map>
108 </constructor-arg>
109 </bean>
110
111 <bean id="adapterValueConverter" class="com.inspiresoftware.lib.dto.geda.test.impl.ValueConverterImpl"/>
112 <bean id="adapterEntityRetriever" class="com.inspiresoftware.lib.dto.geda.test.impl.EntityRetrieverImpl"/>
113 <bean id="adapterMatcher" class="com.inspiresoftware.lib.dto.geda.test.impl.DtoToEntityMatcherImpl"/>
114
115 </beans>
116 {{/code}}
117 )))
118
119 |(% style="color:#337ab7" %){{icon name="info-circle"/}} Note from the example that it is possible to create a list of regex expressions by separating then with a comma.
GeDA - Generic DTO Assembler © Denys Pavlov 2009 - 2019
v.1.0.0