01: package org.objectweb.celtix.bus.configuration.spring;
02:
03: import java.beans.PropertyEditorSupport;
04: import java.util.logging.Logger;
05:
06: import javax.xml.bind.JAXBException;
07: import javax.xml.namespace.QName;
08:
09: import org.w3c.dom.Element;
10:
11: import org.objectweb.celtix.common.i18n.Message;
12: import org.objectweb.celtix.common.logging.LogUtils;
13: import org.objectweb.celtix.configuration.ConfigurationException;
14: import org.objectweb.celtix.configuration.impl.TypeSchema;
15: import org.objectweb.celtix.configuration.impl.TypeSchemaHelper;
16:
17: public class JaxbPropertyEditor extends PropertyEditorSupport {
18:
19: private static final Logger LOG = LogUtils
20: .getL7dLogger(JaxbPropertyEditor.class);
21:
22: public Object getValue() {
23: Object o = super .getValue();
24: if (o instanceof Element) {
25: Element el = (Element) o;
26: QName type = new QName(el.getNamespaceURI(), el
27: .getLocalName());
28: TypeSchema ts = new TypeSchemaHelper(true).get(type
29: .getNamespaceURI());
30: if (null == ts) {
31: throw new ConfigurationException(new Message(
32: "JAXB_PROPERTY_EDITOR_EXC", LOG, type));
33: }
34: try {
35: return ts.unmarshal(type, el);
36: } catch (JAXBException ex) {
37: Message msg = new Message("JAXB_PROPERTY_EDITOR_EXC",
38: LOG, type);
39: throw new ConfigurationException(msg, ex);
40: }
41: }
42:
43: return o;
44: }
45:
46: public String getAsText() {
47: Object o = super .getValue();
48: if (null == o) {
49: return null;
50: } else if (o instanceof Element) {
51: return ((Element) o).getTextContent();
52: }
53: return super .getAsText();
54: }
55:
56: public void setAsText(String text) {
57: Object o = super.getValue();
58: if (null == o) {
59: super.setValue(text);
60: } else {
61: super.setAsText(text);
62: }
63: }
64:
65: }
|