FileDocCategorySizeDatePackage
BaseDeserializerFactory.javaAPI DocApache Axis 1.411064Sat Apr 22 18:57:26 BST 2006org.apache.axis.encoding.ser

BaseDeserializerFactory

public abstract class BaseDeserializerFactory extends BaseFactory implements org.apache.axis.encoding.DeserializerFactory
Base class for Axis Deserialization Factory classes for code reuse
author
Rich Scheuerle

Fields Summary
protected static Log
log
static transient Vector
mechanisms
protected Class
deserClass
protected QName
xmlType
protected Class
javaType
protected transient Constructor
deserClassConstructor
protected transient Method
getDeserializer
private static final Class[]
CLASS_QNAME_CLASS
Constructors Summary
public BaseDeserializerFactory(Class deserClass)
Constructor

param
deserClass is the class of the Deserializer


                  
       
        if (!Deserializer.class.isAssignableFrom(deserClass)) {
            throw new ClassCastException(
                    Messages.getMessage("BadImplementation00",
                            deserClass.getName(),
                            Deserializer.class.getName()));
        }
        this.deserClass = deserClass;
    
public BaseDeserializerFactory(Class deserClass, QName xmlType, Class javaType)

        this(deserClass);
        this.xmlType = xmlType;
        this.javaType = javaType;
    
Methods Summary
public static org.apache.axis.encoding.DeserializerFactorycreateFactory(java.lang.Class factory, java.lang.Class javaType, javax.xml.namespace.QName xmlType)
Utility method that intospects on a factory class to decide how to create the factory. Tries in the following order: public static create(Class javaType, QName xmlType) public (Class javaType, QName xmlType) public ()

param
factory class
param
javaType
param
xmlType

        if (factory == null) {
            return null;
        }

        try {
            if (factory == BeanDeserializerFactory.class) {
                return new BeanDeserializerFactory(javaType, xmlType);
            } else if (factory == SimpleDeserializerFactory.class) {
                return new SimpleDeserializerFactory(javaType, xmlType);
            } else if (factory == EnumDeserializerFactory.class) {
                return new EnumDeserializerFactory(javaType, xmlType);
            } else if (factory == ElementDeserializerFactory.class) {
                return new ElementDeserializerFactory();
            } else if (factory == SimpleListDeserializerFactory.class) {
                return new SimpleListDeserializerFactory(javaType, xmlType);
            }
        } catch (Exception e) {
            if (log.isDebugEnabled()) {
                log.debug(org.apache.axis.utils.Messages.getMessage("exception00"), e);
            }
            return null;
        }

        DeserializerFactory df = null;
        try {
            Method method = 
                factory.getMethod("create", CLASS_QNAME_CLASS);
            df = (DeserializerFactory) 
                method.invoke(null, 
                              new Object[] {javaType, xmlType});
        } catch (NoSuchMethodException e) {
            if(log.isDebugEnabled()) {
                log.debug(org.apache.axis.utils.Messages.getMessage("exception00"), e);
            }
        } catch (IllegalAccessException e) {
            if(log.isDebugEnabled()) {
                log.debug(org.apache.axis.utils.Messages.getMessage("exception00"), e);
            }
        } catch (InvocationTargetException e) {
            if(log.isDebugEnabled()) {
                log.debug(org.apache.axis.utils.Messages.getMessage("exception00"), e);
            }
        }

        if (df == null) {
            try {
                Constructor constructor =  
                    factory.getConstructor(CLASS_QNAME_CLASS);
                df = (DeserializerFactory) 
                    constructor.newInstance(
                        new Object[] {javaType, xmlType});
            } catch (NoSuchMethodException e) {
                if(log.isDebugEnabled()) {
                    log.debug(org.apache.axis.utils.Messages.getMessage("exception00"), e);
                }
            } catch (InstantiationException e) {
                if(log.isDebugEnabled()) {
                    log.debug(org.apache.axis.utils.Messages.getMessage("exception00"), e);
                }
            } catch (IllegalAccessException e) {
                if(log.isDebugEnabled()) {
                    log.debug(org.apache.axis.utils.Messages.getMessage("exception00"), e);
                }
            } catch (InvocationTargetException e) {
                if(log.isDebugEnabled()) {
                    log.debug(org.apache.axis.utils.Messages.getMessage("exception00"), e);
                }
            }
        }
        
        if (df == null) {
            try {
                df = (DeserializerFactory) factory.newInstance();
            } catch (InstantiationException e) {
            } catch (IllegalAccessException e) {}
        }
        return df;
    
