FileDocCategorySizeDatePackage
BaseSerializerFactory.javaAPI DocApache Axis 1.411593Sat Apr 22 18:57:28 BST 2006org.apache.axis.encoding.ser

BaseSerializerFactory

public abstract class BaseSerializerFactory extends BaseFactory implements org.apache.axis.encoding.SerializerFactory
Base class for Axis Serialization Factory classes for code reuse
author
Rich Scheuerle

Fields Summary
protected static Log
log
static transient Vector
mechanisms
protected Class
serClass
protected QName
xmlType
protected Class
javaType
protected transient org.apache.axis.encoding.Serializer
ser
protected transient Constructor
serClassConstructor
protected transient Method
getSerializer
private static final Class[]
CLASS_QNAME_CLASS
Constructors Summary
public BaseSerializerFactory(Class serClass)
Constructor

param
serClass is the class of the Serializer Sharing is only valid for xml primitives.


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

        this(serClass);
        this.xmlType = xmlType;
        this.javaType = javaType;
    
Methods Summary
public static org.apache.axis.encoding.SerializerFactorycreateFactory(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
xmlType
param
javaType

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

        try {
            if (factory == BeanSerializerFactory.class) {
                return new BeanSerializerFactory(javaType, xmlType);
            } else if (factory == SimpleSerializerFactory.class) {
                return new SimpleSerializerFactory(javaType, xmlType);
            } else if (factory == EnumSerializerFactory.class) {
                return new EnumSerializerFactory(javaType, xmlType);
            } else if (factory == ElementSerializerFactory.class) {
                return new ElementSerializerFactory();
            } else if (factory == SimpleListSerializerFactory.class) {
                return new SimpleListSerializerFactory(javaType, xmlType);
            }
        } catch (Exception e) {
            if (log.isDebugEnabled()) {
                log.debug(org.apache.axis.utils.Messages.getMessage("exception00"), e);
            }
            return null;
        }

        SerializerFactory sf = null;
        try {
            Method method = 
                factory.getMethod("create", CLASS_QNAME_CLASS);
            sf = (SerializerFactory) 
                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 (sf == null) {
            try {
                Constructor constructor =  
                    factory.getConstructor(CLASS_QNAME_CLASS);
                sf = (SerializerFactory) 
                    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 (sf == null) {
            try {
                sf = (SerializerFactory) factory.newInstance();
            } catch (InstantiationException e) {
            } catch (IllegalAccessException e) {}
        }
        return sf;
    
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 org.apache.axis.encoding.SerializergetGeneralPurpose(java.lang.String mechanismType)
Obtains a serializer by invoking (javaType, xmlType) on the serClass.

        if (javaType != null && xmlType != null) {
            Constructor serClassConstructor = getSerClassConstructor();
            if (serClassConstructor != null) {
                try {
                    return (Serializer) 
                        serClassConstructor.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.MethodgetGetSerializer()
Returns the getSerializer.

return
Method

    	if (getSerializer == null) {
            getSerializer = getMethod(javaType, "getSerializer");
        }
    	return getSerializer;
    
public java.lang.ClassgetJavaType()
get javaType

return
javaType Class for this factory

        return javaType;
    
protected java.lang.reflect.ConstructorgetSerClassConstructor()
Returns the serClassConstructor.

return
Constructor

    	if (serClassConstructor == null) {
            serClassConstructor = getConstructor(serClass);
        }
    	return serClassConstructor;
    
public javax.xml.rpc.encoding.SerializergetSerializerAs(java.lang.String mechanismType)

        synchronized (this) {
            if (ser==null) {
                ser = getSerializerAsInternal(mechanismType);
            }
            return ser;
        }
    
protected org.apache.axis.encoding.SerializergetSerializerAsInternal(java.lang.String mechanismType)

        // Try getting a specialized Serializer
        Serializer serializer = getSpecialized(mechanismType);
        
        // Try getting a general purpose Serializer via constructor
        // invocation
        if (serializer == null) {
            serializer = getGeneralPurpose(mechanismType);
        }

        try {            
            // If not successfull, try newInstance
            if (serializer == null) {
                serializer = (Serializer) serClass.newInstance();
            }
        } catch (Exception e) {
            throw new JAXRPCException(
                Messages.getMessage("CantGetSerializer", 
                                    serClass.getName()),
                e);
        }
        return serializer;
    
protected org.apache.axis.encoding.SerializergetSpecialized(java.lang.String mechanismType)
Obtains a serializer by invoking getSerializer method in the javaType class or its Helper class.

        if (javaType != null && xmlType != null) {
            Method getSerializer = getGetSerializer();
            if (getSerializer != null) {
                try {
                    return (Serializer) 
                        getSerializer.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 SerializerFactory.

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();
    
public javax.xml.namespace.QNamegetXMLType()
get xmlType

return
xmlType QName for this factory

        return xmlType;