1 package org.objectweb.celtix.bus.configuration.spring; 2 3 import java.beans.PropertyEditorSupport ; 4 import java.util.logging.Logger ; 5 6 import javax.xml.bind.JAXBException; 7 import javax.xml.namespace.QName ; 8 9 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.getL7dLogger(JaxbPropertyEditor.class); 20 21 public Object getValue() { 22 Object o = super.getValue(); 23 if (o instanceof Element ) { 24 Element el = (Element )o; 25 QName type = new QName (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 getAsText() { 42 Object o = super.getValue(); 43 if (null == o) { 44 return null; 45 } else if (o instanceof Element ) { 46 return ((Element )o).getTextContent(); 47 } 48 return super.getAsText(); 49 } 50 51 public void setAsText(String text) { 52 Object o = super.getValue(); 53 if (null == o) { 54 super.setValue(text); 55 } else { 56 super.setAsText(text); 57 } 58 } 59 60 } 61 | Popular Tags |