Java Code Examples for org.apache.commons.beanutils.PropertyUtils#getPropertyType()

The following examples show how to use org.apache.commons.beanutils.PropertyUtils#getPropertyType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PersonServiceImpl.java    From rice with Educational Community License v2.0 7 votes vote down vote up
private boolean isPersonProperty(Object bo, String propertyName) {
    try {
    	if (PropertyAccessorUtils.isNestedOrIndexedProperty( propertyName ) // is a nested property
        		&& !StringUtils.contains(propertyName, "add.") ) {// exclude add line properties (due to path parsing problems in PropertyUtils.getPropertyType)
            int lastIndex = PropertyAccessorUtils.getLastNestedPropertySeparatorIndex(propertyName);
            String propertyTypeName = lastIndex != -1 ? StringUtils.substring(propertyName, 0, lastIndex) : StringUtils.EMPTY;
    		Class<?> type = PropertyUtils.getPropertyType(bo, propertyTypeName);
    		// property type indicates a Person object
    		if ( type != null ) {
    			return Person.class.isAssignableFrom(type);
    		}
    		LOG.warn( "Unable to determine type of nested property: " + bo.getClass().getName() + " / " + propertyName );
    	}
    } catch (Exception ex) {
    	if ( LOG.isDebugEnabled() ) {
    		LOG.debug("Unable to determine if property on " + bo.getClass().getName() + " to a person object: " + propertyName, ex );
    	}
    }
    return false;
}
 
Example 2
Source File: ParameterizedValidation.java    From kfs with GNU Affero General Public License v3.0 7 votes vote down vote up
/**
 * Populates a single parameter field based on a field conversion, given an event to populate data from
 * @param event the event which acts as the source of data
 * @param validation the validation to populate
 * @param conversion the conversion information
 */
protected void populateParameterFromEvent(AttributedDocumentEvent event, ValidationFieldConvertible conversion) {
    try {
        Class propertyClass = PropertyUtils.getPropertyType(event, conversion.getSourceEventProperty());
        Object propertyValue = ObjectUtils.getPropertyValue(event, conversion.getSourceEventProperty());
        if (propertyValue != null) {
            ObjectUtils.setObjectProperty(this, conversion.getTargetValidationProperty(), propertyClass, propertyValue);
        }
    }
    catch (FormatException fe) {
        throw new RuntimeException(fe);
    }
    catch (IllegalAccessException iae) {
        throw new RuntimeException(iae);
    }
    catch (InvocationTargetException ite) {
        throw new RuntimeException(ite);
    }
    catch (NoSuchMethodException nsme) {
        throw new RuntimeException(nsme);
    }
}
 
Example 3
Source File: CustomTag.java    From TranskribusCore with GNU General Public License v3.0 6 votes vote down vote up
public Class<?> getAttributeType(String name) {
	if (!hasAttribute(name))
		return null;

	if (isPredefinedAttribute(name)) { // get type via reflection for
										// predefined attributes
		try {
			return PropertyUtils.getPropertyType(this, name);
		} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
			logger.error(e.getMessage(), e);
			return null;
		}
	} else {
		CustomTagAttribute att = getAttribute(name);
		return att.getType();
	}
}
 
Example 4
Source File: KualiLookupableHelperServiceImpl.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * Check whether the given property represents a property within an EBO starting
 * with the sampleBo object given.  This is used to determine if a criteria needs
 * to be applied to the EBO first, before sending to the normal lookup DAO.
 */
protected boolean isExternalBusinessObjectProperty(Object sampleBo, String propertyName) {
    try {
    	if ( propertyName.indexOf( "." ) > 0 && !StringUtils.contains( propertyName, "add." ) ) {
     	Class propertyClass = PropertyUtils.getPropertyType(
		sampleBo, StringUtils.substringBeforeLast( propertyName, "." ) );
     	if ( propertyClass != null ) {
     		return ExternalizableBusinessObjectUtils.isExternalizableBusinessObjectInterface( propertyClass );
     	} else {
     		if ( LOG.isDebugEnabled() ) {
     			LOG.debug( "unable to get class for " + StringUtils.substringBeforeLast( propertyName, "." ) + " on " + sampleBo.getClass().getName() );
     		}
     	}
    	}
    } catch (Exception e) {
    	LOG.debug("Unable to determine type of property for " + sampleBo.getClass().getName() + "/" + propertyName, e );
    }
    return false;
}
 
