Java Code Examples for java.beans.PropertyEditorManager#registerEditor()

The following examples show how to use java.beans.PropertyEditorManager#registerEditor() . 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: CustomEditorConfigurer.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
protected void registerEditors() {
    for (String key : (Set<String>) customEditors.keySet()) {
        PropertyEditor value = (PropertyEditor) customEditors.get(key);
        try {
            PropertyEditorManager.registerEditor(Class.forName(key), value.getClass());
        }
        catch (ClassNotFoundException e) {
            LOG.debug("Cannot register property editor " + value + " for class " + key, e);
        }
    }
}
 
Example 2
Source File: Test6397609.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    MemoryClassLoader loader = new MemoryClassLoader();
    PropertyEditorManager.registerEditor(
            Object.class,
            loader.compile("Editor",
                           "public class Editor extends java.beans.PropertyEditorSupport {}"));

    if (!isEditorExist(Object.class)) {
        throw new Error("the editor is lost");
    }
    loader = null; // clean the reference
    if (isEditorExist(Object.class)) {
        throw new Error("unexpected editor is found");
    }
}
 
Example 3
Source File: Test6397609.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    MemoryClassLoader loader = new MemoryClassLoader();
    PropertyEditorManager.registerEditor(
            Object.class,
            loader.compile("Editor",
                           "public class Editor extends java.beans.PropertyEditorSupport {}"));

    if (!isEditorExist(Object.class)) {
        throw new Error("the editor is lost");
    }
    loader = null; // clean the reference
    if (isEditorExist(Object.class)) {
        throw new Error("unexpected editor is found");
    }
}
 
Example 4
Source File: LibSwingBoot.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Performs the boot.
 */
protected void performBoot() {
  // nothing required. Just gather the configuration.
  PropertyEditorManager.registerEditor( Boolean.class, BooleanPropertyEditor.class );
  PropertyEditorManager.registerEditor( Font.class, FontPropertyEditor.class );
  PropertyEditorManager.registerEditor( Color.class, ColorPropertyEditor.class );
}
 
Example 5
Source File: TestELSupport.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test(expected=ELException.class)
public void testCoerceToType15() {
    PropertyEditorManager.registerEditor(TesterType.class, TesterTypeEditorError.class);
    Object result = ELSupport.coerceToType("Foo", TesterType.class);
    Assert.assertTrue(result instanceof TesterType);
    Assert.assertEquals("Foo", ((TesterType) result).getValue());
}
 
Example 6
Source File: Test6397609.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    MemoryClassLoader loader = new MemoryClassLoader();
    PropertyEditorManager.registerEditor(
            Object.class,
            loader.compile("Editor",
                           "public class Editor extends java.beans.PropertyEditorSupport {}"));

    if (!isEditorExist(Object.class)) {
        throw new Error("the editor is lost");
    }
    loader = null; // clean the reference
    if (isEditorExist(Object.class)) {
        throw new Error("unexpected editor is found");
    }
}
 
Example 7
Source File: Test6397609.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    MemoryClassLoader loader = new MemoryClassLoader();
    PropertyEditorManager.registerEditor(
            Object.class,
            loader.compile("Editor",
                           "public class Editor extends java.beans.PropertyEditorSupport {}"));

    if (!isEditorExist(Object.class)) {
        throw new Error("the editor is lost");
    }
    loader = null; // clean the reference
    if (isEditorExist(Object.class)) {
        throw new Error("unexpected editor is found");
    }
}
 
Example 8
Source File: Test6397609.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    MemoryClassLoader loader = new MemoryClassLoader();
    PropertyEditorManager.registerEditor(
            Object.class,
            loader.compile("Editor",
                           "public class Editor extends java.beans.PropertyEditorSupport {}"));

    if (!isEditorExist(Object.class)) {
        throw new Error("the editor is lost");
    }
    loader = null; // clean the reference
    if (isEditorExist(Object.class)) {
        throw new Error("unexpected editor is found");
    }
}
 
Example 9
Source File: Test6397609.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    MemoryClassLoader loader = new MemoryClassLoader();
    PropertyEditorManager.registerEditor(
            Object.class,
            loader.compile("Editor",
                           "public class Editor extends java.beans.PropertyEditorSupport {}"));

    if (!isEditorExist(Object.class)) {
        throw new Error("the editor is lost");
    }
    loader = null; // clean the reference
    if (isEditorExist(Object.class)) {
        throw new Error("unexpected editor is found");
    }
}
 
