Skip to content

Commit cd8a638

Browse files
committed
SESPRINGPYTHONPY-62: Added new documentation showing XML usage.
git-svn-id: https://src.springframework.org/svn/se-springpython-py/trunk/springpython@458 ce8fead1-4192-4296-8608-a705134b927f
1 parent f439895 commit cd8a638

4 files changed

Lines changed: 98 additions & 15 deletions

File tree

docs/reference/src/aop.xml

Lines changed: 93 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,35 @@ service = SampleService()
3636
print service.method("something")
3737
3838
"You sent me 'something'"
39-
]]></programlisting>
40-
41-
<para>Now, let's write an interceptor that will catch any results, and wrap them
42-
with <![CDATA[<Wrapped>]]> tags.</para>
39+
]]></programlisting>
40+
41+
<para>To configure the same thing using the IoC container, put the following text into a file named
42+
<filename>app-context.xml</filename>.</para>
43+
44+
<programlisting><![CDATA[
45+
<?xml version="1.0" encoding="UTF-8"?>
46+
<objects xmlns="http://www.springframework.org/springpython/schema/objects"
47+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
48+
xsi:schemaLocation="http://www.springframework.org/springpython/schema/objects
49+
http://springpython.webfactional.com/schema/context/spring-python-context-1.0.xsd">
50+
51+
<object id="service" class="SampleService"/>
52+
53+
</objects>
54+
]]></programlisting>
55+
56+
<para>To instantiate the IoC container, use the following code.</para>
57+
58+
<programlisting><![CDATA[
59+
from springpython.context import ApplicationContext
60+
from springpython.config import XMLConfig
61+
62+
container = ApplicationContext(XMLConfig("app-context.xml"))
63+
service = container.get_object("service")
64+
]]></programlisting>
65+
66+
<para>You can use either mechanism to define an instance of your service. Now, let's write an interceptor
67+
that will catch any results, and wrap them with <![CDATA[<Wrapped>]]> tags.</para>
4368

4469
<programlisting><![CDATA[
4570
from springpython.aop import *
@@ -60,16 +85,53 @@ class WrappingInterceptor(MethodInterceptor):
6085
must be created and given to the client. One way to create this is by creating a
6186
<classname>ProxyFactory</classname>. The factory is used to identify the target service
6287
that is being intercepted. It is used to create the dynamic proxy object to give back to
63-
the client.</para>
88+
the client.</para>
89+
90+
<para>You can use the Spring Python APIs to directly create this proxied service.</para>
6491

6592
<programlisting><![CDATA[
6693
from springpython.aop import *
6794
factory = ProxyFactory()
6895
factory.target = SampleService()
6996
factory.interceptors.append(WrappingInterceptor())
7097
service = factory.getProxy()
71-
]]></programlisting>
72-
98+
]]></programlisting>
99+
100+
<para>Or, you can insert this definition into your <filename>app-context.xml</filename> file.</para>
101+
102+
<programlisting><![CDATA[
103+
<?xml version="1.0" encoding="UTF-8"?>
104+
<objects xmlns="http://www.springframework.org/springpython/schema/objects"
105+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
106+
xsi:schemaLocation="http://www.springframework.org/springpython/schema/objects
107+
http://springpython.webfactional.com/schema/context/spring-python-context-1.0.xsd">
108+
109+
<object id="targetService" class="SampleService"/>
110+
111+
<object id="serviceFactory" class="springpython.aop.ProxyFactory">
112+
<property name="target" ref="targetService"/>
113+
<property name="interceptors">
114+
<object class="WrappingInterceptor"/>
115+
</property>
116+
</object>
117+
118+
</objects>
119+
]]></programlisting>
120+
121+
<para>If you notice, the original Spring Python "service" object has been renamed as "targetService", and there is, instead,
122+
another object called "serviceFactory" which is a Spring AOP ProxyFactory. It points to the target service and also has an
123+
interceptor plugged in. In this case, the interceptor is defined as an inner object, not having a name of its own,
124+
indicating it is not meant to be referenced outside the IoC container. When you get a hold of this, you can request a proxy.</para>
125+
126+
<programlisting><![CDATA[
127+
from springpython.context import ApplicationContext
128+
from springpython.config import XMLConfig
129+
130+
container = ApplicationContext(XMLConfig("app-context.xml"))
131+
serviceFactory = container.get_object("serviceFactory")
132+
service = serviceFactory.getProxy()
133+
]]></programlisting>
134+
73135
<para>Now, the client can call <emphasis>service</emphasis>, and all function calls will
74136
be routed to <classname>SampleService</classname> with one simple detour through
75137
<classname>WrappingInterceptor</classname>.</para>
@@ -85,8 +147,8 @@ print service.method("something")
85147
dynamic nature, Spring Python AOP gives you the power to wrap your own source code
86148
as well as other 3rd party modules.</para>
87149

88-
</section>
89-
150+
</section>
151+
90152
<section id="aop-proxy-factory-objects">
91153
<title>Proxy Factory Objects</title>
92154

@@ -102,8 +164,29 @@ service.interceptors = [WrappingInterceptor()]
102164
print service.method(" proxy factory object")
103165
104166
"You sent me a 'proxy factory object'"
105-
]]></programlisting>
167+
]]></programlisting>
168+
169+
<para>To configure the same thing into your <filename>app-context.xml</filename> file, it looks like this:</para>
106170

171+
<programlisting><![CDATA[
172+
<?xml version="1.0" encoding="UTF-8"?>
173+
<objects xmlns="http://www.springframework.org/springpython/schema/objects"
174+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
175+
xsi:schemaLocation="http://www.springframework.org/springpython/schema/objects
176+
http://springpython.webfactional.com/schema/context/spring-python-context-1.0.xsd">
177+
178+
<object id="targetService" class="SampleService"/>
179+
180+
<object id="service" class="springpython.aop.ProxyFactoryObject">
181+
<property name="target" ref="targetService"/>
182+
<property name="interceptors">
183+
<object class="WrappingInterceptor"/>
184+
</property>
185+
</object>
186+
187+
</objects>
188+
]]></programlisting>
189+
107190
<para>In this case, the <classname>ProxyFactoryObject</classname> acts as both a proxy
108191
and a factory. As a proxy, it behaves just like the target service would, and it also provides
109192
the ability to wrap the service with aspects. It saved us a step of coding, but more importantly,

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>springpython.webfactional.com</groupId>
66
<artifactId>springpython</artifactId>
7-
<version>0.9.1</version>
7+
<version>1.0.0</version>
88
<name>Spring Python</name>
99

1010
<description>

springpython.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# Collection of properties involved in managing Spring Python testing and packaging.
22

3-
version=0.9.1
3+
version=1.0.0
44
natural.name=se-springpython-py
55
project.key=EXT
66

77
# release, milestone or snapshot. Trunk is always snapshot for CI build
88
release.type=snapshot
99

1010
# This property is only un-commented and set for official tagged releases.
11-
#release.type=release
12-
#build.stamp=RELEASE
11+
release.type=release
12+
build.stamp=RC1
1313

1414
# This property is uncommented for milestone releases.
1515
#release.type=milestone

src/plugins/coily

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
"""
17-
__version__ = "0.9.1"
17+
__version__ = "1.0.0"
1818

1919
import os
2020
import re

0 commit comments

Comments
 (0)