Example 5
Source File: KualiLookupableHelperServiceImpl.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Given an property on the main BO class, return the defined type of the ExternalizableBusinessObject.  This will be used
 * by other code to determine the correct module service to call for the lookup.
 *
 * @param boClass
 * @param propertyName
 * @return
 */
protected Class<? extends ExternalizableBusinessObject> getExternalizableBusinessObjectClass(Class boClass, String propertyName) {
    try {
    	return PropertyUtils.getPropertyType(
	boClass.newInstance(), StringUtils.substringBeforeLast( propertyName, "." ) );
    } catch (Exception e) {
    	LOG.debug("Unable to determine type of property for " + boClass.getName() + "/" + propertyName, e );
    }
    return null;
}
 
Example 6
Source File: MyBeanUtils.java    From jeecg with Apache License 2.0 5 votes vote down vote up
/**
 * 将Map内的key与Bean中属性相同的内容复制到BEAN中
 * @param bean Object
 * @param properties Map
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 */
public static void copyMap2Bean(Object bean, Map properties) throws
    IllegalAccessException, InvocationTargetException {
    // Do nothing unless both arguments have been specified
    if ( (bean == null) || (properties == null)) {
        return;
    }
    // Loop through the property name/value pairs to be set
    Iterator names = properties.keySet().iterator();
    while (names.hasNext()) {
        String name = (String) names.next();
        // Identify the property name and value(s) to be assigned
        if (name == null) {
            continue;
        }
        Object value = properties.get(name);
        try {
            Class clazz = PropertyUtils.getPropertyType(bean, name);
            if (null == clazz) {
                continue;
            }
            String className = clazz.getName();
            if (className.equalsIgnoreCase("java.sql.Timestamp")) {
                if (value == null || value.equals("")) {
                    continue;
                }
            }
            getInstance().setSimpleProperty(bean, name, value);
        }
        catch (NoSuchMethodException e) {
            continue;
        }
    }
}
 
Example 7
Source File: TestDataGenerator.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * This method gets the approperiate property value by examining the given parameters
 * 
 * @param businessObject the given business object
 * @param propertyName the given property name
 * @param propertyValue the given property value
 * @return the processed property value
 */
