1 package com.sun.tools.xjc.runtime; 2 3 import javax.xml.bind.Element; 4 import javax.xml.namespace.QName ; 5 import org.xml.sax.SAXException ; 6 import com.sun.xml.bind.JAXBObject; 7 8 65 public class ElementWrapper implements Element, JAXBObject, XMLSerializable { 66 67 private QName tagName; 69 private Object body; 70 71 80 public ElementWrapper( QName tagName, Object body ) { 81 if(tagName==null) throw new IllegalArgumentException ("tag name is null"); 82 setBody(body); 83 this.tagName = tagName; 84 } 85 86 87 88 93 public QName getTagName() { 94 return tagName; 95 } 96 97 104 public void setTagName(QName tagName) { 105 if(tagName==null) throw new IllegalArgumentException ("tag name is null"); 106 this.tagName = tagName; 107 } 108 109 114 public Object getBody() { 115 return body; 116 } 117 118 124 public void setBody(Object body) { 125 if(body==null) throw new IllegalArgumentException ("body is null"); 126 if(!(body instanceof JAXBObject)) 127 throw new IllegalArgumentException (body.getClass().getName()+" is not a JAXB-generated class"); 128 this.body = body; 129 } 130 131 public void serializeBody(XMLSerializer target) throws SAXException { 132 target.startElement(tagName.getNamespaceURI(),tagName.getLocalPart()); 133 target.childAsURIs((JAXBObject)body,"body"); 134 target.endNamespaceDecls(); 135 target.childAsAttributes((JAXBObject)body,"body"); 136 target.endAttributes(); 137 target.childAsBody((JAXBObject)body,"body"); 138 target.endElement(); 139 } 140 141 public void serializeAttributes(XMLSerializer target) throws SAXException { 142 } 144 145 public void serializeURIs(XMLSerializer target) throws SAXException { 146 } 148 } 149 | Popular Tags |