Comment puis-je itérer mon modèle fem d'un éditeur de FMV sans l'analyse du fichier modèle XML?

StackOverflow https://stackoverflow.com/questions/4398541

Question

Je l'ai créé avec succès un éditeur FMV qui dessine des modèles basés sur ma EMF model.What je voulais faire est de itérer par eclasses .Peut de mon modèle cela soit réalisé lors de l'exécution par mon code de plug-in sans avoir à lire le fichier xml l'éditeur de FMV crée-t-il une telle API EMF?

Était-ce utile?

La solution

Lorsque vous générez le code de test à partir du fichier genmodel puis à l'intérieur du XYZ.test plug-in il y a ce type de code que j'étais searching.It à travers le traverse fichier XMI de votre modèle

// 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
        (XYZmetamodelPackage.eNS_URI, 
         XYZmetamodelPackage.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.metamodel"));
            ModelObject root = atagmetamodelFactory.eINSTANCE.createModelObject();
            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();
            }
        }
    }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top