private Object getPropertyValue(Object businessObject, String propertyName, String propertyValue) {
    // get the property type of the given business object
    Class propertyType = null;
    try {
        propertyType = PropertyUtils.getPropertyType(businessObject, propertyName);
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    // implement the type conversion
    String propertyTypeName = propertyType.getName();
    Object finalPropertyValue = propertyValue;
    if (propertyType.isPrimitive()) {
        finalPropertyValue = null;
    }
    else if (propertyTypeName.indexOf("Integer") >= 0) {
        finalPropertyValue = new Integer(propertyValue.trim());
    }
    else if (propertyTypeName.indexOf("Boolean") >= 0) {
        finalPropertyValue = new Boolean(propertyValue.trim());
    }
    else if (propertyTypeName.indexOf("KualiDecimal") >= 0) {
        finalPropertyValue = new KualiDecimal(propertyValue.trim());
    }

    return finalPropertyValue;
}
 
Example 8
Source File: CustomerLoadServiceImpl.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 *
 * This messy thing attempts to compare a property on the batch customer (new) and existing customer, and if
 * the new is blank, but the old is there, to overwrite the new-value with the old-value, thus preventing
 * batch uploads from blanking out certain fields.
 *
 * @param batchCustomer
 * @param existingCustomer
 * @param propertyName
 */
protected void dontBlankOutFieldsOnUpdate(Customer batchCustomer, Customer existingCustomer, String propertyName) {
    String batchValue;
    String existingValue;
    Class<?> propertyClass = null;

    //  try to retrieve the property type to see if it exists at all
    try {
        propertyClass = PropertyUtils.getPropertyType(batchCustomer, propertyName);

        //  if the property doesnt exist, then throw an exception
        if (propertyClass == null) {
            throw new IllegalArgumentException("The propertyName specified [" + propertyName + "] doesnt exist on the Customer object.");
        }

        //  get the String values of both batch and existing, to compare
        batchValue = BeanUtils.getSimpleProperty(batchCustomer, propertyName);
        existingValue = BeanUtils.getSimpleProperty(existingCustomer, propertyName);

        //  if the existing is non-blank, and the new is blank, then over-write the new with the existing value
        if (StringUtils.isBlank(batchValue) && StringUtils.isNotBlank(existingValue)) {

            //  get the real typed value, and then try to set the property value
            Object typedValue = PropertyUtils.getProperty(existingCustomer, propertyName);
            BeanUtils.setProperty(batchCustomer, propertyName, typedValue);
        }
    }
    catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) {
        throw new RuntimeException("Could not set properties on the Customer object", ex);
    }
}
 
Example 9
Source File: KubernetesCloudTest.java    From kubernetes-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void copyConstructor() throws Exception {
    PodTemplate pt = new PodTemplate();
    pt.setName("podTemplate");

    KubernetesCloud cloud = new KubernetesCloud("name");
    ArrayList<String> objectProperties = Lists.newArrayList("templates", "podRetention", "podLabels", "labels", "serverCertificate");
    for (String property: PropertyUtils.describe(cloud).keySet()) {
        if (PropertyUtils.isWriteable(cloud, property)) {
            Class<?> propertyType = PropertyUtils.getPropertyType(cloud, property);
            if (propertyType == String.class) {
                if (property.endsWith("Str")) {
                    // setContainerCapStr
                    // setMaxRequestsPerHostStr
                    PropertyUtils.setProperty(cloud, property, RandomStringUtils.randomNumeric(3));
                } else {
                    PropertyUtils.setProperty(cloud, property, RandomStringUtils.randomAlphabetic(10));
                }
            } else if (propertyType == int.class) {
                PropertyUtils.setProperty(cloud, property, RandomUtils.nextInt());
            } else if (propertyType == Integer.class) {
                PropertyUtils.setProperty(cloud, property, Integer.valueOf(RandomUtils.nextInt()));
            } else if (propertyType == boolean.class) {
                PropertyUtils.setProperty(cloud, property, RandomUtils.nextBoolean());
            } else if (!objectProperties.contains(property)) {
                fail("Unhandled field in copy constructor: " + property);
            }
        }
    }
    cloud.setServerCertificate("-----BEGIN CERTIFICATE-----");
    cloud.setTemplates(Collections.singletonList(pt));
    cloud.setPodRetention(new Always());
    cloud.setPodLabels(PodLabel.listOf("foo", "bar", "cat", "dog"));
    cloud.setLabels(ImmutableMap.of("foo", "bar"));

    KubernetesCloud copy = new KubernetesCloud("copy", cloud);
    assertEquals("copy", copy.name);
    assertEquals("Expected cloud from copy constructor to be equal to the source except for name", cloud, copy);
}
 
