java.beans.PropertyEditor#getValue ( )源码实例Demo

下面列出了java.beans.PropertyEditor#getValue ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Tomcat8-Source-Read   文件: JspRuntimeLibrary.java
public static Object getValueFromBeanInfoPropertyEditor(
                       Class<?> attrClass, String attrName, String attrValue,
                       Class<?> propertyEditorClass)
    throws JasperException
{
    try {
        PropertyEditor pe = (PropertyEditor)propertyEditorClass.getConstructor().newInstance();
        pe.setAsText(attrValue);
        return pe.getValue();
    } catch (Exception ex) {
        throw new JasperException(
            Localizer.getMessage("jsp.error.beans.property.conversion",
                                 attrValue, attrClass.getName(), attrName,
                                 ex.getMessage()));
    }
}
 
源代码2 项目: netbeans   文件: CustomEditorDisplayer.java
public boolean isValueModified() {
    PropertyEditor editor = getPropertyEditor();
    boolean result = editor.getValue() != originalValue;

    if (!result && editor instanceof EnhancedCustomPropertyEditor) {
        Object entered = ((EnhancedCustomPropertyEditor) editor).getPropertyValue();

        if (entered != null) {
            result = entered.equals(originalValue);
        } else {
            result = originalValue == null;
        }
    }

    return result;
}
 
源代码3 项目: Tomcat7.0.67   文件: JspRuntimeLibrary.java
public static Object getValueFromBeanInfoPropertyEditor(
                       Class<?> attrClass, String attrName, String attrValue,
                       Class<?> propertyEditorClass) 
    throws JasperException 
{
    try {
        PropertyEditor pe =
            (PropertyEditor)propertyEditorClass.newInstance();
        pe.setAsText(attrValue);
        return pe.getValue();
    } catch (Exception ex) {
        throw new JasperException(
            Localizer.getMessage("jsp.error.beans.property.conversion",
                                 attrValue, attrClass.getName(), attrName,
                                 ex.getMessage()));
    }
}
 
源代码4 项目: java-technology-stack   文件: PathEditorTests.java
@Test
public void testUnqualifiedPathNameNotFound() throws Exception {
	PropertyEditor pathEditor = new PathEditor();
	String fileName = ClassUtils.classPackageAsResourcePath(getClass()) + "/" +
			ClassUtils.getShortName(getClass()) + ".clazz";
	pathEditor.setAsText(fileName);
	Object value = pathEditor.getValue();
	assertTrue(value instanceof Path);
	Path path = (Path) value;
	File file = path.toFile();
	assertFalse(file.exists());
	String absolutePath = file.getAbsolutePath();
	if (File.separatorChar == '\\') {
		absolutePath = absolutePath.replace('\\', '/');
	}
	assertTrue(absolutePath.endsWith(fileName));
}
 
源代码5 项目: spring4-understanding   文件: FileEditorTests.java
@Test
public void testUnqualifiedFileNameFound() throws Exception {
	PropertyEditor fileEditor = new FileEditor();
	String fileName = ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass())
			+ ".class";
	fileEditor.setAsText(fileName);
	Object value = fileEditor.getValue();
	assertTrue(value instanceof File);
	File file = (File) value;
	assertTrue(file.exists());
	String absolutePath = file.getAbsolutePath();
	if (File.separatorChar == '\\') {
		absolutePath = absolutePath.replace('\\', '/');
	}
	assertTrue(absolutePath.endsWith(fileName));
}
 
源代码6 项目: lucene-solr   文件: ParseContextConfig.java
private Object getValueFromString(Class<?> targetType, String text) {
  final PropertyEditor editor = PropertyEditorManager.findEditor(targetType);
  if (editor == null) {
    throw new IllegalArgumentException("Cannot set properties of type " + targetType.getName());
  }
  editor.setAsText(text);
  return editor.getValue();
}
 
源代码7 项目: spring4-understanding   文件: URIEditorTests.java
@Test
public void standardURLWithWhitespace() throws Exception {
	PropertyEditor uriEditor = new URIEditor();
	uriEditor.setAsText("  http://www.springframework.org  ");
	Object value = uriEditor.getValue();
	assertTrue(value instanceof URI);
	URI uri = (URI) value;
	assertEquals("http://www.springframework.org", uri.toString());
}
 
源代码8 项目: spring4-understanding   文件: URLEditorTests.java
@Test
public void testClasspathURL() throws Exception {
	PropertyEditor urlEditor = new URLEditor();
	urlEditor.setAsText("classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) +
			"/" + ClassUtils.getShortName(getClass()) + ".class");
	Object value = urlEditor.getValue();
	assertTrue(value instanceof URL);
	URL url = (URL) value;
	assertEquals(url.toExternalForm(), urlEditor.getAsText());
	assertTrue(!url.getProtocol().startsWith("classpath"));
}
 
源代码9 项目: spring-analysis-note   文件: URLEditorTests.java
@Test
public void testClasspathURL() throws Exception {
	PropertyEditor urlEditor = new URLEditor();
	urlEditor.setAsText("classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) +
			"/" + ClassUtils.getShortName(getClass()) + ".class");
	Object value = urlEditor.getValue();
	assertTrue(value instanceof URL);
	URL url = (URL) value;
	assertEquals(url.toExternalForm(), urlEditor.getAsText());
	assertTrue(!url.getProtocol().startsWith("classpath"));
}
 
