コード例 #1
0
  public Resource createResource(URI uri) {
    final XMIResource resource = (XMIResource) super.createResource(uri);

    final Map<Object, Object> defaultLoadOptions = resource.getDefaultLoadOptions();
    defaultLoadOptions.put(XMLResource.OPTION_EXTENDED_META_DATA, getExtendedMetaData());
    defaultLoadOptions.put(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE);
    defaultLoadOptions.put(
        XMLResource.OPTION_RESOURCE_HANDLER, new PartitioncontainmentResourceHandler());

    return resource;
  }
  @Override
  public Resource createResource(URI uri) {
    XMIResource resource = new EntityRelationResourceImpl(uri);

    Map<Object, Object> saveOptions = resource.getDefaultSaveOptions();
    saveOptions.put(XMLResource.OPTION_CONFIGURATION_CACHE, Boolean.TRUE);
    saveOptions.put(XMLResource.OPTION_USE_CACHED_LOOKUP_TABLE, lookupTable);

    Map<Object, Object> loadOptions = resource.getDefaultLoadOptions();
    loadOptions.put(XMLResource.OPTION_DEFER_ATTACHMENT, Boolean.TRUE);
    loadOptions.put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION, Boolean.TRUE);
    loadOptions.put(XMLResource.OPTION_USE_DEPRECATED_METHODS, Boolean.FALSE);
    loadOptions.put(XMLResource.OPTION_USE_PARSER_POOL, parserPool);
    loadOptions.put(XMLResource.OPTION_USE_XML_NAME_TO_FEATURE_MAP, nameToFeatureMap);

    return resource;
  }
コード例 #3
0
  @Test
  public void testSerializationBreakURIs() throws IOException {

    StringWriter writer = new StringWriter();
    bRes.save(writer, Collections.EMPTY_MAP);
    writer.flush();
    String fileContent = writer.toString();

    System.out.println(fileContent);
    assertTrue(
        "We should have a src/ in the serialization as we are refering to a.ecore which is in a src folder.",
        fileContent.indexOf("src") > -1);
  }
コード例 #4
0
  @Before
  public void setUp() throws Exception {

    EcoreResourceFactoryImpl resFactory = new EcoreResourceFactoryImpl();
    set.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", resFactory);

    aRes =
        (XMIResource)
            set.createResource(
                URI.createPlatformResourceURI("/myProject/main/src/some/package/a.ecore", true));
    InputStream stream = new ByteArrayInputStream(aResContent.getBytes("US-ASCII"));
    aRes.load(stream, set.getLoadOptions());
    stream.close();

    bRes =
        (XMIResource)
            set.createResource(URI.createPlatformResourceURI("/myProject/model/b.ecore", true));

    stream = new ByteArrayInputStream(bResContent.getBytes("US-ASCII"));
    bRes.load(stream, set.getLoadOptions());
    stream.close();
  }
コード例 #5
0
  private void fromXMItoXML(URI inputModelURI, URI outputModelURI, ResourceSet resourceSet)
      throws IOException {
    // overwrite load options
    Map<Object, Object> loadOptionsMap = resourceSet.getLoadOptions();
    loadOptionsMap.put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
    loadOptionsMap.put(XMIResource.OPTION_SUPPRESS_DOCUMENT_ROOT, Boolean.TRUE);

    // set save options
    Map<Object, Object> saveOptionsMap = new HashMap<Object, Object>();
    saveOptionsMap.put(XMIResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
    saveOptionsMap.put(XMIResource.OPTION_SUPPRESS_DOCUMENT_ROOT, Boolean.TRUE);

    // load input model from file
    XMIResource inputResource = (XMIResource) resourceSet.getResource(inputModelURI, true);

    // create output model resource by copying contents of input model
    Resource outputResource = resourceSet.createResource(outputModelURI);
    XMItoXMLCopier xmiToXmlCopier =
        new XMItoXMLCopier("http://example.com/example-with-anyfeature");
    outputResource.getContents().add(xmiToXmlCopier.copy(inputResource.getContents().get(0)));

    // save output model to file
    outputResource.save(saveOptionsMap);
  }