Example 10
Source File: Test6397609.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    MemoryClassLoader loader = new MemoryClassLoader();
    PropertyEditorManager.registerEditor(
            Object.class,
            loader.compile("Editor",
                           "public class Editor extends java.beans.PropertyEditorSupport {}"));

    if (!isEditorExist(Object.class)) {
        throw new Error("the editor is lost");
    }
    loader = null; // clean the reference
    if (isEditorExist(Object.class)) {
        throw new Error("unexpected editor is found");
    }
}
 
Example 11
Source File: AbstractOptions.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public static PropertyEditor findPropertyEditor(Class<?> originalValueClass) {
	if (originalValueClass == null) {
		return null;
	}

	Class<?> valueClass = originalValueClass;
	while (valueClass != null) {
		//
		if (valueClass.getEnumConstants() != null) {
			// Hack Alert!: we have to put this code here to prevent the built-in EnumEditor
			//              from being used on Java 1.7.  That editor uses bad values for
			//              the display of enum values.
			PropertyEditorManager.registerEditor(originalValueClass, EnumEditor.class);
		}

		PropertyEditor editor = PropertyEditorManager.findEditor(valueClass);
		if (editor instanceof NoRegisteredEditorPropertyEditor) {
			return null; // This editor is a marker to indicate that we have already
			// looked for this editor and did not find one.
		}
		if (editor != null) {
			PropertyEditorManager.registerEditor(originalValueClass, editor.getClass());
			return editor;
		}
		valueClass = valueClass.getSuperclass();
	}
	PropertyEditorManager.registerEditor(originalValueClass,
		NoRegisteredEditorPropertyEditor.class);
	return null;

}
 
Example 12
Source File: EditorInitializer.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
	PropertyEditorManager.registerEditor(String.class, StringEditor.class);
	PropertyEditorManager.registerEditor(Color.class, ColorEditor.class);
	PropertyEditorManager.registerEditor(Font.class, FontPropertyEditor.class);
	PropertyEditorManager.registerEditor(Enum.class, EnumEditor.class);
	PropertyEditorManager.registerEditor(Boolean.class, BooleanEditor.class);
	PropertyEditorManager.registerEditor(Date.class, DateEditor.class);
	PropertyEditorManager.registerEditor(Integer.class, IntEditor.class);
	PropertyEditorManager.registerEditor(File.class, FileChooserEditor.class);
}
 
Example 13
Source File: Test6397609.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    MemoryClassLoader loader = new MemoryClassLoader();
    PropertyEditorManager.registerEditor(
            Object.class,
            loader.compile("Editor",
                           "public class Editor extends java.beans.PropertyEditorSupport {}"));

    if (!isEditorExist(Object.class)) {
        throw new Error("the editor is lost");
    }
    loader = null; // clean the reference
    if (isEditorExist(Object.class)) {
        throw new Error("unexpected editor is found");
    }
}
 
Example 14
Source File: TestELSupport.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Test
public void testCoerceToType14() {
    PropertyEditorManager.registerEditor(TesterType.class, TesterTypeEditorNoError.class);
    Object result = ELSupport.coerceToType("Foo", TesterType.class);
    Assert.assertTrue(result instanceof TesterType);
    Assert.assertEquals("Foo", ((TesterType) result).getValue());
}
 
Example 15
Source File: TestELSupport.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Test(expected=ELException.class)
public void testCoerceToType15() {
    PropertyEditorManager.registerEditor(TesterType.class, TesterTypeEditorError.class);
    Object result = ELSupport.coerceToType("Foo", TesterType.class);
    Assert.assertTrue(result instanceof TesterType);
    Assert.assertEquals("Foo", ((TesterType) result).getValue());
}
 
Example 16
Source File: TestELSupport.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testCoerceToType16() {
    PropertyEditorManager.registerEditor(TesterType.class, TesterTypeEditorError.class);
    Object result = ELManager.getExpressionFactory().coerceToType(
            "", TesterType.class);
    Assert.assertNull(result);
}
 
Example 17
Source File: TestELSupport.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test(expected=ELException.class)
public void testCoerceToType15() {
    PropertyEditorManager.registerEditor(TesterType.class, TesterTypeEditorError.class);
    Object result = ELManager.getExpressionFactory().coerceToType(
            "Foo", TesterType.class);
    Assert.assertTrue(result instanceof TesterType);
    Assert.assertEquals("Foo", ((TesterType) result).getValue());
}
 
