KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.objectweb.celtix.bus.configuration.spring;
2
3 import java.util.logging.Logger JavaDoc;
4
5 import javax.xml.bind.JAXBException;
6 import javax.xml.namespace.QName JavaDoc;
7
8 import org.w3c.dom.Element JavaDoc;
9
10 import org.objectweb.celtix.common.i18n.Message;
11 import org.objectweb.celtix.common.logging.LogUtils;
12 import org.objectweb.celtix.configuration.ConfigurationException;
13 import org.objectweb.celtix.configuration.impl.TypeSchema;
14 import org.objectweb.celtix.configuration.impl.TypeSchemaHelper;
15 import org.springframework.beans.propertyeditors.CustomBooleanEditor;
16
17
18 public class JaxbBooleanEditor extends CustomBooleanEditor {
19     
20     private static final Logger JavaDoc LOG = LogUtils.getL7dLogger(JaxbBooleanEditor.class);
21     
22     public JaxbBooleanEditor() {
23         super(false);
24     }
25     
26     public Object JavaDoc getValue() {
27         Object JavaDoc o = super.getValue();
28         if (o instanceof Element JavaDoc) {
29             Element JavaDoc el = (Element JavaDoc)o;
30             QName JavaDoc type = new QName JavaDoc(el.getNamespaceURI(), el.getLocalName());
31             TypeSchema ts = new TypeSchemaHelper(true).get(type.getNamespaceURI());
32             if (null == ts) {
33                 throw new ConfigurationException(new Message("JAXB_PROPERTY_EDITOR_EXC", LOG, type));
34             }
35             try {
36                 return ts.unmarshal(type, el);
37             } catch (JAXBException ex) {
38                 Message msg = new Message("JAXB_PROPERTY_EDITOR_EXC", LOG, type);
39                 throw new ConfigurationException(msg, ex);
40             }
41         }
42
43         return o;
44     }
45 }
46
Popular Tags