aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/data
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/com/vaadin/data')
-rw-r--r--server/src/com/vaadin/data/util/AbstractProperty.java37
-rw-r--r--server/src/com/vaadin/data/util/IndexedContainer.java38
-rw-r--r--server/src/com/vaadin/data/util/LegacyPropertyHelper.java102
-rw-r--r--server/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java37
4 files changed, 165 insertions, 49 deletions
diff --git a/server/src/com/vaadin/data/util/AbstractProperty.java b/server/src/com/vaadin/data/util/AbstractProperty.java
index 499421a8b4..903f2f50f2 100644
--- a/server/src/com/vaadin/data/util/AbstractProperty.java
+++ b/server/src/com/vaadin/data/util/AbstractProperty.java
@@ -18,7 +18,6 @@ package com.vaadin.data.util;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
-import java.util.logging.Level;
import java.util.logging.Logger;
import com.vaadin.data.Property;
@@ -71,27 +70,33 @@ public abstract class AbstractProperty<T> implements Property<T>,
}
/**
- * Returns the value of the <code>Property</code> in human readable textual
- * format.
+ * Returns a string representation of this object. The returned string
+ * representation depends on if the legacy Property toString mode is enabled
+ * or disabled.
+ * <p>
+ * If legacy Property toString mode is enabled, returns the value of the
+ * <code>Property</code> converted to a String.
+ * </p>
+ * <p>
+ * If legacy Property toString mode is disabled, the string representation
+ * has no special meaning
+ * </p>
*
- * @return String representation of the value stored in the Property
- * @deprecated As of 7.0, use {@link #getValue()} instead and possibly
- * toString on that
+ * @see LegacyPropertyHelper#isLegacyToStringEnabled()
+ *
+ * @return A string representation of the value value stored in the Property
+ * or a string representation of the Property object.
+ * @deprecated As of 7.0. To get the property value, use {@link #getValue()}
+ * instead (and possibly toString on that)
*/
@Deprecated
@Override
public String toString() {
- getLogger()
- .log(Level.WARNING,
- "You are using Property.toString() instead of getValue() to get the value for a {0}."
- + "This will not be supported starting from Vaadin 7.1 "
- + "(your debugger might call toString() and cause this message to appear).",
- getClass().getSimpleName());
- T v = getValue();
- if (v == null) {
- return null;
+ if (!LegacyPropertyHelper.isLegacyToStringEnabled()) {
+ return super.toString();
+ } else {
+ return LegacyPropertyHelper.legacyPropertyToString(this);
}
- return v.toString();
}
/* Events */
diff --git a/server/src/com/vaadin/data/util/IndexedContainer.java b/server/src/com/vaadin/data/util/IndexedContainer.java
index a54bf26e52..31f37ac277 100644
--- a/server/src/com/vaadin/data/util/IndexedContainer.java
+++ b/server/src/com/vaadin/data/util/IndexedContainer.java
@@ -28,7 +28,6 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import java.util.logging.Level;
import java.util.logging.Logger;
import com.vaadin.data.Container;
@@ -954,29 +953,32 @@ public class IndexedContainer extends
}
/**
- * Returns the value of the Property in human readable textual format.
- * The return value should be assignable to the <code>setValue</code>
- * method if the Property is not in read-only mode.
+ * Returns a string representation of this object. The returned string
+ * representation depends on if the legacy Property toString mode is
+ * enabled or disabled.
+ * <p>
+ * If legacy Property toString mode is enabled, returns the value of the
+ * <code>Property</code> converted to a String.
+ * </p>
+ * <p>
+ * If legacy Property toString mode is disabled, the string
+ * representation has no special meaning
+ * </p>
*
- * @return <code>String</code> representation of the value stored in the
- * Property
- * @deprecated As of 7.0, use {@link #getValue()} instead and possibly
- * toString on that
+ * @return A string representation of the value value stored in the
+ * Property or a string representation of the Property object.
+ * @deprecated As of 7.0. To get the property value, use
+ * {@link #getValue()} instead (and possibly toString on
+ * that)
*/
@Deprecated
@Override
public String toString() {
- getLogger()
- .log(Level.WARNING,
- "You are using IndexedContainerProperty.toString() instead of getValue() to get the value for a {0}."
- + " This will not be supported starting from Vaadin 7.1 "
- + "(your debugger might call toString() and cause this message to appear).",
- getClass().getSimpleName());
- Object v = getValue();
- if (v == null) {
- return null;
+ if (!LegacyPropertyHelper.isLegacyToStringEnabled()) {
+ return super.toString();
+ } else {
+ return LegacyPropertyHelper.legacyPropertyToString(this);
}
- return v.toString();
}
private Logger getLogger() {
diff --git a/server/src/com/vaadin/data/util/LegacyPropertyHelper.java b/server/src/com/vaadin/data/util/LegacyPropertyHelper.java
new file mode 100644
index 0000000000..0276e35dbf
--- /dev/null
+++ b/server/src/com/vaadin/data/util/LegacyPropertyHelper.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2000-2013 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.data.util;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import com.vaadin.data.Property;
+import com.vaadin.server.Constants;
+import com.vaadin.server.DeploymentConfiguration.LegacyProperyToStringMode;
+import com.vaadin.server.VaadinService;
+
+/**
+ * Helper class which provides methods for handling Property.toString in a
+ * Vaadin 6 compatible way
+ *
+ * @author Vaadin Ltd
+ * @since 7.1
+ * @deprecated This is only used internally for backwards compatibility
+ */
+@Deprecated
+public class LegacyPropertyHelper {
+
+ /**
+ * Returns the property value converted to a String.
+ *
+ * @param p
+ * The property
+ * @return A string representation of the property value, compatible with
+ * how Property implementations in Vaadin 6 do it
+ */
+ public static String legacyPropertyToString(Property p) {
+ maybeLogLegacyPropertyToStringWarning(p);
+ Object value = p.getValue();
+ if (value == null) {
+ return null;
+ }
+ return value.toString();
+ }
+
+ public static void maybeLogLegacyPropertyToStringWarning(Property p) {
+ if (!logLegacyToStringWarning()) {
+ return;
+ }
+
+ getLogger().log(Level.WARNING,
+ Constants.WARNING_LEGACY_PROPERTY_TOSTRING,
+ p.getClass().getName());
+ }
+
+ /**
+ * Checks if legacy Property.toString() implementation is enabled. The
+ * legacy Property.toString() will return the value of the property somehow
+ * converted to a String. If the legacy mode is disabled, toString() will
+ * return super.toString().
+ * <p>
+ * The legacy toString mode can be toggled using the
+ * "legacyPropertyToString" init parameter
+ * </p>
+ *
+ * @return true if legacy Property.toString() mode is enabled, false
+ * otherwise
+ */
+ public static boolean isLegacyToStringEnabled() {
+ if (VaadinService.getCurrent() == null) {
+ // This should really not happen but we need to handle it somehow.
+ // IF it happens it seems more safe to use the legacy mode and log.
+ return true;
+ }
+ return VaadinService.getCurrent().getDeploymentConfiguration()
+ .getLegacyPropertyToStringMode().useLegacyMode();
+ }
+
+ private static boolean logLegacyToStringWarning() {
+ if (VaadinService.getCurrent() == null) {
+ // This should really not happen but we need to handle it somehow.
+ // IF it happens it seems more safe to use the legacy mode and log.
+ return true;
+ }
+ return VaadinService.getCurrent().getDeploymentConfiguration()
+ .getLegacyPropertyToStringMode() == LegacyProperyToStringMode.WARNING;
+
+ }
+
+ private static Logger getLogger() {
+ return Logger.getLogger(LegacyPropertyHelper.class.getName());
+ }
+
+}
diff --git a/server/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java b/server/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java
index 378372d044..d8448a2b50 100644
--- a/server/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java
+++ b/server/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java
@@ -18,10 +18,10 @@ package com.vaadin.data.util.sqlcontainer;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
-import java.util.logging.Level;
import java.util.logging.Logger;
import com.vaadin.data.Property;
+import com.vaadin.data.util.LegacyPropertyHelper;
import com.vaadin.data.util.converter.Converter.ConversionException;
/**
@@ -255,26 +255,33 @@ final public class ColumnProperty implements Property {
}
/**
- * Returns the value of the Property in human readable textual format.
+ * Returns a string representation of this object. The returned string
+ * representation depends on if the legacy Property toString mode is enabled
+ * or disabled.
+ * <p>
+ * If legacy Property toString mode is enabled, returns the value of this
+ * <code>Property</code> converted to a String.
+ * </p>
+ * <p>
+ * If legacy Property toString mode is disabled, the string representation
+ * has no special meaning
+ * </p>
*
- * @see java.lang.Object#toString()
- * @deprecated As of 7.0, use {@link #getValue()} instead and possibly
- * toString on that
+ * @see LegacyPropertyHelper#isLegacyToStringEnabled()
+ *
+ * @return A string representation of the value value stored in the Property
+ * or a string representation of the Property object.
+ * @deprecated As of 7.0. To get the property value, use {@link #getValue()}
+ * instead (and possibly toString on that)
*/
@Deprecated
@Override
public String toString() {
- getLogger()
- .log(Level.WARNING,
- "You are using ColumnProperty.toString() instead of getValue() to get the value for a {0}. "
- + "This will not be supported starting from Vaadin 7.1 (your debugger might call toString() "
- + "and cause this message to appear).",
- getClass().getSimpleName());
- Object v = getValue();
- if (v == null) {
- return null;
+ if (!LegacyPropertyHelper.isLegacyToStringEnabled()) {
+ return super.toString();
+ } else {
+ return LegacyPropertyHelper.legacyPropertyToString(this);
}
- return v.toString();
}
private static Logger getLogger() {