You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

NestedPropertyDescriptor.java 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.data.util;
  17. import com.vaadin.data.Property;
  18. /**
  19. * Property descriptor that is able to create nested property instances for a
  20. * bean.
  21. *
  22. * The property is specified in the dotted notation, e.g. "address.street", and
  23. * can contain multiple levels of nesting.
  24. *
  25. * @param <BT>
  26. * bean type
  27. *
  28. * @since 6.6
  29. */
  30. public class NestedPropertyDescriptor<BT> implements
  31. VaadinPropertyDescriptor<BT> {
  32. private final String name;
  33. private final Class<?> propertyType;
  34. /**
  35. * Creates a property descriptor that can create MethodProperty instances to
  36. * access the underlying bean property.
  37. *
  38. * @param name
  39. * of the property in a dotted path format, e.g. "address.street"
  40. * @param beanType
  41. * type (class) of the top-level bean
  42. * @throws IllegalArgumentException
  43. * if the property name is invalid
  44. */
  45. public NestedPropertyDescriptor(String name, Class<BT> beanType)
  46. throws IllegalArgumentException {
  47. this.name = name;
  48. NestedMethodProperty<?> property = new NestedMethodProperty<Object>(
  49. beanType, name);
  50. this.propertyType = property.getType();
  51. }
  52. @Override
  53. public String getName() {
  54. return name;
  55. }
  56. @Override
  57. public Class<?> getPropertyType() {
  58. return propertyType;
  59. }
  60. @Override
  61. public Property<?> createProperty(BT bean) {
  62. return new NestedMethodProperty<Object>(bean, name);
  63. }
  64. }