1 7 8 10 package org.jboss.net.jmx.adaptor; 11 12 import org.jboss.axis.Constants; 13 import org.jboss.axis.encoding.SerializationContext; 14 import org.jboss.axis.encoding.Serializer; 15 import org.jboss.axis.encoding.XMLType; 16 import org.jboss.axis.wsdl.fromJava.Types; 17 import org.w3c.dom.Element ; 18 import org.xml.sax.Attributes ; 19 import org.xml.sax.helpers.AttributesImpl ; 20 21 import javax.management.Attribute ; 22 import javax.xml.namespace.QName ; 23 import java.io.IOException ; 24 25 35 36 public class AttributeSer implements Serializer 37 { 38 39 40 protected QName xmlType; 41 42 46 public AttributeSer(Class javaType, QName xmlType) 47 { 48 this.xmlType = xmlType; 49 } 50 51 55 62 public void serialize(QName name, 63 Attributes attributes, 64 Object value, 65 SerializationContext context) 66 throws IOException 67 { 68 69 AttributesImpl attrs; 71 if (attributes != null) 72 attrs = new AttributesImpl (attributes); 73 else 74 attrs = new AttributesImpl (); 75 76 QName qname = new QName ("", "name"); 78 attrs.addAttribute(qname.getNamespaceURI(), 79 qname.getLocalPart(), 80 context.qName2String(qname), 81 "CDATA", 82 ((Attribute )value).getName()); 83 84 context.startElement(name, attrs); 86 87 qname = new QName ("", "value"); 90 Object attrValue = ((Attribute )value).getValue(); 91 context.serialize(qname, null, attrValue); 93 context.endElement(); 95 } 96 97 98 public String getMechanismType() 99 { 100 return Constants.AXIS_SAX; 101 } 102 103 109 110 public Element writeSchema(Class forClass, Types types) throws Exception 111 { 112 Element complexType = types.createElement("complexType"); 114 types.writeSchemaElement(xmlType, complexType); 116 complexType.setAttribute("name", xmlType.getLocalPart()); 117 118 Element nameAttribute = 119 types.createAttributeElement("name", 120 XMLType.XSD_STRING.getClass(), 121 XMLType.XSD_STRING, 122 false, 123 complexType.getOwnerDocument()); 124 complexType.appendChild(nameAttribute); 125 Element complexContent = types.createElement("complexContent"); 126 complexType.appendChild(complexContent); 127 Element all = types.createElement("sequence"); 128 complexContent.appendChild(all); 129 Element valueElement = 130 types.createElement("value", 131 types.getNamespaces().getCreatePrefix(XMLType.XSD_ANYTYPE.getNamespaceURI()) 132 + ":" 133 + XMLType.XSD_ANYTYPE.getLocalPart(), 134 true, 135 false, 136 all.getOwnerDocument()); 137 all.appendChild(valueElement); 138 return complexType; 139 } 140 141 } 142 | Popular Tags |