ProvideX Data/XML Conversion

Class Documentation

The documentation for the XML_Convert class is included here as a reference. The complete documentation for all of the classes can be found in the API Reference.

The source for this sample class is included with the plug-in and is shipped as a text file that can be loaded into any file viewer. This class does not include any code and it is intended to be used as a template for creating new observers.

Overview of the Class Definition

Double Duty Class

Before discussing the structure of this class, it is important to state that this class definition actually performs two distinct functions. It will register itself as an enhancement to an existing event (Data file build). It will also register itself as a contributed tool. This section will discuss the portion of the class that deals with enhancing an existing event.

Class Description

The getDescription$() method must be modified to set a description for the new class.

Event Notification

The getEventNotification() method may need to be changed to return the setting of the event notification flag. The setting of this flag will determine when this observer is notified that an event has been triggered. It will also add a preference to the Contributed Extensions / Tools preference page to allow the user to enable use of the extension.

Do the Work

The update() method must be modified to add the logic that will be executed when the event has been triggered.

update:
enter aPvxState 

	/*
	 * This observer is triggered when an incremental build is initiated on a
	 * data file.
	 *
	 * If the source file ends with the XML extension, it will be converted to
	 * a PVX keyed file.  Otherwise, the file header is read to verify that this
	 * is in fact a PVX keyed file and then it is converted to XML.
	 */
 
	/* Get the major/minor codes for this event. */
	psMajor$=aPvxState'getMajor$(), \
	psMinor$=aPvxState'getMinor$()

	/* Get the parameters that were passed into this event. */
	source$=aPvxState'getArgumentValue$(_pvxConstants'SrcFile$), \
	dest$=aPvxState'getArgumentValue$(_pvxConstants'Dest$), \
	domFile$=aPvxState'getArgumentValue$(_pvxConstants'DomFile$), \
	passwd$=aPvxState'getArgumentValue$(_pvxConstants'pkf_Password$), \
	passwd_type$=aPvxState'getArgumentValue$(_pvxConstants'_iPasswordType$)
	
	/* Create a local reference to the EventLog */
	_eventLog=new("ErrorLogBuilder",_pvxConstants,ViewManager)
	_eventLog'bufferInit()
	_eventLog'bufferAddText("["+psMajor$+"]"+$0A$+"==>"+psMinor$+"<=="+$0A$)

 	switch psMajor$
	case _pvxConstants'Incremental_Build$
		switch psMinor$

		/* Convert a ProvideX data file to XML */
		case _pvxConstants'BuildType_DataFile$
			_obj'data2xml(source$)
			break
		/* Convert a XML to ProvideX data file */
		case _pvxConstants'BuildType_OtherFile$
			_obj'xml2data(source$,dest$)
			break
		end switch
		break
 	end switch

	_eventLog'bufferWriteText()
	drop object _eventLog

return 0

Add logic for the specific events that this observer is monitoring. In this case, the observer is watching for events with a major ID of Incremental Build. Within this event classification, it is watching for two minor events

BuildType_DataFile
This observer will check the file to verify that it is a ProvideX keyed file and will then convert it to XML.
BuildType_OtherFile
This observer will verify that the file has an .xml extension and will then attempt to convert (or create) a ProvideX data file. The conversion logic requires that the XML file be defined for the schema 'providex'.

The source file can be viewed to see the details of this process and how the external programs were used.

Event Arguments

The arguments that are passed into an event are generally the same for all events that share the same major ID. A summary of these arguments is listed in the next section of this document.