Example 10
Source File: MyBeanUtils.java    From jeewx with Apache License 2.0 5 votes vote down vote up
/**
 * Map内的key与Bean中属性相同的内容复制到BEAN中
 * 对于存在空值的取默认值
 * @param bean Object
 * @param properties Map
 * @param defaultValue String
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 */
public static void copyMap2Bean(Object bean, Map properties, String defaultValue) throws
    IllegalAccessException, InvocationTargetException {
    // Do nothing unless both arguments have been specified
    if ( (bean == null) || (properties == null)) {
        return;
    }
    // Loop through the property name/value pairs to be set
    Iterator names = properties.keySet().iterator();
    while (names.hasNext()) {
        String name = (String) names.next();
        // Identify the property name and value(s) to be assigned
        if (name == null) {
            continue;
        }
        Object value = properties.get(name);
        try {
            Class clazz = PropertyUtils.getPropertyType(bean, name);
            if (null == clazz) {
                continue;
            }
            String className = clazz.getName();
            if (className.equalsIgnoreCase("java.sql.Timestamp")) {
                if (value == null || value.equals("")) {
                    continue;
                }
            }
            if (className.equalsIgnoreCase("java.lang.String")) {
                if (value == null) {
                    value = defaultValue;
                }
            }
            setProperty(bean, name, value);
        }
        catch (NoSuchMethodException e) {
            continue;
        }
    }
}
 
Example 11
Source File: MyBeanUtils.java    From jeewx with Apache License 2.0 5 votes vote down vote up
/**
 * 自动转Map key值大写
 * 将Map内的key与Bean中属性相同的内容复制到BEAN中
 * @param bean Object
 * @param properties Map
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 */
public static void copyMap2Bean_Nobig(Object bean, Map properties) throws
    IllegalAccessException, InvocationTargetException {
    // Do nothing unless both arguments have been specified
    if ( (bean == null) || (properties == null)) {
        return;
    }
    // Loop through the property name/value pairs to be set
    Iterator names = properties.keySet().iterator();
    while (names.hasNext()) {
        String name = (String) names.next();
        // Identify the property name and value(s) to be assigned
        if (name == null) {
            continue;
        }
        Object value = properties.get(name);
        name = name.toLowerCase();
        try {
            Class clazz = PropertyUtils.getPropertyType(bean, name);
            if (null == clazz) {
                continue;
            }
            String className = clazz.getName();
            if (className.equalsIgnoreCase("java.sql.Timestamp")) {
                if (value == null || value.equals("")) {
                    continue;
                }
            }
            setProperty(bean, name, value);
        }
        catch (NoSuchMethodException e) {
            continue;
        }
    }
}
 
Example 12
Source File: MyBeanUtils.java    From jeewx with Apache License 2.0 5 votes vote down vote up
/**
 * 将Map内的key与Bean中属性相同的内容复制到BEAN中
 * @param bean Object
 * @param properties Map
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 */
public static void copyMap2Bean(Object bean, Map properties) throws
    IllegalAccessException, InvocationTargetException {
    // Do nothing unless both arguments have been specified
    if ( (bean == null) || (properties == null)) {
        return;
    }
    // Loop through the property name/value pairs to be set
    Iterator names = properties.keySet().iterator();
    while (names.hasNext()) {
        String name = (String) names.next();
        // Identify the property name and value(s) to be assigned
        if (name == null) {
            continue;
        }
        Object value = properties.get(name);
        try {
            Class clazz = PropertyUtils.getPropertyType(bean, name);
            if (null == clazz) {
                continue;
            }
            String className = clazz.getName();
            if (className.equalsIgnoreCase("java.sql.Timestamp")) {
                if (value == null || value.equals("")) {
                    continue;
                }
            }
            setProperty(bean, name, value);
        }
        catch (NoSuchMethodException e) {
            continue;
        }
    }
}
 
