summaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2012-09-21 15:00:08 +0300
committerLeif Åstrand <leif@vaadin.com>2012-09-21 15:00:08 +0300
commitbec5d96c5bdea6f4903ef8b85d056d1d8ff6924d (patch)
tree8ac041519103dcbaaee25cc95d95ee05048337d1 /server/src/com/vaadin
parent360f19b82e5b5d5d2646e444f274d5643f93d3d5 (diff)
downloadvaadin-framework-bec5d96c5bdea6f4903ef8b85d056d1d8ff6924d.tar.gz
vaadin-framework-bec5d96c5bdea6f4903ef8b85d056d1d8ff6924d.zip
Merge UIProvider and AbstractUIProvider (#9642)
Diffstat (limited to 'server/src/com/vaadin')
-rw-r--r--server/src/com/vaadin/server/AbstractUIProvider.java122
-rw-r--r--server/src/com/vaadin/server/DefaultUIProvider.java2
-rw-r--r--server/src/com/vaadin/server/LegacyApplicationUIProvider.java2
-rw-r--r--server/src/com/vaadin/server/UIProvider.java130
4 files changed, 105 insertions, 151 deletions
diff --git a/server/src/com/vaadin/server/AbstractUIProvider.java b/server/src/com/vaadin/server/AbstractUIProvider.java
deleted file mode 100644
index 32322fde65..0000000000
--- a/server/src/com/vaadin/server/AbstractUIProvider.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright 2011 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.vaadin.server;
-
-import java.lang.annotation.Annotation;
-
-import com.vaadin.annotations.PreserveOnRefresh;
-import com.vaadin.annotations.Theme;
-import com.vaadin.annotations.Title;
-import com.vaadin.annotations.Widgetset;
-import com.vaadin.ui.UI;
-
-public abstract class AbstractUIProvider implements UIProvider {
-
- @Override
- public UI createInstance(VaadinRequest request,
- Class<? extends UI> type) {
- try {
- return type.newInstance();
- } catch (InstantiationException e) {
- throw new RuntimeException("Could not instantiate root class", e);
- } catch (IllegalAccessException e) {
- throw new RuntimeException("Could not access root class", e);
- }
- }
-
- /**
- * Helper to get an annotation for a class. If the annotation is not present
- * on the target class, it's superclasses and implemented interfaces are
- * also searched for the annotation.
- *
- * @param type
- * the target class from which the annotation should be found
- * @param annotationType
- * the annotation type to look for
- * @return an annotation of the given type, or <code>null</code> if the
- * annotation is not present on the class
- */
- protected static <T extends Annotation> T getAnnotationFor(Class<?> type,
- Class<T> annotationType) {
- // Find from the class hierarchy
- Class<?> currentType = type;
- while (currentType != Object.class) {
- T annotation = currentType.getAnnotation(annotationType);
- if (annotation != null) {
- return annotation;
- } else {
- currentType = currentType.getSuperclass();
- }
- }
-
- // Find from an implemented interface
- for (Class<?> iface : type.getInterfaces()) {
- T annotation = iface.getAnnotation(annotationType);
- if (annotation != null) {
- return annotation;
- }
- }
-
- return null;
- }
-
- @Override
- public String getTheme(VaadinRequest request,
- Class<? extends UI> uiClass) {
- Theme uiTheme = getAnnotationFor(uiClass, Theme.class);
- if (uiTheme != null) {
- return uiTheme.value();
- } else {
- return null;
- }
- }
-
- @Override
- public String getWidgetset(VaadinRequest request,
- Class<? extends UI> uiClass) {
- Widgetset uiWidgetset = getAnnotationFor(uiClass, Widgetset.class);
- if (uiWidgetset != null) {
- return uiWidgetset.value();
- } else {
- return null;
- }
- }
-
- @Override
- public boolean isPreservedOnRefresh(VaadinRequest request,
- Class<? extends UI> uiClass) {
- PreserveOnRefresh preserveOnRefresh = getAnnotationFor(uiClass,
- PreserveOnRefresh.class);
- return preserveOnRefresh != null;
- }
-
- @Override
- public String getPageTitle(VaadinRequest request,
- Class<? extends UI> uiClass) {
- Title titleAnnotation = getAnnotationFor(uiClass, Title.class);
- if (titleAnnotation == null) {
- return null;
- } else {
- return titleAnnotation.value();
- }
- }
-
- @Override
- public UI getExistingUI(VaadinRequest request) {
- return null;
- }
-}
diff --git a/server/src/com/vaadin/server/DefaultUIProvider.java b/server/src/com/vaadin/server/DefaultUIProvider.java
index 87bb7d27c2..85fc10e716 100644
--- a/server/src/com/vaadin/server/DefaultUIProvider.java
+++ b/server/src/com/vaadin/server/DefaultUIProvider.java
@@ -18,7 +18,7 @@ package com.vaadin.server;
import com.vaadin.ui.UI;
-public class DefaultUIProvider extends AbstractUIProvider {
+public class DefaultUIProvider extends UIProvider {
@Override
public Class<? extends UI> getUIClass(VaadinRequest request) {
diff --git a/server/src/com/vaadin/server/LegacyApplicationUIProvider.java b/server/src/com/vaadin/server/LegacyApplicationUIProvider.java
index 0681d0bee1..f454732ba6 100644
--- a/server/src/com/vaadin/server/LegacyApplicationUIProvider.java
+++ b/server/src/com/vaadin/server/LegacyApplicationUIProvider.java
@@ -22,7 +22,7 @@ import java.util.regex.Pattern;
import com.vaadin.LegacyApplication;
import com.vaadin.ui.UI;
-public abstract class LegacyApplicationUIProvider extends AbstractUIProvider {
+public abstract class LegacyApplicationUIProvider extends UIProvider {
/**
* Ignore initial / and then get everything up to the next /
*/
diff --git a/server/src/com/vaadin/server/UIProvider.java b/server/src/com/vaadin/server/UIProvider.java
index 81a53fae15..53e3a07730 100644
--- a/server/src/com/vaadin/server/UIProvider.java
+++ b/server/src/com/vaadin/server/UIProvider.java
@@ -16,31 +16,84 @@
package com.vaadin.server;
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+
+import com.vaadin.annotations.PreserveOnRefresh;
+import com.vaadin.annotations.Theme;
+import com.vaadin.annotations.Title;
import com.vaadin.annotations.Widgetset;
import com.vaadin.ui.UI;
-public interface UIProvider {
- public Class<? extends UI> getUIClass(VaadinRequest request);
+public abstract class UIProvider implements Serializable {
+ public abstract Class<? extends UI> getUIClass(VaadinRequest request);
- public UI createInstance(VaadinRequest request, Class<? extends UI> type);
+ public UI createInstance(VaadinRequest request, Class<? extends UI> type) {
+ try {
+ return type.newInstance();
+ } catch (InstantiationException e) {
+ throw new RuntimeException("Could not instantiate root class", e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException("Could not access root class", e);
+ }
+ }
- public String getPageTitle(VaadinRequest request,
- Class<? extends UI> uiClass);
+ /**
+ * Helper to get an annotation for a class. If the annotation is not present
+ * on the target class, it's superclasses and implemented interfaces are
+ * also searched for the annotation.
+ *
+ * @param type
+ * the target class from which the annotation should be found
+ * @param annotationType
+ * the annotation type to look for
+ * @return an annotation of the given type, or <code>null</code> if the
+ * annotation is not present on the class
+ */
+ protected static <T extends Annotation> T getAnnotationFor(Class<?> type,
+ Class<T> annotationType) {
+ // Find from the class hierarchy
+ Class<?> currentType = type;
+ while (currentType != Object.class) {
+ T annotation = currentType.getAnnotation(annotationType);
+ if (annotation != null) {
+ return annotation;
+ } else {
+ currentType = currentType.getSuperclass();
+ }
+ }
+
+ // Find from an implemented interface
+ for (Class<?> iface : type.getInterfaces()) {
+ T annotation = iface.getAnnotation(annotationType);
+ if (annotation != null) {
+ return annotation;
+ }
+ }
+
+ return null;
+ }
/**
- * Checks whether the same UI state should be reused if the framework can
- * detect that the application is opened in a browser window where it has
- * previously been open. The framework attempts to discover this by checking
- * the value of window.name in the browser.
+ * Finds the theme to use for a specific UI. If no specific theme is
+ * required, <code>null</code> is returned.
*
- * @param request
- * @param uiClass
+ * TODO Tell what the default implementation does once it does something.
+ *
+ * @param uI
+ * the UI to get a theme for
+ * @return the name of the theme, or <code>null</code> if the default theme
+ * should be used
*
- * @return <code>true</code>if the same UI instance should be reused e.g.
- * when the browser window is refreshed.
*/
- public boolean isPreservedOnRefresh(VaadinRequest request,
- Class<? extends UI> uiClass);
+ public String getTheme(VaadinRequest request, Class<? extends UI> uiClass) {
+ Theme uiTheme = getAnnotationFor(uiClass, Theme.class);
+ if (uiTheme != null) {
+ return uiTheme.value();
+ } else {
+ return null;
+ }
+ }
/**
* Finds the widgetset to use for a specific UI. If no specific widgetset is
@@ -58,21 +111,43 @@ public interface UIProvider {
*
*/
public String getWidgetset(VaadinRequest request,
- Class<? extends UI> uiClass);
+ Class<? extends UI> uiClass) {
+ Widgetset uiWidgetset = getAnnotationFor(uiClass, Widgetset.class);
+ if (uiWidgetset != null) {
+ return uiWidgetset.value();
+ } else {
+ return null;
+ }
+ }
/**
- * Finds the theme to use for a specific UI. If no specific theme is
- * required, <code>null</code> is returned.
- *
- * TODO Tell what the default implementation does once it does something.
+ * Checks whether the same UI state should be reused if the framework can
+ * detect that the application is opened in a browser window where it has
+ * previously been open. The framework attempts to discover this by checking
+ * the value of window.name in the browser.
*
- * @param uI
- * the UI to get a theme for
- * @return the name of the theme, or <code>null</code> if the default theme
- * should be used
+ * @param request
+ * @param uiClass
*
+ * @return <code>true</code>if the same UI instance should be reused e.g.
+ * when the browser window is refreshed.
*/
- public String getTheme(VaadinRequest request, Class<? extends UI> uiClass);
+ public boolean isPreservedOnRefresh(VaadinRequest request,
+ Class<? extends UI> uiClass) {
+ PreserveOnRefresh preserveOnRefresh = getAnnotationFor(uiClass,
+ PreserveOnRefresh.class);
+ return preserveOnRefresh != null;
+ }
+
+ public String getPageTitle(VaadinRequest request,
+ Class<? extends UI> uiClass) {
+ Title titleAnnotation = getAnnotationFor(uiClass, Title.class);
+ if (titleAnnotation == null) {
+ return null;
+ } else {
+ return titleAnnotation.value();
+ }
+ }
/**
* Finds an existing {@link UI} for a request.
@@ -91,6 +166,7 @@ public interface UIProvider {
* @return a UI belonging to the request, or <code>null</code> if this UI
* provider doesn't have an existing UI for the request.
*/
- public UI getExistingUI(VaadinRequest request);
-
+ public UI getExistingUI(VaadinRequest request) {
+ return null;
+ }
}