Package java.beans

Examples of java.beans.PropertyDescriptor


      if (aFieldName.contains("[")) {
        theFieldName = aFieldName.substring(0, aFieldName.indexOf("["));
        collectionIndex = Integer.parseInt(aFieldName.substring(aFieldName.indexOf("[") + 1, aFieldName.indexOf("]")));
      }

      PropertyDescriptor propDescriptor = findPropertyDescriptor(latestClass, theFieldName, deepIndexHintContainer);
      DeepHierarchyElement r = new DeepHierarchyElement(propDescriptor, collectionIndex);

      if (propDescriptor == null) {
        MappingUtils.throwMappingException("Exception occurred determining deep field hierarchy for Class --> "
            + parentClass.getName() + ", Field --> " + field + ".  Unable to determine property descriptor for Class --> "
            + latestClass.getName() + ", Field Name: " + aFieldName);
      }

      latestClass = propDescriptor.getPropertyType();
      if (toks.hasMoreTokens()) {
        if (latestClass.isArray()) {
          latestClass = latestClass.getComponentType();
        } else if (Collection.class.isAssignableFrom(latestClass)) {
          Class<?> genericType = determineGenericsType(propDescriptor);
View Full Code Here


         * Check for existing descriptor with the same name to prevent 2 property descriptors with the same name being added
         * to the result list.  This caused issues when getter and setter of an attribute on different interfaces in
         * an inheritance hierarchy
         */
        for (PropertyDescriptor superPropDescriptor : superInterfacePropertyDescriptors) {
          PropertyDescriptor existingPropDescriptor = findPropDescriptorByName(propDescriptors, superPropDescriptor.getName());
          if (existingPropDescriptor == null) {
            propDescriptors.add(superPropDescriptor);
          } else {
            try {
              if (existingPropDescriptor.getReadMethod() == null) {
                existingPropDescriptor.setReadMethod(superPropDescriptor.getReadMethod());
              }
              if (existingPropDescriptor.getWriteMethod() == null) {
                existingPropDescriptor.setWriteMethod(superPropDescriptor.getWriteMethod());
              }
            } catch (IntrospectionException e) {
              throw new MappingException(e);
            }

View Full Code Here

    }
    return propDescriptors.toArray(new PropertyDescriptor[propDescriptors.size()]);
  }

  private static PropertyDescriptor findPropDescriptorByName(List<PropertyDescriptor> propDescriptors, String name) {
    PropertyDescriptor result = null;
    for (PropertyDescriptor pd : propDescriptors) {
      if (pd.getName().equals(name)) {
        result = pd;
        break;
      }
View Full Code Here

   * @param parameterName the parameter name.
   * @return The method.
   */
  private Method findSetMethod(final String parameterName)
  {
    final PropertyDescriptor descriptor
        = (PropertyDescriptor) this.properties.get(parameterName);
    return descriptor.getWriteMethod();
  }
View Full Code Here

   * @param parameterName the paramater name.
   * @return The method.
   */
  private Method findGetMethod(final String parameterName)
  {
    final PropertyDescriptor descriptor
        = (PropertyDescriptor) this.properties.get(parameterName);
    return descriptor.getReadMethod();
  }
View Full Code Here

      final BeanInfo bi = Introspector.getBeanInfo(className);
      final PropertyDescriptor[] propertyDescriptors
          = bi.getPropertyDescriptors();
      for (int i = 0; i < propertyDescriptors.length; i++)
      {
        final PropertyDescriptor propertyDescriptor = propertyDescriptors[i];
        final Method readMethod = propertyDescriptor.getReadMethod();
        final Method writeMethod = propertyDescriptor.getWriteMethod();
        if (isValidMethod(readMethod, 0) && isValidMethod(writeMethod, 1))
        {
          final String name = propertyDescriptor.getName();
          this.properties.put(name, propertyDescriptor);
          if (init)
          {
            super.setParameterDefinition(name,
                propertyDescriptor.getPropertyType());
          }
        }
      }
    }
    catch (IntrospectionException e)
View Full Code Here

        {
          logger.warn("Expression '" + expression.getExpressionType() + ": Property " + propertyMetaData.getName() + ": Property Type is not valid");
        }

        // should not crash!
        final PropertyDescriptor propertyDescriptor = propertyMetaData.getBeanDescriptor();

        if (propertyMetaData.isDeprecated())
        {
          final String deprecateMessage = propertyMetaData.getDeprecationMessage(locale);
          if (isValid(deprecateMessage, "Deprecated") == false)
          {
            logger.warn("Expression '" + expression.getExpressionType() + ": Property " + propertyMetaData.getName() + ": No valid deprecate message");
          }
        }

      }

      try
      {
        final BeanInfo beanInfo = Introspector.getBeanInfo(expression.getExpressionType());
        final PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
        for (int propIdx = 0; propIdx < descriptors.length; propIdx++)
        {
          final PropertyDescriptor descriptor = descriptors[propIdx];
          final String key = descriptor.getName();

          if ("runtime".equals(key))
          {
            continue;
          }
          if ("active".equals(key))
          {
            continue;
          }
          if ("preserve".equals(key))
          {
            continue;
          }

          if (descriptor.getReadMethod() == null || descriptor.getWriteMethod() == null)
          {
            continue;
          }

          if (expression.getPropertyDescription(key) == null)
View Full Code Here

      final BeanInfo beanInfo = Introspector.getBeanInfo(aClass);
      final PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
      for (int j = 0; j < descriptors.length; j++)
      {
        final PropertyDescriptor descriptor = descriptors[j];
        final String key = descriptor.getName();

        if ("runtime".equals(key))
        {
          continue;
        }
        if ("active".equals(key))
        {
          continue;
        }
        if ("preserve".equals(key))
        {
          continue;
        }

        if (descriptor.getReadMethod() == null || descriptor.getWriteMethod() == null)
        {
          continue;
        }

        final AttributeList propAttrList = new AttributeList();
        propAttrList.setAttribute(META_NAMESPACE, "name", descriptor.getName());
        if ("name".equals(key))
        {
          propAttrList.setAttribute(META_NAMESPACE, "mandatory", "true");
          propAttrList.setAttribute(META_NAMESPACE, "preferred", "true");
          propAttrList.setAttribute(META_NAMESPACE, "value-role", "Name");
View Full Code Here

      final BeanInfo beanInfo = Introspector.getBeanInfo(aClass);
      final BeanUtility bu = new BeanUtility(aClass.newInstance());
      final PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
      for (int j = 0; j < descriptors.length; j++)
      {
        final PropertyDescriptor descriptor = descriptors[j];
        final String key = descriptor.getName();

        if ("runtime".equals(key))
        {
          continue;
        }
        if ("active".equals(key))
        {
          continue;
        }
        if ("preserve".equals(key))
        {
          continue;
        }

        if (descriptor.getReadMethod() == null)
        {
//          System.out.println("Skipping " + key + " from " + aClass + " No read method");
          continue;
        }
        if (descriptor.getWriteMethod() == null)
        {
//          System.out.println("Skipping " + key + " from " + aClass + " No write method");
          continue;
        }
View Full Code Here

  }

  @SuppressWarnings("unchecked")
  public static void inject (Object bean, String... properties) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    for (String propertyName : properties) {
      PropertyDescriptor property = BeanUtils.getPropertyDescriptor(bean.getClass(), propertyName);
      Class<?> propertyClass = property.getPropertyType();
      Map<String, Object> deps = applicationContext.getBeansOfType(propertyClass);
            if (!CollectionUtils.isEmpty(deps)) {
                if (deps.size() != 1) logger.warn("More than one bean of type [" + propertyClass + "] in context. Unexpected errors may happen with unserialized bean!");
                Object dependency = deps.entrySet().iterator().next().getValue();
                property.getWriteMethod().invoke(bean, dependency);
            }
    }
  }
View Full Code Here

TOP

Related Classes of java.beans.PropertyDescriptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.