Example 13
Source File: MyBeanUtils.java    From jeewx with Apache License 2.0 5 votes vote down vote up
/**
 * Map内的key与Bean中属性相同的内容复制到BEAN中
 * 对于存在空值的取默认值
 * @param bean Object
 * @param properties Map
 * @param defaultValue String
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 */
public static void copyMap2Bean(Object bean, Map properties, String defaultValue) throws
    IllegalAccessException, InvocationTargetException {
    // Do nothing unless both arguments have been specified
    if ( (bean == null) || (properties == null)) {
        return;
    }
    // Loop through the property name/value pairs to be set
    Iterator names = properties.keySet().iterator();
    while (names.hasNext()) {
        String name = (String) names.next();
        // Identify the property name and value(s) to be assigned
        if (name == null) {
            continue;
        }
        Object value = properties.get(name);
        try {
            Class clazz = PropertyUtils.getPropertyType(bean, name);
            if (null == clazz) {
                continue;
            }
            String className = clazz.getName();
            if (className.equalsIgnoreCase("java.sql.Timestamp")) {
                if (value == null || value.equals("")) {
                    continue;
                }
            }
            if (className.equalsIgnoreCase("java.lang.String")) {
                if (value == null) {
                    value = defaultValue;
                }
            }
            setProperty(bean, name, value);
        }
        catch (NoSuchMethodException e) {
            continue;
        }
    }
}
 
Example 14
Source File: MyBeanUtils.java    From jeewx with Apache License 2.0 5 votes vote down vote up
/**
 * 将Map内的key与Bean中属性相同的内容复制到BEAN中
 * @param bean Object
 * @param properties Map
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 */
public static void copyMap2Bean(Object bean, Map properties) throws
    IllegalAccessException, InvocationTargetException {
    // Do nothing unless both arguments have been specified
    if ( (bean == null) || (properties == null)) {
        return;
    }
    // Loop through the property name/value pairs to be set
    Iterator names = properties.keySet().iterator();
    while (names.hasNext()) {
        String name = (String) names.next();
        // Identify the property name and value(s) to be assigned
        if (name == null) {
            continue;
        }
        Object value = properties.get(name);
        try {
            Class clazz = PropertyUtils.getPropertyType(bean, name);
            if (null == clazz) {
                continue;
            }
            String className = clazz.getName();
            if (className.equalsIgnoreCase("java.sql.Timestamp")) {
                if (value == null || value.equals("")) {
                    continue;
                }
            }
            setProperty(bean, name, value);
        }
        catch (NoSuchMethodException e) {
            continue;
        }
    }
}
 
Example 15
Source File: MyBeanUtils.java    From jeewx with Apache License 2.0 5 votes vote down vote up
/**
 * Map内的key与Bean中属性相同的内容复制到BEAN中
 * 对于存在空值的取默认值
 * @param bean Object
 * @param properties Map
 * @param defaultValue String
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 */
public static void copyMap2Bean(Object bean, Map properties, String defaultValue) throws
    IllegalAccessException, InvocationTargetException {
    // Do nothing unless both arguments have been specified
    if ( (bean == null) || (properties == null)) {
        return;
    }
    // Loop through the property name/value pairs to be set
    Iterator names = properties.keySet().iterator();
    while (names.hasNext()) {
        String name = (String) names.next();
        // Identify the property name and value(s) to be assigned
        if (name == null) {
            continue;
        }
        Object value = properties.get(name);
        try {
            Class clazz = PropertyUtils.getPropertyType(bean, name);
            if (null == clazz) {
                continue;
            }
            String className = clazz.getName();
            if (className.equalsIgnoreCase("java.sql.Timestamp")) {
                if (value == null || value.equals("")) {
                    continue;
                }
            }
            if (className.equalsIgnoreCase("java.lang.String")) {
                if (value == null) {
                    value = defaultValue;
                }
            }
            setProperty(bean, name, value);
        }
        catch (NoSuchMethodException e) {
            continue;
        }
    }
}
 
