Search in sources :

Example 76 with PropertyEditor

use of java.beans.PropertyEditor in project geronimo-xbean by apache.

the class XBeanNamespaceHandler method getValue.

protected Object getValue(String value, String propertyEditor) {
    if (value == null)
        return null;
    // 
    if (NULL_REFERENCE.equals(value)) {
        return null;
    }
    // 
    if (value.startsWith(BEAN_REFERENCE_PREFIX)) {
        // strip off the #
        value = value.substring(BEAN_REFERENCE_PREFIX.length());
        // if the new value starts with a #, then we had an excaped value (e.g. ##value)
        if (!value.startsWith(BEAN_REFERENCE_PREFIX)) {
            return new RuntimeBeanReference(value);
        }
    }
    if (propertyEditor != null) {
        PropertyEditor p = createPropertyEditor(propertyEditor);
        RootBeanDefinition def = new RootBeanDefinition();
        def.setBeanClass(PropertyEditorFactory.class);
        def.getPropertyValues().addPropertyValue("propertyEditor", p);
        def.getPropertyValues().addPropertyValue("value", value);
        return def;
    }
    // 
    return value;
}
Also used : PropertyEditor(java.beans.PropertyEditor) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 77 with PropertyEditor

use of java.beans.PropertyEditor in project geronimo-xbean by apache.

the class PropertyEditorRegistry method findEditor.

/**
 * Locate a property editor for qiven class of object.
 *
 * @param type The target object class of the property.
 * @return The resolved editor, if any.  Returns null if a suitable editor
 *         could not be located.
 */
protected PropertyEditor findEditor(final Type type) {
    if (type == null)
        throw new NullPointerException("type is null");
    Class clazz = toClass(type);
    // try to locate this directly from the editor manager first.
    PropertyEditor editor = PropertyEditorManager.findEditor(clazz);
    // we're outta here if we got one.
    if (editor != null) {
        return editor;
    }
    // resolvable
    if (clazz.isArray() && !clazz.getComponentType().isArray()) {
        // do a recursive lookup on the base type
        editor = findEditor(clazz.getComponentType());
        // wrapper this in an array adaptor for real use
        if (editor != null) {
            return new ArrayConverter(clazz, editor);
        }
    }
    // nothing found
    return null;
}
Also used : PropertyEditor(java.beans.PropertyEditor) RecipeHelper.toClass(org.apache.xbean.recipe.RecipeHelper.toClass)

Example 78 with PropertyEditor

use of java.beans.PropertyEditor in project geronimo-xbean by apache.

the class PropertyEditorRegistry method createConverterFromEditor.

protected Converter createConverterFromEditor(final Type type) {
    if (type == null) {
        throw new NullPointerException("type is null");
    }
    final Class<?> clazz = toClass(type);
    // try to locate this directly from the editor manager first.
    final PropertyEditor editor = PropertyEditorManager.findEditor(clazz);
    // we're outta here if we got one.
    if (editor != null) {
        return new PropertyEditorConverter(clazz);
    }
    // resolvable
    if (clazz.isArray() && !clazz.getComponentType().isArray()) {
        // do a recursive lookup on the base type
        final PropertyEditor arrayEditor = findEditor(clazz.getComponentType());
        // wrapper this in an array adaptor for real use
        if (findEditor(clazz.getComponentType()) != null) {
            return new ArrayConverter(clazz, arrayEditor);
        }
    }
    return null;
}
Also used : PropertyEditor(java.beans.PropertyEditor)

Example 79 with PropertyEditor

use of java.beans.PropertyEditor in project gephi by gephi.

the class FilterModelPersistenceProvider method readQuery.

