Search in sources :

Example 1 with Resource

use of org.eclipse.emf.ecore.resource.Resource in project coffeescript-eclipse by adamschmideg.

the class Main method runGenerator.

protected void runGenerator(String string) {
    // load the resource
    ResourceSet set = resourceSetProvider.get();
    Resource resource = set.getResource(URI.createURI(string), true);
    // validate the resource
    List<Issue> list = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
    if (!list.isEmpty()) {
        for (Issue issue : list) {
            System.err.println(issue);
        }
        return;
    }
    // configure and start the generator
    fileAccess.setOutputPath("src-gen/");
    generator.doGenerate(resource, fileAccess);
    System.out.println("Code generation finished.");
}
Also used : Issue(org.eclipse.xtext.validation.Issue) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet)

Example 2 with Resource

use of org.eclipse.emf.ecore.resource.Resource in project mechanoid by robotoworks.

the class NewMechanoidOpsFileWizard method createElementResource.

@Override
protected IResource createElementResource(IProgressMonitor monitor, IPath path) {
    try {
        if (monitor == null) {
            monitor = new NullProgressMonitor();
        }
        monitor.beginTask(Messages.NewMechanoidOpsFileWizard_Progress_Message, 1);
        URI newEmfResourceURI = URI.createURI(//$NON-NLS-1$
        "platform:/resource" + path.toPortableString());
        Resource emfResource = mResourceSet.createResource(newEmfResourceURI);
        Model model = OpServiceModelFactory.eINSTANCE.createModel();
        model.setPackageName(mSelectedPackageName);
        emfResource.getContents().add(model);
        ServiceBlock service = (ServiceBlock) OpServiceModelFactory.eINSTANCE.createServiceBlock();
        service.setName(mSelectedElementName);
        model.setService(service);
        emfResource.save(Collections.EMPTY_MAP);
        IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(newEmfResourceURI.toPlatformString(true));
        monitor.worked(1);
        return resource;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) Model(com.robotoworks.mechanoid.ops.opServiceModel.Model) URI(org.eclipse.emf.common.util.URI) ServiceBlock(com.robotoworks.mechanoid.ops.opServiceModel.ServiceBlock) IResource(org.eclipse.core.resources.IResource)

Example 3 with Resource

use of org.eclipse.emf.ecore.resource.Resource in project mechanoid by robotoworks.

the class NewMechanoidNetFileWizard method createElementResource.

@Override
protected IResource createElementResource(IProgressMonitor monitor, IPath path) {
    try {
        if (monitor == null) {
            monitor = new NullProgressMonitor();
        }
        monitor.beginTask(Messages.NewMechanoidNetFileWizard_Progress_Message, 1);
        URI newEmfResourceURI = URI.createURI(//$NON-NLS-1$
        "platform:/resource" + path.toPortableString());
        Resource emfResource = mResourceSet.createResource(newEmfResourceURI);
        Model model = NetModelFactory.eINSTANCE.createModel();
        model.setPackageName(mSelectedPackageName);
        emfResource.getContents().add(model);
        Client client = (Client) NetModelFactory.eINSTANCE.createClient();
        client.setName(mSelectedElementName);
        if (!Strings.isNullOrEmpty(mSelectedBaseUrl)) {
            client.setBaseUrl(mSelectedBaseUrl);
        }
        model.getDeclarations().add(client);
        emfResource.save(Collections.EMPTY_MAP);
        IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(newEmfResourceURI.toPlatformString(true));
        monitor.worked(1);
        return resource;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) Model(com.robotoworks.mechanoid.net.netModel.Model) Client(com.robotoworks.mechanoid.net.netModel.Client) URI(org.eclipse.emf.common.util.URI) IResource(org.eclipse.core.resources.IResource)

Example 4 with Resource

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

the class ComponentsFactory method loadComponentResource.

/**
     * DOC guanglong.du Comment method "loadComponentResource".
     * 
     * @param eclipseProject
     * @return
     * @throws IOException
     */
private ComponentsCache loadComponentResource(String installLocation) throws IOException {
    String filePath = ComponentsFactory.TALEND_COMPONENT_CACHE + LanguageManager.getCurrentLanguage().toString().toLowerCase() + ComponentsFactory.TALEND_FILE_NAME;
    URI uri = URI.createFileURI(installLocation).appendSegment(filePath);
    ComponentCacheResourceFactoryImpl compFact = new ComponentCacheResourceFactoryImpl();
    Resource resource = compFact.createResource(uri);
    Map optionMap = new HashMap();
    optionMap.put(XMLResource.OPTION_DEFER_ATTACHMENT, Boolean.TRUE);
    optionMap.put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION, Boolean.TRUE);
    optionMap.put(XMLResource.OPTION_USE_PARSER_POOL, new XMLParserPoolImpl());
    optionMap.put(XMLResource.OPTION_USE_XML_NAME_TO_FEATURE_MAP, new HashMap());
    optionMap.put(XMLResource.OPTION_USE_DEPRECATED_METHODS, Boolean.FALSE);
    resource.load(optionMap);
    ComponentsCache cache = (ComponentsCache) EcoreUtil.getObjectByType(resource.getContents(), ComponentCachePackage.eINSTANCE.getComponentsCache());
    return cache;
}
Also used : HashMap(java.util.HashMap) XMLParserPoolImpl(org.eclipse.emf.ecore.xmi.impl.XMLParserPoolImpl) Resource(org.eclipse.emf.ecore.resource.Resource) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) ComponentsCache(org.talend.core.model.component_cache.ComponentsCache) URI(org.eclipse.emf.common.util.URI) Map(java.util.Map) HashMap(java.util.HashMap) ComponentCacheResourceFactoryImpl(org.talend.core.model.component_cache.util.ComponentCacheResourceFactoryImpl)

Example 5 with Resource

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

the class DiagramResourceManager method createResource.

private Resource createResource(IFile file) {
    ResourceSet resourceSet = new ResourceSetImpl();
    Resource resource = resourceSet.getResource(URI.createPlatformResourceURI(file.getFullPath().toString()), true);
    return resource;
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet)

Aggregations

Resource (org.eclipse.emf.ecore.resource.Resource)58 URI (org.eclipse.emf.common.util.URI)23 IOException (java.io.IOException)18 IResource (org.eclipse.core.resources.IResource)11 EObject (org.eclipse.emf.ecore.EObject)10 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)10 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)9 PersistenceException (org.talend.commons.exception.PersistenceException)8 XmiResourceManager (org.talend.core.repository.utils.XmiResourceManager)8 ArrayList (java.util.ArrayList)7 CoreException (org.eclipse.core.runtime.CoreException)7 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)7 XMIResourceFactoryImpl (org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl)7 List (java.util.List)6 IProject (org.eclipse.core.resources.IProject)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 IFile (org.eclipse.core.resources.IFile)5 TalendXMIResource (org.talend.commons.runtime.model.emf.TalendXMIResource)5 ByteArrayResource (org.talend.core.model.properties.helper.ByteArrayResource)5 CwmResource (org.talend.model.emf.CwmResource)5