Skip to content
This repository
Browse code

Restructure: split wrapping of application and component in separate …

…packages. This should also ensure the code is modular enough to allow clean external extensions.
  • Loading branch information...
commit b06c5fff0fc8401f03afe4ee8a6d30b176c16deb 1 parent 47866aa
Wouter Coekaerts authored

Showing 22 changed files with 317 additions and 147 deletions. Show diff stats Hide diff stats

  1. 4  pom.xml
  2. 96  src/main/java/com/bsb/common/vaadin/embed/EmbedVaadinConfig.java
  3. 61  src/main/java/com/bsb/common/vaadin/embed/EmbedVaadinServerBuilder.java
  4. 4  src/main/java/com/bsb/common/vaadin/embed/{ → application}/ApplicationBasedEmbedVaadinTomcat.java
  5. 22  src/main/java/com/bsb/common/vaadin/embed/{ → application}/EmbedVaadinApplication.java
  6. 13  src/main/java/com/bsb/common/vaadin/embed/{ → component}/ComponentBasedEmbedVaadinTomcat.java
  7. 14  src/main/java/com/bsb/common/vaadin/embed/component/ComponentBasedVaadinServer.java
  8. 6  src/main/java/com/bsb/common/vaadin/embed/{ → component}/ComponentWrapper.java
  9. 6  src/main/java/com/bsb/common/vaadin/embed/{ → component}/DevApplication.java
  10. 3  src/main/java/com/bsb/common/vaadin/embed/{ → component}/DevApplicationHeader.java
  11. 4  src/main/java/com/bsb/common/vaadin/embed/{ → component}/DevApplicationServlet.java
  12. 61  src/main/java/com/bsb/common/vaadin/embed/component/EmbedComponentConfig.java
  13. 27  src/main/java/com/bsb/common/vaadin/embed/{ → component}/EmbedVaadinComponent.java
  14. 4  src/main/java/com/bsb/common/vaadin/embed/{ → support}/EmbedVaadin.java
  15. 5  src/test/java/com/bsb/common/vaadin/embed/AbstractEmbedTest.java
  16. 1  src/test/java/com/bsb/common/vaadin/embed/ApplicationBasedEmbedVaadinTomcatTest.java
  17. 14  src/test/java/com/bsb/common/vaadin/embed/EmbedVaadinConfigTest.java
  18. 1  src/test/java/com/bsb/common/vaadin/embed/SampleMain.java
  19. 5  src/test/java/com/bsb/common/vaadin/embed/{ → component}/ComponentBasedEmbedVaadinTomcatTest.java
  20. 16  src/test/java/com/bsb/common/vaadin/embed/{ → component}/ComponentWrapperTest.java
  21. 50  src/test/java/com/bsb/common/vaadin/embed/component/EmbedComponentConfigTest.java
  22. 47  src/test/java/com/bsb/common/vaadin/embed/{ → support}/EmbedVaadinTest.java
4  pom.xml
@@ -32,6 +32,10 @@
32 32
             <id>snicoll</id>
33 33
             <name>Stephane Nicoll</name>
34 34
         </developer>
  35
+        <developer>
  36
+            <id>wco</id>
  37
+            <name>Wouter Coekaerts</name>
  38
+        </developer>
35 39
     </developers>
36 40
 
37 41
     <properties>
96  src/main/java/com/bsb/common/vaadin/embed/EmbedVaadinConfig.java
@@ -37,7 +37,6 @@
37 37
  * <li><tt>context.path</tt>: to specify the context path of the deployed application</li>
38 38
  * <li><tt>context.rootDir</tt>: to specify the root directory of the web application</li>
39 39
  * <li><tt>server.await</tt>: to specify if the thread should block when the server has started</li>
40  
- * <li><tt>vaadin.theme</tt>: to specify the theme to use for the vaadin application</li>
41 40
  * <li><tt>vaadin.widgetSet</tt>: to specify the widgetSet to use for the vaadin application</li>
42 41
  * </ul>
43 42
  *
@@ -66,11 +65,6 @@
66 65
     public static final boolean DEFAULT_WAITING = true;
67 66
 
68 67
     /**
69  
-     * The default theme if none is set.
70  
-     */
71  
-    public static final String DEFAULT_THEME = "reindeer";
72  
-
73  
-    /**
74 68
      * Do not start the browser by default.
75 69
      */
76 70
     public static final boolean DEFAULT_START_BROWSER = false;
@@ -81,12 +75,16 @@
81 75
     private File contextRootDirectory;
82 76
     private boolean waiting;
83 77
 
84  
-    private String theme;
85 78
     private String widgetSet;
86 79
 
87 80
     private boolean openBrowser;
88 81
 
