summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksi Hietanen <aleksi@vaadin.com>2017-11-21 14:24:10 +0200
committerGitHub <noreply@github.com>2017-11-21 14:24:10 +0200
commit0fbeb0a6261b5a9f6485928965f0932fea0e624f (patch)
tree543873dfdd6a59adc69f6f8952375944579adbda
parent44364146b6298ca904faadf7c8dbfa018ecc7c3b (diff)
downloadvaadin-framework-0fbeb0a6261b5a9f6485928965f0932fea0e624f.tar.gz
vaadin-framework-0fbeb0a6261b5a9f6485928965f0932fea0e624f.zip
Extract AbstractBeanPropertyDefinition and PropertyFilterDefinition (#10344)
This commit extracts the private nested class AbstractBeanPropertyDefinition from BeanPropertySet to a public class of package com.vaadin.data. Additionally, the nested protected class PropertyFilterDefinition is extracted from NestedBeanPropertyDefinition to a public class in package com.vaadin.data.
-rw-r--r--server/src/main/java/com/vaadin/data/AbstractBeanPropertyDefinition.java101
-rw-r--r--server/src/main/java/com/vaadin/data/BeanPropertySet.java130
-rw-r--r--server/src/main/java/com/vaadin/data/Binder.java1
-rw-r--r--server/src/main/java/com/vaadin/data/PropertyFilterDefinition.java77
-rw-r--r--server/src/test/java/com/vaadin/data/BinderInstanceFieldTest.java1
5 files changed, 192 insertions, 118 deletions
diff --git a/server/src/main/java/com/vaadin/data/AbstractBeanPropertyDefinition.java b/server/src/main/java/com/vaadin/data/AbstractBeanPropertyDefinition.java
new file mode 100644
index 0000000000..3d8bd7ad0b
--- /dev/null
+++ b/server/src/main/java/com/vaadin/data/AbstractBeanPropertyDefinition.java
@@ -0,0 +1,101 @@
+/*
+ * 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.data;
+
+import java.beans.PropertyDescriptor;
+
+import com.vaadin.shared.util.SharedUtil;
+import com.vaadin.util.ReflectTools;
+
+/**
+ * Abstract base class for PropertyDefinition implementations for beans.
+ *
+ * @author Vaadin Ltd
+ * @since 8.2
+ *
+ * @param <T>
+ * the type of the property set
+ * @param <V>
+ * the property type
+ */
+public abstract class AbstractBeanPropertyDefinition<T, V>
+ implements PropertyDefinition<T, V> {
+
+ private final PropertyDescriptor descriptor;
+ private final BeanPropertySet<T> propertySet;
+ private final Class<?> propertyHolderType;
+
+ /**
+ * Constructor for setting the immutable descriptor, property set and
+ * property holder type used by this instance.
+ *
+ * @param propertySet
+ * property set this property belongs to
+ * @param parent
+ * parent property for this nested property
+ * @param descriptor
+ * property descriptor
+ */
+ public AbstractBeanPropertyDefinition(BeanPropertySet<T> propertySet,
+ Class<?> propertyHolderType, PropertyDescriptor descriptor) {
+ this.propertySet = propertySet;
+ this.propertyHolderType = propertyHolderType;
+ this.descriptor = descriptor;
+
+ if (descriptor.getReadMethod() == null) {
+ throw new IllegalArgumentException(
+ "Bean property has no accessible getter: "
+ + propertySet.getBeanType() + "."
+ + descriptor.getName());
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Class<V> getType() {
+ return (Class<V>) ReflectTools
+ .convertPrimitiveType(descriptor.getPropertyType());
+ }
+
+ @Override
+ public String getName() {
+ return descriptor.getName();
+ }
+
+ @Override
+ public String getCaption() {
+ return SharedUtil.propertyIdToHumanFriendly(getName());
+ }
+
+ @Override
+ public BeanPropertySet<T> getPropertySet() {
+ return propertySet;
+ }
+
+ /**
+ * Gets the property descriptor of this instance.
+ *
+ * @return the property descriptor
+ */
+ protected PropertyDescriptor getDescriptor() {
+ return descriptor;
+ }
+
+ @Override
+ public Class<?> getPropertyHolderType() {
+ return propertyHolderType;
+ }
+}
diff --git a/server/src/main/java/com/vaadin/data/BeanPropertySet.java b/server/src/main/java/com/vaadin/data/BeanPropertySet.java
index fbd60c8563..b302c83709 100644
--- a/server/src/main/java/com/vaadin/data/BeanPropertySet.java
+++ b/server/src/main/java/com/vaadin/data/BeanPropertySet.java
@@ -21,7 +21,6 @@ import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -35,8 +34,6 @@ import java.util.stream.Stream;
import com.vaadin.data.util.BeanUtil;
import com.vaadin.server.Setter;
-import com.vaadin.shared.util.SharedUtil;
-import com.vaadin.util.ReflectTools;
/**
* A {@link PropertySet} that uses reflection to find bean properties.
@@ -106,58 +103,6 @@ public class BeanPropertySet<T> implements PropertySet<T> {
}
}
- private abstract static class AbstractBeanPropertyDefinition<T, V>
- implements PropertyDefinition<T, V> {
- private final PropertyDescriptor descriptor;
- private final BeanPropertySet<T> propertySet;
- private final Class<?> propertyHolderType;
-
- public AbstractBeanPropertyDefinition(BeanPropertySet<T> propertySet,
- Class<?> propertyHolderType, PropertyDescriptor descriptor) {
- this.propertySet = propertySet;
- this.propertyHolderType = propertyHolderType;
- this.descriptor = descriptor;
-
- if (descriptor.getReadMethod() == null) {
- throw new IllegalArgumentException(
- "Bean property has no accessible getter: "
- + propertySet.beanType + "."
- + descriptor.getName());
- }
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Class<V> getType() {
- return (Class<V>) ReflectTools
- .convertPrimitiveType(descriptor.getPropertyType());
- }
-
- @Override
- public String getName() {
- return descriptor.getName();
- }
-
- @Override
- public String getCaption() {
- return SharedUtil.propertyIdToHumanFriendly(getName());
- }
-
- @Override
- public BeanPropertySet<T> getPropertySet() {
- return propertySet;
- }
-
- protected PropertyDescriptor getDescriptor() {
- return descriptor;
- }
-
- @Override
- public Class<?> getPropertyHolderType() {
- return propertyHolderType;
- }
- }
-
private static class BeanPropertyDefinition<T, V>
extends AbstractBeanPropertyDefinition<T, V> {
@@ -223,63 +168,6 @@ public class BeanPropertySet<T> implements PropertySet<T> {
*/
protected static final int MAX_PROPERTY_NESTING_DEPTH = 10;
- /**
- * Class containing the constraints for filtering nested properties.
- *
- * @since 8.2
- *
- */
- protected static class PropertyFilterDefinition
- implements Serializable {
- private int maxNestingDepth;
- private List<String> ignorePackageNamesStartingWith;
-
- /**
- * Create a property filter with max nesting depth and package names
- * to ignore.
- *
- * @param maxNestingDepth
- * The maximum amount of nesting levels for
- * sub-properties.
- * @param ignorePackageNamesStartingWith
- * Ignore package names that start with this string, for
- * example "java.lang".
- */
- public PropertyFilterDefinition(int maxNestingDepth,
- List<String> ignorePackageNamesStartingWith) {
- this.maxNestingDepth = maxNestingDepth;
- this.ignorePackageNamesStartingWith = ignorePackageNamesStartingWith;
- }
-
- /**
- * Returns the maximum amount of nesting levels for sub-properties.
- *
- * @return maximum nesting depth
- */
- public int getMaxNestingDepth() {
- return maxNestingDepth;
- }
-
- /**
- * Returns a list of package name prefixes to ignore.
- *
- * @return list of strings that
- */
- public List<String> getIgnorePackageNamesStartingWith() {
- return ignorePackageNamesStartingWith;
- }
-
- /**
- * Get the default nested property filtering conditions.
- *
- * @return default property filter
- */
- public static PropertyFilterDefinition getDefaultFilter() {
- return new PropertyFilterDefinition(MAX_PROPERTY_NESTING_DEPTH,
- Arrays.asList("java"));
- }
- }
-
private final PropertyDefinition<T, ?> parent;
private boolean useLongFormName = false;
@@ -295,7 +183,7 @@ public class BeanPropertySet<T> implements PropertySet<T> {
* Create nested property definition. Allows use of a long form name.
*
* @param propertySet
- * property set this property belongs is.
+ * property set this property belongs to
* @param parent
* parent property for this nested property
* @param descriptor
@@ -463,7 +351,7 @@ public class BeanPropertySet<T> implements PropertySet<T> {
}
private BeanPropertySet(Class<T> beanType, boolean checkNestedDefinitions,
- NestedBeanPropertyDefinition.PropertyFilterDefinition propertyFilterDefinition) {
+ PropertyFilterDefinition propertyFilterDefinition) {
this(beanType);
if (checkNestedDefinitions) {
Objects.requireNonNull(propertyFilterDefinition,
@@ -474,7 +362,7 @@ public class BeanPropertySet<T> implements PropertySet<T> {
private void findNestedDefinitions(
Map<String, PropertyDefinition<T, ?>> parentDefinitions, int depth,
- NestedBeanPropertyDefinition.PropertyFilterDefinition filterCallback) {
+ PropertyFilterDefinition filterCallback) {
if (depth >= filterCallback.getMaxNestingDepth()) {
return;
}
@@ -554,7 +442,7 @@ public class BeanPropertySet<T> implements PropertySet<T> {
@SuppressWarnings("unchecked")
public static <T> PropertySet<T> get(Class<? extends T> beanType,
boolean checkNestedDefinitions,
- NestedBeanPropertyDefinition.PropertyFilterDefinition filterDefinition) {
+ PropertyFilterDefinition filterDefinition) {
Objects.requireNonNull(beanType, "Bean type cannot be null");
InstanceKey key = new InstanceKey(beanType, false,
filterDefinition.getMaxNestingDepth(),
@@ -608,6 +496,16 @@ public class BeanPropertySet<T> implements PropertySet<T> {
return definition;
}
+ /**
+ * Gets the bean type of this bean property set.
+ *
+ * @since 8.2
+ * @return the bean type of this bean property set
+ */
+ public Class<T> getBeanType() {
+ return beanType;
+ }
+
private static boolean hasNonObjectReadMethod(
PropertyDescriptor descriptor) {
Method readMethod = descriptor.getReadMethod();
diff --git a/server/src/main/java/com/vaadin/data/Binder.java b/server/src/main/java/com/vaadin/data/Binder.java
index 96739f175d..0fe357e368 100644
--- a/server/src/main/java/com/vaadin/data/Binder.java
+++ b/server/src/main/java/com/vaadin/data/Binder.java
@@ -38,7 +38,6 @@ import java.util.stream.Stream;
import com.googlecode.gentyref.GenericTypeReflector;
import com.vaadin.annotations.PropertyId;
-import com.vaadin.data.BeanPropertySet.NestedBeanPropertyDefinition.PropertyFilterDefinition;
import com.vaadin.data.HasValue.ValueChangeEvent;
import com.vaadin.data.HasValue.ValueChangeListener;
import com.vaadin.data.converter.StringToIntegerConverter;
diff --git a/server/src/main/java/com/vaadin/data/PropertyFilterDefinition.java b/server/src/main/java/com/vaadin/data/PropertyFilterDefinition.java
new file mode 100644
index 0000000000..47d5812735
--- /dev/null
+++ b/server/src/main/java/com/vaadin/data/PropertyFilterDefinition.java
@@ -0,0 +1,77 @@
+/*
+ * 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.data;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Class containing the constraints for filtering nested properties.
+ *
+ * @author Vaadin Ltd
+ * @since 8.2
+ */
+public class PropertyFilterDefinition
+ implements Serializable {
+ private int maxNestingDepth;
+ private List<String> ignorePackageNamesStartingWith;
+
+ /**
+ * Create a property filter with max nesting depth and package names
+ * to ignore.
+ *
+ * @param maxNestingDepth
+ * The maximum amount of nesting levels for
+ * sub-properties.
+ * @param ignorePackageNamesStartingWith
+ * Ignore package names that start with this string, for
+ * example "java.lang".
+ */
+ public PropertyFilterDefinition(int maxNestingDepth,
+ List<String> ignorePackageNamesStartingWith) {
+ this.maxNestingDepth = maxNestingDepth;
+ this.ignorePackageNamesStartingWith = ignorePackageNamesStartingWith;
+ }
+
+ /**
+ * Returns the maximum amount of nesting levels for sub-properties.
+ *
+ * @return maximum nesting depth
+ */
+ public int getMaxNestingDepth() {
+ return maxNestingDepth;
+ }
+
+ /**
+ * Returns a list of package name prefixes to ignore.
+ *
+ * @return list of strings that
+ */
+ public List<String> getIgnorePackageNamesStartingWith() {
+ return ignorePackageNamesStartingWith;
+ }
+
+ /**
+ * Get the default nested property filtering conditions.
+ *
+ * @return default property filter
+ */
+ public static PropertyFilterDefinition getDefaultFilter() {
+ return new PropertyFilterDefinition(BeanPropertySet.NestedBeanPropertyDefinition.MAX_PROPERTY_NESTING_DEPTH,
+ Arrays.asList("java"));
+ }
+}
diff --git a/server/src/test/java/com/vaadin/data/BinderInstanceFieldTest.java b/server/src/test/java/com/vaadin/data/BinderInstanceFieldTest.java
index 03f98bdc08..dc6e79879f 100644
--- a/server/src/test/java/com/vaadin/data/BinderInstanceFieldTest.java
+++ b/server/src/test/java/com/vaadin/data/BinderInstanceFieldTest.java
@@ -26,7 +26,6 @@ import org.junit.Assert;
import org.junit.Test;
import com.vaadin.annotations.PropertyId;
-import com.vaadin.data.BeanPropertySet.NestedBeanPropertyDefinition.PropertyFilterDefinition;
import com.vaadin.data.converter.StringToIntegerConverter;
import com.vaadin.data.validator.StringLengthValidator;
import com.vaadin.tests.data.bean.Address;