源代码10 项目: spring-analysis-note   文件: FileEditorTests.java
@Test
public void testAbsoluteFileName() throws Exception {
	PropertyEditor fileEditor = new FileEditor();
	fileEditor.setAsText("/no_way_this_file_is_found.doc");
	Object value = fileEditor.getValue();
	assertTrue(value instanceof File);
	File file = (File) value;
	assertTrue(!file.exists());
}
 
源代码11 项目: spring-analysis-note   文件: ResourceEditorTests.java
@Test
public void sunnyDay() throws Exception {
	PropertyEditor editor = new ResourceEditor();
	editor.setAsText("classpath:org/springframework/core/io/ResourceEditorTests.class");
	Resource resource = (Resource) editor.getValue();
	assertNotNull(resource);
	assertTrue(resource.exists());
}
 
源代码12 项目: lams   文件: ThreadSafePropertyEditor.java
public Object setAsText(String str) {
    PropertyEditor editor = fetchFromPool();
    try {
        editor.setAsText(str);
        return editor.getValue();
    } finally {
        pool.putInPool(editor);
    }
}
 
源代码13 项目: spring4-understanding   文件: URLEditorTests.java
@Test
public void testStandardURL() throws Exception {
	PropertyEditor urlEditor = new URLEditor();
	urlEditor.setAsText("http://www.springframework.org");
	Object value = urlEditor.getValue();
	assertTrue(value instanceof URL);
	URL url = (URL) value;
	assertEquals(url.toExternalForm(), urlEditor.getAsText());
}
 
源代码14 项目: java-technology-stack   文件: URIEditorTests.java
private void doTestURI(String uriSpec) {
	PropertyEditor uriEditor = new URIEditor();
	uriEditor.setAsText(uriSpec);
	Object value = uriEditor.getValue();
	assertTrue(value instanceof URI);
	URI uri = (URI) value;
	assertEquals(uriSpec, uri.toString());
}
 
@Test
public void testVanillaResource() throws Exception {
	PropertyEditor editor = new ResourceArrayPropertyEditor();
	editor.setAsText("classpath:org/springframework/core/io/support/ResourceArrayPropertyEditor.class");
	Resource[] resources = (Resource[]) editor.getValue();
	assertNotNull(resources);
	assertTrue(resources[0].exists());
}
 
源代码16 项目: spring-analysis-note   文件: FileEditorTests.java
@Test
public void testWithNonExistentFile() throws Exception {
	PropertyEditor fileEditor = new FileEditor();
	fileEditor.setAsText("file:no_way_this_file_is_found.doc");
	Object value = fileEditor.getValue();
	assertTrue(value instanceof File);
	File file = (File) value;
	assertTrue(!file.exists());
}
 
源代码17 项目: tomee   文件: IntrospectionSupport.java
private static Object convert(final Object value, final Class type)
    throws URISyntaxException {
    final PropertyEditor editor = PropertyEditorManager.findEditor(type);
    if (editor != null) {
        editor.setAsText(value.toString());
        return editor.getValue();
    }
    if (type == URI.class) {
        return URLs.uri(value.toString());
    }
    return null;
}
 
源代码18 项目: lams   文件: TypeConverterDelegate.java
/**
 * Convert the given text value using the given property editor.
 * @param oldValue the previous value, if available (may be {@code null})
 * @param newTextValue the proposed text value
 * @param editor the PropertyEditor to use
 * @return the converted value
 */
private Object doConvertTextValue(Object oldValue, String newTextValue, PropertyEditor editor) {
	try {
		editor.setValue(oldValue);
	}
	catch (Exception ex) {
		if (logger.isDebugEnabled()) {
			logger.debug("PropertyEditor [" + editor.getClass().getName() + "] does not support setValue call", ex);
		}
		// Swallow and proceed.
	}
	editor.setAsText(newTextValue);
	return editor.getValue();
}
 
源代码19 项目: spring-analysis-note   文件: URIEditorTests.java
@Test
public void standardURLWithWhitespace() throws Exception {
	PropertyEditor uriEditor = new URIEditor();
	uriEditor.setAsText("  https://www.springframework.org  ");
	Object value = uriEditor.getValue();
	assertTrue(value instanceof URI);
	URI uri = (URI) value;
	assertEquals("https://www.springframework.org", uri.toString());
}
 
@Test(expected=IllegalArgumentException.class)
public void testStrictSystemPropertyReplacement() {
	PropertyEditor editor = new ResourceArrayPropertyEditor(
			new PathMatchingResourcePatternResolver(), new StandardEnvironment(),
			false);
	System.setProperty("test.prop", "foo");
	try {
		editor.setAsText("${test.prop}-${bar}");
		Resource[] resources = (Resource[]) editor.getValue();
		assertEquals("foo-${bar}", resources[0].getFilename());
	}
	finally {
		System.getProperties().remove("test.prop");
	}
}