[Previous slide] [Next slide] Moving to XML

Let's see that again [ii]: the event element generator

The event element is a simple wrapper round a context element generator:

    //~ Inner Classes ---------------------------------------------------------

    /**
     * a generator for an XML element representing a single event. This uses
     * ContextElementGenerator which knows how to construct a DOM element
     * node by taking values out of a context, so all we need to do is tell
     * it which value names to treat as attributes and which as children
     */
    class EventElementGenerator extends ContextElementGenerator
    {
        //~ Constructors ------------------------------------------------------

        /**
         * the tag of the element I generate is 'event'
         */
        public EventElementGenerator(  )
        {
            super( "event" );
        }

        //~ Methods -----------------------------------------------------------

        /**
         * return a String array of the names of my properties to output as
         * attributes
         */
        protected String[] getAttrNames(  )
        {
            String[] attrNames =
            { "event", "type", "location", "starttime", "endtime", "actor" };

            return attrNames;
        }

        /**
         * return a String array of the names of my properties to output as
         * children
         */
        protected String[] getChildNames(  )
        {
            String[] childNames = { "description" };

            return childNames;
        }
    }
}