User: cgjung  
  Date: 02/04/19 09:16:51

  Added:       jboss.net/src/main/org/jboss/net/jmx/adaptor
                        AttributeDeserializer.java
                        AttributeDeserializerFactory.java
                        AttributeSerializer.java
                        AttributeSerializerFactory.java
  Log:
  added JMX attribute serialization (not tested).
  
  Revision  Changes    Path
  1.1                  
contrib/jboss.net/src/main/org/jboss/net/jmx/adaptor/AttributeDeserializer.java
  
  Index: AttributeDeserializer.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  // $Id: AttributeDeserializer.java,v 1.1 2002/04/19 16:16:50 cgjung Exp $
  
  package org.jboss.net.jmx.adaptor;
  
  import org.apache.axis.encoding.DeserializerImpl;
  import org.apache.axis.encoding.DeserializationContext;
  import org.apache.axis.encoding.Target;
  import org.apache.axis.message.SOAPHandler;
  import org.apache.axis.encoding.Deserializer;
  import org.apache.axis.encoding.TypeMapping;
  
  import javax.xml.rpc.namespace.QName;
  
  import org.xml.sax.SAXException;
  import org.xml.sax.Attributes;
  
  
  import javax.management.Attribute;
  
  /**
   * Deserializer that turns well-formed XML-elements back
   * into JMX Attributes.
   * <br>
   * <ul>
   * </ul>
   * @created 19.04.2002
   * @author <a href="mailto:[EMAIL PROTECTED]";>Christoph G. Jung</a>
   * @version $Revision: 1.1 $
   */
  
  public class AttributeDeserializer extends DeserializerImpl {
  
        //
        // Attributes
        //
  
        protected String attributeName;
        protected Object attributeValue;
        protected QName xmlType;
  
        //
        // Constructors
        //
  
        public AttributeDeserializer(QName xmlType) {
                this.xmlType = xmlType;
        }
  
        /** we can already defer the attribute name */
        public void onStartElement(
                String namespace,
                String localName,
                String qName,
                Attributes attributes,
                DeserializationContext context)
                throws SAXException {
                attributeName = attributes.getValue("", "name");
        }
  
        /** dispatch to the deserializer for the value element */
        public SOAPHandler onStartChild(
                String namespace,
                String localName,
                String prefix,
                Attributes attributes,
                DeserializationContext context)
                throws SAXException {
                if (localName.equals("value") && namespace.equals("")) {
                        QName qn = context.getTypeFromAttributes(namespace, localName, 
attributes);
                        // get the deserializer
                        Deserializer dSer = context.getDeserializerForType(qn);
                        // If no deserializer, use the base DeserializerImpl.
                        // There may not be enough information yet to choose the
                        // specific deserializer.
                        if (dSer == null) {
                                dSer = new DeserializerImpl();
                                // determine a default type for this child element
                                TypeMapping tm = context.getTypeMapping();
                                dSer.setDefaultType(tm.getTypeQName(Object.class));
                                dSer.registerValueTarget(new AttributeValueTarget());
                        }
                        return (SOAPHandler) dSer;
                } else {
                        return null;
                }
        }
  
        /**
         * Append any characters to the value.  This method is defined by 
         * Deserializer.
         */
        public void onEndElement(
                String namespace,
                String localName,
                DeserializationContext context)
                throws SAXException {
                if (isNil) {
                        value = null;
                        return;
                }
  
                value = new Attribute(attributeName, attributeValue);
        }
  
        //
        // Inner classes
        //
  
        protected class AttributeValueTarget implements Target {
                public void set(Object value) throws SAXException {
                        attributeValue = value;
                }
        }
  
  }
  
  
  1.1                  