Example 18
Source File: TestPropertyEditor.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void run() {
    PropertyEditorManager.registerEditor(ThirdBean.class, ThirdBeanEditor.class);

    test(FirstBean.class, FirstBeanEditor.class);
    test(SecondBean.class, null);
    test(ThirdBean.class, ThirdBeanEditor.class);
    // test editors for default primitive types
    test(Byte.TYPE, ByteEditor.class);
    test(Short.TYPE, ShortEditor.class);
    test(Integer.TYPE, IntegerEditor.class);
    test(Long.TYPE, LongEditor.class);
    test(Boolean.TYPE, BooleanEditor.class);
    test(Float.TYPE, FloatEditor.class);
    test(Double.TYPE, DoubleEditor.class);
    // test editors for default object types
    test(Byte.class, ByteEditor.class);
    test(Short.class, ShortEditor.class);
    test(Integer.class, IntegerEditor.class);
    test(Long.class, LongEditor.class);
    test(Boolean.class, BooleanEditor.class);
    test(Float.class, FloatEditor.class);
    test(Double.class, DoubleEditor.class);
    test(String.class, StringEditor.class);
    test(Color.class, ColorEditor.class);
    test(Font.class, FontEditor.class);
    test(Enumeration.class, EnumEditor.class);

    PropertyEditorManager.registerEditor(ThirdBean.class, null);
    PropertyEditorManager.setEditorSearchPath(SEARCH_PATH);

    test(FirstBean.class, FirstBeanEditor.class);
    test(SecondBean.class, SecondBeanEditor.class);
    test(ThirdBean.class, ThirdBeanEditor.class);
    // test editors for default primitive types
    test(Byte.TYPE, ByteEditor.class);
    test(Short.TYPE, ShortEditor.class);
    test(Integer.TYPE, IntegerEditor.class);
    test(Long.TYPE, LongEditor.class);
    test(Boolean.TYPE, BooleanEditor.class);
    test(Float.TYPE, FloatEditor.class);
    test(Double.TYPE, DoubleEditor.class);
    // test editors for default object types
    test(Byte.class, null);
    test(Short.class, null);
    test(Integer.class, null);
    test(Long.class, null);
    test(Boolean.class, null);
    test(Float.class, null);
    test(Double.class, null);
    test(String.class, null);
    test(Color.class, null);
    test(Font.class, null);
    test(Enumeration.class, EnumEditor.class);
}
 
Example 19
Source File: TestELSupport.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Test
public void testCoerceToType16() {
    PropertyEditorManager.registerEditor(TesterType.class, TesterTypeEditorError.class);
    Object result = ELSupport.coerceToType("", TesterType.class);
    Assert.assertNull(result);
}
 
Example 20
Source File: TestPropertyEditor.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public void run() {
    PropertyEditorManager.registerEditor(ThirdBean.class, ThirdBeanEditor.class);

    test(FirstBean.class, FirstBeanEditor.class);
    test(SecondBean.class, null);
    test(ThirdBean.class, ThirdBeanEditor.class);
    // test editors for default primitive types
    test(Byte.TYPE, ByteEditor.class);
    test(Short.TYPE, ShortEditor.class);
    test(Integer.TYPE, IntegerEditor.class);
    test(Long.TYPE, LongEditor.class);
    test(Boolean.TYPE, BooleanEditor.class);
    test(Float.TYPE, FloatEditor.class);
    test(Double.TYPE, DoubleEditor.class);
    // test editors for default object types
    test(Byte.class, ByteEditor.class);
    test(Short.class, ShortEditor.class);
    test(Integer.class, IntegerEditor.class);
    test(Long.class, LongEditor.class);
    test(Boolean.class, BooleanEditor.class);
    test(Float.class, FloatEditor.class);
    test(Double.class, DoubleEditor.class);
    test(String.class, StringEditor.class);
    test(Color.class, ColorEditor.class);
    test(Font.class, FontEditor.class);
    test(Enumeration.class, EnumEditor.class);

    PropertyEditorManager.registerEditor(ThirdBean.class, null);
    PropertyEditorManager.setEditorSearchPath(SEARCH_PATH);

    test(FirstBean.class, FirstBeanEditor.class);
    test(SecondBean.class, SecondBeanEditor.class);
    test(ThirdBean.class, ThirdBeanEditor.class);
    // test editors for default primitive types
    test(Byte.TYPE, ByteEditor.class);
    test(Short.TYPE, ShortEditor.class);
    test(Integer.TYPE, IntegerEditor.class);
    test(Long.TYPE, LongEditor.class);
    test(Boolean.TYPE, BooleanEditor.class);
    test(Float.TYPE, FloatEditor.class);
    test(Double.TYPE, DoubleEditor.class);
    // test editors for default object types
    test(Byte.class, null);
    test(Short.class, null);
    test(Integer.class, null);
    test(Long.class, null);
    test(Boolean.class, null);
    test(Float.class, null);
    test(Double.class, null);
    test(String.class, null);
    test(Color.class, null);
    test(Font.class, null);
    test(Enumeration.class, EnumEditor.class);
}