JAXB Data Import & Export
JAXB for Import & Export
To reduce duplication of configuration and increase usability of the uPortal data file formats XML Schemas and JAXB are being used for importing and exporting portal data. This ability is meant to slowly replace the existing Cernunnos scripts used for importing and exporting data. The portal framework for this process includes the following parts:
- One XSD for each portal data type that describes the external XML form of the data. (ex: stylesheet-descriptor-4.0.xsd)
- Use of an XJC maven plugin to auto-generate the corresponding JAXB annotated Java classes for each portal data XSD.
- A generic import/export service that handles marshalling and unmarshalling of the portal data XML and location of the correct portal data import/export implementation to handle the data.
- A service interface that is implemented once for each portal data type that handles converting the data between its internal and external forms and interfacing with the appropriate portal DAOs.
Important Interfaces
JaxbDataImportExportService
implementsIDataImportExportService
- List all available data types that can be exported
- List all available data for each type
- Import from an XML Source
- Upgrade then import from an XML Source
- Export to an XML Result
IDataImporterExporter
- Maps between XJC generated classes and the portal data type
- Provides a list of data available to export to the
IDataImportExportService
- Provides JAXB marshaller and unmarshaller objects to use for converting the data to and from XML
IDataUpgrader
- Transforms an XML Source into a Result, updating the data format in the process
The Import Process
JaxbDataImportExportService.importData(source)
is called with an XML file- A key is generated based on the root element name along with the script and version attribute values.
- If a
IDataImporterExporter
that handles the data key is found- Get the unmarshaller and conver the XML to an object graph
- Pass the object graph to the {{IDataImporterExporter} to import
- If no importer but a
IDataUpgrader
that handles the data key is found- Transform the Source XML into a Result and then recurse on the result data
- If no handler is found throw an exception
The Export Process
JaxbDataImportExportService.exportData(String typeId, String dataId)
- The typeId is used to lookup a
IDataImporterExporter
implementation
- The typeId is used to lookup a
IDataImporterExporter.exportData(dataId)
is called byJaxbDataImportExportService
- Retrieve the data from the portal DAO using the id
- Map all of the data from the internal data object to the external data object and return it
JaxbDataImportExportService
marshalls the external data object to XML and returns the result.
Setting up a New Portal Data Type
- Create a new XSD that describes the external data format. This format MUST NOT reference any generated ID and be human editable.
- List the XSD directory in the xjc plugin
uportal-war/pom.xml
maven-jaxb2-plugin - List the XSD in
uportal-war/src/main/binding/bindings.xjb
and define a package name underorg.jasig.portal.io.xml
for the generated classes - Create an extension of
AbstractJaxbIDataImporterExporter
that does the following- Describes the data via the
IPortalDataType
interface - List all available data in the portal via the
IPortalData
interface - Can map the XJC generated classes to and from the internal portal object model for the data
- Describes the data via the