From 9fce56f6a4b81b69bbdf70a5434a51d6f85aebd8 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 29 Aug 2016 14:59:28 +0300 Subject: [PATCH] Move V7 Converter and ConverterFactory to compatibility package Change-Id: I48d1ea501a621f653bde840d646ae01e6edc3eea --- .../v7/data/util/converter/Converter.java | 0 .../data/util/converter/ConverterFactory.java | 0 .../v7/data/util/converter/ConverterUtil.java | 21 ++++++---- .../java/com/vaadin/server/VaadinSession.java | 41 +++++++++---------- .../converters/DesignResourceConverter.java | 18 +------- 5 files changed, 35 insertions(+), 45 deletions(-) rename {server => compatibility-server}/src/main/java/com/vaadin/v7/data/util/converter/Converter.java (100%) rename {server => compatibility-server}/src/main/java/com/vaadin/v7/data/util/converter/ConverterFactory.java (100%) diff --git a/server/src/main/java/com/vaadin/v7/data/util/converter/Converter.java b/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/Converter.java similarity index 100% rename from server/src/main/java/com/vaadin/v7/data/util/converter/Converter.java rename to compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/Converter.java diff --git a/server/src/main/java/com/vaadin/v7/data/util/converter/ConverterFactory.java b/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/ConverterFactory.java similarity index 100% rename from server/src/main/java/com/vaadin/v7/data/util/converter/ConverterFactory.java rename to compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/ConverterFactory.java diff --git a/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/ConverterUtil.java b/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/ConverterUtil.java index b0679e9caf..0a874f465f 100644 --- a/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/ConverterUtil.java +++ b/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/ConverterUtil.java @@ -51,7 +51,13 @@ public class ConverterUtil implements Serializable { } if (session != null) { - ConverterFactory factory = session.getConverterFactory(); + ConverterFactory factory = (ConverterFactory) session + .getConverterFactory(); + if (factory == null) { + // Assume DefaultConverterFactory should be in session + factory = new DefaultConverterFactory(); + session.setConverterFactory(factory); + } converter = factory.createConverter(presentationType, modelType); } return converter; @@ -84,8 +90,8 @@ public class ConverterUtil implements Serializable { public static PRESENTATIONTYPE convertFromModel( MODELTYPE modelValue, Class presentationType, - Converter converter, - Locale locale) throws Converter.ConversionException { + Converter converter, Locale locale) + throws Converter.ConversionException { if (converter != null) { /* * If there is a converter, always use it. It must convert or throw @@ -145,8 +151,8 @@ public class ConverterUtil implements Serializable { */ public static MODELTYPE convertToModel( PRESENTATIONTYPE presentationValue, Class modelType, - Converter converter, - Locale locale) throws Converter.ConversionException { + Converter converter, Locale locale) + throws Converter.ConversionException { if (converter != null) { /* * If there is a converter, always use it. It must convert or throw @@ -233,9 +239,8 @@ public class ConverterUtil implements Serializable { * @return true if the converter possibly support conversion between the * given presentation and model type, false otherwise */ - public static boolean canConverterPossiblyHandle( - Converter converter, Class presentationType, - Class modelType) { + public static boolean canConverterPossiblyHandle(Converter converter, + Class presentationType, Class modelType) { if (converter == null) { return false; } diff --git a/server/src/main/java/com/vaadin/server/VaadinSession.java b/server/src/main/java/com/vaadin/server/VaadinSession.java index bcd7e66518..8b503b9b37 100644 --- a/server/src/main/java/com/vaadin/server/VaadinSession.java +++ b/server/src/main/java/com/vaadin/server/VaadinSession.java @@ -52,7 +52,6 @@ import com.vaadin.shared.communication.PushMode; import com.vaadin.ui.UI; import com.vaadin.util.CurrentInstance; import com.vaadin.util.ReflectTools; -import com.vaadin.v7.data.util.converter.ConverterFactory; /** * Contains everything that Vaadin needs to store for a specific user. This is @@ -225,7 +224,7 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { * session. */ @Deprecated - private ConverterFactory converterFactory; + private Object converterFactory; private LinkedList requestHandlers = new LinkedList(); @@ -278,12 +277,11 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { public VaadinSession(VaadinService service) { this.service = service; try { - // This is to avoid having DefaultConverterFactory in the server - // package - Class cls = (Class) getClass() - .getClassLoader().loadClass( - "com.vaadin.v7.data.util.converter.DefaultConverterFactory"); - ConverterFactory factory = cls.newInstance(); + // This is to avoid having ConverterFactory/DefaultConverterFactory + // in the server package + Class cls = getClass().getClassLoader().loadClass( + "com.vaadin.v7.data.util.converter.DefaultConverterFactory"); + Object factory = cls.newInstance(); converterFactory = factory; } catch (Exception e) { // DefaultConverterFactory not found, go on without and warn later @@ -602,32 +600,33 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { } /** - * Gets the {@link ConverterFactory} used to locate a suitable + * Gets the {@code ConverterFactory} used to locate a suitable * {@code Converter} for fields in the session. - * - * See {@link #setConverterFactory(ConverterFactory)} for more details + *

+ * Note that the this and {@link #setConverterFactory(Object))} use Object + * and not {@code ConverterFactory} in Vaadin 8 to avoid a core dependency + * on the compatibility packages. * * @return The converter factory used in the session */ @Deprecated - public ConverterFactory getConverterFactory() { + public Object getConverterFactory() { assert hasLock(); - if (converterFactory == null) { - throw new IllegalStateException( - "No converter factory has been set and com.vaadin.v7.data.util.converter.DefaultConverterFactory could not be found when creating the session"); - } return converterFactory; } /** - * Sets the {@link ConverterFactory} used to locate a suitable - * {@link Converter} for fields in the session. + * Sets the {@code ConverterFactory} used to locate a suitable + * {@code Converter} for fields in the session. *

- * The {@link ConverterFactory} is used to find a suitable converter when + * The {@code ConverterFactory} is used to find a suitable converter when * binding data to a UI component and the data type does not match the UI * component type, e.g. binding a Double to a TextField (which is based on a * String). - *

+ *

+ * Note that the this and {@code #getConverterFactory()} use Object and not + * {@code ConverterFactory} in Vaadin 8 to avoid a core dependency on the + * compatibility packages. *

* The converter factory must never be set to null. * @@ -635,7 +634,7 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { * The converter factory used in the session */ @Deprecated - public void setConverterFactory(ConverterFactory converterFactory) { + public void setConverterFactory(Object converterFactory) { assert hasLock(); this.converterFactory = converterFactory; } diff --git a/server/src/main/java/com/vaadin/ui/declarative/converters/DesignResourceConverter.java b/server/src/main/java/com/vaadin/ui/declarative/converters/DesignResourceConverter.java index 23f21b4eda..cc9d6ac655 100644 --- a/server/src/main/java/com/vaadin/ui/declarative/converters/DesignResourceConverter.java +++ b/server/src/main/java/com/vaadin/ui/declarative/converters/DesignResourceConverter.java @@ -32,7 +32,6 @@ import com.vaadin.server.Resource; import com.vaadin.server.ResourceReference; import com.vaadin.server.ThemeResource; import com.vaadin.ui.declarative.DesignAttributeHandler; -import com.vaadin.v7.data.util.converter.Converter.ConversionException; /** * A converter for {@link Resource} implementations supported by @@ -106,14 +105,7 @@ public class DesignResourceConverter implements Converter { final int codepoint = Integer.valueOf(familyAndCode[1], 16); if (FontAwesome.FONT_FAMILY.equals(familyAndCode[0])) { - try { - return FontAwesome.fromCodepoint(codepoint); - } catch (IllegalArgumentException iae) { - throw new ConversionException( - "Unknown codepoint in FontAwesome: " - + codepoint, - iae); - } + return FontAwesome.fromCodepoint(codepoint); } FontIcon generic = new GenericFontIcon(familyAndCode[0], @@ -136,13 +128,7 @@ public class DesignResourceConverter implements Converter { // Deprecated, 7.4 syntax is // font://"+FontAwesome.valueOf(foo) eg. "font://AMBULANCE" final String iconName = (value.split("://", 2))[1]; - - try { - return FontAwesome.valueOf(iconName); - } catch (IllegalArgumentException iae) { - throw new ConversionException( - "Unknown FontIcon constant: " + iconName, iae); - } + return FontAwesome.valueOf(iconName); } @Override -- 2.39.5