Package java.beans

Examples of java.beans.PropertyEditor


    }

    protected PropertyEditor loadPropertyEditor(GAttributeInfo attribute, ClassLoader classLoader) {
        String propertyEditor = propertyEditors.get(attribute.getName());
        if (null == propertyEditor) {
            PropertyEditor editor;
            try {
                editor = PropertyEditors.findEditor(attribute.getType(), classLoader);
            } catch (ClassNotFoundException e) {
                log.error("Unable to load attribute type " + attribute.getType());
                return null;
View Full Code Here


            if (null == value || value instanceof String) {
                return (String) value;
            }
           
            Class typeClass = ClassLoading.loadClass(type, classLoader);
            PropertyEditor editor = PropertyEditors.findEditor(value.getClass());
            if (null == editor) {
                editor = PropertyEditors.findEditor(typeClass);
                if (null == editor) {
                    throw new InvalidAttributeException("Unable to format attribute of type " + type + "; no editor found");
                }
            }
           
            if (!type.equals(value.getClass().getName())
                    && !typeClass.isPrimitive()
                    && !Collection.class.isAssignableFrom(typeClass)) {
                propertyEditors.put(attributeName, editor.getClass().getName());
            }

            editor.setValue(value);
            return editor.getAsText();
        } catch (ClassNotFoundException e) {
            //todo: use the Configuration's ClassLoader to load the attribute, if this ever becomes an issue
            throw (InvalidAttributeException) new InvalidAttributeException("Unable to store attribute type " + type).initCause(e);
        }
    }
View Full Code Here

                log.debug("No editor for property "+name);
                editors[i]= null;
                continue;
            }

            PropertyEditor propertyEditor;
            Class editorClass= descriptors[i].getPropertyEditorClass();
           
            if (log.isDebugEnabled())
            {
                log.debug("Property "+name
                        +" has editor class "+editorClass);
            }
           
            if (editorClass != null)
            {
                try
                {
                    propertyEditor= (PropertyEditor)editorClass.newInstance();
                }
                catch (InstantiationException e)
                {
                    log.error("Can't create property editor.", e);
                    throw new Error(e.toString());
                }
                catch (IllegalAccessException e)
                {
                    log.error("Can't create property editor.", e);
                    throw new Error(e.toString());
                }
            }
            else
            {
                Class c= descriptors[i].getPropertyType();
                propertyEditor= PropertyEditorManager.findEditor(c);
            }

            if (log.isDebugEnabled())
            {
                log.debug("Property "+name
                        +" has property editor "+propertyEditor);
            }
           
            if (propertyEditor == null)
            {
                log.debug("No editor for property "+name);
                editors[i]= null;
                continue;
            }
           
            if (! propertyEditor.supportsCustomEditor())
            {
        propertyEditor= createWrapperEditor(
          propertyEditor, descriptors[i]);

        if (log.isDebugEnabled())
        {
          log.debug("Editor for property "+name
              +" is wrapped in "+propertyEditor);
        }
            }
           
      editors[i]= propertyEditor;

      // Initialize the editor with the provided default value or null:
            setEditorValue(i, descriptors[i].getValue(DEFAULT));

            // Now subscribe as a listener (we didn't want to receive the event
            // for the setEditorValue above!)
            propertyEditor.addPropertyChangeListener(this);
        }

    // Obtain message formats:
    propertyFieldLabelMessage= new MessageFormat
      JMeterUtils.getResString("property_as_field_label"));
View Full Code Here

    boolean notExpression=
      Boolean.TRUE.equals(descriptor.getValue(NOT_EXPRESSION));
    boolean notOther=
      Boolean.TRUE.equals(descriptor.getValue(NOT_OTHER));

    PropertyEditor guiEditor;
    if (notNull && tags==null)
    {
      guiEditor= new FieldStringEditor();
    }
    else
View Full Code Here

            throw new IllegalArgumentException("type is null");
        }


        // try to locate this directly from the editor manager first.
        PropertyEditor editor = PropertyEditorManager.findEditor(type);

        // we're outta here if we got one.
        if (editor != null) {
            return editor;
        }
View Full Code Here

     *         be resolved.
     * @throws PropertyEditorException Unable to find a suitable editor for this class.
     */
    public static PropertyEditor getEditor(Class type) {
        // just call the non-exceptional lookup
        PropertyEditor editor = findEditor(type);
        // this one throws an exception if not found.
        if (editor == null) {
            throw new PropertyEditorException("No property editor for type: " + type);
        }
        return editor;
View Full Code Here

        String value = (String) atts.get(attribute.getName());
        if(value == null) {
            return null; // nothing specified for this attribute
        }
        try {
            PropertyEditor editor = PropertyEditors.findEditor(attribute.getType(), getClass().getClassLoader());
            if (editor == null) {
                log.debug("Unable to parse attribute of type "+attribute.getType()+"; no editor found");
                return null;
            }
            editor.setAsText(value);
            log.debug("Setting value for "+configurationName+"/"+gbean+"/" + attribute.getName() + " to value " + value);
            return editor.getValue();
        } catch (ClassNotFoundException e) {
            //todo: use the Configuration's ClassLoader to load the attribute, if this ever becomes an issue
            log.error("Unable to load attribute type "+attribute.getType());
            return null;
        }
View Full Code Here

            }
        }
        try {
            String string = null;
            if(value != null) {
                PropertyEditor editor = PropertyEditors.findEditor(attribute.getType(), getClass().getClassLoader());
                if (editor == null) {
                    log.error("Unable to format attribute of type "+attribute.getType()+"; no editor found");
                    return;
                }
                editor.setValue(value);
                string = editor.getAsText();
            }
            if(string == null) {
                atts.remove(attribute.getName());
            } else {
                atts.put(attribute.getName(), string);
View Full Code Here

            return null;
        } else if (pClass.isAssignableFrom(pValue.getClass())) {
            return pValue;
        } else if (pValue instanceof String) {
            String str = (String) pValue;
            PropertyEditor pe = PropertyEditorManager.findEditor(pClass);
            if (pe == null) {
                if ("".equals(str)) {
                    return null;
                } else {
                    if (pLogger.isLoggingError()) {
                        pLogger.logError
                                (Constants.NO_PROPERTY_EDITOR,
                                        str,
                                        pClass.getName());
                    }
                    return null;
                }
            }
            try {
                pe.setAsText(str);
                return pe.getValue();
            }
            catch (IllegalArgumentException exc) {
                if ("".equals(str)) {
                    return null;
                } else {
View Full Code Here

  }

  @Test
  public void usesCustomEditorIfConfigured() throws Exception {

    PropertyEditor customEditor = mock(PropertyEditor.class);
    when(customEditor.getValue()).thenReturn(1);

    when(registry.findCustomEditor(Integer.class, null)).thenReturn(customEditor);

    convertsPlainIdTypeCorrectly();
View Full Code Here

TOP

Related Classes of java.beans.PropertyEditor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.