--- /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.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;
+ }
+}
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;
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.
}
}
- 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> {
*/
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;
* 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
}
private BeanPropertySet(Class<T> beanType, boolean checkNestedDefinitions,
- NestedBeanPropertyDefinition.PropertyFilterDefinition propertyFilterDefinition) {
+ PropertyFilterDefinition propertyFilterDefinition) {
this(beanType);
if (checkNestedDefinitions) {
Objects.requireNonNull(propertyFilterDefinition,
private void findNestedDefinitions(
Map<String, PropertyDefinition<T, ?>> parentDefinitions, int depth,
- NestedBeanPropertyDefinition.PropertyFilterDefinition filterCallback) {
+ PropertyFilterDefinition filterCallback) {
if (depth >= filterCallback.getMaxNestingDepth()) {
return;
}
@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(),
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();
--- /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.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"));
+ }
+}