Example 16
Source File: MyBeanUtils.java    From jeecg with Apache License 2.0 5 votes vote down vote up
/**
 * Map内的key与Bean中属性相同的内容复制到BEAN中
 * 对于存在空值的取默认值
 * @param bean Object
 * @param properties Map
 * @param defaultValue String
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 */
public static void copyMap2Bean(Object bean, Map properties, String defaultValue) throws
    IllegalAccessException, InvocationTargetException {
    // Do nothing unless both arguments have been specified
    if ( (bean == null) || (properties == null)) {
        return;
    }
    // Loop through the property name/value pairs to be set
    Iterator names = properties.keySet().iterator();
    while (names.hasNext()) {
        String name = (String) names.next();
        // Identify the property name and value(s) to be assigned
        if (name == null) {
            continue;
        }
        Object value = properties.get(name);
        try {
            Class clazz = PropertyUtils.getPropertyType(bean, name);
            if (null == clazz) {
                continue;
            }
            String className = clazz.getName();
            if (className.equalsIgnoreCase("java.sql.Timestamp")) {
                if (value == null || value.equals("")) {
                    continue;
                }
            }
            if (className.equalsIgnoreCase("java.lang.String")) {
                if (value == null) {
                    value = defaultValue;
                }
            }
            getInstance().setSimpleProperty(bean, name, value);
        }
        catch (NoSuchMethodException e) {
            continue;
        }
    }
}
 
Example 17
Source File: MyBeanUtils.java    From jeewx with Apache License 2.0 5 votes vote down vote up
/**
 * 将Map内的key与Bean中属性相同的内容复制到BEAN中
 * @param bean Object
 * @param properties Map
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 */
public static void copyMap2Bean(Object bean, Map properties) throws
    IllegalAccessException, InvocationTargetException {
    // Do nothing unless both arguments have been specified
    if ( (bean == null) || (properties == null)) {
        return;
    }
    // Loop through the property name/value pairs to be set
    Iterator names = properties.keySet().iterator();
    while (names.hasNext()) {
        String name = (String) names.next();
        // Identify the property name and value(s) to be assigned
        if (name == null) {
            continue;
        }
        Object value = properties.get(name);
        try {
            Class clazz = PropertyUtils.getPropertyType(bean, name);
            if (null == clazz) {
                continue;
            }
            String className = clazz.getName();
            if (className.equalsIgnoreCase("java.sql.Timestamp")) {
                if (value == null || value.equals("")) {
                    continue;
                }
            }
            setProperty(bean, name, value);
        }
        catch (NoSuchMethodException e) {
            continue;
        }
    }
}
 
Example 18
Source File: ObjectUtils.java    From rice with Educational Community License v2.0 4 votes vote down vote up
/**
 * Returns the type of the property in the object. This implementation is not smart enough to look through a
 * Collection to get the property type
 * of an attribute of an element in the collection.
 * <p/>
 * NOTE: A patch file attached to https://test.kuali.org/jira/browse/KULRNE-4435 contains a modified version of this
 * method which IS smart enough
 * to look through Collections. This patch is currently under review.
 *
 * @param object An instance of the Class for which we're trying to get the property type.
 * @param propertyName The name of the property of the Class the Class of which we're trying to get. Dot notation is
 * used to separate properties.
 * TODO: The rules about this dot notation needs to be explained in Confluence using examples.
 * @param persistenceStructureService Needed to get the type of elements in a Collection from OJB.
 * @return Object will be null if any parent property for the given property is null.
 */
