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;
}
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;
}
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;
}
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;
}
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();
}
}
Aggregations