本文整理匯總了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);
}
}
示例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()));
}
}
示例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()));
}
}
示例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()));
}
}
示例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()));
}
}
示例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()));
}
}
示例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());
}
示例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());
}
示例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());
}
示例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);
}
}
示例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();
}
示例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 () );
}
}
示例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()));
}
}
示例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();
}
示例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);
}
}