You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Tony Thompson <to...@stone-ware.com> on 2003/05/21 20:40:53 UTC

Opinions Needed

After much struggling, I was able to hack together something that seems
to function as a deserializer.  The way I did it seems a little
complicated so, I was hoping someone might be able to offer a better
(cleaner) solution.  At the very least, I am looking for ways to improve
the deserializer because I have several more that I will need to write.

Thanks for any help.
Tony


public class ComponentDefinitionDeserializer extends DeserializerImpl
{
    private static final String     F_NAME          = "name";
    private static final String     F_CONTEXT       = "context";
    private static final String     F_DATA          = "data";
    private static final String     F_TYPE          = "type";
    private static final String     F_HEIGHT        = "height";
    private static final String     F_ISWINDOWED    = "isWindowed";
    private static final String     F_SHOWBORDER    = "showBorder";
    private static final String     F_SHOWHELPLINK  = "showHelpLink";
    private static final String     F_SHOWMINIMIZEMAXIMIZE        =
"showMinimizeMaximize";
    private static final String     F_SHOWQUICKLINK        =
"showQuickLink";
    private static final String     F_TITLE         = "title";
    private static final String     F_TITLEBACKGROUNDCOLOR        =
"titleBackgroundColor";
    private static final String     F_TITLEBACKGROUNDIMAGE        =
"titleBackgroundImage";
    private static final String     F_TITLEFOREGROUNDCOLOR        =
"titleForegroundColor";
    private static final String     F_USESCROLLBARS        =
"useScrollbars";
    private static final String     F_WIDTH        = "width";

    private static final Hashtable  m_typeMap       = new Hashtable( 5
);

    static {
        m_typeMap.put( F_NAME, Constants.XSD_STRING );
        m_typeMap.put( F_CONTEXT, Constants.XSD_STRING );
        m_typeMap.put( F_DATA, Constants.XSD_STRING );
        m_typeMap.put( F_TYPE, Constants.XSD_INT );
        m_typeMap.put( F_HEIGHT, Constants.XSD_INT );
        m_typeMap.put( F_ISWINDOWED, Constants.XSD_BOOLEAN );
        m_typeMap.put( F_SHOWBORDER, Constants.XSD_BOOLEAN );
        m_typeMap.put( F_SHOWHELPLINK, Constants.XSD_BOOLEAN );
        m_typeMap.put( F_SHOWMINIMIZEMAXIMIZE, Constants.XSD_BOOLEAN
);
        m_typeMap.put( F_SHOWQUICKLINK, Constants.XSD_BOOLEAN );
        m_typeMap.put( F_TITLE, Constants.XSD_STRING );
        m_typeMap.put( F_TITLEBACKGROUNDCOLOR, Constants.XSD_STRING );
        m_typeMap.put( F_TITLEBACKGROUNDIMAGE, Constants.XSD_STRING );
        m_typeMap.put( F_TITLEFOREGROUNDCOLOR, Constants.XSD_STRING );
        m_typeMap.put( F_USESCROLLBARS, Constants.XSD_BOOLEAN );
        m_typeMap.put( F_WIDTH, Constants.XSD_INT );
    }

   
/***************************************************************************/
    /**
     * Creates a new instance of ComponentDefinitionDeserializer.
     */
    public ComponentDefinitionDeserializer() {
    }

    public SOAPHandler onStartChild( String namespace, String
localName, String prefix,
            Attributes attributes, DeserializationContext context )
throws SAXException {

        System.out.println( "deser local name: "+localName );
        if( attributes != null ) {
          for( int i=0; i<attributes.getLength(); i++ ) {
              System.out.println( "   name: "+attributes.getLocalName(
i ) );
              System.out.println( "   value: "+attributes.getValue( i )
);
          }
        }

        QName typeQName = (QName)m_typeMap.get( localName );
        if( typeQName == null ) {
            System.out.println( "don't know: "+localName );
            throw new SAXException( "Invalid element in
ComponentDefinition - " + localName );
        }

        Deserializer dserializer = context.getDeserializerForType(
typeQName );
        System.out.println( "dserializer value:
"+dserializer.getValue() );
        dserializer.registerValueTarget( new CallbackTarget( this,
localName ) );

        return (SOAPHandler)dserializer;
    }

    private String m_name;
    private String m_context;
    private String m_data;
    private int    m_type;

    public void setValue( Object value, Object hint ) throws
SAXException {
        System.out.println( "field: "+hint );
        System.out.println( "value: "+value );

        if( "name".equals( hint ) ) {
            m_name = (String)value;
        }
        else if( "context".equals( hint ) ) {
            m_context = (String)value;
        }
        else if( "data".equals( hint ) ) {
            m_data = (String)value;
        }
        else if( "type".equals( hint ) ) {
            m_type = ((Integer)value).intValue();
        }
    }

    public void valueComplete() throws SAXException {
        System.out.println( "********** Setting the value." );
        value = new com.stoneware.beans.ComponentDefinition( m_name,
m_context, m_data, m_type );
        super.valueComplete();
    }
}