Examples of PropertyDescriptor


Examples of java.beans.PropertyDescriptor

        {
          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

Examples of java.beans.PropertyDescriptor

      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

Examples of java.beans.PropertyDescriptor

      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

Examples of java.beans.PropertyDescriptor

  }

  @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

Examples of java.beans.PropertyDescriptor

      if (collection != null) {
        OneToMany oneToMany = collection.getAnnotation(OneToMany.class);
      if (oneToMany != null) {
        String reverse = oneToMany.mappedBy();
        if (hasText(reverse)) {
          PropertyDescriptor reverseProperty = BeanUtils.getPropertyDescriptor(target, reverse);
          if (reverseProperty != null) reverseSetter = reverseProperty.getWriteMethod();
        }
      }
      if (reverseSetter == null) {
        Class<?> targetFieldClass = ClassUtils.getGenericType(collection);
        if (targetFieldClass != null)
          for (PropertyDescriptor reverseProperty : BeanUtils.getPropertyDescriptors(targetFieldClass))
            if (reverseProperty.getPropertyType().isAssignableFrom(primary))
              reverseSetter = reverseProperty.getWriteMethod();
      }
      }
    return reverseSetter;
    }
View Full Code Here

Examples of java.beans.PropertyDescriptor

        for (PropertyDescriptor targetPd : targetPds) {
            String name = targetPd.getName();
            Method writeMethod = targetPd.getWriteMethod();
            if ((ignoreProperties == null) || (!ignoreProperties.contains(name))) {
                if (Hibernate.isPropertyInitialized(source, name) & (writeMethod != null)) {
                    PropertyDescriptor sourcePd = org.springframework.beans.BeanUtils.getPropertyDescriptor(clazz, name);
                    try {
                        Method readMethod = sourcePd.getReadMethod();
                        Object value = readMethod.invoke(source);
                        if (Hibernate.isInitialized(value)) writeMethod.invoke(target, new Object[]{value});
                    } catch (Exception ex) {
                        throw new FatalBeanException("Could not copy property[" + name + "] from source to target", ex);
                    }
View Full Code Here

Examples of java.beans.PropertyDescriptor

  }

  private Object getPropertyForSpecification(final PropertySpecification name)
      throws BeanException
  {
    final PropertyDescriptor pd = (PropertyDescriptor) properties.get(name.getName());
    if (pd == null)
    {
      throw new BeanException("No such property:" + name);
    }

    if (pd instanceof IndexedPropertyDescriptor && name.getIndex() != null)
    {
      final IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
      final Method readMethod = ipd.getIndexedReadMethod();
      if (readMethod == null)
      {
        throw new BeanException("Property is not readable: " + name);
      }
      try
      {
        return readMethod.invoke(bean, new Object[]{new Integer(name.getIndex())});
      }
      catch (Exception e)
      {
        throw BeanException.getInstance("InvokationError", e);
      }
    }
    else
    {
      final Method readMethod = pd.getReadMethod();
      if (readMethod == null)
      {
        throw BeanException.getInstance("Property is not readable: " + name, null);
      }
      if (name.getIndex() != null)
View Full Code Here

Examples of java.beans.PropertyDescriptor

  public String getPropertyAsString(final String name)
      throws BeanException
  {
    final PropertySpecification ps = new PropertySpecification(name);
    final PropertyDescriptor pd = (PropertyDescriptor) properties.get(ps.getName());
    if (pd == null)
    {
      throw new BeanException("No such property:" + name);
    }
    final Object o = getPropertyForSpecification(ps);
View Full Code Here

Examples of java.beans.PropertyDescriptor

  }

  private void setProperty(final PropertySpecification name, final Object o)
      throws BeanException
  {
    final PropertyDescriptor pd = (PropertyDescriptor) properties.get(name.getName());
    if (pd == null)
    {
      throw new BeanException("No such property:" + name);
    }

    if (pd instanceof IndexedPropertyDescriptor && name.getIndex() != null)
    {
      final IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
      final Method writeMethod = ipd.getIndexedWriteMethod();
      if (writeMethod != null)
      {
        try
        {
          writeMethod.invoke(bean, new Object[]{new Integer(name.getIndex()), o});
        }
        catch (Exception e)
        {
          throw BeanException.getInstance("InvokationError", e);
        }
        // we've done the job ...
        return;
      }
    }

    final Method writeMethod = pd.getWriteMethod();
    if (writeMethod == null)
    {
      throw BeanException.getInstance("Property is not writeable: " + name, null);
    }
View Full Code Here

Examples of java.beans.PropertyDescriptor

    if (txt == null)
    {
      throw new NullPointerException("Text must not be null");
    }
    final PropertySpecification ps = new PropertySpecification(name);
    final PropertyDescriptor pd = (PropertyDescriptor) properties.get(ps.getName());
    if (pd == null)
    {
      throw new BeanException("No such property:" + name);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.