Package org.eclipse.emf.ecore.resource

Examples of org.eclipse.emf.ecore.resource.ResourceSet


                revisitSequenceFlows(def, bpmn2);
                // another hack if id == name
                revisitNodeNames(def);

                // get the xml from Definitions
                ResourceSet rSet = new ResourceSetImpl();
                rSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("bpmn2", new JBPMBpmn2ResourceFactoryImpl());
                JBPMBpmn2ResourceImpl bpmn2resource = (JBPMBpmn2ResourceImpl) rSet.createResource(URI.createURI("virtual.bpmn2"));
                rSet.getResources().add(bpmn2resource);
                bpmn2resource.getContents().add(def);
                ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                bpmn2resource.save(outputStream, new HashMap<Object, Object>());
                String fullXmlModel =  outputStream.toString();
                // convert to json and write response
                String json = profile.createUnmarshaller().parseModel(fullXmlModel, profile, pp);
                resp.setContentType("application/json");
                resp.getWriter().print(json);
            } catch(Exception e) {
                _logger.error(e.getMessage());
                resp.setContentType("application/json");
                resp.getWriter().print("{}");
            }
        }  else if (transformto != null && transformto.equals(BPMN2_TO_JSON)) {
            try {
                if(convertServiceTasks != null && convertServiceTasks.equals("true")) {
                    bpmn2in = bpmn2in.replaceAll("drools:taskName=\".*?\"", "drools:taskName=\"ReadOnlyService\"");
                    bpmn2in = bpmn2in.replaceAll("tns:taskName=\".*?\"", "tns:taskName=\"ReadOnlyService\"");
                }

                Definitions def = ((JbpmProfileImpl) profile).getDefinitions(bpmn2in);
                def.setTargetNamespace("http://www.omg.org/bpmn20");

                if(convertServiceTasks != null && convertServiceTasks.equals("true")) {
                    // fix the data input associations for converted tasks
                    List<RootElement> rootElements =  def.getRootElements();
                    for(RootElement root : rootElements) {
                        if(root instanceof Process) {
                            updateTaskDataInputs((Process) root, def);
                        }
                    }
                }


                // get the xml from Definitions
                ResourceSet rSet = new ResourceSetImpl();
                rSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("bpmn2", new JBPMBpmn2ResourceFactoryImpl());
                JBPMBpmn2ResourceImpl bpmn2resource = (JBPMBpmn2ResourceImpl) rSet.createResource(URI.createURI("virtual.bpmn2"));
                bpmn2resource.getDefaultLoadOptions().put(JBPMBpmn2ResourceImpl.OPTION_ENCODING, "UTF-8");
                bpmn2resource.getDefaultLoadOptions().put(JBPMBpmn2ResourceImpl.OPTION_DEFER_IDREF_RESOLUTION, true);
                bpmn2resource.getDefaultLoadOptions().put( JBPMBpmn2ResourceImpl.OPTION_DISABLE_NOTIFY, true );
                bpmn2resource.getDefaultLoadOptions().put(JBPMBpmn2ResourceImpl.OPTION_PROCESS_DANGLING_HREF, JBPMBpmn2ResourceImpl.OPTION_PROCESS_DANGLING_HREF_RECORD);
                bpmn2resource.setEncoding("UTF-8");
                rSet.getResources().add(bpmn2resource);
                bpmn2resource.getContents().add(def);
                ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                bpmn2resource.save(outputStream, new HashMap<Object, Object>());
                String revisedXmlModel =  outputStream.toString();
                String json = profile.createUnmarshaller().parseModel(revisedXmlModel, profile, pp);
View Full Code Here


     * @throws java.io.IOException
     */
    private Bpmn2Resource unmarshall(JsonParser parser, String preProcessingData) throws JsonParseException, IOException {
        try {
            parser.nextToken(); // open the object
            ResourceSet rSet = new ResourceSetImpl();
            rSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("bpmn2",
                    new JBPMBpmn2ResourceFactoryImpl());
            Bpmn2Resource bpmn2 = (Bpmn2Resource) rSet.createResource(URI.createURI("virtual.bpmn2"));
            rSet.getResources().add(bpmn2);
            _currentResource = bpmn2;

            if(preProcessingData == null || preProcessingData.length() < 1) {
                preProcessingData = "ReadOnlyService";
            }
View Full Code Here

  private <T> Collection<IEObjectDescription> imported(Protobuf start, FinderStrategy<T> strategy, T criteria) {
    List<Import> allImports = protobufs.importsIn(start);
    if (allImports.isEmpty()) {
      return emptyList();
    }
    ResourceSet resourceSet = start.eResource().getResourceSet();
    return imported(allImports, modelObjects.packageOf(start), resourceSet, strategy, criteria);
  }
View Full Code Here

    }
    List<Import> allImports = protobufs.publicImportsIn(start);
    if (allImports.isEmpty()) {
      return emptyList();
    }
    ResourceSet resourceSet = start.eResource().getResourceSet();
    return imported(allImports, modelObjects.packageOf(start), resourceSet, strategy, criteria);
  }
View Full Code Here

    return (!locations.isEmpty()) ? locations.get(0) : null;
  }

  private Resource protoFileResource(IPath protoFilePath, IEditorPart editor) {
    IFile cppHeaderFile = editors.fileDisplayedIn(editor);
    ResourceSet resourceSet = resourceSetProvider.get(cppHeaderFile.getProject());
    if (resourceSet != null) {
      IResourceDescription description = indexLookup.resourceIn(protoFilePath);
      return (description != null) ? resourceSet.getResource(description.getURI(), true) : null;
    }
    return null;
  }
View Full Code Here

   * resolved.
   */
  public Resource importedResource(Import anImport) {
    URI resolvedUri = resolvedUriOf(anImport);
    if (resolvedUri != null) {
      ResourceSet resourceSet = anImport.eResource().getResourceSet();
      return resourceSets.findResource(resourceSet, resolvedUri);
    }
    return null;
  }
View Full Code Here

   * @return the created {@code XtextResource}.
   * @throws IOException if something goes wrong.
   */
  public XtextResource createResource(URI uri, String contents) throws IOException {
    // TODO get project from URI.
    ResourceSet resourceSet = resourceSetProvider.get(projects.activeProject());
    XtextResource resource = (XtextResource) resourceSet.createResource(uri, UNSPECIFIED_CONTENT_TYPE);
    resource.load(new StringInputStream(contents), singletonMap(OPTION_ENCODING, UTF_8));
    resolveLazyCrossReferences(resource, NullImpl);
    return resource;
  }
View Full Code Here

   
    monitor.beginTask("Verifying model '" + o.getName() + "'", 10);

    monitor.subTask("Loading model");
    // try and load the file directly
    ResourceSet resourceSet = new ResourceSetImpl();
    Resource resource = resourceSet.getResource(URI.createFileURI(o
        .getLocation().toString()), true);

    // we can only do one model
    if (resource.getContents().size() != 1) {
      return new Status(
View Full Code Here

   * @throws ModelLoadException if the resource is null, or the resource contains too many elements
   * @deprecated
   *     use {@link ModelLoader#load(File)} to ensure loaded paths are not relative
   */
  public static EObject load(String filename) throws ModelLoadException {
    ResourceSet resourceSet = new ResourceSetImpl();
    URI uri = URI.createFileURI(filename);
    Resource resource = resourceSet.getResource(uri, true);
   
    if (resource == null)
      throw new ModelLoadException(new NullPointerException("Unexpected null resource in '" + filename + "'"));
   
    if (resource.getContents().size() != 1) {
View Full Code Here

   * @param f the file to load
   * @return
   * @throws ModelLoadException if the resource is null, or the resource contains too many elements
   */
  public static EObject load(File f) throws ModelLoadException {
    ResourceSet resourceSet = new ResourceSetImpl();
    URI uri = URI.createFileURI(f.getAbsolutePath());
    Resource resource = resourceSet.getResource(uri, true);
   
    if (resource == null)
      throw new ModelLoadException(new NullPointerException("Unexpected null resource in '" + f + "'"));
   
    if (resource.getContents().size() != 1) {
View Full Code Here

TOP

Related Classes of org.eclipse.emf.ecore.resource.ResourceSet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.