Commit 5830b1d90a2b20a43ae37ca7d021c4346027e15c
1 parent
b39acb64
Exists in
master
Implementando melhorias para iniciar uma aplicação SE com CDI.
Showing
12 changed files
with
788 additions
and
35 deletions
Show diff stats
impl/extension/se/pom.xml
@@ -66,6 +66,11 @@ | @@ -66,6 +66,11 @@ | ||
66 | <artifactId>weld-se-core</artifactId> | 66 | <artifactId>weld-se-core</artifactId> |
67 | <scope>test</scope> | 67 | <scope>test</scope> |
68 | </dependency> | 68 | </dependency> |
69 | + <dependency> | ||
70 | + <groupId>org.slf4j</groupId> | ||
71 | + <artifactId>slf4j-log4j12</artifactId> | ||
72 | + <scope>test</scope> | ||
73 | + </dependency> | ||
69 | </dependencies> | 74 | </dependencies> |
70 | 75 | ||
71 | <licenses> | 76 | <licenses> |
impl/extension/se/src/main/java/br/gov/frameworkdemoiselle/Demoiselle.java
0 → 100644
@@ -0,0 +1,347 @@ | @@ -0,0 +1,347 @@ | ||
1 | +/* | ||
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
37 | +package br.gov.frameworkdemoiselle; | ||
38 | + | ||
39 | +import java.awt.EventQueue; | ||
40 | +import java.awt.event.WindowEvent; | ||
41 | +import java.awt.event.WindowListener; | ||
42 | +import java.lang.reflect.Method; | ||
43 | +import java.util.MissingResourceException; | ||
44 | +import java.util.ResourceBundle; | ||
45 | + | ||
46 | +import javax.swing.JFrame; | ||
47 | + | ||
48 | +import org.jboss.weld.environment.se.Weld; | ||
49 | +import org.jboss.weld.environment.se.WeldContainer; | ||
50 | + | ||
51 | +import br.gov.frameworkdemoiselle.bootstrap.MainClass; | ||
52 | +import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; | ||
53 | +import br.gov.frameworkdemoiselle.lifecycle.AfterStartupProccess; | ||
54 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
55 | + | ||
56 | +/** | ||
57 | + * Central class to bootstrap Demoiselle SE applications. | ||
58 | + * | ||
59 | + * @author serpro | ||
60 | + */ | ||
61 | +public class Demoiselle { | ||
62 | + | ||
63 | + private static final String BUNDLE_NAME = "demoiselle-se-bundle"; | ||
64 | + | ||
65 | + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); | ||
66 | + | ||
67 | + protected Demoiselle() { | ||
68 | + throw new UnsupportedOperationException(getString("se-util-instantiation-error")); | ||
69 | + } | ||
70 | + | ||
71 | + /** | ||
72 | + * <p> | ||
73 | + * Bootstrapper that initializes the framework and call a main method. This method will ensure that the framework | ||
74 | + * facilities (CDI, etc.) are started before calling the application's real main method and that they are shut down | ||
75 | + * before the application's end. | ||
76 | + * </p> | ||
77 | + * <p> | ||
78 | + * To start an application using this method, execute the following code on a terminal: | ||
79 | + * </p> | ||
80 | + * | ||
81 | + * <pre> | ||
82 | + * ~$ java br.gov.frameworkdemoiselle.Demoiselle com.application.ClassWithMainMethod | ||
83 | + * </pre> | ||
84 | + * <p> | ||
85 | + * As you can see, you must pass the full qualified name of the class that has a main method as the first argument | ||
86 | + * of your application. | ||
87 | + * </p> | ||
88 | + * <p> | ||
89 | + * If your application needs more arguments, pass them normally after the class name. This method will remove the | ||
90 | + * class name of the argument list, so your real main method will se the first argument after the class name as | ||
91 | + * index 0 (zero) of the <code>args</code> parameter. Ex: | ||
92 | + * </p> | ||
93 | + * | ||
94 | + * <pre> | ||
95 | + * ~$ java br.gov.frameworkdemoiselle.Demoiselle com.application.ClassWithMainMethod firstArg secondArg | ||
96 | + * </pre> | ||
97 | + * <p> | ||
98 | + * Your application's main method will run as follow: | ||
99 | + * <p> | ||
100 | + * | ||
101 | + * <pre> | ||
102 | + * <code> | ||
103 | + * package com.application; | ||
104 | + * public class ClassWithMainMethod { | ||
105 | + * public static void main(String[] args){ | ||
106 | + * System.out.println(args[0]); //will print "firstArg" | ||
107 | + * System.out.println(args[1]); //will print "secondArg" | ||
108 | + * } | ||
109 | + * } | ||
110 | + * </code> | ||
111 | + * </pre> | ||
112 | + * | ||
113 | + * @param args | ||
114 | + * Arguments array. The first argument must be the full qualified name of the real class that has the | ||
115 | + * desired main method. All following arguments will be passed to the real main method. | ||
116 | + */ | ||
117 | + public static void main(String[] args) { | ||
118 | + if (args == null || args.length <= 0) { | ||
119 | + throw new DemoiselleException(getString("se-util-no-main-defined")); | ||
120 | + } | ||
121 | + | ||
122 | + Class<?> mainClass; | ||
123 | + try { | ||
124 | + mainClass = Class.forName(args[0]); | ||
125 | + } catch (ClassNotFoundException e) { | ||
126 | + throw new DemoiselleException(getString("se-util-invalid-main-defined"), e); | ||
127 | + } | ||
128 | + | ||
129 | + Weld weld = new Weld(); | ||
130 | + WeldContainer container = weld.initialize(); | ||
131 | + | ||
132 | + // Fire the AfterStartupProccess event. Methods annotated with @Startup will run now | ||
133 | + container.getBeanManager().fireEvent(new AfterStartupProccess() { | ||
134 | + }); | ||
135 | + | ||
136 | + String[] passedArgs = null; | ||
137 | + if (args.length > 1) { | ||
138 | + passedArgs = new String[args.length - 1]; | ||
139 | + System.arraycopy(args, 1, passedArgs, 0, args.length - 1); | ||
140 | + } | ||
141 | + | ||
142 | + Method mainMethod; | ||
143 | + try { | ||
144 | + mainMethod = mainClass.getMethod("main", String[].class); | ||
145 | + } catch (Exception e) { | ||
146 | + throw new DemoiselleException(getString("se-util-invalid-main-defined"), e); | ||
147 | + } | ||
148 | + | ||
149 | + try { | ||
150 | + mainMethod.invoke(null, ((Object) passedArgs)); | ||
151 | + } catch (Exception e) { | ||
152 | + throw new DemoiselleException(getString("se-util-error-calling-main"), e); | ||
153 | + } finally { | ||
154 | + container.getBeanManager().fireEvent(new AfterShutdownProccess() { | ||
155 | + }); | ||
156 | + weld.shutdown(); | ||
157 | + } | ||
158 | + } | ||
159 | + | ||
160 | + /** | ||
161 | + * <p> | ||
162 | + * Bootstrapper that initializes the framework and call a predefined user method. This method will ensure that the | ||
163 | + * framework facilities (CDI, etc.) are started before calling the application's {@link MainClass#run(String[] args)} | ||
164 | + * method. | ||
165 | + * <p> | ||
166 | + * To use this method you need to do two things: | ||
167 | + * </p> | ||
168 | + * <ul> | ||
169 | + * <li>Create a concrete class that implements the {@link MainClass} interface</li> | ||
170 | + * <li>Create a <code>main</code> class that calls this method passing your <code>MainClass</code> as argument</li> | ||
171 | + * </ul> | ||
172 | + * <p> | ||
173 | + * Here is an example of bootstrap with this method. | ||
174 | + * </p> | ||
175 | + * | ||
176 | + * <pre> | ||
177 | + * <code> | ||
178 | + * package com.application; | ||
179 | + * | ||
180 | + * import br.gov.frameworkdemoiselle.bootstrap.MainClass; | ||
181 | + * | ||
182 | + * public class MyStarterClass implements MainClass { | ||
183 | + * | ||
184 | + * public static void main(String[] args){ | ||
185 | + * Demoiselle.runStarterClass(MyStarterClass.class , args); | ||
186 | + * } | ||
187 | + * | ||
188 | + * public void run(String[] args){ | ||
189 | + * //Real startup code runs here | ||
190 | + * } | ||
191 | + * | ||
192 | + * @Startup | ||
193 | + * protected void init(){ | ||
194 | + * //This method will be called by the framework before the <code>run</code> method runs | ||
195 | + * } | ||
196 | + * | ||
197 | + * @Shutdown | ||
198 | + * protected void cleanup(){ | ||
199 | + * //This method will be called by the framework after the <code>run</code> method | ||
200 | + * //finishes and before the application closes. | ||
201 | + * } | ||
202 | + * | ||
203 | + * } | ||
204 | + * </code> | ||
205 | + * </pre> | ||
206 | + * | ||
207 | + * @param args | ||
208 | + * Arguments array. It will be passed unmodified to the {@link MainClass#run(String[] args)} method. | ||
209 | + */ | ||
210 | + public static void runStarterClass(final Class<? extends MainClass> mainClass, String[] args) { | ||
211 | + Weld weld = new Weld(); | ||
212 | + WeldContainer container = weld.initialize(); | ||
213 | + | ||
214 | + // Fire the AfterStartupProccess event. Methods annotated with @Startup will run now | ||
215 | + container.getBeanManager().fireEvent(new AfterStartupProccess() { | ||
216 | + }); | ||
217 | + | ||
218 | + MainClass mainClassInstance = null; | ||
219 | + try { | ||
220 | + mainClassInstance = Beans.getReference(mainClass); | ||
221 | + mainClassInstance.run(args); | ||
222 | + } catch (Exception e) { | ||
223 | + mainClassInstance = null; | ||
224 | + throw new DemoiselleException(getString("se-util-error-calling-run"), e); | ||
225 | + } finally { | ||
226 | + container.getBeanManager().fireEvent(new AfterShutdownProccess() { | ||
227 | + }); | ||
228 | + weld.shutdown(); | ||
229 | + | ||
230 | + mainClassInstance = null; | ||
231 | + } | ||
232 | + } | ||
233 | + | ||
234 | + /** | ||
235 | + * <p> | ||
236 | + * Bootstraps CDI and starts a main window. This window will be instantiated using the default constructor and have | ||
237 | + * all of it's injections resolved before instantiation. Also any methods annotated with <code>@Startup</code> | ||
238 | + * and <code>@Shutdown</code> will run before this window is created and after this window is closed, | ||
239 | + * respectively. | ||
240 | + * </p> | ||
241 | + * <p> | ||
242 | + * The new window will be started on the AWT event dispatcher thread, so it follows the recomendation of creating a | ||
243 | + * single thread to show the user interface and dispatch events since Swing components aren't thread-safe. | ||
244 | + * </p> | ||
245 | + * <p> | ||
246 | + * <p> | ||
247 | + * A typical use case of this method is: | ||
248 | + * </p> | ||
249 | + * | ||
250 | + * <pre> | ||
251 | + * <code> | ||
252 | + * package com.application; | ||
253 | + * | ||
254 | + * public class MyMainWindow extends JFrame { | ||
255 | + * | ||
256 | + * //Main method | ||
257 | + * public static void main(String args[]){ | ||
258 | + * Demoiselle.runMainWindow(MyMainWindow.class); | ||
259 | + * } | ||
260 | + * | ||
261 | + * //Configures the window | ||
262 | + * public MyMainWindow(){ | ||
263 | + * super("My Main Window"); | ||
264 | + * } | ||
265 | + * | ||
266 | + * //This method will be called after the window is constructed | ||
267 | + * @PostConstruct | ||
268 | + * public void initComponents(){ | ||
269 | + * //Initializes components. | ||
270 | + * | ||
271 | + * setVisible(true); | ||
272 | + * } | ||
273 | + * | ||
274 | + * } | ||
275 | + * </code> | ||
276 | + * </pre> | ||
277 | + * | ||
278 | + * @param jFrameClass | ||
279 | + * Type of the window that will be created. | ||
280 | + */ | ||
281 | + public static void runMainWindow(final Class<? extends JFrame> jFrameClass) { | ||
282 | + final Weld weld = new Weld(); | ||
283 | + final WeldContainer container = weld.initialize(); | ||
284 | + | ||
285 | + EventQueue.invokeLater(new Runnable() { | ||
286 | + | ||
287 | + public void run() { | ||
288 | + container.getBeanManager().fireEvent(new AfterStartupProccess() { | ||
289 | + }); | ||
290 | + | ||
291 | + JFrame jframe = null; | ||
292 | + try { | ||
293 | + jframe = Beans.getReference(jFrameClass); | ||
294 | + | ||
295 | + if (jframe.getDefaultCloseOperation() == JFrame.HIDE_ON_CLOSE) { | ||
296 | + jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
297 | + } | ||
298 | + | ||
299 | + jframe.addWindowListener(new WindowListener() { | ||
300 | + | ||
301 | + @Override | ||
302 | + public void windowOpened(WindowEvent e) { | ||
303 | + } | ||
304 | + | ||
305 | + @Override | ||
306 | + public void windowIconified(WindowEvent e) { | ||
307 | + } | ||
308 | + | ||
309 | + @Override | ||
310 | + public void windowDeiconified(WindowEvent e) { | ||
311 | + } | ||
312 | + | ||
313 | + @Override | ||
314 | + public void windowDeactivated(WindowEvent e) { | ||
315 | + } | ||
316 | + | ||
317 | + @Override | ||
318 | + public void windowClosing(WindowEvent e) { | ||
319 | + container.getBeanManager().fireEvent(new AfterShutdownProccess() { | ||
320 | + }); | ||
321 | + weld.shutdown(); | ||
322 | + } | ||
323 | + | ||
324 | + @Override | ||
325 | + public void windowClosed(WindowEvent e) { | ||
326 | + } | ||
327 | + | ||
328 | + @Override | ||
329 | + public void windowActivated(WindowEvent e) { | ||
330 | + } | ||
331 | + }); | ||
332 | + } catch (Exception e) { | ||
333 | + throw new DemoiselleException(getString("se-util-error-starting-jframe"), e); | ||
334 | + } | ||
335 | + } | ||
336 | + }); | ||
337 | + } | ||
338 | + | ||
339 | + private static String getString(String key) { | ||
340 | + try { | ||
341 | + return RESOURCE_BUNDLE.getString(key); | ||
342 | + } catch (MissingResourceException e) { | ||
343 | + return '!' + key + '!'; | ||
344 | + } | ||
345 | + } | ||
346 | + | ||
347 | +} |
impl/extension/se/src/main/java/br/gov/frameworkdemoiselle/bootstrap/MainClass.java
0 → 100644
@@ -0,0 +1,58 @@ | @@ -0,0 +1,58 @@ | ||
1 | +/* | ||
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
37 | +package br.gov.frameworkdemoiselle.bootstrap; | ||
38 | + | ||
39 | +import br.gov.frameworkdemoiselle.Demoiselle; | ||
40 | + | ||
41 | +/** | ||
42 | + * Simple interface a class must implement to be started by the {@link Demoiselle#runStarterClass(Class, String[])} utility method. | ||
43 | + * | ||
44 | + * @author serpro | ||
45 | + * | ||
46 | + */ | ||
47 | +public interface MainClass { | ||
48 | + | ||
49 | + /** | ||
50 | + * <p>Bootstrap CDI and run startup code for your application. This method will | ||
51 | + * be automatically called when {@link Demoiselle#runStarterClass(Class, String[])} | ||
52 | + * is called passing this method's owner class.</p> | ||
53 | + * | ||
54 | + * @param args The same arguments received by your main method. | ||
55 | + */ | ||
56 | + void run(String[] args); | ||
57 | + | ||
58 | +} |
@@ -0,0 +1 @@ | @@ -0,0 +1 @@ | ||
1 | +Demoiselle.0=Essa classe utilitária não deve ser instanciada |
impl/extension/se/src/main/resources/demoiselle-se-bundle.properties
0 → 100644
@@ -0,0 +1,42 @@ | @@ -0,0 +1,42 @@ | ||
1 | +# Demoiselle Framework | ||
2 | +# Copyright (C) 2010 SERPRO | ||
3 | +# ---------------------------------------------------------------------------- | ||
4 | +# This file is part of Demoiselle Framework. | ||
5 | +# | ||
6 | +# Demoiselle Framework is free software; you can redistribute it and/or | ||
7 | +# modify it under the terms of the GNU Lesser General Public License version 3 | ||
8 | +# as published by the Free Software Foundation. | ||
9 | +# | ||
10 | +# This program is distributed in the hope that it will be useful, | ||
11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | +# GNU General Public License for more details. | ||
14 | +# | ||
15 | +# You should have received a copy of the GNU Lesser General Public License version 3 | ||
16 | +# along with this program; if not, see <http://www.gnu.org/licenses/> | ||
17 | +# or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
18 | +# Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | +# ---------------------------------------------------------------------------- | ||
20 | +# Este arquivo é parte do Framework Demoiselle. | ||
21 | +# | ||
22 | +# O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
23 | +# modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
24 | +# do Software Livre (FSF). | ||
25 | +# | ||
26 | +# Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
27 | +# GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
28 | +# APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
29 | +# para maiores detalhes. | ||
30 | +# | ||
31 | +# Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
32 | +# "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
33 | +# ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
34 | +# 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
35 | + | ||
36 | +se-util-instantiation-error=Essa classe utilit\u00E1ria n\u00E3o deve ser instanciada | ||
37 | +se-util-no-main-defined=\u00C9 necess\u00E1rio informar o nome completo da classe que cont\u00E9m o m\u00E9todo "public static void main" | ||
38 | +se-util-invalid-main-defined=A classe informada n\u00E3o cont\u00E9m um m\u00E9todo "public static void main" ou n\u00E3o existe | ||
39 | +se-util-invalid-class-defined=A classe informada n\u00E3o \u00E9 conhecida pelo container CDI ou n\u00E3o existe | ||
40 | +se-util-error-calling-main=N\u00E3o foi poss\u00EDvel iniciar a aplica\u00E7\u00E3o, o m\u00E9todo "main" disparou uma exce\u00E7\u00E3o ao ser invocado | ||
41 | +se-util-error-calling-run=N\u00E3o foi poss\u00EDvel iniciar a aplica\u00E7\u00E3o, o m\u00E9todo "start" disparou uma exce\u00E7\u00E3o ao ser invocado | ||
42 | +se-util-error-starting-jframe=N\u00E3o foi poss\u00EDvel criar a janela principal da aplica\u00E7\u00E3o. | ||
0 | \ No newline at end of file | 43 | \ No newline at end of file |
impl/extension/se/src/main/resources/demoiselle-swing-bundle.properties
@@ -1,35 +0,0 @@ | @@ -1,35 +0,0 @@ | ||
1 | -# Demoiselle Framework | ||
2 | -# Copyright (C) 2010 SERPRO | ||
3 | -# ---------------------------------------------------------------------------- | ||
4 | -# This file is part of Demoiselle Framework. | ||
5 | -# | ||
6 | -# Demoiselle Framework is free software; you can redistribute it and/or | ||
7 | -# modify it under the terms of the GNU Lesser General Public License version 3 | ||
8 | -# as published by the Free Software Foundation. | ||
9 | -# | ||
10 | -# This program is distributed in the hope that it will be useful, | ||
11 | -# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | -# GNU General Public License for more details. | ||
14 | -# | ||
15 | -# You should have received a copy of the GNU Lesser General Public License version 3 | ||
16 | -# along with this program; if not, see <http://www.gnu.org/licenses/> | ||
17 | -# or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
18 | -# Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | -# ---------------------------------------------------------------------------- | ||
20 | -# Este arquivo é parte do Framework Demoiselle. | ||
21 | -# | ||
22 | -# O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
23 | -# modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
24 | -# do Software Livre (FSF). | ||
25 | -# | ||
26 | -# Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
27 | -# GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
28 | -# APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
29 | -# para maiores detalhes. | ||
30 | -# | ||
31 | -# Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
32 | -# "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
33 | -# ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
34 | -# 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
35 | - |
impl/extension/se/src/test/java/bootstraper/ClassImplementingMainClass.java
0 → 100644
@@ -0,0 +1,78 @@ | @@ -0,0 +1,78 @@ | ||
1 | +/* | ||
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
37 | +package bootstraper; | ||
38 | + | ||
39 | +import javax.inject.Inject; | ||
40 | + | ||
41 | +import br.gov.frameworkdemoiselle.bootstrap.MainClass; | ||
42 | +import br.gov.frameworkdemoiselle.lifecycle.Shutdown; | ||
43 | +import br.gov.frameworkdemoiselle.lifecycle.Startup; | ||
44 | + | ||
45 | + | ||
46 | +public class ClassImplementingMainClass implements MainClass { | ||
47 | + | ||
48 | + public static String startupData; | ||
49 | + | ||
50 | + public static String shutdownData; | ||
51 | + | ||
52 | + public static String firstArgument; | ||
53 | + | ||
54 | + public static String lastArgument; | ||
55 | + | ||
56 | + public static String dataFromInjectedResource; | ||
57 | + | ||
58 | + @Inject | ||
59 | + public InjectedResource injectedResource; | ||
60 | + | ||
61 | + @Startup | ||
62 | + public void fillData(){ | ||
63 | + startupData = "filled"; | ||
64 | + } | ||
65 | + | ||
66 | + @Shutdown | ||
67 | + public void eraseData(){ | ||
68 | + shutdownData = "filled"; | ||
69 | + } | ||
70 | + | ||
71 | + @Override | ||
72 | + public void run(String[] args) { | ||
73 | + dataFromInjectedResource = injectedResource.getData(); | ||
74 | + firstArgument = args[0]; | ||
75 | + lastArgument = args[args.length-1]; | ||
76 | + } | ||
77 | + | ||
78 | +} |
impl/extension/se/src/test/java/bootstraper/ClassWithMain.java
0 → 100644
@@ -0,0 +1,73 @@ | @@ -0,0 +1,73 @@ | ||
1 | +/* | ||
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
37 | +package bootstraper; | ||
38 | + | ||
39 | +import br.gov.frameworkdemoiselle.lifecycle.Shutdown; | ||
40 | +import br.gov.frameworkdemoiselle.lifecycle.Startup; | ||
41 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
42 | + | ||
43 | + | ||
44 | +public class ClassWithMain { | ||
45 | + | ||
46 | + public static String startupData; | ||
47 | + | ||
48 | + public static String shutdownData; | ||
49 | + | ||
50 | + public static String firstArgument; | ||
51 | + | ||
52 | + public static String lastArgument; | ||
53 | + | ||
54 | + public static String dataFromInjectedResource; | ||
55 | + | ||
56 | + public static void main(String[] args){ | ||
57 | + InjectedResource injectedResource = Beans.getReference(InjectedResource.class); | ||
58 | + dataFromInjectedResource = injectedResource.getData(); | ||
59 | + firstArgument = args[0]; | ||
60 | + lastArgument = args[args.length-1]; | ||
61 | + } | ||
62 | + | ||
63 | + @Startup | ||
64 | + public void fillData(){ | ||
65 | + startupData = "filled"; | ||
66 | + } | ||
67 | + | ||
68 | + @Shutdown | ||
69 | + public void eraseData(){ | ||
70 | + shutdownData = "filled"; | ||
71 | + } | ||
72 | + | ||
73 | +} |
impl/extension/se/src/test/java/bootstraper/DemoiselleSeBootstrapTest.java
0 → 100644
@@ -0,0 +1,76 @@ | @@ -0,0 +1,76 @@ | ||
1 | +/* | ||
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
37 | +package bootstraper; | ||
38 | + | ||
39 | +import org.junit.Assert; | ||
40 | +import org.junit.Test; | ||
41 | + | ||
42 | +import br.gov.frameworkdemoiselle.Demoiselle; | ||
43 | + | ||
44 | + | ||
45 | +public class DemoiselleSeBootstrapTest { | ||
46 | + | ||
47 | + @Test | ||
48 | + public void startThroughMainMethod(){ | ||
49 | + Demoiselle.main(new String[]{"bootstraper.ClassWithMain" , "firstArgument" , "secondArgument" , "lastArgument"}); | ||
50 | + | ||
51 | + Assert.assertEquals("firstArgument", ClassWithMain.firstArgument); | ||
52 | + Assert.assertEquals("lastArgument", ClassWithMain.lastArgument); | ||
53 | + Assert.assertEquals("injected resource data", ClassWithMain.dataFromInjectedResource); | ||
54 | + Assert.assertEquals("filled", ClassWithMain.startupData); | ||
55 | + Assert.assertEquals("filled", ClassWithMain.shutdownData); | ||
56 | + } | ||
57 | + | ||
58 | + @Test | ||
59 | + public void startThroughMainClassInterface(){ | ||
60 | + Demoiselle.runStarterClass(ClassImplementingMainClass.class, new String[]{"firstArgument" , "secondArgument" , "lastArgument"}); | ||
61 | + | ||
62 | + Assert.assertEquals("firstArgument", ClassImplementingMainClass.firstArgument); | ||
63 | + Assert.assertEquals("lastArgument", ClassImplementingMainClass.lastArgument); | ||
64 | + Assert.assertEquals("injected resource data", ClassImplementingMainClass.dataFromInjectedResource); | ||
65 | + Assert.assertEquals("filled", ClassImplementingMainClass.startupData); | ||
66 | + Assert.assertEquals("filled", ClassImplementingMainClass.shutdownData); | ||
67 | + } | ||
68 | + | ||
69 | + @Test | ||
70 | + public void startJFrame(){ | ||
71 | + Demoiselle.runMainWindow(FakeJFrame.class); | ||
72 | + | ||
73 | + Assert.assertEquals("injected resource data", FakeJFrame.dataFromInjectedResource); | ||
74 | + Assert.assertEquals("dataFromPostConstruct", FakeJFrame.dataFromPostConstruct); | ||
75 | + } | ||
76 | +} |
impl/extension/se/src/test/java/bootstraper/FakeJFrame.java
0 → 100644
@@ -0,0 +1,43 @@ | @@ -0,0 +1,43 @@ | ||
1 | +package bootstraper; | ||
2 | + | ||
3 | +import java.awt.GraphicsConfiguration; | ||
4 | +import java.awt.HeadlessException; | ||
5 | + | ||
6 | +import javax.annotation.PostConstruct; | ||
7 | +import javax.inject.Inject; | ||
8 | +import javax.swing.JFrame; | ||
9 | + | ||
10 | + | ||
11 | +public class FakeJFrame extends JFrame { | ||
12 | + | ||
13 | + private static final long serialVersionUID = 1L; | ||
14 | + | ||
15 | + @Inject | ||
16 | + private InjectedResource injectedResource; | ||
17 | + | ||
18 | + public static String dataFromInjectedResource; | ||
19 | + | ||
20 | + public static String dataFromPostConstruct; | ||
21 | + | ||
22 | + public static FakeJFrame instance; | ||
23 | + | ||
24 | + public FakeJFrame() throws HeadlessException { | ||
25 | + } | ||
26 | + | ||
27 | + public FakeJFrame(GraphicsConfiguration gc) { | ||
28 | + } | ||
29 | + | ||
30 | + public FakeJFrame(String title) throws HeadlessException { | ||
31 | + } | ||
32 | + | ||
33 | + public FakeJFrame(String title, GraphicsConfiguration gc) { | ||
34 | + } | ||
35 | + | ||
36 | + @PostConstruct | ||
37 | + public void init(){ | ||
38 | + dataFromPostConstruct = "dataFromPostConstruct"; | ||
39 | + dataFromInjectedResource = injectedResource.getData(); | ||
40 | + instance = this; | ||
41 | + } | ||
42 | + | ||
43 | +} |
impl/extension/se/src/test/java/bootstraper/InjectedResource.java
0 → 100644
@@ -0,0 +1,54 @@ | @@ -0,0 +1,54 @@ | ||
1 | +/* | ||
2 | + * Demoiselle Framework | ||
3 | + * Copyright (C) 2010 SERPRO | ||
4 | + * ---------------------------------------------------------------------------- | ||
5 | + * This file is part of Demoiselle Framework. | ||
6 | + * | ||
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + * as published by the Free Software Foundation. | ||
10 | + * | ||
11 | + * This program is distributed in the hope that it will be useful, | ||
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + * GNU General Public License for more details. | ||
15 | + * | ||
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + * ---------------------------------------------------------------------------- | ||
21 | + * Este arquivo é parte do Framework Demoiselle. | ||
22 | + * | ||
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + * do Software Livre (FSF). | ||
26 | + * | ||
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + * para maiores detalhes. | ||
31 | + * | ||
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | + */ | ||
37 | +package bootstraper; | ||
38 | + | ||
39 | + | ||
40 | +public class InjectedResource { | ||
41 | + | ||
42 | + public String data = "injected resource data"; | ||
43 | + | ||
44 | + | ||
45 | + public String getData() { | ||
46 | + return data; | ||
47 | + } | ||
48 | + | ||
49 | + | ||
50 | + public void setData(String data) { | ||
51 | + this.data = data; | ||
52 | + } | ||
53 | + | ||
54 | +} |
@@ -0,0 +1,11 @@ | @@ -0,0 +1,11 @@ | ||
1 | +<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
2 | + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> | ||
3 | + | ||
4 | + <interceptors> | ||
5 | + <class>br.gov.frameworkdemoiselle.transaction.TransactionalInterceptor</class> | ||
6 | + <class>br.gov.frameworkdemoiselle.security.RequiredPermissionInterceptor</class> | ||
7 | + <class>br.gov.frameworkdemoiselle.security.RequiredRoleInterceptor</class> | ||
8 | + <class>br.gov.frameworkdemoiselle.exception.ExceptionHandlerInterceptor</class> | ||
9 | + </interceptors> | ||
10 | + | ||
11 | +</beans> |