當前位置: 首頁>>代碼示例>>Java>>正文


Java PropertyDescriptor.getWriteMethod方法代碼示例

本文整理匯總了Java中java.beans.PropertyDescriptor.getWriteMethod方法的典型用法代碼示例。如果您正苦於以下問題:Java PropertyDescriptor.getWriteMethod方法的具體用法?Java PropertyDescriptor.getWriteMethod怎麽用?Java PropertyDescriptor.getWriteMethod使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.beans.PropertyDescriptor的用法示例。


在下文中一共展示了PropertyDescriptor.getWriteMethod方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: _getMergedWriteMethod

import java.beans.PropertyDescriptor; //導入方法依賴的package包/類
/**
 * Necessary because no support for PropertyDescriptor.setWriteMethod()
 * until JDK 1.2.
 */
private static Method _getMergedWriteMethod(
  PropertyDescriptor secondaryDescriptor,
  PropertyDescriptor primaryDescriptor
  )
{
  //
  // merge the write method
  //
  Method writeMethod = primaryDescriptor.getWriteMethod();

  // Give priority to the primary write method.
  if (writeMethod == null)
  {
    writeMethod = secondaryDescriptor.getWriteMethod();
  }

  return writeMethod;
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:23,代碼來源:JavaIntrospector.java

示例2: run

import java.beans.PropertyDescriptor; //導入方法依賴的package包/類
public void run() {
    for (String name : this.names) {
        Object bean;
        try {
            bean = this.loader.loadClass(name).newInstance();
        } catch (Exception exception) {
            throw new Error("could not instantiate bean: " + name, exception);
        }
        if (this.loader != bean.getClass().getClassLoader()) {
            throw new Error("bean class loader is not equal to default one");
        }
        PropertyDescriptor[] pds = getPropertyDescriptors(bean);
        for (PropertyDescriptor pd : pds) {
            Class type = pd.getPropertyType();
            Method setter = pd.getWriteMethod();
            Method getter = pd.getReadMethod();

            if (type.equals(String.class)) {
                executeMethod(setter, bean, "Foo");
            } else if (type.equals(int.class)) {
                executeMethod(setter, bean, Integer.valueOf(1));
            }
            executeMethod(getter, bean);
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:27,代碼來源:Test4508780.java

示例3: serializablePropertiesFor

import java.beans.PropertyDescriptor; //導入方法依賴的package包/類
/**
 * @deprecated As of 1.3.1, use {@link #propertiesFor(Class)} instead
 */
@Deprecated
public Iterator<BeanProperty> serializablePropertiesFor(final Class<?> type) {
    final Collection<BeanProperty> beanProperties = new ArrayList<BeanProperty>();
    final Collection<PropertyDescriptor> descriptors = buildMap(type).values();
    for (final PropertyDescriptor descriptor : descriptors) {
        if (descriptor.getReadMethod() != null && descriptor.getWriteMethod() != null) {
            beanProperties.add(new BeanProperty(type, descriptor.getName(), descriptor.getPropertyType()));
        }
    }
    return beanProperties.iterator();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:15,代碼來源:PropertyDictionary.java

示例4: toBean

import java.beans.PropertyDescriptor; //導入方法依賴的package包/類
/**
 * 將map 轉為 bean
 */
public static <T> T toBean(Map<String, Object> beanMap, Class<T> valueType) {
	T bean = BeanUtils.newInstance(valueType);
	PropertyDescriptor[] beanPds = getPropertyDescriptors(valueType);
	for (PropertyDescriptor propDescriptor : beanPds) {
		String propName = propDescriptor.getName();
		// 過濾class屬性 
		if (propName.equals("class")) {
			continue;
		}
		if (beanMap.containsKey(propName)) { 
			Method writeMethod = propDescriptor.getWriteMethod();
			if (null == writeMethod) {
				continue;
			}
			Object value = beanMap.get(propName);
			if (!writeMethod.isAccessible()) {
				writeMethod.setAccessible(true);
			}
			try {
				writeMethod.invoke(bean, value);
			} catch (Throwable e) {
				throw new RuntimeException("Could not set property '" + propName + "' to bean", e);
			}
		} 
	}
	return bean;
}
 
開發者ID:TomChen001,項目名稱:xmanager,代碼行數:31,代碼來源:BeanUtils.java

示例5: updateProperty

import java.beans.PropertyDescriptor; //導入方法依賴的package包/類
/**
 * Set a value on a Bean, if its a persistent bean, try to use an update method first
 * (for v1.0 domain objects), otherwise use the setter (for v1.1 and above).
 */
static void updateProperty(PropertyDescriptor pd, Object value, Object source)
        throws IllegalAccessException, InvocationTargetException, TransformException {
    if (source instanceof Persistent) {
        if (pd != null && pd.getWriteMethod() != null) {
            try {
                Method m = source.getClass().getMethod("update" + StringHelper.getUpper1(pd.getName()), pd.getWriteMethod().getParameterTypes());
                if (!m.isAccessible())
                    m.setAccessible(true);
                Class tClass = m.getParameterTypes()[0];
                if (value == null || tClass.isAssignableFrom(value.getClass())) {
                    m.invoke(source, new Object[]{value});
                    if (log.isDebugEnabled())
                        log.debug("Update property '" + pd.getName() + '=' + value + "' on object '" + source.getClass().getName() + '\'');
                    // See if there is a datatype mapper for these classes
                } else if (DataTypeMapper.instance().isMappable(value.getClass(), tClass)) {
                    value = DataTypeMapper.instance().map(value, tClass);
                    m.invoke(source, new Object[]{value});
                    if (log.isDebugEnabled())
                        log.debug("Translate+Update property '" + pd.getName() + '=' + value + "' on object '" + source.getClass().getName() + '\'');
                } else {
                    // Data type mismatch
                    throw new TransformException(TransformException.DATATYPE_MISMATCH, source.getClass().getName() + '.' + m.getName(), tClass.getName(), value.getClass().getName());
                }
            } catch (NoSuchMethodException e) {
                if (log.isDebugEnabled())
                    log.debug("No Updator, try Setter for DO property '" + pd.getName() + "' on object '" + source.getClass().getName() + '\'');
                // try to use the setter if there is no update method
                setProperty(pd, value, source);
            }
        } else {
            TransformException me = new TransformException(TransformException.NO_SETTER, null,
                    pd == null ? "???" : pd.getName(), source.getClass().getName());
            log.error(me.getLocalizedMessage());
            throw me;
        }
    } else
        setProperty(pd, value, source);
}
 
開發者ID:jaffa-projects,項目名稱:jaffa-framework,代碼行數:43,代碼來源:TransformerUtils.java

示例6: findPropertyForMethod

import java.beans.PropertyDescriptor; //導入方法依賴的package包/類
public PropertyDescriptor findPropertyForMethod(Method method)
{
	for( PropertyDescriptor pd : propertyMap.values() )
	{
		if( pd.getReadMethod() == method || pd.getWriteMethod() == method )
		{
			return pd;
		}
	}
	return null;
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:12,代碼來源:CachedPropertyInfo.java

示例7: EntityField

import java.beans.PropertyDescriptor; //導入方法依賴的package包/類
/**
 * 構造方法
 *
 * @param field              字段
 * @param propertyDescriptor 字段name對應的property
 */
public EntityField(Field field, PropertyDescriptor propertyDescriptor) {
    if (field != null) {
        this.field = field;
        this.name = field.getName();
        this.javaType = field.getType();
    }
    if (propertyDescriptor != null) {
        this.name = propertyDescriptor.getName();
        this.setter = propertyDescriptor.getWriteMethod();
        this.getter = propertyDescriptor.getReadMethod();
        this.javaType = propertyDescriptor.getPropertyType();
    }
}
 
開發者ID:godlike110,項目名稱:tk-mybatis,代碼行數:20,代碼來源:EntityField.java

示例8: test

import java.beans.PropertyDescriptor; //導入方法依賴的package包/類
private static void test(Class type) {
    PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(type, "prop");
    if (pd instanceof IndexedPropertyDescriptor) {
        error(pd, type.getSimpleName() + ".prop should not be an indexed property");
    }
    if (!pd.getPropertyType().equals(Color.class)) {
        error(pd, type.getSimpleName() + ".prop type should be a Color");
    }
    if (null == pd.getReadMethod()) {
        error(pd, type.getSimpleName() + ".prop should have classic read method");
    }
    if (null == pd.getWriteMethod()) {
        error(pd, type.getSimpleName() + ".prop should have classic write method");
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:16,代碼來源:Test4168833.java

示例9: getWriter

import java.beans.PropertyDescriptor; //導入方法依賴的package包/類
protected Method getWriter(String name) throws IntrospectionException {
    BeanInfo beanInfo = Introspector.getBeanInfo(into.getClass());
    for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
        if (name.equals(pd.getName()))
            return pd.getWriteMethod();
    }
    return null;
}
 
開發者ID:limberest,項目名稱:limberest,代碼行數:9,代碼來源:Objectifier.java

示例10: loadProperties

import java.beans.PropertyDescriptor; //導入方法依賴的package包/類
/**
 * Force the definition of the bean to be loaded.  Subclasses
 * should call this method if they override <code>addProperty</code>
 * @see #addProperty
 */
synchronized protected void loadProperties()
{
  if (_defs == null)
  {
    Map<String, PropertyDef> defs;

    try
    {
      Class<?> objClass = _getClass();
      // Grab all the getters and setters using JavaBeans
      BeanInfo info = JavaIntrospector.getBeanInfo(objClass);
      PropertyDescriptor[] descriptors = info.getPropertyDescriptors();

      int length = (descriptors != null) ? descriptors.length : 0;
      defs = new HashMap<String, PropertyDef>(Math.max(length, 1));
      _defs = defs;

      for (int i = 0; i < length; i++)
      {
        PropertyDescriptor property = descriptors[i];
        String name   = property.getName();
        if ((name != null) && (property.getWriteMethod() != null))
        {
          addProperty(property);
        }
      }
    }
    catch (Exception e)
    {
      // =-=AEW ERROR???
      _defs = new HashMap<String, PropertyDef>(1);
    }
  }
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:40,代碼來源:IntrospectionBeanDef.java

示例11: extractCollectionComponentType

import java.beans.PropertyDescriptor; //導入方法依賴的package包/類
@SuppressWarnings( { "unchecked" })
private Class<?> extractCollectionComponentType(BeanInfo beanInfo, PropertyDescriptor propertyDescriptor) {
	final java.lang.reflect.Type collectionAttributeType;
	if ( propertyDescriptor.getReadMethod() != null ) {
		collectionAttributeType = propertyDescriptor.getReadMethod().getGenericReturnType();
	}
	else if ( propertyDescriptor.getWriteMethod() != null ) {
		collectionAttributeType = propertyDescriptor.getWriteMethod().getGenericParameterTypes()[0];
	}
	else {
		// we need to look for the field and look at it...
		try {
			collectionAttributeType = ownerClass.getField( propertyDescriptor.getName() ).getGenericType();
		}
		catch ( Exception e ) {
			return null;
		}
	}

	if ( ParameterizedType.class.isInstance( collectionAttributeType ) ) {
		final java.lang.reflect.Type[] types = ( (ParameterizedType) collectionAttributeType ).getActualTypeArguments();
		if ( types == null ) {
			return null;
		}
		else if ( types.length == 1 ) {
			return (Class<?>) types[0];
		}
		else if ( types.length == 2 ) {
			// Map<K,V>
			return (Class<?>) types[1];
		}
	}
	return null;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:35,代碼來源:Binder.java

示例12: unsatisfiedNonSimpleProperties

import java.beans.PropertyDescriptor; //導入方法依賴的package包/類
/**
 * Return an array of non-simple bean properties that are unsatisfied.
 * These are probably unsatisfied references to other beans in the
 * factory. Does not include simple properties like primitives or Strings.
 * @param mbd the merged bean definition the bean was created with
 * @param bw the BeanWrapper the bean was created with
 * @return an array of bean property names
 * @see org.springframework.beans.BeanUtils#isSimpleProperty
 */
protected String[] unsatisfiedNonSimpleProperties(AbstractBeanDefinition mbd, BeanWrapper bw) {
	Set<String> result = new TreeSet<String>();
	PropertyValues pvs = mbd.getPropertyValues();
	PropertyDescriptor[] pds = bw.getPropertyDescriptors();
	for (PropertyDescriptor pd : pds) {
		if (pd.getWriteMethod() != null && !isExcludedFromDependencyCheck(pd) && !pvs.contains(pd.getName()) &&
				!BeanUtils.isSimpleProperty(pd.getPropertyType())) {
			result.add(pd.getName());
		}
	}
	return StringUtils.toStringArray(result);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:22,代碼來源:AbstractAutowireCapableBeanFactory.java

示例13: getDiff

import java.beans.PropertyDescriptor; //導入方法依賴的package包/類
/**
 * @param oldBean
 * @param newBean
 * @return
 */
public static <T> T getDiff(T oldBean, T newBean) {
    if (oldBean == null && newBean != null) {
        return newBean;
    } else if (newBean == null) {
        return null;
    } else {
        Class<?> cls1 = oldBean.getClass();
        try {
            @SuppressWarnings("unchecked")
            T object = (T)cls1.newInstance();
            BeanInfo beanInfo = Introspector.getBeanInfo(cls1);
            PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
            for (PropertyDescriptor property : propertyDescriptors) {
                String key = property.getName();
                // 過濾class屬性
                if (!key.equals("class")) {
                    // 得到property對應的getter方法
                    Method getter = property.getReadMethod();
                    // 得到property對應的setter方法
                    Method setter = property.getWriteMethod();
                    Object oldValue = getter.invoke(oldBean);
                    Object newValue = getter.invoke(newBean);
                    if (newValue != null) {
                        if (oldValue == null) {
                            setter.invoke(object, newValue);
                        } else if (oldValue != null && !newValue.equals(oldValue)) {
                            setter.invoke(object, newValue);
                        }
                    }
                }
            }
            return object;
        } catch (Exception e) {
            throw new DataParseException(e);
        }
    }
}
 
開發者ID:guokezheng,項目名稱:automat,代碼行數:43,代碼來源:InstanceUtil.java

示例14: testIntrospection

import java.beans.PropertyDescriptor; //導入方法依賴的package包/類
/** Test resource introspection */
@SuppressWarnings("unused")
public void testIntrospection() throws Exception {
  // get the gate.Document resource and its class
  ResourceData docRd = reg.get("gate.corpora.DocumentImpl");
  assertNotNull("couldn't find document res data (2)", docRd);
  Class<?> resClass = docRd.getResourceClass();

  // get the beaninfo and property descriptors for the resource
  BeanInfo docBeanInfo = Introspector.getBeanInfo(resClass, Object.class);
  PropertyDescriptor[] propDescrs = docBeanInfo.getPropertyDescriptors();

  // print all the properties in the reource's bean info;
  // remember the setFeatures method
  Method setFeaturesMethod = null;
  for(int i = 0; i<propDescrs.length; i++) {
    Method getMethodDescr = null;
    Method setMethodDescr = null;
    Class<?> propClass = null;

    PropertyDescriptor propDescr = propDescrs[i];
    propClass = propDescr.getPropertyType();
    getMethodDescr = propDescr.getReadMethod();
    setMethodDescr = propDescr.getWriteMethod();

    if(
      setMethodDescr != null &&
      setMethodDescr.getName().equals("setFeatures")
    )
      setFeaturesMethod = setMethodDescr;

    if(DEBUG) printProperty(propDescrs[i]);
  }

  // try setting the features property
  // invoke(Object obj, Object[] args)
  LanguageResource res = (LanguageResource) resClass.newInstance();
  FeatureMap feats = Factory.newFeatureMap();
  feats.put("things are sunny in sunny countries", "aren't they?");
  Object[] args = new Object[1];
  args[0] = feats;
  setFeaturesMethod.invoke(res, args);
  assertTrue(
    "features not added to resource properly",
    res.getFeatures().get("things are sunny in sunny countries")
      .equals("aren't they?")
  );
}
 
開發者ID:GateNLP,項目名稱:gate-core,代碼行數:49,代碼來源:TestCreole.java

示例15: hasServiceProperty

import java.beans.PropertyDescriptor; //導入方法依賴的package包/類
protected ServiceReference hasServiceProperty(PropertyDescriptor propertyDescriptor) {
	Method setter = propertyDescriptor.getWriteMethod();
	return setter != null ? AnnotationUtils.getAnnotation(setter, ServiceReference.class) : null;
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:5,代碼來源:ServiceReferenceInjectionBeanPostProcessor.java


注:本文中的java.beans.PropertyDescriptor.getWriteMethod方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。