--- /dev/null
+/*
+ * Copyright 2000-2016 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.v7.data.util.converter;
+
+import java.io.Serializable;
+import java.util.Locale;
+
+/**
+ * Interface that implements conversion between a model and a presentation type.
+ * <p>
+ * Typically {@link #convertToPresentation(Object, Class, Locale)} and
+ * {@link #convertToModel(Object, Class, Locale)} should be symmetric so that
+ * chaining these together returns the original result for all input but this is
+ * not a requirement.
+ * </p>
+ * <p>
+ * Converters must not have any side effects (never update UI from inside a
+ * converter).
+ * </p>
+ * <p>
+ * All Converters must be stateless and thread safe.
+ * </p>
+ * <p>
+ * If conversion of a value fails, a {@link ConversionException} is thrown.
+ * </p>
+ *
+ * @param <PRESENTATION>
+ * The presentation type. Must be compatible with what
+ * {@link #getPresentationType()} returns.
+ * @param <MODEL>
+ * The model type. Must be compatible with what
+ * {@link #getModelType()} returns.
+ * @author Vaadin Ltd.
+ * @since 7.0
+ */
+@Deprecated
+public interface Converter<PRESENTATION, MODEL> extends Serializable {
+
+ /**
+ * Converts the given value from target type to source type.
+ * <p>
+ * A converter can optionally use locale to do the conversion.
+ * </p>
+ * A converter should in most cases be symmetric so chaining
+ * {@link #convertToPresentation(Object, Class, Locale)} and
+ * {@link #convertToModel(Object, Class, Locale)} should return the original
+ * value.
+ *
+ * @param value
+ * The value to convert, compatible with the target type. Can be
+ * null
+ * @param targetType
+ * The requested type of the return value
+ * @param locale
+ * The locale to use for conversion. Can be null.
+ * @return The converted value compatible with the source type
+ * @throws ConversionException
+ * If the value could not be converted
+ */
+ public MODEL convertToModel(PRESENTATION value,
+ Class<? extends MODEL> targetType, Locale locale)
+ throws ConversionException;
+
+ /**
+ * Converts the given value from source type to target type.
+ * <p>
+ * A converter can optionally use locale to do the conversion.
+ * </p>
+ * A converter should in most cases be symmetric so chaining
+ * {@link #convertToPresentation(Object, Class, Locale)} and
+ * {@link #convertToModel(Object, Class, Locale)} should return the original
+ * value.
+ *
+ * @param value
+ * The value to convert, compatible with the target type. Can be
+ * null
+ * @param targetType
+ * The requested type of the return value
+ * @param locale
+ * The locale to use for conversion. Can be null.
+ * @return The converted value compatible with the source type
+ * @throws ConversionException
+ * If the value could not be converted
+ */
+ public PRESENTATION convertToPresentation(MODEL value,
+ Class<? extends PRESENTATION> targetType, Locale locale)
+ throws ConversionException;
+
+ /**
+ * The source type of the converter.
+ *
+ * Values of this type can be passed to
+ * {@link #convertToPresentation(Object, Class, Locale)}.
+ *
+ * @return The source type
+ */
+ public Class<MODEL> getModelType();
+
+ /**
+ * The target type of the converter.
+ *
+ * Values of this type can be passed to
+ * {@link #convertToModel(Object, Class, Locale)}.
+ *
+ * @return The target type
+ */
+ public Class<PRESENTATION> getPresentationType();
+
+ /**
+ * An exception that signals that the value passed to
+ * {@link Converter#convertToPresentation(Object, Class, Locale)} or
+ * {@link Converter#convertToModel(Object, Class, Locale)} could not be
+ * converted.
+ *
+ * @author Vaadin Ltd
+ * @since 7.0
+ */
+ public static class ConversionException extends RuntimeException {
+
+ /**
+ * Constructs a new <code>ConversionException</code> without a detail
+ * message.
+ */
+ public ConversionException() {
+ }
+
+ /**
+ * Constructs a new <code>ConversionException</code> with the specified
+ * detail message.
+ *
+ * @param msg
+ * the detail message
+ */
+ public ConversionException(String msg) {
+ super(msg);
+ }
+
+ /**
+ * Constructs a new {@code ConversionException} with the specified
+ * cause.
+ *
+ * @param cause
+ * The cause of the the exception
+ */
+ public ConversionException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Constructs a new <code>ConversionException</code> with the specified
+ * detail message and cause.
+ *
+ * @param message
+ * the detail message
+ * @param cause
+ * The cause of the the exception
+ */
+ public ConversionException(String message, Throwable cause) {
+ super(message, cause);
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Copyright 2000-2016 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.v7.data.util.converter;
+
+import java.io.Serializable;
+
+/**
+ * Factory interface for providing Converters based on a presentation type and a
+ * model type.
+ *
+ * @author Vaadin Ltd.
+ * @since 7.0
+ *
+ */
+@Deprecated
+public interface ConverterFactory extends Serializable {
+ public <PRESENTATION, MODEL> Converter<PRESENTATION, MODEL> createConverter(
+ Class<PRESENTATION> presentationType, Class<MODEL> modelType);
+
+}
}
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;
public static <PRESENTATIONTYPE, MODELTYPE> PRESENTATIONTYPE convertFromModel(
MODELTYPE modelValue,
Class<? extends PRESENTATIONTYPE> presentationType,
- Converter<PRESENTATIONTYPE, MODELTYPE> converter,
- Locale locale) throws Converter.ConversionException {
+ Converter<PRESENTATIONTYPE, MODELTYPE> converter, Locale locale)
+ throws Converter.ConversionException {
if (converter != null) {
/*
* If there is a converter, always use it. It must convert or throw
*/
public static <MODELTYPE, PRESENTATIONTYPE> MODELTYPE convertToModel(
PRESENTATIONTYPE presentationValue, Class<MODELTYPE> modelType,
- Converter<PRESENTATIONTYPE, MODELTYPE> converter,
- Locale locale) throws Converter.ConversionException {
+ Converter<PRESENTATIONTYPE, MODELTYPE> converter, Locale locale)
+ throws Converter.ConversionException {
if (converter != null) {
/*
* If there is a converter, always use it. It must convert or throw
* @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;
}
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
* session.
*/
@Deprecated
- private ConverterFactory converterFactory;
+ private Object converterFactory;
private LinkedList<RequestHandler> requestHandlers = new LinkedList<RequestHandler>();
public VaadinSession(VaadinService service) {
this.service = service;
try {
- // This is to avoid having DefaultConverterFactory in the server
- // package
- Class<? extends ConverterFactory> cls = (Class<? extends ConverterFactory>) 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
}
/**
- * 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
+ * <p>
+ * 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.
* <p>
- * 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).
- * </p>
+ * <p>
+ * 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.
* <p>
* The converter factory must never be set to null.
*
* The converter factory used in the session
*/
@Deprecated
- public void setConverterFactory(ConverterFactory converterFactory) {
+ public void setConverterFactory(Object converterFactory) {
assert hasLock();
this.converterFactory = converterFactory;
}
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
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],
// 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
+++ /dev/null
-/*
- * Copyright 2000-2016 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.v7.data.util.converter;
-
-import java.io.Serializable;
-import java.util.Locale;
-
-/**
- * Interface that implements conversion between a model and a presentation type.
- * <p>
- * Typically {@link #convertToPresentation(Object, Class, Locale)} and
- * {@link #convertToModel(Object, Class, Locale)} should be symmetric so that
- * chaining these together returns the original result for all input but this is
- * not a requirement.
- * </p>
- * <p>
- * Converters must not have any side effects (never update UI from inside a
- * converter).
- * </p>
- * <p>
- * All Converters must be stateless and thread safe.
- * </p>
- * <p>
- * If conversion of a value fails, a {@link ConversionException} is thrown.
- * </p>
- *
- * @param <PRESENTATION>
- * The presentation type. Must be compatible with what
- * {@link #getPresentationType()} returns.
- * @param <MODEL>
- * The model type. Must be compatible with what
- * {@link #getModelType()} returns.
- * @author Vaadin Ltd.
- * @since 7.0
- */
-@Deprecated
-public interface Converter<PRESENTATION, MODEL> extends Serializable {
-
- /**
- * Converts the given value from target type to source type.
- * <p>
- * A converter can optionally use locale to do the conversion.
- * </p>
- * A converter should in most cases be symmetric so chaining
- * {@link #convertToPresentation(Object, Class, Locale)} and
- * {@link #convertToModel(Object, Class, Locale)} should return the original
- * value.
- *
- * @param value
- * The value to convert, compatible with the target type. Can be
- * null
- * @param targetType
- * The requested type of the return value
- * @param locale
- * The locale to use for conversion. Can be null.
- * @return The converted value compatible with the source type
- * @throws ConversionException
- * If the value could not be converted
- */
- public MODEL convertToModel(PRESENTATION value,
- Class<? extends MODEL> targetType, Locale locale)
- throws ConversionException;
-
- /**
- * Converts the given value from source type to target type.
- * <p>
- * A converter can optionally use locale to do the conversion.
- * </p>
- * A converter should in most cases be symmetric so chaining
- * {@link #convertToPresentation(Object, Class, Locale)} and
- * {@link #convertToModel(Object, Class, Locale)} should return the original
- * value.
- *
- * @param value
- * The value to convert, compatible with the target type. Can be
- * null
- * @param targetType
- * The requested type of the return value
- * @param locale
- * The locale to use for conversion. Can be null.
- * @return The converted value compatible with the source type
- * @throws ConversionException
- * If the value could not be converted
- */
- public PRESENTATION convertToPresentation(MODEL value,
- Class<? extends PRESENTATION> targetType, Locale locale)
- throws ConversionException;
-
- /**
- * The source type of the converter.
- *
- * Values of this type can be passed to
- * {@link #convertToPresentation(Object, Class, Locale)}.
- *
- * @return The source type
- */
- public Class<MODEL> getModelType();
-
- /**
- * The target type of the converter.
- *
- * Values of this type can be passed to
- * {@link #convertToModel(Object, Class, Locale)}.
- *
- * @return The target type
- */
- public Class<PRESENTATION> getPresentationType();
-
- /**
- * An exception that signals that the value passed to
- * {@link Converter#convertToPresentation(Object, Class, Locale)} or
- * {@link Converter#convertToModel(Object, Class, Locale)} could not be
- * converted.
- *
- * @author Vaadin Ltd
- * @since 7.0
- */
- public static class ConversionException extends RuntimeException {
-
- /**
- * Constructs a new <code>ConversionException</code> without a detail
- * message.
- */
- public ConversionException() {
- }
-
- /**
- * Constructs a new <code>ConversionException</code> with the specified
- * detail message.
- *
- * @param msg
- * the detail message
- */
- public ConversionException(String msg) {
- super(msg);
- }
-
- /**
- * Constructs a new {@code ConversionException} with the specified
- * cause.
- *
- * @param cause
- * The cause of the the exception
- */
- public ConversionException(Throwable cause) {
- super(cause);
- }
-
- /**
- * Constructs a new <code>ConversionException</code> with the specified
- * detail message and cause.
- *
- * @param message
- * the detail message
- * @param cause
- * The cause of the the exception
- */
- public ConversionException(String message, Throwable cause) {
- super(message, cause);
- }
- }
-
-}
+++ /dev/null
-/*
- * Copyright 2000-2016 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.v7.data.util.converter;
-
-import java.io.Serializable;
-
-/**
- * Factory interface for providing Converters based on a presentation type and a
- * model type.
- *
- * @author Vaadin Ltd.
- * @since 7.0
- *
- */
-@Deprecated
-public interface ConverterFactory extends Serializable {
- public <PRESENTATION, MODEL> Converter<PRESENTATION, MODEL> createConverter(
- Class<PRESENTATION> presentationType, Class<MODEL> modelType);
-
-}