1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.portlet; |
16 |
| |
17 |
| import java.io.IOException; |
18 |
| import java.util.Locale; |
19 |
| |
20 |
| import javax.portlet.ActionRequest; |
21 |
| import javax.portlet.ActionResponse; |
22 |
| import javax.portlet.Portlet; |
23 |
| import javax.portlet.PortletConfig; |
24 |
| import javax.portlet.PortletException; |
25 |
| import javax.portlet.RenderRequest; |
26 |
| import javax.portlet.RenderResponse; |
27 |
| |
28 |
| import org.apache.hivemind.ClassResolver; |
29 |
| import org.apache.hivemind.Registry; |
30 |
| import org.apache.hivemind.Resource; |
31 |
| import org.apache.hivemind.impl.DefaultClassResolver; |
32 |
| import org.apache.hivemind.impl.RegistryBuilder; |
33 |
| import org.apache.hivemind.impl.XmlModuleDescriptorProvider; |
34 |
| import org.apache.tapestry.web.WebContext; |
35 |
| import org.apache.tapestry.web.WebContextResource; |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
| |
45 |
| |
46 |
| |
47 |
| public class ApplicationPortlet implements Portlet |
48 |
| { |
49 |
| Registry _registry; |
50 |
| |
51 |
| ActionRequestServicer _actionRequestServicer; |
52 |
| |
53 |
| RenderRequestServicer _renderRequestServicer; |
54 |
| |
55 |
2
| public void destroy()
|
56 |
| { |
57 |
2
| try
|
58 |
| { |
59 |
2
| _registry.shutdown();
|
60 |
| } |
61 |
| finally |
62 |
| { |
63 |
2
| _registry = null;
|
64 |
2
| _actionRequestServicer = null;
|
65 |
2
| _renderRequestServicer = null;
|
66 |
| } |
67 |
| } |
68 |
| |
69 |
8
| public void init(PortletConfig config) throws PortletException
|
70 |
| { |
71 |
8
| _registry = constructRegistry(config);
|
72 |
| |
73 |
8
| PortletApplicationInitializer initializer = (PortletApplicationInitializer) _registry
|
74 |
| .getService( |
75 |
| "tapestry.portlet.PortletApplicationInitializer", |
76 |
| PortletApplicationInitializer.class); |
77 |
| |
78 |
8
| initializer.initialize(config);
|
79 |
| |
80 |
8
| _actionRequestServicer = (ActionRequestServicer) _registry.getService(
|
81 |
| "tapestry.portlet.ActionRequestServicer", |
82 |
| ActionRequestServicer.class); |
83 |
| |
84 |
8
| _renderRequestServicer = (RenderRequestServicer) _registry.getService(
|
85 |
| "tapestry.portlet.RenderRequestServicer", |
86 |
| RenderRequestServicer.class); |
87 |
| } |
88 |
| |
89 |
| |
90 |
| |
91 |
| |
92 |
| |
93 |
| |
94 |
| |
95 |
| |
96 |
| |
97 |
| |
98 |
| |
99 |
| |
100 |
2
| protected Registry constructRegistry(PortletConfig config)
|
101 |
| { |
102 |
2
| RegistryBuilder builder = new RegistryBuilder();
|
103 |
| |
104 |
2
| ClassResolver resolver = new DefaultClassResolver();
|
105 |
| |
106 |
2
| builder.addModuleDescriptorProvider(new XmlModuleDescriptorProvider(resolver));
|
107 |
| |
108 |
2
| String name = config.getPortletName();
|
109 |
2
| WebContext context = new PortletWebContext(config.getPortletContext());
|
110 |
| |
111 |
2
| addModuleIfExists(builder, resolver, context, "/WEB-INF/" + name + "/hivemodule.xml");
|
112 |
2
| addModuleIfExists(builder, resolver, context, "/WEB-INF/hivemodule.xml");
|
113 |
| |
114 |
2
| return builder.constructRegistry(Locale.getDefault());
|
115 |
| } |
116 |
| |
117 |
| |
118 |
| |
119 |
| |
120 |
| |
121 |
| |
122 |
| |
123 |
| |
124 |
4
| protected void addModuleIfExists(RegistryBuilder builder, ClassResolver resolver,
|
125 |
| WebContext context, String path) |
126 |
| { |
127 |
4
| Resource r = new WebContextResource(context, path);
|
128 |
| |
129 |
4
| if (r.getResourceURL() == null)
|
130 |
0
| return;
|
131 |
| |
132 |
4
| builder.addModuleDescriptorProvider(new XmlModuleDescriptorProvider(resolver, r));
|
133 |
| } |
134 |
| |
135 |
2
| public void processAction(ActionRequest request, ActionResponse response)
|
136 |
| throws PortletException, IOException |
137 |
| { |
138 |
2
| try
|
139 |
| { |
140 |
2
| _registry.setupThread();
|
141 |
| |
142 |
2
| _actionRequestServicer.service(request, response);
|
143 |
| } |
144 |
| catch (RuntimeException ex) |
145 |
| { |
146 |
0
| throw new PortletException(PortletMessages.errorProcessingAction(ex), ex);
|
147 |
| } |
148 |
| finally |
149 |
| { |
150 |
2
| _registry.cleanupThread();
|
151 |
| } |
152 |
| } |
153 |
| |
154 |
2
| public void render(RenderRequest request, RenderResponse response) throws PortletException,
|
155 |
| IOException |
156 |
| { |
157 |
2
| try
|
158 |
| { |
159 |
2
| _registry.setupThread();
|
160 |
| |
161 |
2
| _renderRequestServicer.service(request, response);
|
162 |
| } |
163 |
| catch (RuntimeException ex) |
164 |
| { |
165 |
0
| throw new PortletException(PortletMessages.errorProcessingRender(ex), ex);
|
166 |
| } |
167 |
| finally |
168 |
| { |
169 |
2
| _registry.cleanupThread();
|
170 |
| } |
171 |
| } |
172 |
| } |