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


Java PropertyEditor.setAsText方法代碼示例

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


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

示例1: testTheEditorHonoursSeparatorAttribute

import java.beans.PropertyEditor; //導入方法依賴的package包/類
public void testTheEditorHonoursSeparatorAttribute () throws Exception {
    NP np = new NP ();
    np.setValue ("item.separator", "-");
    
    PropertyEditor p = np.getPropertyEditor ();
    assertNotNull ("There is some editor", p);
    assertEquals ("It is StringArrayEditor", StringArrayEditor.class, p.getClass ());
    ((StringArrayEditor)p).readEnv (np);
    
    p.setAsText ("A-B");
    
    String[] value = (String[])p.getValue ();
    
    assertNotNull ("Values is there", value);
    if (value.length != 2 || !"A".equals (value[0]) || !"B".equals(value[1])) {
        fail ("Unexpected arrays: " + Arrays.asList (value));
    }
    
    p.setValue (new String[] { "X", "Y" });
    String t = np.getPropertyEditor ().getAsText ();
    if (!"X- Y".equals (t)) {
        fail ("Wrong text: " + t);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:25,代碼來源:StringArrayEditorTest.java

示例2: getValueFromBeanInfoPropertyEditor

import java.beans.PropertyEditor; //導入方法依賴的package包/類
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()));
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:18,代碼來源:JspRuntimeLibrary.java

示例3: getValueFromPropertyEditorManager

import java.beans.PropertyEditor; //導入方法依賴的package包/類
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()));
	}
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:17,代碼來源:JspRuntimeLibrary.java

示例4: getValueFromBeanInfoPropertyEditor

import java.beans.PropertyEditor; //導入方法依賴的package包/類
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()));
}
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:17,代碼來源:JspRuntimeLibrary.java

示例5: getValueFromPropertyEditorManager

import java.beans.PropertyEditor; //導入方法依賴的package包/類
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()));
}
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:22,代碼來源:JspRuntimeLibrary.java

示例6: getValueFromPropertyEditorManager

import java.beans.PropertyEditor; //導入方法依賴的package包/類
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()));
    }
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:22,代碼來源:JspRuntimeLibrary.java

示例7: testEnumPropEd

