001: /*
002: * Copyright (C) The MX4J Contributors.
003: * All rights reserved.
004: *
005: * This software is distributed under the terms of the MX4J License version 1.0.
006: * See the terms of the MX4J License in the documentation provided with this software.
007: */
008:
009: package mx4j.tools.remote.soap.axis.ser;
010:
011: import java.io.IOException;
012: import javax.management.MBeanAttributeInfo;
013: import javax.xml.namespace.QName;
014:
015: import org.apache.axis.encoding.SerializationContext;
016: import org.apache.axis.encoding.XMLType;
017: import org.apache.axis.wsdl.fromJava.Types;
018: import org.w3c.dom.Element;
019: import org.xml.sax.Attributes;
020:
021: /**
022: * @version $Revision: 1.5 $
023: */
024: public class MBeanAttributeInfoSer extends AxisSerializer {
025: static final String TYPE = "MBeanAttributeInfo";
026: static final String NAME = "name";
027: static final String CLASS_NAME = "type";
028: static final String DESCRIPTION = "description";
029: static final String IS_READABLE = "isReadable";
030: static final String IS_WRITABLE = "isWritable";
031: static final String IS_IS = "isIs";
032: private static final QName NAME_QNAME = new QName("", NAME);
033: private static final QName TYPE_QNAME = new QName("", CLASS_NAME);
034: private static final QName DESCRIPTION_QNAME = new QName("",
035: DESCRIPTION);
036: private static final QName IS_READABLE_QNAME = new QName("",
037: IS_READABLE);
038: private static final QName IS_WRITABLE_QNAME = new QName("",
039: IS_WRITABLE);
040: private static final QName IS_IS_QNAME = new QName("", IS_IS);
041:
042: public void serialize(QName name, Attributes attributes,
043: Object value, SerializationContext context)
044: throws IOException {
045: MBeanAttributeInfo info = (MBeanAttributeInfo) value;
046: context.startElement(name, attributes);
047: context.serialize(NAME_QNAME, null, info.getName());
048: context.serialize(TYPE_QNAME, null, info.getType());
049: context.serialize(DESCRIPTION_QNAME, null, info
050: .getDescription());
051: context.serialize(IS_READABLE_QNAME, null,
052: info.isReadable() ? Boolean.TRUE : Boolean.FALSE);
053: context.serialize(IS_WRITABLE_QNAME, null,
054: info.isWritable() ? Boolean.TRUE : Boolean.FALSE);
055: context.serialize(IS_IS_QNAME, null, info.isIs() ? Boolean.TRUE
056: : Boolean.FALSE);
057: context.endElement();
058: }
059:
060: public Element writeSchema(Class aClass, Types types)
061: throws Exception {
062: Element complexType = types.createElement(SCHEMA_COMPLEX_TYPE);
063: complexType.setAttribute("name", TYPE);
064: Element allElement = types.createElement(SCHEMA_ALL);
065: complexType.appendChild(allElement);
066:
067: Element nameElement = types.createElement(SCHEMA_ELEMENT);
068: nameElement.setAttribute("name", NAME);
069: nameElement.setAttribute("type", XMLType.XSD_STRING
070: .getLocalPart());
071: allElement.appendChild(nameElement);
072:
073: Element typeElement = types.createElement(SCHEMA_ELEMENT);
074: typeElement.setAttribute("name", CLASS_NAME);
075: typeElement.setAttribute("type", XMLType.XSD_STRING
076: .getLocalPart());
077: allElement.appendChild(typeElement);
078:
079: Element descrElement = types.createElement(SCHEMA_ELEMENT);
080: descrElement.setAttribute("name", DESCRIPTION);
081: descrElement.setAttribute("type", XMLType.XSD_STRING
082: .getLocalPart());
083: allElement.appendChild(descrElement);
084:
085: Element readableElement = types.createElement(SCHEMA_ELEMENT);
086: readableElement.setAttribute("name", IS_READABLE);
087: readableElement.setAttribute("type", XMLType.XSD_BOOLEAN
088: .getLocalPart());
089: allElement.appendChild(readableElement);
090:
091: Element writableElement = types.createElement(SCHEMA_ELEMENT);
092: writableElement.setAttribute("name", IS_WRITABLE);
093: writableElement.setAttribute("type", XMLType.XSD_BOOLEAN
094: .getLocalPart());
095: allElement.appendChild(writableElement);
096:
097: Element isElement = types.createElement(SCHEMA_ELEMENT);
098: isElement.setAttribute("name", IS_IS);
099: isElement.setAttribute("type", XMLType.XSD_BOOLEAN
100: .getLocalPart());
101: allElement.appendChild(isElement);
102:
103: return complexType;
104: }
105: }
|