/** * License (BSD Style License): * Copyright (c) 2011 * Software Engineering * Department of Computer Science * Technische Universität Darmstadt * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * - Neither the name of the Software Engineering Group or Technische * Universität Darmstadt nor the names of its contributors may be used to * endorse or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ package de.tud.cs.st.vespucci.vespucci_model.tests; import de.tud.cs.st.vespucci.vespucci_model.ShapesDiagram; import de.tud.cs.st.vespucci.vespucci_model.Vespucci_modelFactory; import de.tud.cs.st.vespucci.vespucci_model.Vespucci_modelPackage; import java.io.File; import java.io.IOException; import org.eclipse.emf.common.util.Diagnostic; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; import org.eclipse.emf.ecore.util.Diagnostician; import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; /** * <!-- begin-user-doc --> * A sample utility for the '<em><b>vespucci_model</b></em>' package. * <!-- end-user-doc --> * @generated */ public class Vespucci_modelExample { /** * <!-- begin-user-doc --> * Load all the argument file paths or URIs as instances of the model. * <!-- end-user-doc --> * @param args the file paths or URIs. * @generated */ public static void main(String[] args) { // Create a resource set to hold the resources. // ResourceSet resourceSet = new ResourceSetImpl(); // Register the appropriate resource factory to handle all file extensions. // resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put (Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl()); // Register the package to ensure it is available during loading. // resourceSet.getPackageRegistry().put (Vespucci_modelPackage.eNS_URI, Vespucci_modelPackage.eINSTANCE); // If there are no arguments, emit an appropriate usage message. // if (args.length == 0) { System.out.println("Enter a list of file paths or URIs that have content like this:"); try { Resource resource = resourceSet.createResource(URI.createURI("http:///My.sam")); ShapesDiagram root = Vespucci_modelFactory.eINSTANCE.createShapesDiagram(); resource.getContents().add(root); resource.save(System.out, null); } catch (IOException exception) { exception.printStackTrace(); } } else { // Iterate over all the arguments. // for (int i = 0; i < args.length; ++i) { // Construct the URI for the instance file. // The argument is treated as a file path only if it denotes an existing file. // Otherwise, it's directly treated as a URL. // File file = new File(args[i]); URI uri = file.isFile() ? URI.createFileURI(file.getAbsolutePath()): URI.createURI(args[i]); try { // Demand load resource for this file. // Resource resource = resourceSet.getResource(uri, true); System.out.println("Loaded " + uri); // Validate the contents of the loaded resource. // for (EObject eObject : resource.getContents()) { Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eObject); if (diagnostic.getSeverity() != Diagnostic.OK) { printDiagnostic(diagnostic, ""); } } } catch (RuntimeException exception) { System.out.println("Problem loading " + uri); exception.printStackTrace(); } } } } /** * <!-- begin-user-doc --> * Prints diagnostics with indentation. * <!-- end-user-doc --> * @param diagnostic the diagnostic to print. * @param indent the indentation for printing. * @generated */ protected static void printDiagnostic(Diagnostic diagnostic, String indent) { System.out.print(indent); System.out.println(diagnostic.getMessage()); for (Diagnostic child : diagnostic.getChildren()) { printDiagnostic(child, indent + " "); } } } //Vespucci_modelExample