Search in sources :

Example 1 with EPackage

use of org.eclipse.emf.ecore.EPackage in project tdi-studio-se by Talend.

the class ImportItemUtil method computeProperty.

private void computeProperty(ResourcesManager manager, ItemRecord itemRecord) {
    InputStream stream = null;
    try {
        stream = manager.getStream(itemRecord.getPath());
        final Resource resource = createResource(itemRecord, itemRecord.getPath(), false);
        URIConverter uriConverter = resource.getResourceSet().getURIConverter();
        resource.getResourceSet().setURIConverter(new ExtensibleURIConverterImpl() {

            /*
                 * (non-Javadoc)
                 * 
                 * @see org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl#createInputStream(org.eclipse.
                 * emf.common.util.URI, java.util.Map)
                 */
            @Override
            public InputStream createInputStream(URI uri, Map<?, ?> options) throws IOException {
                InputStream inputStream = null;
                EPackage ePackage = resource.getResourceSet().getPackageRegistry().getEPackage(uri.toString());
                if (ePackage != null || !"http".equals(uri.scheme())) {
                    inputStream = super.createInputStream(uri, options);
                } else {
                    inputStream = null;
                }
                return inputStream;
            }
        });
        EmfHelper.loadResource(resource, stream, null);
        resource.getResourceSet().setURIConverter(uriConverter);
        itemRecord.setProperty((Property) EcoreUtil.getObjectByType(resource.getContents(), PropertiesPackage.eINSTANCE.getProperty()));
    } catch (Exception e) {
    // ignore, must be one invalid or unknown item
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (IOException e) {
            // ignore
            }
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CwmResource(org.talend.model.emf.CwmResource) TalendXMIResource(org.talend.commons.runtime.model.emf.TalendXMIResource) ByteArrayResource(org.talend.core.model.properties.helper.ByteArrayResource) Resource(org.eclipse.emf.ecore.resource.Resource) ExtensibleURIConverterImpl(org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl) IOException(java.io.IOException) URIConverter(org.eclipse.emf.ecore.resource.URIConverter) URI(org.eclipse.emf.common.util.URI) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException) PersistenceException(org.talend.commons.exception.PersistenceException) EPackage(org.eclipse.emf.ecore.EPackage)

Example 2 with EPackage

use of org.eclipse.emf.ecore.EPackage in project benchmarx by eMoflon.

the class MediniQVTFamiliesToPersons method initiateSynchronisationDialogue.

/**
	 * Initiates a synchronization between a source and a target model. The medini QVT engine is initialized,
	 * the required metamodels are registered and empty source and target models are created.
	 * Finally a FamilyRegister is added to the source model and an initial forward transformation is issued
	 * to create a corresponding PersonRegister.
	 */
@Override
public void initiateSynchronisationDialogue() {
    // delete content of traces folder
    File tracesFolder = new File("./src/org/benchmarx/examples/familiestopersons/implementations/medini/base/traces");
    final File[] files = tracesFolder.listFiles();
    if (files != null) {
        for (File f : files) {
            if (f != null)
                f.delete();
        }
    }
    // Initialise resource set of models
    this.resourceSet = new ResourceSetImpl();
    this.resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
    // Collect all necessary packages from the metamodel(s)
    Collection<EPackage> metaPackages = new ArrayList<EPackage>();
    this.collectMetaModels(metaPackages);
    // Make these packages known to the QVT engine
    init(metaPackages);
    // Create resources for models
    source = resourceSet.createResource(URI.createURI("source.xmi"));
    target = resourceSet.createResource(URI.createURI("target.xmi"));
    // Collect the models, which should participate in the transformation.
    // You can provide a list of models for each direction.
    // The models must be added in the same order as defined in your transformation!
    Collection<Collection<Resource>> modelResources = new ArrayList<Collection<Resource>>();
    Collection<Resource> firstSetOfModels = new ArrayList<Resource>();
    Collection<Resource> secondSetOfModels = new ArrayList<Resource>();
    Collection<Resource> thirdSetOfModels = new ArrayList<Resource>();
    modelResources.add(firstSetOfModels);
    modelResources.add(secondSetOfModels);
    modelResources.add(thirdSetOfModels);
    firstSetOfModels.add(source);
    secondSetOfModels.add(target);
    URI directory = URI.createFileURI(basePath + "traces");
    this.preExecution(modelResources, directory);
    source.getContents().add(FamiliesFactory.eINSTANCE.createFamilyRegister());
    launchFWD();
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) ArrayList(java.util.ArrayList) Resource(org.eclipse.emf.ecore.resource.Resource) Collection(java.util.Collection) File(java.io.File) URI(org.eclipse.emf.common.util.URI) EPackage(org.eclipse.emf.ecore.EPackage)

Example 3 with EPackage

use of org.eclipse.emf.ecore.EPackage in project benchmarx by eMoflon.

the class MediniQVTFamiliesToPersonsConfig method initiateSynchronisationDialogue.

/**
	 * Initiates a synchronization between a source and a target model. The medini QVT engine is initialized,
	 * the required metamodels are registered and empty source, target and configuration models are created.
	 * Finally a FamilyRegister is added to the source model and an initial forward transformation is issued
	 * to create a corresponding PersonRegister.
	 */
@Override
public void initiateSynchronisationDialogue() {
    // delete content of traces folder
    File tracesFolder = new File("./src/org/benchmarx/examples/familiestopersons/implementations/medini/base/traces");
    final File[] files = tracesFolder.listFiles();
    if (files != null) {
        for (File f : files) {
            if (f != null)
                f.delete();
        }
    }
    // in case, no configuration is set, switch to default
    checkConfiguration();
    // Initialise resource set of models
    this.resourceSet = new ResourceSetImpl();
    this.resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
    // Collect all necessary packages from the metamodel(s)
    Collection<EPackage> metaPackages = new ArrayList<EPackage>();
    this.collectMetaModels(metaPackages);
    // Make these packages known to the QVT engine
    init(metaPackages);
    // Create resources for models
    source = resourceSet.createResource(URI.createURI(RESULTPATH + "/source.xmi"));
    config = resourceSet.createResource(URI.createURI(RESULTPATH + "/config.xmi"));
    target = resourceSet.createResource(URI.createURI(RESULTPATH + "/target.xmi"));
    // Collect the models, which should participate in the transformation.
    // You can provide a list of models for each direction.
    // The models must be added in the same order as defined in your transformation!
    Collection<Collection<Resource>> modelResources = new ArrayList<Collection<Resource>>();
    Collection<Resource> firstSetOfModels = new ArrayList<Resource>();
    Collection<Resource> secondSetOfModels = new ArrayList<Resource>();
    Collection<Resource> thirdSetOfModels = new ArrayList<Resource>();
    modelResources.add(firstSetOfModels);
    modelResources.add(secondSetOfModels);
    modelResources.add(thirdSetOfModels);
    firstSetOfModels.add(source);
    secondSetOfModels.add(config);
    thirdSetOfModels.add(target);
    URI directory = URI.createFileURI(basePath + "traces");
    this.preExecution(modelResources, directory);
    // Call setConfigurator, which will initialize the configurator with default decisions
    setConfigurator(new Configurator<Decisions>());
    source.getContents().add(FamiliesFactory.eINSTANCE.createFamilyRegister());
    config.getContents().add(ConfigFactory.eINSTANCE.createConfiguration());
    launchFWD();
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) ArrayList(java.util.ArrayList) Resource(org.eclipse.emf.ecore.resource.Resource) Decisions(org.benchmarx.examples.familiestopersons.testsuite.Decisions) URI(org.eclipse.emf.common.util.URI) EPackage(org.eclipse.emf.ecore.EPackage) Collection(java.util.Collection) File(java.io.File)

Example 4 with EPackage

use of org.eclipse.emf.ecore.EPackage in project benchmarx by eMoflon.

the class ChangeRecorder method WriteFullElement.

private void WriteFullElement(EObject element, String type) {
    buffer.append("\t\t<");
    buffer.append(type);
    buffer.append(" xsi:type=\"");
    EClass eClass = element.eClass();
    EPackage ePackage = (EPackage) eClass.eContainer();
    buffer.append(ePackage.getNsPrefix());
    buffer.append(":");
    buffer.append(eClass.getName());
    buffer.append("\" xmlns:");
    buffer.append(ePackage.getNsPrefix());
    buffer.append("=\"");
    buffer.append(ePackage.getNsURI());
    buffer.append("\"");
    for (EAttribute att : eClass.getEAllAttributes()) {
        if (element.eIsSet(att)) {
            Object value = element.eGet(att);
            WriteAttribute(att.getName(), toCompatibleString(value));
        }
    }
    buffer.append(" />\n");
    this.RegisterNewElement(element, this.changeCounter, type);
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EAttribute(org.eclipse.emf.ecore.EAttribute) EObject(org.eclipse.emf.ecore.EObject) EPackage(org.eclipse.emf.ecore.EPackage)

Example 5 with EPackage

use of org.eclipse.emf.ecore.EPackage in project xtext-core by eclipse.

the class FragmentFakingEcoreResource method calculateURIFragment.

private void calculateURIFragment(final EPackage ePackage, final StringBuilder result, final Set<EPackage> visited) {
    boolean _add = visited.add(ePackage);
    boolean _not = (!_add);
    if (_not) {
        throw new IllegalStateException();
    }
    EPackage _eSuperPackage = ePackage.getESuperPackage();
    boolean _tripleNotEquals = (_eSuperPackage != null);
    if (_tripleNotEquals) {
        Resource _eResource = ePackage.eResource();
        Resource _eResource_1 = ePackage.getESuperPackage().eResource();
        boolean _tripleEquals = (_eResource == _eResource_1);
        if (_tripleEquals) {
            this.calculateURIFragment(ePackage.getESuperPackage(), result, visited);
            boolean _isEmpty = ePackage.getEClassifiers().isEmpty();
            boolean _not_1 = (!_isEmpty);
            if (_not_1) {
                int _length = result.length();
                boolean _tripleNotEquals_1 = (_length != 0);
                if (_tripleNotEquals_1) {
                    result.append(ePackage.getName()).append("/");
                } else {
                    result.append("//");
                }
            }
        } else {
            result.append("//");
        }
    } else {
        result.append("//");
    }
}
Also used : XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) Resource(org.eclipse.emf.ecore.resource.Resource) EPackage(org.eclipse.emf.ecore.EPackage)

Aggregations

EPackage (org.eclipse.emf.ecore.EPackage)424 ParserRule (org.eclipse.xtext.ParserRule)201 Action (org.eclipse.xtext.Action)196 Parameter (org.eclipse.xtext.Parameter)196 Test (org.junit.Test)101 EClass (org.eclipse.emf.ecore.EClass)85 Resource (org.eclipse.emf.ecore.resource.Resource)50 EObject (org.eclipse.emf.ecore.EObject)39 EClassifier (org.eclipse.emf.ecore.EClassifier)32 URI (org.eclipse.emf.common.util.URI)30 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)23 Grammar (org.eclipse.xtext.Grammar)22 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)16 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)15 GenPackage (org.eclipse.emf.codegen.ecore.genmodel.GenPackage)14 AbstractMetamodelDeclaration (org.eclipse.xtext.AbstractMetamodelDeclaration)14 XtextResource (org.eclipse.xtext.resource.XtextResource)14 EEnum (org.eclipse.emf.ecore.EEnum)13 EReference (org.eclipse.emf.ecore.EReference)12 IOException (java.io.IOException)11