package org.jboss.net.jmx.adaptor;
import org.jboss.axis.Constants;
import org.jboss.axis.encoding.SerializationContext;
import org.jboss.axis.encoding.Serializer;
import org.jboss.axis.encoding.XMLType;
import org.jboss.axis.wsdl.fromJava.Types;
import org.w3c.dom.Element;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.AttributesImpl;
import javax.management.Attribute;
import javax.xml.namespace.QName;
import java.io.IOException;
public class AttributeSer implements Serializer
{
protected QName xmlType;
public AttributeSer(Class javaType, QName xmlType)
{
this.xmlType = xmlType;
}
public void serialize(QName name,
Attributes attributes,
Object value,
SerializationContext context)
throws IOException
{
AttributesImpl attrs;
if (attributes != null)
attrs = new AttributesImpl(attributes);
else
attrs = new AttributesImpl();
QName qname = new QName("", "name");
attrs.addAttribute(qname.getNamespaceURI(),
qname.getLocalPart(),
context.qName2String(qname),
"CDATA",
((Attribute)value).getName());
context.startElement(name, attrs);
qname = new QName("", "value");
Object attrValue = ((Attribute)value).getValue();
context.serialize(qname, null, attrValue);
context.endElement();
}
public String getMechanismType()
{
return Constants.AXIS_SAX;
}
public Element writeSchema(Class forClass, Types types) throws Exception
{
Element complexType = types.createElement("complexType");
types.writeSchemaElement(xmlType, complexType);
complexType.setAttribute("name", xmlType.getLocalPart());
Element nameAttribute =
types.createAttributeElement("name",
XMLType.XSD_STRING.getClass(),
XMLType.XSD_STRING,
false,
complexType.getOwnerDocument());
complexType.appendChild(nameAttribute);
Element complexContent = types.createElement("complexContent");
complexType.appendChild(complexContent);
Element all = types.createElement("sequence");
complexContent.appendChild(all);
Element valueElement =
types.createElement("value",
types.getNamespaces().getCreatePrefix(XMLType.XSD_ANYTYPE.getNamespaceURI())
+ ":"
+ XMLType.XSD_ANYTYPE.getLocalPart(),
true,
false,
all.getOwnerDocument());
all.appendChild(valueElement);
return complexType;
}
}