01: /*
02: * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2006.
03: *
04: * Licensed under the Aduna BSD-style license.
05: */
06: package org.openrdf.http.webclient.properties;
07:
08: import java.beans.PropertyEditorSupport;
09:
10: import org.slf4j.Logger;
11: import org.slf4j.LoggerFactory;
12:
13: import org.openrdf.http.protocol.Protocol;
14: import org.openrdf.model.Value;
15: import org.openrdf.model.ValueFactory;
16:
17: public class ValuePropertyEditor extends PropertyEditorSupport {
18:
19: final Logger logger = LoggerFactory.getLogger(this .getClass());
20:
21: private ValueFactory valueFactory;
22:
23: public ValuePropertyEditor(ValueFactory valueFactory) {
24: this .valueFactory = valueFactory;
25: }
26:
27: @Override
28: public String getAsText() {
29: String result = null;
30:
31: Value value = (Value) getValue();
32: if (value != null) {
33: result = Protocol.encodeValue(value);
34: logger.debug("Getting value as " + result);
35: }
36:
37: return result;
38: }
39:
40: @Override
41: public void setAsText(String text) throws IllegalArgumentException {
42: if (!"".equals(text)) {
43: Value value = Protocol.decodeValue(text, valueFactory);
44: logger.debug("Setting value to " + value);
45: setValue(value);
46: } else {
47: setValue(null);
48: }
49: }
50:
51: }
|