import java.beans.PropertyEditor; //導入方法依賴的package包/類
public void testEnumPropEd() throws Exception {
    EProp prop = new EProp();
    PropertyEditor ed = PropUtils.getPropertyEditor(prop);
    assertEquals( EnumPropertyEditor.class, ed.getClass());
    assertFalse(ed.supportsCustomEditor());
    assertFalse(ed.isPaintable());
    String[] tags = ed.getTags();
    assertNotNull(tags);
    assertEquals("[CHOCOLATE, VANILLA, STRAWBERRY]", Arrays.toString(tags));
    assertEquals(E.VANILLA, ed.getValue());
    assertEquals("VANILLA", ed.getAsText());
    ed.setAsText("STRAWBERRY");
    assertEquals(E.STRAWBERRY, ed.getValue());
    assertEquals(E.class.getName().replace('$', '.') + ".STRAWBERRY", ed.getJavaInitializationString());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:16,代碼來源:EnumPropertyEditorTest.java

示例8: testNulls

import java.beans.PropertyEditor; //導入方法依賴的package包/類
public void testNulls() throws Exception {
    EProp prop = new EProp();
    PropertyEditor ed = PropUtils.getPropertyEditor(prop);
    assertEquals( EnumPropertyEditor.class, ed.getClass());
    ed.setAsText("");
    assertEquals(null, ed.getValue());
    assertEquals("", ed.getAsText());
    assertEquals("null", ed.getJavaInitializationString());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:10,代碼來源:EnumPropertyEditorTest.java

示例9: testLocalizedNames

import java.beans.PropertyEditor; //導入方法依賴的package包/類
public void testLocalizedNames() throws Exception {
    ABProp prop = new ABProp();
    PropertyEditor ed = PropUtils.getPropertyEditor(prop);
    assertEquals( EnumPropertyEditor.class, ed.getClass());
    ed.setAsText("");
    assertEquals("myA", ed.getTags()[0]);
    assertEquals("myB", ed.getTags()[1]);
    assertEquals(null, ed.getValue());
    ed.setAsText("myB");
    assertEquals("myB", ed.getAsText());
    assertEquals(BetterToString.class.getName().replace('$', '.') + ".B", ed.getJavaInitializationString());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:13,代碼來源:EnumPropertyEditorTest.java

示例10: loadFromProperties

import java.beans.PropertyEditor; //導入方法依賴的package包/類
/**
 * Initializes folder from the properties object.
 * @param props
 */
protected void loadFromProperties(Properties props, String prefix) throws IntrospectionException {
    Enumeration<String> keys = (Enumeration<String>) props.propertyNames();
    prefix = prefix + getName() + ".";
    // load properties in this folder
    while (keys.hasMoreElements()) {
        String key = keys.nextElement();
        if (key.startsWith(prefix)) {
            String posfix = key.replaceFirst(prefix, "");
            if (!posfix.contains(".")) {
                // the posfix represents a name of a property
                Property prop = getProperty(posfix);
                if (prop == null) {
                	continue;
                }
                // exploit the JavaBeans property editors to convert the values from text
                PropertyEditor editor = PropertyEditorManager.findEditor(prop.getType());
                if (editor == null) {
                	continue;
                }
                editor.setAsText(props.getProperty(key));
                prop.setValue(editor.getValue());
             
            }
        }
        ;
    }

    // load all subfolders
    for (Folder folder : getFolders()) {
        folder.loadFromProperties(props, prefix);
    }

}
 
開發者ID:kefik,項目名稱:Pogamut3,代碼行數:38,代碼來源:Folder.java

示例11: parseImp

import java.beans.PropertyEditor; //導入方法依賴的package包/類
@Override
public Object parseImp(String input, ParserHelper helper) {
    PropertyEditor editor = findEditor(helper.getRawTargetClass());
    if (editor == null) {
        return TRY_NEXT;
    }
    editor.setAsText(input);
    return editor.getValue();
}
 
開發者ID:Yoio,項目名稱:X4J,代碼行數:10,代碼來源:DynamicParsers.java

示例12: writeAttribute

import java.beans.PropertyEditor; //導入方法依賴的package包/類
protected void writeAttribute ( final PropertyDescriptor pd, final Variant value ) throws Exception
{
    final Method m = pd.getWriteMethod ();
    if ( m == null )
    {
        throw new RuntimeException ( "Failed to write since write method cannot be found" );
    }

    final Object target = getTarget ();

    if ( target == null )
    {
        throw new RuntimeException ( "No current target attached" );
    }

    final Class<?> targetType = pd.getPropertyType ();
    final Object o = convertWriteType ( targetType, value );

    if ( o != null )
    {
        // try the direct approach
        m.invoke ( target, o );
    }
    else
    {
        // try a "by string" approach
        final PropertyEditor pe = PropertyEditorManager.findEditor ( targetType );
        pe.setAsText ( value.asString () );
    }

}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:32,代碼來源:AbstractObjectExporter.java

示例13: getValueFromBeanInfoPropertyEditor

import java.beans.PropertyEditor; //導入方法依賴的package包/類
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()));
	}
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:12,代碼來源:JspRuntimeLibrary.java

示例14: doConvertTextValue

import java.beans.PropertyEditor; //導入方法依賴的package包/類
/**
 * 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();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:TypeConverterDelegate.java

示例15: setAsText

import java.beans.PropertyEditor; //導入方法依賴的package包/類
public Object setAsText(final String str) {
    final PropertyEditor editor = fetchFromPool();
    try {
        editor.setAsText(str);
        return editor.getValue();
    } finally {
        pool.putInPool(editor);
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:10,代碼來源:ThreadSafePropertyEditor.java


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