001/* 002 * Copyright c 2018 Rusi Popov, MDA Tools.net All rights reserved. 003 * 004 * This program and the accompanying materials are made available under the terms of the 005 * Eclipse Public License v2.0 which accompanies this distribution, and is available at 006 * http://www.eclipse.org/legal/epl-v20.html 007 */ 008package net.mdatools.modelant.uml13.maven.plugin.reverse; 009 010import java.io.File; 011 012import javax.jmi.reflect.RefPackage; 013 014import org.apache.maven.plugin.AbstractMojo; 015import org.apache.maven.plugin.MojoFailureException; 016import org.apache.maven.plugins.annotations.Execute; 017import org.apache.maven.plugins.annotations.LifecyclePhase; 018import org.apache.maven.plugins.annotations.Mojo; 019import org.apache.maven.plugins.annotations.Parameter; 020 021import net.mdatools.modelant.core.api.Function; 022import net.mdatools.modelant.repository.api.ModelRepository; 023import net.mdatools.modelant.repository.api.ModelRepositoryFactory; 024import net.mdatools.modelant.uml13.reverse.ReverseXsdOperation; 025 026/** 027 * Reverse engineer a XML schema and storing the results as UML 028 * 1.3 objects. The model produced is in fact a Platform Specific Model, which might need additional 029 * processing and tuning. 030 * <p> 031 * Conventions for the model produced: <ul> 032 * <li> The model elements (classes, association names) that represent elements in the output XML 033 * are marked with <<element>> stereotype 034 * <li> For representation purposes local types (UML classes) could be introduced for XSD groups, unions, 035 * local / inlined types. All of them are marked with <<local type>> stereotype 036 * <li>The column types are converted to DataType instances named: <type 037 * name>[_<column size>[_<column precision>]]. Additionally as tagged values named 038 * TAG_VALUE_DATA_TYPE_SIZE and TAG_VALUE_DATA_TYPE_PRECISION these values are bound to the concrete 039 * data type. 040 * <li>The TAG_VALUE_DATA_TYPE_PRECISION tagged value is optional. When not provided, the precision 041 * should be treated as 0 042 * <li>Any comments found while reverse engineering the XSD are bound as 'documentation' tagged 043 * values. These tagged values are compatible with the Rose's approach to documentation. They are 044 * optional. 045 * </ul> 046 * @author Rusi Popov (popovr@mdatools.net) 047 */ 048@Mojo(name="xsd-to-uml13", 049 defaultPhase=LifecyclePhase.COMPILE 050) 051@Execute(phase=LifecyclePhase.COMPILE) 052public class ReverseEngineerXsdMojo extends AbstractMojo { 053 054 /** 055 * The schema file to reverse engineer 056 */ 057 @Parameter(required=true) 058 private File schemaFile; 059 060 /** 061 * The name of the file where to export the produced UML 1.3 model in XMI 1.2 format 062 */ 063 @Parameter(required=true) 064 private File outputFile; 065 066 /** 067 * The directory where to store the repository files 068 */ 069 @Parameter(property="project.build.directory", required=true) 070 private File workDir; 071 072 /** 073 * Performs the reverse engineering of the database by describing the database schema into the 074 * repository provided. 075 */ 076 public void execute() throws MojoFailureException { 077 ModelRepository modelRepository; 078 RefPackage extent; 079 Function<File, RefPackage> reverse; 080 081 try { 082 modelRepository = ModelRepositoryFactory.construct(workDir); 083 try { 084 reverse = new ReverseXsdOperation( modelRepository ); 085 extent = reverse.execute( schemaFile ); 086 087 getLog().info( "Writing "+outputFile); 088 modelRepository.writeExtent( extent, 089 outputFile, 090 ModelRepository.DEFAULT_XMI_VERSION ); 091 } finally { 092 modelRepository.shutdown(); 093 } 094 } catch (Exception ex) { 095 throw new MojoFailureException("No model exported", ex); 096 } 097 } 098}