KickJava   Java API By Example, From Geeks To Geeks.

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


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.CustomNumberEditor;
16
17 public class JaxbNumberEditor extends CustomNumberEditor {
18
19     private static final Logger JavaDoc LOG = LogUtils.getL7dLogger(JaxbNumberEditor.class);
20     
21     JaxbNumberEditor(Class JavaDoc cl) {
22         super(cl, false);
23     }
24     
25     public Object JavaDoc getValue() {
26         Object JavaDoc o = super.getValue();
27         if (o instanceof Element JavaDoc) {
28             Element JavaDoc el = (Element JavaDoc)o;
29             QName JavaDoc type = new QName JavaDoc(el.getNamespaceURI(), el.getLocalName());
30             TypeSchema ts = new TypeSchemaHelper(true).get(type.getNamespaceURI());
31             if (null == ts) {
32                 throw new ConfigurationException(new Message("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", LOG, type);
38                 throw new ConfigurationException(msg, ex);
39             }
40         }
41
42         return o;
43     }
44 }
45
Popular Tags