下面列出了怎么用java.beans.PropertyEditorManager的API类实例代码及写法,或者点击链接到github查看源代码。
public static Object getValueFromPropertyEditorManager(
Class<?> attrClass, String attrName, String attrValue)
throws JasperException
{
try {
PropertyEditor propEditor =
PropertyEditorManager.findEditor(attrClass);
if (propEditor != null) {
propEditor.setAsText(attrValue);
return propEditor.getValue();
} else {
throw new IllegalArgumentException(
Localizer.getMessage("jsp.error.beans.propertyeditor.notregistered"));
}
} catch (IllegalArgumentException ex) {
throw new JasperException(
Localizer.getMessage("jsp.error.beans.property.conversion",
attrValue, attrClass.getName(), attrName,
ex.getMessage()));
}
}
public void run() {
try {
Thread.sleep(this.time); // increase the chance of the deadlock
if (this.sync) {
synchronized (Test6963811.class) {
PropertyEditorManager.findEditor(Super.class);
}
}
else {
PropertyEditorManager.findEditor(Sub.class);
}
}
catch (Exception exception) {
exception.printStackTrace();
}
}
public static Object getValueFromPropertyEditorManager(
Class<?> attrClass, String attrName, String attrValue)
throws JasperException
{
try {
PropertyEditor propEditor =
PropertyEditorManager.findEditor(attrClass);
if (propEditor != null) {
propEditor.setAsText(attrValue);
return propEditor.getValue();
} else {
throw new IllegalArgumentException(
Localizer.getMessage("jsp.error.beans.propertyeditor.notregistered"));
}
} catch (IllegalArgumentException ex) {
throw new JasperException(
Localizer.getMessage("jsp.error.beans.property.conversion",
attrValue, attrClass.getName(), attrName,
ex.getMessage()));
}
}
public void run() {
try {
Thread.sleep(this.time); // increase the chance of the deadlock
if (this.sync) {
synchronized (Test6963811.class) {
PropertyEditorManager.findEditor(Super.class);
}
}
else {
PropertyEditorManager.findEditor(Sub.class);
}
}
catch (Exception exception) {
exception.printStackTrace();
}
}
private static PropertyEditor findThePropertyEditor(Class clazz) {
PropertyEditor pe;
if (Object.class.equals(clazz)) {
pe = null;
} else {
pe = PropertyEditorManager.findEditor(clazz);
if (pe == null) {
Class sclazz = clazz.getSuperclass();
if (sclazz != null) {
pe = findPropertyEditor(sclazz);
}
}
}
classesWithPE.put(clazz, pe != null);
return pe;
}
public void testPackageUnregistering() {
MockLookup.setInstances(new NodesRegistrationSupport.PEPackageRegistration("test1.pkg"));
NodeOp.registerPropertyEditors();
MockLookup.setInstances(new NodesRegistrationSupport.PEPackageRegistration("test2.pkg"));
String[] editorSearchPath = PropertyEditorManager.getEditorSearchPath();
int count = 0;
for (int i = 0; i < editorSearchPath.length; i++) {
assertNotSame("test1.pkg", editorSearchPath[i]);
if ("test2.pkg".equals(editorSearchPath[i])) {
count++;
}
}
assertEquals(1, count);
}
private void btnSelectFontActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelectFontActionPerformed
PropertyEditor pe = PropertyEditorManager.findEditor(Font.class);
if (pe != null) {
pe.setValue(outputOptions.getFont());
DialogDescriptor dd = new DialogDescriptor(pe.getCustomEditor(),
NbBundle.getMessage(Controller.class,
"LBL_Font_Chooser_Title")); //NOI18N
String defaultFont = NbBundle.getMessage(Controller.class,
"BTN_Defaul_Font"); //NOI18N
dd.setOptions(new Object[]{DialogDescriptor.OK_OPTION,
defaultFont, DialogDescriptor.CANCEL_OPTION}); //NOI18N
DialogDisplayer.getDefault().createDialog(dd).setVisible(true);
if (dd.getValue() == DialogDescriptor.OK_OPTION) {
Font f = (Font) pe.getValue();
outputOptions.setFont(f);
} else if (dd.getValue() == defaultFont) {
outputOptions.setFont(null);
}
updateFontField();
}
}
private void fontButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fontButtonActionPerformed
PropertyEditor pe = PropertyEditorManager.findEditor(Font.class);
if (pe != null) {
pe.setValue(termOptions.getFont());
DialogDescriptor dd = new DialogDescriptor(pe.getCustomEditor(), FontChooser_title());
String defaultFontString = FontChooser_defaultFont_label();
dd.setOptions(new Object[]{DialogDescriptor.OK_OPTION,
defaultFontString, DialogDescriptor.CANCEL_OPTION}); //NOI18N
DialogDisplayer.getDefault().createDialog(dd).setVisible(true);
if (dd.getValue() == DialogDescriptor.OK_OPTION) {
Font f = (Font) pe.getValue();
termOptions.setFont(f);
applyTermOptions();
} else if (dd.getValue() == defaultFontString) {
Font controlFont = UIManager.getFont("controlFont"); //NOI18N
int fontSize = (controlFont == null) ? 12 : controlFont.getSize();
termOptions.setFont(new Font("monospaced", Font.PLAIN, fontSize)); //NOI18N
}
}
}
/**
* @param requiredType
* @param propertyPath
* @return
*/
public PropertyEditor findCustomEditor ( final Class<?> requiredType, final String propertyPath )
{
// first try to find exact match
String key = requiredType.getCanonicalName () + ":" + propertyPath;
PropertyEditor pe = this.propertyEditors.get ( key );
// 2nd: try to find for class only
if ( pe == null )
{
key = requiredType.getCanonicalName () + ":";
pe = this.propertyEditors.get ( key );
}
// 3rd: try to get internal
if ( pe == null )
{
pe = PropertyEditorManager.findEditor ( requiredType );
}
return pe;
}
public static Object getValueFromPropertyEditorManager(
Class<?> attrClass, String attrName, String attrValue)
throws JasperException
{
try {
PropertyEditor propEditor =
PropertyEditorManager.findEditor(attrClass);
if (propEditor != null) {
propEditor.setAsText(attrValue);
return propEditor.getValue();
} else {
throw new IllegalArgumentException(
Localizer.getMessage("jsp.error.beans.propertyeditor.notregistered"));
}
} catch (IllegalArgumentException ex) {
throw new JasperException(
Localizer.getMessage("jsp.error.beans.property.conversion",
attrValue, attrClass.getName(), attrName,
ex.getMessage()));
}
}
public void run() {
try {
Thread.sleep(this.time); // increase the chance of the deadlock
if (this.sync) {
synchronized (Test6963811.class) {
PropertyEditorManager.findEditor(Super.class);
}
}
else {
PropertyEditorManager.findEditor(Sub.class);
}
}
catch (Exception exception) {
exception.printStackTrace();
}
}
public void run() {
try {
Thread.sleep(this.time); // increase the chance of the deadlock
if (this.sync) {
synchronized (Test6963811.class) {
PropertyEditorManager.findEditor(Super.class);
}
}
else {
PropertyEditorManager.findEditor(Sub.class);
}
}
catch (Exception exception) {
exception.printStackTrace();
}
}
public static Object getValueFromPropertyEditorManager(
Class attrClass, String attrName, String attrValue)
throws JasperException
{
try {
PropertyEditor propEditor =
PropertyEditorManager.findEditor(attrClass);
if (propEditor != null) {
propEditor.setAsText(attrValue);
return propEditor.getValue();
} else {
throw new IllegalArgumentException(
Localizer.getMessage("jsp.error.beans.propertyeditor.notregistered"));
}
} catch (IllegalArgumentException ex) {
throw new JasperException(
Localizer.getMessage("jsp.error.beans.property.conversion",
attrValue, attrClass.getName(), attrName,
ex.getMessage()));
}
}
public void run() {
try {
Thread.sleep(this.time); // increase the chance of the deadlock
if (this.sync) {
synchronized (Test6963811.class) {
PropertyEditorManager.findEditor(Super.class);
}
}
else {
PropertyEditorManager.findEditor(Sub.class);
}
}
catch (Exception exception) {
exception.printStackTrace();
}
}
public void run() {
try {
Thread.sleep(this.time); // increase the chance of the deadlock
if (this.sync) {
synchronized (Test6963811.class) {
PropertyEditorManager.findEditor(Super.class);
}
}
else {
PropertyEditorManager.findEditor(Sub.class);
}
}
catch (Exception exception) {
exception.printStackTrace();
}
}
@Test
public void testCoerceToType14() {
PropertyEditorManager.registerEditor(TesterType.class, TesterTypeEditorNoError.class);
Object result = ELManager.getExpressionFactory().coerceToType(
"Foo", TesterType.class);
Assert.assertTrue(result instanceof TesterType);
Assert.assertEquals("Foo", ((TesterType) result).getValue());
}
private static void test(String[] path) {
try {
Beans.setDesignTime(true);
Beans.setGuiAvailable(true);
Introspector.setBeanInfoSearchPath(path);
PropertyEditorManager.setEditorSearchPath(path);
} catch (SecurityException exception) {
throw new Error("unexpected security exception", exception);
}
}
@Test
public void testCoerceToType16() {
PropertyEditorManager.registerEditor(TesterType.class, TesterTypeEditorError.class);
Object result = ELManager.getExpressionFactory().coerceToType(
"", TesterType.class);
Assert.assertNull(result);
}
TestEditor(Class type) {
System.out.println("Property class: " + type);
this.editor = PropertyEditorManager.findEditor(type);
if (this.editor == null)
throw new Error("could not find editor for " + type);
System.out.println("PropertyEditor class: " + this.editor.getClass());
validate(null, null);
}
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");
}
}
private static void test(Class<?> type, Class<? extends PropertyEditor> expected) {
PropertyEditor actual = PropertyEditorManager.findEditor(type);
if ((actual == null) && (expected != null)) {
throw new Error("expected editor is not found");
}
if ((actual != null) && !actual.getClass().equals(expected)) {
throw new Error("found unexpected editor");
}
}
private static boolean isEditorExist(Class type) {
for (int i = 0; i < 10; i++) {
System.gc(); // clean all weak references
if (null == PropertyEditorManager.findEditor(type)) {
return false;
}
}
return true;
}
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");
}
}
private static boolean isEditorExist(Class type) {
for (int i = 0; i < 10; i++) {
System.gc(); // clean all weak references
if (null == PropertyEditorManager.findEditor(type)) {
return false;
}
}
return true;
}
@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);
}
public static void main(String[] args) {
String[] oldPath = PropertyEditorManager.getEditorSearchPath();
String[] newPath = {"aaa.bbb", "aaa.ccc",};
PropertyEditorManager.setEditorSearchPath(newPath);
if (null != PropertyEditorManager.findEditor(Test4968709.class))
throw new Error("found unexpected editor");
PropertyEditorManager.setEditorSearchPath(oldPath);
if (null == PropertyEditorManager.findEditor(Double.TYPE))
throw new Error("expected editor is not found");
}
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");
}
}
private static void test(Class<?> type, Class<? extends PropertyEditor> expected) {
PropertyEditor actual = PropertyEditorManager.findEditor(type);
if ((actual == null) && (expected != null)) {
throw new Error("expected editor is not found");
}
if ((actual != null) && !actual.getClass().equals(expected)) {
throw new Error("found unexpected editor");
}
}
private static void test(Class<?> type, Class<? extends PropertyEditor> expected) {
PropertyEditor actual = PropertyEditorManager.findEditor(type);
if ((actual == null) && (expected != null)) {
throw new Error("expected editor is not found");
}
if ((actual != null) && !actual.getClass().equals(expected)) {
throw new Error("found unexpected editor");
}
}
public static void main(String[] args) {
String[] oldPath = PropertyEditorManager.getEditorSearchPath();
String[] newPath = {"aaa.bbb", "aaa.ccc",};
PropertyEditorManager.setEditorSearchPath(newPath);
if (null != PropertyEditorManager.findEditor(Test4968709.class))
throw new Error("found unexpected editor");
PropertyEditorManager.setEditorSearchPath(oldPath);
if (null == PropertyEditorManager.findEditor(Double.TYPE))
throw new Error("expected editor is not found");
}