private java.lang.reflect.ConstructorgetConstructor(java.lang.Class clazz)
return constructor for class if any

    
                
         
        try {
            return clazz.getConstructor(CLASS_QNAME_CLASS);
        } catch (NoSuchMethodException e) {}
        return null;
     
protected java.lang.reflect.ConstructorgetDeserClassConstructor()
Returns the deserClassConstructor.

return
Constructor

    	if (deserClassConstructor == null) { 
            deserClassConstructor = getConstructor(deserClass);
        } 
    	return deserClassConstructor;
    
public javax.xml.rpc.encoding.DeserializergetDeserializerAs(java.lang.String mechanismType)

        Deserializer deser = null;

        // Need to add code to check against mechanisms vector.

        // Try getting a specialized Deserializer
        deser = getSpecialized(mechanismType);
        
        // Try getting a general purpose Deserializer via constructor
        // invocation
        if (deser == null) {
            deser = getGeneralPurpose(mechanismType);
        }
        
        try {
            // If not successfull, try newInstance
            if (deser == null) {
                deser = (Deserializer) deserClass.newInstance();
            }
        } catch (Exception e) {
            throw new JAXRPCException(e);
        }
        return deser;
    
protected org.apache.axis.encoding.DeserializergetGeneralPurpose(java.lang.String mechanismType)
Obtains a deserializer by invoking (javaType, xmlType) on the deserClass.

        if (javaType != null && xmlType != null) {
            Constructor deserClassConstructor = getDeserClassConstructor();
            if (deserClassConstructor != null) {
                try {
                    return (Deserializer) 
                        deserClassConstructor.newInstance(
                            new Object[] {javaType, xmlType});
                } catch (InstantiationException e) {
                    if(log.isDebugEnabled()) {
                        log.debug(org.apache.axis.utils.Messages.getMessage("exception00"), e);
                    }
                } catch (IllegalAccessException e) {
                    if(log.isDebugEnabled()) {
                        log.debug(org.apache.axis.utils.Messages.getMessage("exception00"), e);
                    }
                } catch (InvocationTargetException e) {
                    if(log.isDebugEnabled()) {
                        log.debug(org.apache.axis.utils.Messages.getMessage("exception00"), e);
                    }
                }
            }
        }
        return null;
    
protected java.lang.reflect.MethodgetGetDeserializer()
Returns the getDeserializer.

return
Method

    	if (getDeserializer == null) {
            getDeserializer = getMethod(javaType,"getDeserializer");    
        }
    	return getDeserializer;
    
protected org.apache.axis.encoding.DeserializergetSpecialized(java.lang.String mechanismType)
Obtains a deserializer by invoking getDeserializer method in the javaType class or its Helper class.

        if (javaType != null && xmlType != null) {
            Method getDeserializer = getGetDeserializer();
            if (getDeserializer != null) {
                try {
                    return (Deserializer) 
                        getDeserializer.invoke(
                                             null,
                                             new Object[] {mechanismType, 
                                                           javaType, 
                                                           xmlType});
                } catch (IllegalAccessException e) {
                    if(log.isDebugEnabled()) {
                        log.debug(org.apache.axis.utils.Messages.getMessage("exception00"), e);
                    }
                } catch (InvocationTargetException e) {
                    if(log.isDebugEnabled()) {
                        log.debug(org.apache.axis.utils.Messages.getMessage("exception00"), e);
                    }
                }
            }
        }
        return null;
    
public java.util.IteratorgetSupportedMechanismTypes()
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

        if (mechanisms == null) {
            mechanisms = new Vector(1);
            mechanisms.add(Constants.AXIS_SAX);
        }
        return mechanisms.iterator();