89  
-    private EmbedVaadinConfig(Properties properties) {
  82
+    /**
  83
+     * Creates a new instance using the configuration in the given {@link Properties}
  84
+     * 
  85
+     * @param properties configuration properties
  86
+     */
  87
+    public EmbedVaadinConfig(Properties properties) {
90 88
         port = Integer.valueOf(properties.getProperty("server.port", String.valueOf(DEFAULT_PORT)));
91 89
         contextPath = properties.getProperty("context.path", DEFAULT_CONTEXT_PATH);
92 90
         final String contextBase = properties.getProperty("context.rootDir");
@@ -97,7 +95,6 @@ private EmbedVaadinConfig(Properties properties) {
97 95
         }
98 96
         waiting = Boolean.valueOf(properties.getProperty("server.await", String.valueOf(DEFAULT_WAITING)));
99 97
 
100  
-        theme = properties.getProperty("vaadin.theme", DEFAULT_THEME);
101 98
         widgetSet = properties.getProperty("vaadin.widgetSet");
102 99
 
103 100
         openBrowser = Boolean.valueOf(properties.getProperty("open.browser", String.valueOf(DEFAULT_START_BROWSER)));
@@ -113,44 +110,16 @@ private EmbedVaadinConfig(Properties properties) {
113 110
      *
114 111
      * @param clone the instance to clone
115 112
      */
116  
-    public EmbedVaadinConfig(EmbedVaadinConfig clone) {
  113
+    protected EmbedVaadinConfig(EmbedVaadinConfig clone) {
117 114
         this.port = clone.port;
118 115
         this.contextPath = clone.contextPath;
119 116
         this.contextRootDirectory = clone.contextRootDirectory;
120 117
         this.waiting = clone.waiting;
121  
-        this.theme = clone.theme;
122 118
         this.widgetSet = clone.widgetSet;
123 119
         this.openBrowser = clone.openBrowser;
124 120
     }
125 121
 
126 122
     /**
127  
-     * Loads a configuration file from the default {@link #CONFIG_LOCATION config location}.
128  
-     * <p/>
129  
-     * If no file is found, only the standard default are available.
130  
-     *
131  
-     * @return a new instance with the default settings, potentially customized by an
132  
-     *         external properties file at the default location
133  
-     * @see #CONFIG_LOCATION
134  
-     */
135  
-    public static EmbedVaadinConfig load() {
136  
-        return new EmbedVaadinConfig(loadProperties(CONFIG_LOCATION, false));
137  
-    }
138  
-
139  
-
140  
-    /**
141  
-     * Loads a configuration file from the specified location. Fails if the
142  
-     * specified <tt>path</tt> does not exist.
143  
-     *
144  
-     * @param path the location of a properties file in the classpath
145  
-     * @return a new instance with the default settings customized by an
146  
-     *         external properties file at the specified location
147  
-     * @throws IllegalStateException if no such properties file is found
148  
-     */
149  
-    public static EmbedVaadinConfig load(String path) {
150  
-        return new EmbedVaadinConfig(loadProperties(path, true));
151  
-    }
152  
-
153  
-    /**
154 123
      * Creates a new instance with the default settings, i.e. does not attempt
155 124
      * to load customized settings from the {@link #CONFIG_LOCATION config location}.
156 125
      *
@@ -212,17 +181,6 @@ public boolean isWaiting() {
212 181
     }
213 182
 
214 183
     /**
215  
-     * Returns the vaadin theme to use for the application. Only taken into account
216  
-     * when a wrapper application is created for a component.
217  
-     *
218  
-     * @return the theme to use
219  
-     * @see #DEFAULT_THEME
220  
-     */
221  
-    public String getTheme() {
222  
-        return theme;
223  
-    }
224  
-
225  
-    /**
226 184
      * Returns the vaadin widgetSet to use for the application. Returns <tt>null</tt>
227 185
      * if no specific widgetSet is configured and the default one should be used.
228 186
      *
@@ -241,31 +199,27 @@ public boolean shouldOpenBrowser() {
241 199
         return openBrowser;
242 200
     }
243 201
 
244  
-    protected void setPort(int port) {
  202
+    void setPort(int port) {
245 203
         this.port = port;
246 204
     }
247 205
 
248  
-    protected void setContextPath(String contextPath) {
  206
+    void setContextPath(String contextPath) {
249 207
         this.contextPath = contextPath;
250 208
     }
251 209
 
252  
-    protected void setContextRootDirectory(File contextRootDirectory) {
  210
+    void setContextRootDirectory(File contextRootDirectory) {
253 211
         this.contextRootDirectory = contextRootDirectory;
254 212
     }
255 213
 
256  
-    protected void setWaiting(boolean waiting) {
  214
+    void setWaiting(boolean waiting) {
257 215
         this.waiting = waiting;
258 216
     }
259 217
 
260  
-    protected void setTheme(String theme) {
261  
-        this.theme = theme;
262  
-    }
263  
-
264  
-    protected void setWidgetSet(String widgetSet) {
  218
+    void setWidgetSet(String widgetSet) {
265 219
         this.widgetSet = widgetSet;
266 220
     }
267 221
 
268  
-    protected void setOpenBrowser(boolean openBrowser) {
  222
+    void setOpenBrowser(boolean openBrowser) {
269 223
         this.openBrowser = openBrowser;
270 224
     }
271 225
 
@@ -276,6 +230,30 @@ private void validate() {
276 230
         }
277 231
     }
278 232
 
  233
+    /**
  234
+     * Loads a configuration file from the default {@link #CONFIG_LOCATION config location}.
  235
+     * <p/>
  236
+     * If no file is found, only the standard default are available.
  237
+     *
  238
+     * @return Properties loaded from the default locations, or empty Properties if the file doesn't exist.
  239
+     * @see #CONFIG_LOCATION
  240
+     */
  241
+    public static Properties loadProperties() {
  242
+        return loadProperties(CONFIG_LOCATION, false);
  243
+    }
  244
+
  245
+    /**
  246
+     * Loads a configuration file from the specified location. Fails if the
  247
+     * specified <tt>path</tt> does not exist.
  248
+     *
  249
+     * @param path the location of a properties file in the classpath
  250
+     * @return Properties Properties loaded from the <code>.properties</code> file at the specified location
  251
+     * @throws IllegalStateException if no such properties file is found
  252
+     */
  253
+    public static Properties loadProperties(String path) {
  254
+        return loadProperties(path, true);
  255
+    }
  256
+    
279 257
     private static Properties loadProperties(String path, boolean failIfNotFound) {
280 258
         try {
281 259
             final Properties properties = new Properties();
61  src/main/java/com/bsb/common/vaadin/embed/EmbedVaadinServerBuilder.java
@@ -16,6 +16,7 @@
16 16
 package com.bsb.common.vaadin.embed;
17 17
 
18 18
 import java.io.File;
  19
+import java.util.Properties;
19 20
 
20 21
 /**
21 22
  * A basic builder for an {@link EmbedVaadinServer}.
@@ -25,21 +26,10 @@
25 26
 public abstract class EmbedVaadinServerBuilder<B extends EmbedVaadinServerBuilder<B, S>,
26 27
         S extends EmbedVaadinServer> {
27 28
 
28  
-    private EmbedVaadinConfig config;
29  
-
30 29
     /**
31  
-     * Creates a new instance, initializing the properties with a default
32  
-     * {@link EmbedVaadinConfig} instance.
33  
-     *
34  
-     * @param loadDefault <tt>true</tt> to initialize the builder with the default config
35  
-     * @see EmbedVaadinConfig#load()
  30
+     * Creates a new instance
36 31
      */
37  
-    protected EmbedVaadinServerBuilder(boolean loadDefault) {
38  
-        if (loadDefault) {
39  
-            this.config = EmbedVaadinConfig.load();
40  
-        } else {
41  
-            this.config = EmbedVaadinConfig.defaultConfig();
42  
-        }
  32
+    protected EmbedVaadinServerBuilder() {
43 33
     }
44 34
 
45 35
     /**
@@ -57,26 +47,34 @@ protected EmbedVaadinServerBuilder(boolean loadDefault) {
57 47
     public abstract S build();
58 48
 
59 49
     /**
60  
-     * Applies the content of the specified {@link EmbedVaadinConfig}.
  50
+     * Loads a configuration file from the specified location. Fails if the
  51
+     * specified <tt>path</tt> does not exist.
61 52
      *
62  
-     * @param config the configuration to use
  53
+     * @param path the location of a properties file in the classpath
63 54
      * @return this
  55
+     * @throws IllegalStateException if no such properties file is found
64 56
      */
65  
-    public B withConfig(EmbedVaadinConfig config) {
66  
-        assertNotNull(config, "embed config could not be null.");
67  
-        this.config = new EmbedVaadinConfig(config);
68  
-
  57
+    public B withConfigPath(String path) {
  58
+        withConfigProperties(EmbedVaadinConfig.loadProperties(path));
69 59
         return self();
70 60
     }
71 61
 
72 62
     /**
  63
+     * Loads configuration from the specified {@link Properties}, usually read from a <code>.properties</code> file.
  64
+     *
  65
+     * @param properties configuration properties
  66
+     * @return this
  67
+     */
  68
+    public abstract B withConfigProperties(Properties properties);
  69
+    
  70
+    /**
73 71
      * Specifies the HTTP port to use.
74 72
      *
75 73
      * @param httpPort the http port
76 74
      * @return this
77 75
      */
78 76
     public B withHttpPort(int httpPort) {
79  
-        this.config.setPort(httpPort);
  77
+        getConfig().setPort(httpPort);
80 78
         return self();
81 79
     }
82 80
 
@@ -92,11 +90,11 @@ public B withContextPath(String contextPath) {
92 90
 
93 91
         // Special handling so that / can be used for the root context as well
94 92
         if (contextPath.equals("/") || contextPath.trim().equals("")) {
95  
-            this.config.setContextPath("");
  93
+            getConfig().setContextPath("");
96 94
         } else if (!contextPath.startsWith("/")) {
97  
-            this.config.setContextPath("/" + contextPath);
  95
+            getConfig().setContextPath("/" + contextPath);
98 96
         } else {
99  
-            this.config.setContextPath(contextPath);
  97
+            getConfig().setContextPath(contextPath);
100 98
         }
101 99
         return self();
102 100
     }
@@ -120,7 +118,7 @@ public B withContextRootDirectory(File webappRootDirectory) {
120 118
             throw new IllegalArgumentException("the specified value ["
121 119
                     + webappRootDirectory.getAbsolutePath() + "] is not a directory!");
122 120
         }
123  
-        this.config.setContextRootDirectory(webappRootDirectory);
  121
+        getConfig().setContextRootDirectory(webappRootDirectory);
124 122
         return self();
125 123
     }
126 124
 
@@ -152,7 +150,7 @@ public B withContextRootDirectory(String relativeDirectory) {
152 150
      * @return this
153 151
      */
154 152
     public B withWidgetSet(String widgetSet) {
155  
-        this.config.setWidgetSet(widgetSet);
  153
+        getConfig().setWidgetSet(widgetSet);
156 154
         return self();
157 155
     }
158 156
 
@@ -167,7 +165,7 @@ public B withWidgetSet(String widgetSet) {
167 165
      * @return this
168 166
      */
169 167
     public B wait(boolean shouldWait) {
170  
-        this.config.setWaiting(shouldWait);
  168
+        getConfig().setWaiting(shouldWait);
171 169
         return self();
172 170
     }
173 171
 
@@ -179,7 +177,7 @@ public B wait(boolean shouldWait) {
179 177
      * @return this
180 178
      */
181 179
     public B openBrowser(boolean open) {
182  
-        this.config.setOpenBrowser(open);
  180
+        getConfig().setOpenBrowser(open);
183 181
         return self();
184 182
     }
185 183
 
@@ -194,18 +192,15 @@ public S start() {
194 192
         return server;
195 193
     }
196 194
 
197  
-
198  
-    // Helpers for concrete builders
199  
-
200 195
     /**
201 196
      * Returns the underling {@link EmbedVaadinConfig} that this instance is managing.
  197
+     * Must be implemented by a concrete builder because the type of configuration can be different.
202 198
      *
203 199
      * @return the configuration
204 200
      */
205  
-    protected EmbedVaadinConfig getConfig() {
206  
-        return config;
207  
-    }
  201
+    protected abstract EmbedVaadinConfig getConfig();
208 202
 
  203
+    // Helpers for concrete builders
209 204
 
210 205
     protected void assertNotNull(Object value, String message) {
211 206
         if (value == null) {
4  ...adin/embed/ApplicationBasedEmbedVaadinTomcat.java → ...pplication/ApplicationBasedEmbedVaadinTomcat.java
@@ -13,8 +13,10 @@
13 13
  * See the License for the specific language governing permissions and
14 14
  * limitations under the License.
15 15
  */
16  
-package com.bsb.common.vaadin.embed;
  16
+package com.bsb.common.vaadin.embed.application;
17 17
 
  18
+import com.bsb.common.vaadin.embed.AbstractEmbedVaadinTomcat;
  19
+import com.bsb.common.vaadin.embed.EmbedVaadinConfig;
18 20
 import com.vaadin.Application;
19 21
 import com.vaadin.terminal.gwt.server.ApplicationServlet;
20 22
 import org.apache.catalina.Wrapper;
22  ...b/common/vaadin/embed/EmbedVaadinApplication.java → ...din/embed/application/EmbedVaadinApplication.java
... ...
@@ -1,7 +1,12 @@
1  
-package com.bsb.common.vaadin.embed;
  1
+package com.bsb.common.vaadin.embed.application;
2 2
 
  3
+import com.bsb.common.vaadin.embed.EmbedVaadinConfig;
  4
+import com.bsb.common.vaadin.embed.EmbedVaadinServer;
  5
+import com.bsb.common.vaadin.embed.EmbedVaadinServerBuilder;
3 6
 import com.vaadin.Application;
4 7
 
  8
+import java.util.Properties;
  9
+
5 10
 /**
6 11
  * A builder for a server embedding an application.
7 12
  *
@@ -10,11 +15,13 @@
10 15
 public class EmbedVaadinApplication extends EmbedVaadinServerBuilder<EmbedVaadinApplication, EmbedVaadinServer> {
11 16
 
12 17
     private final Class<? extends Application> applicationClass;
  18
+    private EmbedVaadinConfig config;
13 19
 
14 20
     public EmbedVaadinApplication(Class<? extends Application> applicationClass) {
15  
-        super(true);
  21
+        super();
16 22
         assertNotNull(applicationClass, "applicationClass could not be null.");
17 23
         this.applicationClass = applicationClass;
  24
+        withConfigProperties(EmbedVaadinConfig.loadProperties());
18 25
     }
19 26
 
20 27
     /**
@@ -35,4 +42,15 @@ protected EmbedVaadinApplication self() {
35 42
     public EmbedVaadinServer build() {
36 43
         return new ApplicationBasedEmbedVaadinTomcat(getConfig(), getApplicationClass());
37 44
     }
  45
+
  46
+    @Override
  47
+    public EmbedVaadinApplication withConfigProperties(Properties properties) {
  48
+        this.config = new EmbedVaadinConfig(properties);
  49
+        return self();
  50
+    }
  51
+
  52
+    @Override
  53
+    protected EmbedVaadinConfig getConfig() {
  54
+        return config;
  55
+    }
38 56
 }
13  ...vaadin/embed/ComponentBasedEmbedVaadinTomcat.java → ...ed/component/ComponentBasedEmbedVaadinTomcat.java
@@ -13,8 +13,9 @@
13 13
  * See the License for the specific language governing permissions and
14 14
  * limitations under the License.
15 15
  */
16  
-package com.bsb.common.vaadin.embed;
  16
+package com.bsb.common.vaadin.embed.component;
17 17
 
  18
+import com.bsb.common.vaadin.embed.AbstractEmbedVaadinTomcat;
18 19
 import com.vaadin.ui.Component;
19 20
 import org.apache.catalina.Wrapper;
20 21
 
@@ -26,8 +27,9 @@
26 27
  *
27 28
  * @author Stephane Nicoll
28 29
  */
29  
-public class ComponentBasedEmbedVaadinTomcat extends AbstractEmbedVaadinTomcat {
  30
+public class ComponentBasedEmbedVaadinTomcat extends AbstractEmbedVaadinTomcat implements ComponentBasedVaadinServer {
30 31
 
  32
+    private final EmbedComponentConfig config;
31 33
     private final Component component;
32 34
 
33 35
     /**
@@ -36,11 +38,16 @@
36 38
      * @param config the config to use
37 39
      * @param component the component to display
38 40
      */
39  
-    public ComponentBasedEmbedVaadinTomcat(EmbedVaadinConfig config, Component component) {
  41
+    public ComponentBasedEmbedVaadinTomcat(EmbedComponentConfig config, Component component) {
40 42
         super(config);
  43
+        this.config = config;
41 44
         this.component = component;
42 45
     }
43 46
 
  47
+    public EmbedComponentConfig getConfig() {
  48
+        return config;
  49
+    }
  50
+
44 51
     @Override
45 52
     protected void configure() {
46 53
         initConfiguration();
14  src/main/java/com/bsb/common/vaadin/embed/component/ComponentBasedVaadinServer.java
... ...
@@ -0,0 +1,14 @@
  1
+package com.bsb.common.vaadin.embed.component;
  2
+
  3
+import com.bsb.common.vaadin.embed.EmbedVaadinServer;
  4
+
  5
+/**
  6
+ * A {@link EmbedVaadinServer} that deploys a component.
  7
+ * 
  8
+ * @author Wouter Coekaerts
  9
+ */
  10
+public interface ComponentBasedVaadinServer extends EmbedVaadinServer {
  11
+
  12
+    // overriding, narrowing return type
  13
+    EmbedComponentConfig getConfig();
  14
+}
6  ...com/bsb/common/vaadin/embed/ComponentWrapper.java → ...mmon/vaadin/embed/component/ComponentWrapper.java
@@ -13,7 +13,7 @@
13 13
  * See the License for the specific language governing permissions and
14 14
  * limitations under the License.
15 15
  */
16  
-package com.bsb.common.vaadin.embed;
  16
+package com.bsb.common.vaadin.embed.component;
17 17
 
18 18
 import com.vaadin.Application;
19 19
 import com.vaadin.terminal.Sizeable;
@@ -30,14 +30,14 @@
30 30
  */
31 31
 public class ComponentWrapper {
32 32
 
33  
-    private final EmbedVaadinServer server;
  33
+    private final ComponentBasedVaadinServer server;
34 34
 
35 35
     /**
36 36
      * Creates a new instance.
37 37
      *
38 38
      * @param server the server handling this application
39 39
      */
40  
-    public ComponentWrapper(EmbedVaadinServer server) {
  40
+    public ComponentWrapper(ComponentBasedVaadinServer server) {
41 41
         this.server = server;
42 42
     }
43 43
 
6  ...a/com/bsb/common/vaadin/embed/DevApplication.java → ...common/vaadin/embed/component/DevApplication.java
@@ -13,7 +13,7 @@
13 13
  * See the License for the specific language governing permissions and
14 14
  * limitations under the License.
15 15
  */
16  
-package com.bsb.common.vaadin.embed;
  16
+package com.bsb.common.vaadin.embed.component;
17 17
 
18 18
 import com.vaadin.Application;
19 19
 import com.vaadin.ui.Window;
@@ -25,7 +25,7 @@
25 25
  */
26 26
 public class DevApplication extends Application {
27 27
 
28  
-    private final transient EmbedVaadinServer server;
  28
+    private final transient ComponentBasedVaadinServer server;
29 29
     private final Window mainWindow;
30 30
 
31 31
     /**
@@ -34,7 +34,7 @@
34 34
      * @param server the server handling this application
35 35
      * @param mainWindow the main window
36 36
      */
37  
-    public DevApplication(EmbedVaadinServer server, Window mainWindow) {
  37
+    public DevApplication(ComponentBasedVaadinServer server, Window mainWindow) {
38 38
         this.server = server;
39 39
         this.mainWindow = mainWindow;
40 40
     }
3  ...bsb/common/vaadin/embed/DevApplicationHeader.java → .../vaadin/embed/component/DevApplicationHeader.java
@@ -13,8 +13,9 @@
13 13
  * See the License for the specific language governing permissions and
14 14
  * limitations under the License.
15 15
  */
16  
-package com.bsb.common.vaadin.embed;
  16
+package com.bsb.common.vaadin.embed.component;
17 17
 
  18
+import com.bsb.common.vaadin.embed.EmbedVaadinServer;
18 19
 import com.vaadin.ui.Alignment;
19 20
 import com.vaadin.ui.Button;
20 21
 import com.vaadin.ui.HorizontalLayout;
4  ...sb/common/vaadin/embed/DevApplicationServlet.java → ...vaadin/embed/component/DevApplicationServlet.java
@@ -13,7 +13,7 @@
13 13
  * See the License for the specific language governing permissions and
14 14
  * limitations under the License.
15 15
  */
16  
-package com.bsb.common.vaadin.embed;
  16
+package com.bsb.common.vaadin.embed.component;
17 17
 
18 18
 import com.vaadin.Application;
19 19
 import com.vaadin.terminal.gwt.server.ApplicationServlet;
@@ -42,7 +42,7 @@
42 42
      * @param server the server handling this application
43 43
      * @param component the component to display
44 44
      */
45  
-    public DevApplicationServlet(EmbedVaadinServer server, Component component) {
  45
+    public DevApplicationServlet(ComponentBasedVaadinServer server, Component component) {
46 46
         this.application = new ComponentWrapper(server).wrap(component);
47 47
     }
48 48
 
61  src/main/java/com/bsb/common/vaadin/embed/component/EmbedComponentConfig.java
... ...
@@ -0,0 +1,61 @@
  1
+package com.bsb.common.vaadin.embed.component;
  2
+
  3
+import com.bsb.common.vaadin.embed.EmbedVaadinConfig;
  4
+
  5
+import java.util.Properties;
  6
+
  7
+/**
  8
+ * Configuration for an embedded server showing a component.
  9
+ * <p>
  10
+ * This extends the {@link EmbedVaadinConfig} and is configured in the same way.
  11
+ * The properties file may contain any of the properties documented on {@link EmbedVaadinConfig} and
  12
+ * additionally:
  13
+ * <ul>
  14
+ * <li><tt>vaadin.theme</tt>: to specify the theme to use for the vaadin application</li>
  15
+ * </ul>
  16
+ * 
  17
+ * @author Wouter Coekaerts
  18
+ */
  19
+public final class EmbedComponentConfig extends EmbedVaadinConfig {
  20
+    /**
  21
+     * The default theme if none is set.
  22
+     */
  23
+    public static final String DEFAULT_THEME = "reindeer";
  24
+    
  25
+    private String theme;
  26
+
  27
+    protected EmbedComponentConfig(Properties properties) {
  28
+        super(properties);
  29
+        theme = properties.getProperty("vaadin.theme", DEFAULT_THEME);
  30
+    }
  31
+
  32
+    protected EmbedComponentConfig(EmbedComponentConfig clone) {
  33
+        super(clone);
  34
+        theme = clone.theme;
  35
+    }
  36
+    
  37
+    /**
  38
+     * Returns the vaadin theme to use for the application. Only taken into account
  39
+     * when a wrapper application is created for a component.
  40
+     *
  41
+     * @return the theme to use
  42
+     * @see #DEFAULT_THEME
  43
+     */
  44
+    public String getTheme() {
  45
+        return theme;
  46
+    }
  47
+
  48
+    void setTheme(String theme) {
  49
+        this.theme = theme;
  50
+    }
  51
+
  52
+    /**
  53
+     * Creates a new instance with the default settings, i.e. does not attempt
  54
+     * to load customized settings from the {@link #CONFIG_LOCATION config location}.
  55
+     *
  56
+     * @return a new instance with the default settings
  57
+     */
  58
+    public static EmbedComponentConfig defaultConfig() {
  59
+        return new EmbedComponentConfig(new Properties());
  60
+    }
  61
+}
27  ...bsb/common/vaadin/embed/EmbedVaadinComponent.java → .../vaadin/embed/component/EmbedVaadinComponent.java
... ...
@@ -1,7 +1,12 @@
1  
-package com.bsb.common.vaadin.embed;
  1
+package com.bsb.common.vaadin.embed.component;
2 2
 
  3
+import com.bsb.common.vaadin.embed.EmbedVaadinConfig;
  4
+import com.bsb.common.vaadin.embed.EmbedVaadinServer;
  5
+import com.bsb.common.vaadin.embed.EmbedVaadinServerBuilder;
3 6
 import com.vaadin.ui.Component;
4 7
 
  8
+import java.util.Properties;
  9
+
5 10
 /**
6 11
  * A builder for a server embedding a component.
7 12
  *
@@ -10,11 +15,13 @@
10 15
 public class EmbedVaadinComponent extends EmbedVaadinServerBuilder<EmbedVaadinComponent, EmbedVaadinServer> {
11 16
 
12 17
     private final Component component;
  18
+    private EmbedComponentConfig config;
13 19
 
14 20
     public EmbedVaadinComponent(Component component) {
15  
-        super(true);
  21
+        super();
16 22
         assertNotNull(component, "component could not be null.");
17 23
         this.component = component;
  24
+        withConfigProperties(EmbedVaadinConfig.loadProperties());
18 25
     }
19 26
 
20 27
     /**
@@ -25,7 +32,6 @@ public EmbedVaadinComponent(Component component) {
25 32
      */
26 33
     public EmbedVaadinComponent withTheme(String theme) {
27 34
         assertNotNull(theme, "theme could not be null.");
28  
-
29 35
         getConfig().setTheme(theme);
30 36
         return self();
31 37
     }
@@ -45,7 +51,18 @@ protected EmbedVaadinComponent self() {
45 51
     }
46 52
 
47 53
     @Override
48  
-    public EmbedVaadinServer build() {
49  
-        return new ComponentBasedEmbedVaadinTomcat(getConfig(), getComponent());
  54
+    public ComponentBasedVaadinServer build() {
  55
+        return new ComponentBasedEmbedVaadinTomcat(config, getComponent());
  56
+    }
  57
+
  58
+    @Override
  59
+    public EmbedVaadinComponent withConfigProperties(Properties properties) {
  60
+        this.config = new EmbedComponentConfig(properties);
  61
+        return self();
  62
+    }
  63
+
  64
+    @Override
  65
+    protected EmbedComponentConfig getConfig() {
  66
+        return config;
50 67
     }
51 68
 }
4  ...java/com/bsb/common/vaadin/embed/EmbedVaadin.java → .../bsb/common/vaadin/embed/support/EmbedVaadin.java
@@ -13,8 +13,10 @@
13 13
  * See the License for the specific language governing permissions and
14 14
  * limitations under the License.
15 15
  */
16  
-package com.bsb.common.vaadin.embed;
  16
+package com.bsb.common.vaadin.embed.support;
17 17
 
  18
+import com.bsb.common.vaadin.embed.application.EmbedVaadinApplication;
  19
+import com.bsb.common.vaadin.embed.component.EmbedVaadinComponent;
18 20
 import com.vaadin.Application;
19 21
 import com.vaadin.ui.Component;
20 22
 
5  src/test/java/com/bsb/common/vaadin/embed/AbstractEmbedTest.java
@@ -36,9 +36,8 @@ protected void assertServerConfig(EmbedVaadinConfig config, int port, String con
36 36
         assertEquals("Wrong waiting flag", waiting, config.isWaiting());
37 37
     }
38 38
 
39  
-    protected void assertVaadinConfig(EmbedVaadinConfig config, String theme, String widgetSet) {
  39
+    protected void assertVaadinConfig(EmbedVaadinConfig config, String widgetSet) {
40 40
         assertConfigIsNotNull(config);
41  
-        assertEquals("Wrong theme", theme, config.getTheme());
42 41
         assertEquals("Wrong widgetSet", widgetSet, config.getWidgetSet());
43 42
     }
44 43
 
@@ -69,7 +68,7 @@ protected void checkVaadinIsDeployed(int port, String context) {
69 68
         }
70 69
     }
71 70
 
72  
-    private void assertConfigIsNotNull(EmbedVaadinConfig config) {
  71
+    protected void assertConfigIsNotNull(EmbedVaadinConfig config) {
73 72
         assertNotNull("config could not be null.", config);
74 73
     }
75 74
 }
1  src/test/java/com/bsb/common/vaadin/embed/ApplicationBasedEmbedVaadinTomcatTest.java
@@ -15,6 +15,7 @@
15 15
  */
16 16
 package com.bsb.common.vaadin.embed;
17 17
 
  18
+import com.bsb.common.vaadin.embed.support.EmbedVaadin;
18 19
 import com.bsb.common.vaadin.embed.test.TestApplication;
19 20
 import org.junit.Test;
20 21
 
14  src/test/java/com/bsb/common/vaadin/embed/EmbedVaadinConfigTest.java
@@ -29,26 +29,27 @@ public void createDefaultInstance() {
29 29
         final EmbedVaadinConfig config = EmbedVaadinConfig.defaultConfig();
30 30
         assertServerConfig(config, EmbedVaadinConfig.DEFAULT_PORT, EmbedVaadinConfig.DEFAULT_CONTEXT_PATH,
31 31
                 EmbedVaadinConfig.DEFAULT_WAITING);
32  
-        assertVaadinConfig(config, EmbedVaadinConfig.DEFAULT_THEME, null);
  32
+        assertVaadinConfig(config, null);
33 33
         assertBrowserConfig(config, EmbedVaadinConfig.DEFAULT_START_BROWSER);
34 34
     }
35 35
 
36 36
     @Test(expected = IllegalStateException.class)
37 37
     public void loadUnknownFile() {
38  
-        EmbedVaadinConfig.load("/foo/bar/does-not-exist.properties");
  38
+        EmbedVaadinConfig.loadProperties("/foo/bar/does-not-exist.properties");
39 39
     }
40 40
 
41 41
     @Test
42 42
     public void load() {
43  
-        final EmbedVaadinConfig config = EmbedVaadinConfig.load("/config/simple-embed-vaadin.properties");
  43
+        final EmbedVaadinConfig config = new EmbedVaadinConfig(
  44
+                EmbedVaadinConfig.loadProperties("/config/simple-embed-vaadin.properties"));
44 45
         assertServerConfig(config, 12345, "/foo", false);
45  
-        assertVaadinConfig(config, "myTheme", "com.bsb.foo.MyWidgetSet");
  46
+        assertVaadinConfig(config, "com.bsb.foo.MyWidgetSet");
46 47
         assertBrowserConfig(config, true);
47 48
     }
48 49
 
49 50
     @Test(expected = IllegalStateException.class)
50 51
     public void loadWithInvalidRootWebDir() {
51  
-        EmbedVaadinConfig.load("/config/root-dir-embed-vaadin.properties");
  52
+        new EmbedVaadinConfig(EmbedVaadinConfig.loadProperties("/config/root-dir-embed-vaadin.properties"));
52 53
     }
53 54
 
54 55
     @Test
@@ -60,7 +61,6 @@ public void cloneConfig() {
60 61
         config.setPort(1);
61 62
         config.setContextPath("/foo/bar");
62 63
         config.setContextRootDirectory(new File("."));
63  
-        config.setTheme("fooBarTheme");
64 64
         config.setWidgetSet("com.bar.MyAnotherWidgetSet");
65 65
         config.setWaiting(true);
66 66
         config.setOpenBrowser(true);
@@ -68,7 +68,7 @@ public void cloneConfig() {
68 68
         // Now validate the clone has not changed
69 69
         assertServerConfig(clone, EmbedVaadinConfig.DEFAULT_PORT, EmbedVaadinConfig.DEFAULT_CONTEXT_PATH,
70 70
                 EmbedVaadinConfig.DEFAULT_WAITING);
71  
-        assertVaadinConfig(clone, EmbedVaadinConfig.DEFAULT_THEME, null);
  71
+        assertVaadinConfig(clone, null);
72 72
         assertBrowserConfig(clone, EmbedVaadinConfig.DEFAULT_START_BROWSER);
73 73
 
74 74
     }
1  src/test/java/com/bsb/common/vaadin/embed/SampleMain.java
... ...
@@ -1,5 +1,6 @@
1 1
 package com.bsb.common.vaadin.embed;
2 2
 
  3
+import com.bsb.common.vaadin.embed.support.EmbedVaadin;
3 4
 import com.vaadin.ui.Button;
4 5
 
5 6
 /**
5  ...in/embed/ComponentBasedEmbedVaadinTomcatTest.java → ...omponent/ComponentBasedEmbedVaadinTomcatTest.java
@@ -13,8 +13,11 @@
13 13
  * See the License for the specific language governing permissions and
14 14
  * limitations under the License.
15 15
  */
16  
-package com.bsb.common.vaadin.embed;
  16
+package com.bsb.common.vaadin.embed.component;
17 17
 
  18
+import com.bsb.common.vaadin.embed.AbstractEmbedTest;
  19
+import com.bsb.common.vaadin.embed.EmbedVaadinServer;
  20
+import com.bsb.common.vaadin.embed.support.EmbedVaadin;
18 21
 import com.vaadin.ui.Button;
19 22
 import org.junit.Test;
20 23
 
16  ...bsb/common/vaadin/embed/ComponentWrapperTest.java → .../vaadin/embed/component/ComponentWrapperTest.java
@@ -13,8 +13,9 @@
13 13
  * See the License for the specific language governing permissions and
14 14
  * limitations under the License.
15 15
  */
16  
-package com.bsb.common.vaadin.embed;
  16
+package com.bsb.common.vaadin.embed.component;
17 17
 
  18
+import com.bsb.common.vaadin.embed.AbstractEmbedVaadinTomcat;
18 19
 import com.vaadin.Application;
19 20
 import com.vaadin.ui.Button;
20 21
 import com.vaadin.ui.HorizontalLayout;
@@ -34,7 +35,7 @@
34 35
 public class ComponentWrapperTest {
35 36
 
36 37
     private final ComponentWrapper instance = new ComponentWrapper(
37  
-            new TestableEmbedVaadinServer(EmbedVaadinConfig.defaultConfig()));
  38
+            new TestableEmbedVaadinServer(EmbedComponentConfig.defaultConfig()));
38 39
 
39 40
     @Test
40 41
     public void wrapWindow() {
@@ -80,15 +81,22 @@ private Layout assertWrappingLayout(Application app) {
80 81
 
81 82
 
82 83
     // A testable server that does not need any vaadin component
83  
-    private static final class TestableEmbedVaadinServer extends AbstractEmbedVaadinTomcat {
  84
+    private static final class TestableEmbedVaadinServer extends AbstractEmbedVaadinTomcat
  85
+            implements ComponentBasedVaadinServer{
  86
+        private final EmbedComponentConfig config;
84 87
 
85  
-        private TestableEmbedVaadinServer(EmbedVaadinConfig config) {
  88
+        private TestableEmbedVaadinServer(EmbedComponentConfig config) {
86 89
             super(config);
  90
+            this.config = config;
87 91
         }
88 92
 
89 93
         @Override
90 94
         protected void configure() {
91 95
         }
  96
+
  97
+        public EmbedComponentConfig getConfig() {
  98
+            return config;
  99
+        }
92 100
     }
93 101
 
94 102
 
50  src/test/java/com/bsb/common/vaadin/embed/component/EmbedComponentConfigTest.java
... ...
@@ -0,0 +1,50 @@
  1
+package com.bsb.common.vaadin.embed.component;
  2
+
  3
+import com.bsb.common.vaadin.embed.AbstractEmbedTest;
  4
+import com.bsb.common.vaadin.embed.EmbedVaadinConfig;
  5
+import org.junit.Test;
  6
+
  7
+import static junit.framework.Assert.assertEquals;
  8
+
  9
+/**
  10
+ * @author Wouter Coekaerts
  11
+ */
  12
+public class EmbedComponentConfigTest extends AbstractEmbedTest {
  13
+
  14
+    @Test
  15
+    public void createDefaultInstance() {
  16
+        final EmbedComponentConfig config = EmbedComponentConfig.defaultConfig();
  17
+        assertServerConfig(config, EmbedVaadinConfig.DEFAULT_PORT, EmbedVaadinConfig.DEFAULT_CONTEXT_PATH,
  18
+                EmbedVaadinConfig.DEFAULT_WAITING);
  19
+        assertComponentConfig(config, EmbedComponentConfig.DEFAULT_THEME);
  20
+        assertVaadinConfig(config, null);
  21
+        assertBrowserConfig(config, EmbedVaadinConfig.DEFAULT_START_BROWSER);
  22
+    }
  23
+
  24
+    @Test
  25
+    public void load() {
  26
+        final EmbedComponentConfig config = new EmbedComponentConfig(
  27
+                EmbedVaadinConfig.loadProperties("/config/simple-embed-vaadin.properties"));
  28
+        assertServerConfig(config, 12345, "/foo", false);
  29
+        assertVaadinConfig(config, "com.bsb.foo.MyWidgetSet");
  30
+        assertComponentConfig(config, "myTheme");
  31
+        assertBrowserConfig(config, true);
  32
+    }
  33
+
  34
+    @Test
  35
+    public void cloneConfig() {
  36
+        final EmbedComponentConfig config = EmbedComponentConfig.defaultConfig();
  37
+        final EmbedComponentConfig clone = new EmbedComponentConfig(config);
  38
+
  39
+        // Change stuff
  40
+        config.setTheme("fooBarTheme");
  41
+
  42
+        // Now validate the clone has not changed
  43
+        assertComponentConfig(clone, EmbedComponentConfig.DEFAULT_THEME);
  44
+    }
  45
+
  46
+    protected void assertComponentConfig(EmbedComponentConfig config, String theme) {
  47
+        assertConfigIsNotNull(config);
  48
+        assertEquals("Wrong theme", theme, config.getTheme());
  49
+    }
  50
+}
47  .../com/bsb/common/vaadin/embed/EmbedVaadinTest.java → .../common/vaadin/embed/support/EmbedVaadinTest.java
@@ -13,8 +13,11 @@
13 13
  * See the License for the specific language governing permissions and
14 14
  * limitations under the License.
15 15
  */
16  
-package com.bsb.common.vaadin.embed;
  16
+package com.bsb.common.vaadin.embed.support;
17 17
 
  18
+import com.bsb.common.vaadin.embed.AbstractEmbedTest;
  19
+import com.bsb.common.vaadin.embed.component.EmbedComponentConfig;
  20
+import com.bsb.common.vaadin.embed.component.EmbedVaadinComponent;
18 21
 import com.google.common.io.Files;
19 22
 import com.vaadin.ui.Button;
20 23
 import org.junit.Test;
@@ -47,9 +50,14 @@ public void withNullContextRootDirectoryAsFile() {
47 50
         EmbedVaadin.forComponent(component).withContextRootDirectory((String) null);
48 51
     }
49 52
 
50  
-    @Test(expected = IllegalArgumentException.class)
51  
-    public void withNullConfig() {
52  
-        EmbedVaadin.forComponent(component).withConfig(null);
  53
+    @Test(expected = NullPointerException.class)
  54
+    public void withNullConfigPath() {
  55
+        EmbedVaadin.forComponent(component).withConfigPath(null);
  56
+    }
  57
+
  58
+    @Test(expected = NullPointerException.class)
  59
+    public void withNullConfigProperties() {
  60
+        EmbedVaadin.forComponent(component).withConfigProperties(null);
53 61
     }
54 62
 
55 63
     @Test(expected = IllegalArgumentException.class)
@@ -60,33 +68,33 @@ public void withNullTheme() {
60 68
     @Test
61 69
     public void withPort() {
62 70
         final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component).withHttpPort(8080);
63  
-        assertEquals("was not detected as expected", 8080, embed.getConfig().getPort());
  71
+        assertEquals("was not detected as expected", 8080, embed.build().getConfig().getPort());
64 72
     }
65 73
 
66 74
     @Test
67 75
     public void withRootContextPath() {
68 76
         final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component).withContextPath("/");
69  
-        assertEquals("/ was not detected as root context properly", "", embed.getConfig().getContextPath());
  77
+        assertEquals("/ was not detected as root context properly", "", embed.build().getConfig().getContextPath());
70 78
     }
71 79
 
72 80
     @Test
73 81
     public void withEmptyContextPath() {
74 82
         final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component).withContextPath(" ");
75 83
         assertEquals("empty string was not detected as root context properly",
76  
-                "", embed.getConfig().getContextPath());
  84
+                "", embed.build().getConfig().getContextPath());
77 85
     }
78 86
 
79 87
     @Test
80 88
     public void withContextWithoutForwardSlash() {
81 89
         final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component).withContextPath("foo");
82 90
         assertEquals("forward slash was not added to context as expected",
83  
-                "/foo", embed.getConfig().getContextPath());
  91
+                "/foo", embed.build().getConfig().getContextPath());
84 92
     }
85 93
 
86 94
     @Test
87 95
     public void withSimpleContextPath() {
88 96
         final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component).withContextPath("/bar");
89  
-        assertEquals("was not detected as expected", "/bar", embed.getConfig().getContextPath());
  97
+        assertEquals("was not detected as expected", "/bar", embed.build().getConfig().getContextPath());
90 98
     }
91 99
 
92 100
     @Test(expected = IllegalArgumentException.class)
@@ -103,7 +111,7 @@ public void withFileContextRootDirectory() throws IOException {
103 111
     public void withContextRootDirectoryAsFile() {
104 112
         final File rootContextDir = Files.createTempDir();
105 113
         final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component).withContextRootDirectory(rootContextDir);
106  
-        assertEquals("was not detected as expected", rootContextDir, embed.getConfig().getContextRootDirectory());
  114
+        assertEquals("was not detected as expected", rootContextDir, embed.build().getConfig().getContextRootDirectory());
107 115
     }
108 116
 
109 117
     @Test
@@ -112,40 +120,41 @@ public void withContextRootDirectoryAsRelativeDirectory() {
112 120
         assertTrue("src/main/java should exist [" + f.getAbsolutePath() + "] make sure you are running " +
113 121
                 "the tests with the working directory set to this module.", f.exists());
114 122
         final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component).withContextRootDirectory("src/main/java");
115  
-        assertEquals("was not detected as expected", f, embed.getConfig().getContextRootDirectory());
  123