KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > bus > configuration > spring > JaxbPropertyEditor


1 package org.objectweb.celtix.bus.configuration.spring;
2
3 import java.beans.PropertyEditorSupport JavaDoc;
4 import java.util.logging.Logger JavaDoc;
5
6 import javax.xml.bind.JAXBException;
7 import javax.xml.namespace.QName JavaDoc;
8
9 import org.w3c.dom.Element JavaDoc;
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 JavaDoc {
18
19     private static final Logger JavaDoc LOG = LogUtils.getL7dLogger(JaxbPropertyEditor.class);
20
21     public Object JavaDoc getValue() {
22         Object JavaDoc o = super.getValue();
23         if (o instanceof Element JavaDoc) {
24             Element JavaDoc el = (Element JavaDoc)o;
25             QName JavaDoc type = new QName JavaDoc(el.getNamespaceURI(), el.getLocalName());
26             TypeSchema ts = new TypeSchemaHelper(true).get(type.getNamespaceURI());
27             if (null == ts) {
28                 throw new ConfigurationException(new Message("JAXB_PROPERTY_EDITOR_EXC", LOG, type));
29             }
30             try {
31                 return ts.unmarshal(type, el);
32             } catch (JAXBException ex) {
33                 Message msg = new Message("JAXB_PROPERTY_EDITOR_EXC", LOG, type);
34                 throw new ConfigurationException(msg, ex);
35             }
36         }
37
38         return o;
39     }
40     
41     public String JavaDoc getAsText() {
42         Object JavaDoc o = super.getValue();
43         if (null == o) {
44             return null;
45         } else if (o instanceof Element JavaDoc) {
46             return ((Element JavaDoc)o).getTextContent();
47         }
48         return super.getAsText();
49     }
50
51     public void setAsText(String JavaDoc text) {
52         Object JavaDoc o = super.getValue();
53         if (null == o) {
54             super.setValue(text);
55         } else {
56             super.setAsText(text);
57         }
58     }
59
60 }
61
Popular Tags