private Query readQuery(XMLStreamReader reader, FilterModelImpl model) throws XMLStreamException {
    String builderClassName = reader.getAttributeValue(null, "builder");
    String filterClassName = reader.getAttributeValue(null, "filter");
    FilterBuilder builder = null;
    for (FilterBuilder fb : model.getLibrary().getLookup().lookupAll(FilterBuilder.class)) {
        if (fb.getClass().getName().equals(builderClassName)) {
            if (filterClassName != null) {
                if (fb.getFilter(model.getWorkspace()).getClass().getName().equals(filterClassName)) {
                    builder = fb;
                    break;
                }
            } else {
                builder = fb;
                break;
            }
        }
    }
    if (builder == null) {
        for (CategoryBuilder catBuilder : Lookup.getDefault().lookupAll(CategoryBuilder.class)) {
            for (FilterBuilder fb : catBuilder.getBuilders(model.getWorkspace())) {
                if (fb.getClass().getName().equals(builderClassName)) {
                    if (filterClassName != null) {
                        if (fb.getFilter(model.getWorkspace()).getClass().getName().equals(filterClassName)) {
                            builder = fb;
                            break;
                        }
                    } else {
                        builder = fb;
                        break;
                    }
                }
            }
        }
    }
    if (builder != null) {
        //Create filter
        Filter filter = builder.getFilter(model.getWorkspace());
        Query query;
        if (filter instanceof Operator) {
            query = new OperatorQueryImpl((Operator) filter);
        } else {
            query = new FilterQueryImpl(builder, filter);
        }
        FilterProperty property = null;
        boolean end = false;
        while (reader.hasNext() && !end) {
            Integer eventType = reader.next();
            if (eventType.equals(XMLEvent.START_ELEMENT)) {
                String name = reader.getLocalName();
                if ("parameter".equalsIgnoreCase(name)) {
                    int index = Integer.parseInt(reader.getAttributeValue(null, "index"));
                    property = query.getFilter().getProperties()[index];
                }
            } else if (eventType.equals(XMLStreamReader.CHARACTERS) && property != null) {
                try {
                    PropertyEditor editor = property.getPropertyEditor();
                    if (editor == null) {
                        editor = PropertyEditorManager.findEditor(property.getValueType());
                    }
                    if (editor != null) {
                        String textValue = reader.getText();
                        if (editor instanceof AttributeColumnPropertyEditor) {
                            GraphController gc = Lookup.getDefault().lookup(GraphController.class);
                            GraphModel graphModel = gc.getGraphModel(model.getWorkspace());
                            ((AttributeColumnPropertyEditor) editor).setGraphModel(graphModel);
                        }
                        editor.setAsText(textValue);
                        property.setValue(editor.getValue());
                        model.updateParameters(query);
                        if (editor instanceof AttributeColumnPropertyEditor) {
                            ((AttributeColumnPropertyEditor) editor).setGraphModel(null);
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else if (eventType.equals(XMLStreamReader.END_ELEMENT)) {
                property = null;
                if ("query".equalsIgnoreCase(reader.getLocalName())) {
                    end = true;
                }
            }
        }
        return query;
    }
    return null;
}
Also used : Query(org.gephi.filters.api.Query) XMLStreamException(javax.xml.stream.XMLStreamException) GraphModel(org.gephi.graph.api.GraphModel) PropertyEditor(java.beans.PropertyEditor) GraphController(org.gephi.graph.api.GraphController)

Example 80 with PropertyEditor

use of java.beans.PropertyEditor in project gephi by gephi.

the class FilterModelPersistenceProvider method writeParameter.

private void writeParameter(XMLStreamWriter writer, int index, FilterProperty property) {
    try {
        PropertyEditor editor = property.getPropertyEditor();
        if (editor == null) {
            editor = PropertyEditorManager.findEditor(property.getValueType());
        }
        if (editor == null) {
            return;
        }
        Object val = property.getValue();
        editor.setValue(val);
        writer.writeStartElement("parameter");
        writer.writeAttribute("index", String.valueOf(index));
        writer.writeCharacters(editor.getAsText());
        writer.writeEndElement();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : PropertyEditor(java.beans.PropertyEditor) XMLStreamException(javax.xml.stream.XMLStreamException)

Aggregations

PropertyEditor (java.beans.PropertyEditor)167 Test (org.junit.jupiter.api.Test)59 HashMap (java.util.HashMap)14 Test (org.junit.Test)13 Map (java.util.Map)11 File (java.io.File)10 URI (java.net.URI)9 TestBean (org.springframework.beans.testfixture.beans.TestBean)9 IOException (java.io.IOException)7 Path (java.nio.file.Path)7 Resource (org.springframework.core.io.Resource)7 Method (java.lang.reflect.Method)6 URL (java.net.URL)6 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)6 IndexedTestBean (org.springframework.beans.testfixture.beans.IndexedTestBean)6 PropertyDescriptor (java.beans.PropertyDescriptor)5 Field (java.lang.reflect.Field)4 ArrayList (java.util.ArrayList)4 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)4 StringArrayPropertyEditor (org.springframework.beans.propertyeditors.StringArrayPropertyEditor)4