Clover coverage report - Ivory - 1.0-alpha-5
Coverage timestamp: Sun Nov 9 2003 22:02:40 EST
file stats: LOC: 195   Methods: 4
NCLOC: 127   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
MetadataSerializer.java 3.6% 5.6% 25% 5.8%
coverage coverage
 1   
 package org.codehaus.ivory.serialize;
 2   
 
 3   
 import java.lang.reflect.Modifier;
 4   
 import java.util.List;
 5   
 
 6   
 import org.apache.axis.wsdl.fromJava.Types;
 7   
 import javax.xml.namespace.QName;
 8   
 
 9   
 import org.apache.axis.description.FieldDesc;
 10   
 import org.apache.axis.description.TypeDesc;
 11   
 import org.apache.axis.encoding.ser.BeanSerializer;
 12   
 import org.apache.axis.utils.BeanPropertyDescriptor;
 13   
 import org.w3c.dom.Element;
 14   
 
 15   
 /**
 16   
  * A BeanSerializer with metadata support.
 17   
  * 
 18   
  * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
 19   
  * @since May 21, 2003
 20   
  */
 21   
 public class MetadataSerializer extends BeanSerializer
 22   
 {
 23   
     // Construct BeanSerializer for the indicated class/qname
 24  0
     public MetadataSerializer(Class javaType, QName xmlType)
 25   
     {
 26  0
         this(javaType, xmlType, TypeDesc.getTypeDescForClass(javaType));
 27   
     }
 28   
 
 29   
     // Construct BeanSerializer for the indicated class/qname
 30  1
     public MetadataSerializer(Class javaType, QName xmlType, TypeDesc typeDesc)
 31   
     {
 32  1
         super(javaType, xmlType, typeDesc, null);
 33   
 
 34  1
         if (typeDesc != null)
 35   
         {
 36  0
             propertyDescriptor = typeDesc.getPropertyDescriptors();
 37   
         }
 38   
         else
 39   
         {
 40  1
             propertyDescriptor = MetaBeanUtils.getPd(javaType, null);
 41   
         }
 42   
     }
 43   
 
 44   
     // Construct BeanSerializer for the indicated class/qname/propertyDesc
 45  0
     public MetadataSerializer(
 46   
         Class javaType,
 47   
         QName xmlType,
 48   
         TypeDesc typeDesc,
 49   
         BeanPropertyDescriptor[] propertyDescriptor)
 50   
     {
 51  0
         super(javaType, xmlType, typeDesc, propertyDescriptor);
 52   
     }
 53   
 
 54   
     /**
 55   
      * Return XML schema for the specified type, suitable for insertion into
 56   
      * the &lt;types&gt; element of a WSDL document, or underneath an
 57   
      * &lt;element&gt; or &lt;attribute&gt; declaration.
 58   
      *
 59   
      * @param javaType the Java Class we're writing out schema for
 60   
      * @param types the Java2WSDL Types object which holds the context
 61   
      *              for the WSDL being generated.
 62   
      * @return a type element containing a schema simpleType/complexType
 63   
      * @see org.apache.axis.wsdl.fromJava.Types
 64   
      */
 65  0
     public Element writeSchema(Class javaType, Types types) throws Exception {
 66   
 
 67   
         // ComplexType representation of bean class
 68  0
         Element complexType = types.createElement("complexType");
 69   
 
 70   
         // See if there is a super class, stop if we hit a stop class
 71  0
         Element e = null;
 72  0
         Class superClass = javaType.getSuperclass();
 73  0
         BeanPropertyDescriptor[] superPd = null;
 74  0
         List stopClasses = types.getStopClasses();
 75  0
         if (superClass != null &&
 76   
                 superClass != java.lang.Object.class &&
 77   
                 superClass != java.lang.Exception.class &&
 78   
                 superClass != java.lang.Throwable.class &&
 79   
                 superClass != java.rmi.RemoteException.class &&
 80   
                 superClass != org.apache.axis.AxisFault.class &&
 81   
                 (stopClasses == null ||
 82   
                 !(stopClasses.contains(superClass.getName()))) ) {
 83   
             // Write out the super class
 84  0
             String base = types.writeType(superClass);
 85  0
             Element complexContent = types.createElement("complexContent");
 86  0
             complexType.appendChild(complexContent);
 87  0
             Element extension = types.createElement("extension");
 88  0
             complexContent.appendChild(extension);
 89  0
             extension.setAttribute("base", base);
 90  0
             e = extension;
 91   
             // Get the property descriptors for the super class
 92  0
             TypeDesc superTypeDesc = TypeDesc.getTypeDescForClass(superClass);
 93  0
             if (superTypeDesc != null) {
 94  0
                 superPd = superTypeDesc.getPropertyDescriptors();
 95   
             } else {
 96  0
                 superPd = MetaBeanUtils.getPd(superClass, null);
 97   
             }
 98   
         } else {
 99  0
             e = complexType;
 100   
         }
 101   
 
 102   
         // Add fields under sequence element.
 103   
         // Note: In most situations it would be okay
 104   
         // to put the fields under an all element.
 105   
         // However it is illegal schema to put an
 106   
         // element with minOccurs=0 or maxOccurs>1 underneath
 107   
         // an all element.  This is the reason why a sequence
 108   
         // element is used.
 109  0
         Element all = types.createElement("sequence");
 110  0
         e.appendChild(all);
 111   
 
 112  0
         if (Modifier.isAbstract(javaType.getModifiers())) {
 113  0
             complexType.setAttribute("abstract", "true");
 114   
         }
 115   
 
 116   
         // Serialize each property
 117  0
         for (int i=0; i<propertyDescriptor.length; i++) {
 118  0
             String propName = propertyDescriptor[i].getName();
 119   
 
 120   
             // Don't serializer properties named class
 121  0
             boolean writeProperty = true;
 122  0
             if (propName.equals("class")) {
 123  0
                 writeProperty = false;
 124   
             }
 125   
 
 126   
             // Don't serialize the property if it is present
 127   
             // in the super class property list
 128  0
             if (superPd != null && writeProperty) {
 129  0
                 for (int j=0; j<superPd.length && writeProperty; j++) {
 130  0
                     if (propName.equals(superPd[j].getName())) {
 131  0
                         writeProperty = false;
 132   
                     }
 133   
                 }
 134   
             }
 135  0
             if (!writeProperty) {
 136  0
                 continue;
 137   
             }
 138   
 
 139  0
             Class fieldType = propertyDescriptor[i].getType();
 140   
 
 141   
             // If we have type metadata, check to see what we're doing
 142   
             // with this field.  If it's an attribute, skip it.  If it's
 143   
             // an element, use whatever qname is in there.  If we can't
 144   
             // find any of this info, use the default.
 145   
 
 146  0
             if (typeDesc != null) {
 147  0
                 FieldDesc field = typeDesc.getFieldByName(propName);
 148   
 
 149  0
                 if (field != null) {
 150  0
                     QName qname = field.getXmlName();
 151  0
                     QName fieldXmlType = field.getXmlType();
 152  0
                     boolean isAnonymous = fieldXmlType.getLocalPart().startsWith(">");
 153   
 
 154  0
                     if (qname != null) {
 155   
                         // FIXME!
 156   
                         // Check to see if this is in the right namespace -
 157   
                         // if it's not, we need to use an <element ref="">
 158   
                         // to represent it!!!
 159   
 
 160   
                         // Use the default...
 161  0
                         propName = qname.getLocalPart();
 162   
                     }
 163  0
                     if (!field.isElement()) {
 164  0
                         writeAttribute(types,
 165   
                                        propName,
 166   
                                        fieldType,
 167   
                                        field.getXmlType(),
 168   
                                        complexType);
 169   
                     } else {
 170  0
                         writeField(types,
 171   
                                    propName,
 172   
                                    fieldType,
 173   
                                    propertyDescriptor[i].isIndexed(),
 174   
                                    field.isMinOccursZero(),
 175   
                                    all, isAnonymous);
 176   
                     }
 177   
                 } else {
 178  0
                     writeField(types,
 179   
                                propName,
 180   
                                fieldType,
 181   
                                propertyDescriptor[i].isIndexed(), false, all, false);
 182   
                 }
 183   
             } else {
 184  0
                 writeField(types,
 185   
                            propName,
 186   
                            fieldType,
 187   
                            propertyDescriptor[i].isIndexed(), false, all, false);
 188   
             }
 189   
         }
 190   
 
 191   
         // done
 192  0
         return complexType;
 193   
     }
 194   
 }
 195