contrib/jboss.net/src/main/org/jboss/net/jmx/adaptor/AttributeDeserializerFactory.java
  
  Index: AttributeDeserializerFactory.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  // $Id: AttributeDeserializerFactory.java,v 1.1 2002/04/19 16:16:51 cgjung Exp $
  
  package org.jboss.net.jmx.adaptor;
  
  import org.apache.axis.encoding.DeserializerFactory;
  import javax.xml.rpc.encoding.Deserializer;
  import javax.xml.rpc.JAXRPCException;
  import javax.xml.rpc.namespace.QName;
  
  import javax.management.Attribute;
  
  import java.util.Set;
  
  
  /**
   * Factory for stateful ObjectName Deserialization.
   * <br>
   * <ul>
   * <li> jung, 10.03.2002: made axis alpha3 compliant. </li>
   * </ul>
   * @created 2. Oktober 2001, 14:05
   * @author <a href="mailto:[EMAIL PROTECTED]";>Christoph G. Jung</a>
   * @version $Revision: 1.1 $
   */
  
  public class AttributeDeserializerFactory implements DeserializerFactory {
  
        //
        // Attributes
        //
        
        final protected Set mechanisms=new java.util.HashSet(1);
        final protected Class javaType;
        final protected QName xmlType;
        
        //
        // Constructors
        //
        
        public AttributeDeserializerFactory(Class javaType, QName xmlType) throws 
Exception {
           if(!(Attribute.class.isAssignableFrom(javaType))) {
              throw new Exception("Could only build deserializers for JMX Attribute.");
           }
           mechanisms.add(org.apache.axis.Constants.AXIS_SAX);
           this.javaType=javaType;
           this.xmlType=xmlType;
        }
        
        //
        // Public API
        //
        
        public Deserializer getDeserializerAs(String mechanismType)
          throws JAXRPCException {
                if(!mechanisms.contains(mechanismType)) {
                        throw new JAXRPCException("Unsupported mechanism 
"+mechanismType);
          }
         return new AttributeDeserializer(xmlType);    
      }
          
  
      /**
       * Returns a list of all XML processing mechanism types supported by this 
DeserializerFactory.
       *
       * @return List of unique identifiers for the supported XML processing mechanism 
types
       */
      public java.util.Iterator getSupportedMechanismTypes() {
                return mechanisms.iterator();           
      }
      
      
  }
  
  
  1.1                  
contrib/jboss.net/src/main/org/jboss/net/jmx/adaptor/AttributeSerializer.java
  
  Index: AttributeSerializer.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  // $Id: AttributeSerializer.java,v 1.1 2002/04/19 16:16:51 cgjung Exp $
  
  package org.jboss.net.jmx.adaptor;
  
  import org.apache.axis.Constants;
  import org.apache.axis.encoding.Serializer;
  import org.apache.axis.encoding.SerializationContext;
  import org.apache.axis.encoding.XMLType;
  import org.apache.axis.wsdl.fromJava.Types;
  
  import org.xml.sax.Attributes;
  import org.w3c.dom.Element;
  import org.xml.sax.helpers.AttributesImpl;
  
  import javax.xml.rpc.namespace.QName;
  
  import javax.management.Attribute;
  
  import java.io.IOException;
  
  /**
   * Serializer specialized to turn JMX-Attributes into
   * corresponding XML-types.
   * <br>
   * <ul>
   * </ul>
   * @created 09.04.02
   * @author <a href="mailto:[EMAIL PROTECTED]";>Christoph G. Jung</a>
   * @version $Revision: 1.1 $
   */
  
  public class AttributeSerializer implements Serializer {
  
        /** this is the fully-qualified type that we serialize into */
        protected QName xmlType;
  
        // 
        // Constructors
        //
  
        public AttributeSerializer(QName xmlType) {
                this.xmlType = xmlType;
        }
  
        //
        // Public API
        //
  
        /** 
         *  turns a JMX objectname into a string-based xml element 
         *  @param name the name of the element that carries our type
         *  @param attributes the attributes of the element that carries our type
         *  @param value the objectname to serialize
         *  @param context the serialization context we live into
         */
        public void serialize(
                QName name,
                Attributes attributes,
                Object value,
                SerializationContext context)
                throws IOException {
  
                // do some initialisation of attributes
                AttributesImpl attrs;
                if (attributes != null)
                        attrs = new AttributesImpl(attributes);
                else
                        attrs = new AttributesImpl();
  
                // next we utter the attribute name as an attribute
                QName qname = new QName("", "name");
                attrs.addAttribute(
                        qname.getNamespaceURI(),
                        qname.getLocalPart(),
                        context.qName2String(qname),
                        "CDATA",
                        ((Attribute) value).getName());
  
                // start the attribute tag
                context.startElement(name, attrs);
  
                // next we utter an embedded value object of any-type with the
                // attributes content
                qname = new QName("", "value");
                Object attrValue = ((Attribute) value).getValue();
                // lets hope that Object is mapped semantically to xsd:any??    
                context.serialize(qname, null, attrValue, Object.class);
                // end the attribute tag
                context.endElement();
        }
  
        /** we use sax approach */
        public String getMechanismType() {
                return Constants.AXIS_SAX;
        }
  
        /**
         * Return XML schema for the specified type.
         * The Attribute type has a string-based name attribute and a
         */
  
        public boolean writeSchema(Types types) throws Exception {
                // Emit WSDL for simpleContent
                javax.wsdl.QName qName = types.getWsdlQName(xmlType);
                // ComplexType representation of SimpleType bean class
                Element complexType = types.createElement("complexType");
                types.writeSchemaElement(qName, complexType);
                complexType.setAttribute("name", qName.getLocalPart());
                Element nameAttribute =
                        types.createAttributeElement(
                                "name",
                                XMLType.XSD_STRING.toString(),
                                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",
                                XMLType.XSD_ANYTYPE.toString(),
                                true,
                                all.getOwnerDocument());
                all.appendChild(valueElement);
                return true;
        }
  
  }
  
  
  1.1                  
contrib/jboss.net/src/main/org/jboss/net/jmx/adaptor/AttributeSerializerFactory.java
  
  Index: AttributeSerializerFactory.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  // $Id: AttributeSerializerFactory.java,v 1.1 2002/04/19 16:16:51 cgjung Exp $
  
  package org.jboss.net.jmx.adaptor;
  
  import java.util.Iterator;
  
  import javax.xml.rpc.JAXRPCException;
  import javax.xml.rpc.encoding.Serializer;
  import org.apache.axis.encoding.SerializerFactory;
  
  import javax.xml.rpc.namespace.QName;
  
  import javax.management.Attribute;
  
  import java.util.Set;
  
  /**
   * Factory for Attribute Serialization.
   * <br>
   * <h3>Change History</h3>
   * <ul>
   * </ul>
   * @created 19.04.2002
   * @author <a href="mailto:[EMAIL PROTECTED]";>Christoph G. Jung</a>
   * @version $Revision: 1.1 $
   */
  
  public class AttributeSerializerFactory implements SerializerFactory {
  
        //
        // Attributes
        //
        
        final protected Set mechanisms=new java.util.HashSet(1);
        final protected Class javaType;
        final protected QName xmlType;
  
        //
        // Constructors
        //
        
        public AttributeSerializerFactory(Class javaType, QName xmlType) throws 
Exception {
           if(!(Attribute.class.isAssignableFrom(javaType))) {
              throw new Exception("Could only build serializers for JMX Attributes.");
           }
           mechanisms.add(org.apache.axis.Constants.AXIS_SAX);
           this.javaType=javaType;
           this.xmlType=xmlType;
        }
        
        //
        // Public API
        //
        
        public Serializer getSerializerAs(String mechanismType)
          throws JAXRPCException {
                if(!mechanisms.contains(mechanismType)) {
                        throw new JAXRPCException("Unsupported mechanism 
"+mechanismType);
          }
         return new AttributeSerializer(xmlType);    
      }
          
  
      /**
       * Returns a list of all XML processing mechanism types supported by this 
DeserializerFactory.
       *
       * @return List of unique identifiers for the supported XML processing mechanism 
types
       */
      public java.util.Iterator getSupportedMechanismTypes() {
                return mechanisms.iterator();           
      }
  
  }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to