@Deprecated
public static Class getPropertyType(Object object, String propertyName,
        PersistenceStructureService persistenceStructureService) {
    if (object == null || propertyName == null) {
        throw new RuntimeException("Business object and property name can not be null");
    }

    Class propertyType = null;
    try {
        try {
            // Try to simply use the default or simple way of getting the property type.
            propertyType = PropertyUtils.getPropertyType(object, propertyName);
        } catch (IllegalArgumentException ex) {
            // swallow the exception, propertyType stays null
        } catch (NoSuchMethodException nsme) {
            // swallow the exception, propertyType stays null
        }

        // if the property type as determined from the object is PersistableBusinessObject,
        // then this must be an extension attribute -- attempt to get the property type from the
        // persistence structure service
        if (propertyType != null && propertyType.equals(PersistableBusinessObjectExtension.class)) {
            propertyType = persistenceStructureService.getBusinessObjectAttributeClass(ProxyHelper.getRealClass(
                    object), propertyName);
        }

        // If the easy way didn't work ...
        if (null == propertyType && -1 != propertyName.indexOf('.')) {
            if (null == persistenceStructureService) {
                LOG.info(
                        "PropertyType couldn't be determined simply and no PersistenceStructureService was given. If you pass in a PersistenceStructureService I can look in other places to try to determine the type of the property.");
            } else {
                String prePeriod = StringUtils.substringBefore(propertyName, ".");
                String postPeriod = StringUtils.substringAfter(propertyName, ".");

                Class prePeriodClass = getPropertyType(object, prePeriod, persistenceStructureService);
                Object prePeriodClassInstance = prePeriodClass.newInstance();
                propertyType = getPropertyType(prePeriodClassInstance, postPeriod, persistenceStructureService);
            }

        } else if (Collection.class.isAssignableFrom(propertyType)) {
            Map<String, Class> map = persistenceStructureService.listCollectionObjectTypes(object.getClass());
            propertyType = map.get(propertyName);
        }

    } catch (Exception e) {
        LOG.debug("unable to get property type for " + propertyName + " " + e.getMessage());
        // continue and return null for propertyType
    }

    return propertyType;
}
 
Example 19
Source File: MyBeanUtils.java    From jeecg with Apache License 2.0 4 votes vote down vote up
/**
   * 自动转Map key值大写
   * 将Map内的key与Bean中属性相同的内容复制到BEAN中
   * @param bean Object
   * @param properties Map
   * @throws IllegalAccessException
   * @throws InvocationTargetException
   */
  public static void copyMap2Bean_Nobig(Object bean, Map properties) throws
      IllegalAccessException, InvocationTargetException {
      // Do nothing unless both arguments have been specified
      if ( (bean == null) || (properties == null)) {
          return;
      }
      // Loop through the property name/value pairs to be set
      Iterator names = properties.keySet().iterator();
      while (names.hasNext()) {
          String name = (String) names.next();
          // Identify the property name and value(s) to be assigned
          if (name == null) {
              continue;
          }
          Object value = properties.get(name);
          // 命名应该大小写应该敏感(否则取不到对象的属性)
          //name = name.toLowerCase();
          try {
        	  if (value == null) {	// 不光Date类型,好多类型在null时会出错
                  continue;	// 如果为null不用设 (对象如果有特殊初始值也可以保留?)
              }
              Class clazz = PropertyUtils.getPropertyType(bean, name);
              if (null == clazz) {	// 在bean中这个属性不存在
                  continue;
              }
              String className = clazz.getName();
              // 临时对策(如果不处理默认的类型转换时会出错)
              if (className.equalsIgnoreCase("java.util.Date")) {
                  value = new java.util.Date(((java.sql.Timestamp)value).getTime());// wait to do:貌似有时区问题, 待进一步确认
              }
//              if (className.equalsIgnoreCase("java.sql.Timestamp")) {
//                  if (value == null || value.equals("")) {
//                      continue;
//                  }
//              }
              getInstance().setSimpleProperty(bean, name, value);
          }
          catch (NoSuchMethodException e) {
              continue;
          }
      }
  }
 
Example 20
Source File: KRADUtils.java    From rice with Educational Community License v2.0 3 votes vote down vote up
/**
 * LegacyCase - This method simply uses PojoPropertyUtilsBean logic to get the Class of a Class property.
 * This method does not have any of the logic needed to obtain the Class of an element of a Collection specified in
 * the DataDictionary.
 *
 * @param object An instance of the Class of which we're trying to get the property Class.
 * @param propertyName The name of the property.
 * @return property type
 * @throws IllegalAccessException
 * @throws NoSuchMethodException
 * @throws InvocationTargetException
 */
static public Class easyGetPropertyType(Object object,
        String propertyName) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
    if (LegacyUtils.useLegacyForObject(object)) {
        return PropertyUtils.getPropertyType(object, propertyName);
    }
    return KradDataServiceLocator.getDataObjectService().wrap(object).getPropertyType(propertyName);
}